haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.65k stars 354 forks source link

Add code action to suppress specific hlint warnings #600

Open srid opened 3 years ago

srid commented 3 years ago

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:

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

Anrock commented 3 years ago

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

jneira commented 3 years ago

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

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 😄

SeungheonOh commented 3 years ago

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

ndmitchell commented 3 years ago

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.

jneira commented 2 years ago

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

eddiemundo commented 2 years ago

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.

ndmitchell commented 2 years ago

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.