kowainik / stan

🕵️ Haskell STatic ANalyser
https://kowainik.github.io/projects/stan
Mozilla Public License 2.0
562 stars 48 forks source link

Support disabling inspections in a specific line with a comment #444

Open ilkecan opened 2 years ago

ilkecan commented 2 years ago

I want to disable an inspection for a specific line or a function. For example, the user could do this with a comment such as:

-- stan-disable-next-line STAN-0006
mapCyclic = zipWith id . cycle

or

mapCyclic = zipWith id . cycle  -- stan-disable-line STAN-0006

Is it feasible to implement something like this?

ilkecan commented 2 years ago

I realized it is already possible to disable a specific observation using the ignore variable:

# .stan.toml
ignore = [
    { id = "OBS-STAN-0006-NO6o1e-42:26" },
    { id = "OBS-STAN-0101-NO6o1e-11:12" },
    { id = "OBS-STAN-0103-NO6o1e-34:12" },
    { id = "OBS-STAN-0103-YrzpQi-26:19" },
    { id = "OBS-STAN-0103-YrzpQi-26:57" },
    { id = "OBS-STAN-0105-NO6o1e-46:13" },
    { id = "OBS-STAN-0105-NO6o1e-46:24" },
]

But the problem with this is that the observation ID depends on the line number and this requires manual bookkeeping if any line is removed or added before that line. So an option to ignore a line with a comment before or in that line would be more convenient.

drlkf commented 6 months ago

commenting in addition to thumbsup for visibility, i think this is an essential feature for a static analyzer, especially with the recent inclusion of STAN in HLS

tomjaguarpaw commented 6 months ago

I agree with this. I suspect we should probably learn from how hlint does it. To get started it might make most sense to do the easiest possible thing and just copy how ormolu can be disabled in regions of code. What do people think?

stan currently has no active developers. I'm only maintaining stan to keep it building with newer GHCs. I will put this reasonably high on my stack of things to look at, but can't guarantee it will ever reach the top. I'm willing to assist someone who wants to tackle it though.

I don't know where to start to add this feature. The first step would be to determine in which part of the code it belongs.