haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Add code action to suppress specific hlint warnings

Open srid opened this issue 5 years ago • 7 comments

I'm using VSCode + HLS 0.6.0.

I'd like to permanently disable certain hlint suggestions, such as the "Suggestion: Use camelCase" on ADTs. On a per-project basis, if possible.

It would be nice if there was an extra code action to disable the specific hlint. So we would see the list as:

  • Apply hint: ...
  • Apply all hints
  • Ignore this hint: ...

If the user selects "Ignore this hint", then the project's .hlint.yaml would be updated accordingly.

srid avatar Nov 14 '20 22:11 srid

Some related discussion in #571 and per-file supression in https://github.com/haskell/ghcide/pull/897

Anrock avatar Nov 15 '20 10:11 Anrock

@srid Hi, this is a sensible feature. However implement at project level will be harder than a module level:

  • We have to locate o create .hlint.yaml and update in a reliable way (it canbe trickier that it sounds)
  • At module level we only should add a directive in the source of the module at hand (similar to the languages pragmas we are already adding)

So i think we could start with Ignore this hint: ... in the module (that can be useful too) and add the project afterwards

I think implememt it at module level would not be terribly difficult 😄

jneira avatar Jun 13 '21 01:06 jneira

In addition, it would be useful to suppress hint on specific line by, for example, using commenting at the end of the line.

SeungheonOh avatar Aug 07 '21 00:08 SeungheonOh

HLint doesn't have a way to supress hints by line, only by definition. However, if you don't like a hint, I'd usually just ignore it for the whole module unless you find that hint gives a lot of value elsewhere in the module - and they are hints, so are usually nice to have at best. It's also much easier from an HLS perspective to just put the pragma at the top of the file.

ndmitchell avatar Sep 03 '21 18:09 ndmitchell

#2458 will add the mentioned ignore hint in a module using pragmas

jneira avatar Dec 09 '21 09:12 jneira

It's probably not too hard to do the original idea of add ignore rule to .hlint.yaml.

We can reuse what HLint does to look for the config file. What hls-hlint-plugin does currently is call HLint's argSettings with any custom plugin cmdline flags, argSettings in turn calls readAllSettings which calls https://github.com/ndmitchell/hlint/blob/8e10b5143acf97fbdf9baff40ee2da93881e0bf8/src/CmdLine.hs#L180-L201

So either we get hlint to expose cmdHintFiles (and maybe getCmd) or something like it, or copy the logic. Then we can use a yaml library to read and add an ignore rule, and write it back, or just append the ignore rule to the file without the yaml library.

I dunno if there are extra complications around writing non-hs files, but yeah, the hard part is probably figuring what to expose in HLint upstream.

eddiemundo avatar Dec 10 '21 21:12 eddiemundo

I think having HLint have a function to find the .hlint.yaml file is perfectly reasonable to add to the HLint API.

Writing the file is probably OK with doing it by appending a line at the end. While you can craft YAML files that would break, I imagine it works for 99.9%+ of files.

ndmitchell avatar Jan 02 '22 16:01 ndmitchell