Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hlint produces suggestions for code inserted by preprocessor #1245

Open
andrewufrank opened this issue May 8, 2021 · 3 comments
Open

hlint produces suggestions for code inserted by preprocessor #1245

andrewufrank opened this issue May 8, 2021 · 3 comments

Comments

@andrewufrank
Copy link

use case: HTF wiih the pragma

{-# OPTIONS_GHC -F -pgmF htfpp #-}

produces many hints about the bracket the precompiler inserts (defensively, I think):

{
	"resource": "/home/frank/Workspace11/u4blog/uniform-pandoc/tests/Uniform/DocRep_test.hs",
	"owner": "Haskell (uniform-pandoc)",
	"code": "refact:Redundant bracket",
	"severity": 2,
	"message": "Redundant bracket\nFound:\n  (assertEqual_\n   (makeLoc\n      \"/home/frank/Workspace11/u4blog/uniform-pandoc/tests/Uniform/DocRep_test.hs\"\n      45))\n  \"DocRep {yam = Null, pan = Pandoc (Meta {unMeta = fromList []}) []}\"\nWhy not:\n  assertEqual_\n  (makeLoc\n     \"/home/frank/Workspace11/u4blog/uniform-pandoc/tests/Uniform/DocRep_test.hs\"\n     45)\n  \"DocRep {yam = Null, pan = Pandoc (Meta {unMeta = fromList []}) []}\"\n",
	"source": "hlint",
	"startLineNumber": 45,
	"startColumn": 13,
	"endLineNumber": 45,
	"endColumn": 117
}

I tried to avoid this by adding to my hlint.yaml:

- arguments: [-XNoCPP]

but did not work (I restarted HSL, what else would have been necessary), the same hints are produced (which I can not act on).

I am confused assuming that -XNoCPP would avoid running the preprocessor on my code and show me only the hints I can fix. What is my misunderstanding? How to achieve that hlint shows only user fixable things?
Thank you for a VERY useful tool!

@ndmitchell
Copy link
Owner

If you are using HLS, then HLint sees the code after preprocessing. If you are using hlint on the command line, then it sees the code before preprocessing. For other preprocessors, e.g. record-dot-preprocessor, it emits HLint clean code, and disables the lints that it still raises - see ndmitchell/record-dot-preprocessor#37 which disables them. I suspect that if htfpp wants to be usable with HLint through HLS it probably needs to do the same trick.

The -XNoCpp is a bit of a red herring. With HLS, it has no effect. With HLint, it only disables the C Pre Processor, not other preprocessors (which HLint itself can't deal with anyway)

@andrewufrank
Copy link
Author

I see that the issue seems more complex and asking more questions than I expected. To avoid more questions, perhaps you put a note where the -XNoCpp flag is mentioned and say that it does not have an effect on HLS - saves time and head scratching.

For code with preprocessors I will use hlint on the command line when I really need it. usually I can ignore the effects when looking at the hints and warnings fro hlint.

In general, i find hlint very helpful, especially when pointing out unused things. what I would wish for, but which is not in the design enveloppe, are unused imports, unused dependencies and, especially, unused functions. HLS makes good progress and might eventually help with these. - thank you for your help over the years! andre

@georgefst
Copy link
Contributor

what I would wish for, but which is not in the design enveloppe, are unused imports, unused dependencies and, especially, unused functions

If I understand correctly, GHC itself is capable of warning about these. You just need -Wall and the recently-added -Wunused-packages. And the warnings will show up nicely in HLS.

georgefst added a commit to hackworthltd/primer that referenced this issue Oct 20, 2021
The comment about HLint running over the output of `tasty-discover` is only actually true within HLS and not through a local command line or on CI. See ndmitchell/hlint#1245 (comment).

Until haskell/haskell-language-server#638 is fixed, we're going to have to deal with spurious HLint warnings from HLS anyway. It should be easy to silence them in all LSP clients.

And even without that issue, we'll sometimes see extra hints in HLS due to version mismatches, since the HLint in HLS is statically linked, so we have no control over the version. For example, HLS 1.4 alerts to some redundant parentheses at line 140 in `Tests/Gen/Core/Typed.hs`, but these hints have been disabled in a recent HLint version - see ndmitchell/hlint#1282.
georgefst added a commit to hackworthltd/primer that referenced this issue Oct 20, 2021
The comment about HLint running over the output of `tasty-discover` is only actually true within HLS and not through a local command line or on CI. See ndmitchell/hlint#1245 (comment).

Until haskell/haskell-language-server#638 is fixed, we're going to have to deal with spurious HLint warnings from HLS anyway. It should be easy to silence them in all LSP clients.

And even without that issue, we'll sometimes see extra hints in HLS due to version mismatches, since the HLint in HLS is statically linked, so we have no control over the version. For example, HLS 1.4 alerts to some redundant parentheses at line 140 in `Tests/Gen/Core/Typed.hs`, but these hints have been disabled in a recent HLint version - see ndmitchell/hlint#1282.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants