Skip to content

Use plain comments instead of annotations for HLint ignores #4669

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

Merged
merged 2 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ import System.Environment (setEnv,
#endif

import Development.IDE.GHC.Compat (DynFlags,
WarningFlag (Opt_WarnUnrecognisedPragmas),
extensionFlags,
ms_hspp_opts,
topDir,
wopt)
topDir)
import qualified Development.IDE.GHC.Compat.Util as EnumSet

#if MIN_GHC_API_VERSION(9,4,0)
Expand Down Expand Up @@ -466,19 +464,10 @@ mkSuppressHintTextEdits dynFlags fileContents hint =
NextPragmaInfo{ nextPragmaLine, lineSplitTextEdits } = getNextPragmaInfo dynFlags (Just fileContents)
nextPragmaLinePosition = Position (fromIntegral nextPragmaLine) 0
nextPragmaRange = Range nextPragmaLinePosition nextPragmaLinePosition
wnoUnrecognisedPragmasText =
if wopt Opt_WarnUnrecognisedPragmas dynFlags
then Just "{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}\n"
else Nothing
hlintIgnoreText = Just ("{-# HLINT ignore \"" <> hint <> "\" #-}\n")
-- we combine the texts into a single text because lsp-test currently
-- applies text edits backwards and I want the options pragma to
-- appear above the hlint pragma in the tests
combinedText = mconcat $ catMaybes [wnoUnrecognisedPragmasText, hlintIgnoreText]
combinedTextEdit = LSP.TextEdit nextPragmaRange combinedText
textEdit = LSP.TextEdit nextPragmaRange $ "{- HLINT ignore \"" <> hint <> "\" -}\n"
lineSplitTextEditList = maybe [] (\LineSplitTextEdits{..} -> [lineSplitInsertTextEdit, lineSplitDeleteTextEdit]) lineSplitTextEdits
in
combinedTextEdit : lineSplitTextEditList
textEdit : lineSplitTextEditList
-- ---------------------------------------------------------------------

ignoreHint :: Recorder (WithPriority Log) -> IdeState -> NormalizedFilePath -> VersionedTextDocumentIdentifier -> HintTitle -> IO (Either PluginError WorkspaceEdit)
Expand Down
17 changes: 6 additions & 11 deletions plugins/hls-hlint-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ resolveTests :: TestTree
resolveTests = knownBrokenForGhcVersions [GHC910] "apply-refact doesn't work on 9.10" $ testGroup "hlint resolve tests"
[
ignoreHintGoldenResolveTest
"Resolve version of: Ignore hint in this module inserts -Wno-unrecognised-pragmas and hlint ignore pragma if warn unrecognized pragmas is off"
"UnrecognizedPragmasOff"
(Point 3 8)
"Resolve version of: Ignore hint in this module inserts hlint ignore pragma"
"IgnoreHintAction"
(Point 2 8)
"Eta reduce"
, applyHintGoldenResolveTest
"Resolve version of: [#2612] Apply hint works when operator fixities go right-to-left"
Expand All @@ -64,14 +64,9 @@ ignoreHintTests :: TestTree
ignoreHintTests = testGroup "hlint ignore hint tests"
[
ignoreHintGoldenTest
"Ignore hint in this module inserts -Wno-unrecognised-pragmas and hlint ignore pragma if warn unrecognized pragmas is off"
"UnrecognizedPragmasOff"
(Point 3 8)
"Eta reduce"
, ignoreHintGoldenTest
"Ignore hint in this module inserts only hlint ignore pragma if warn unrecognized pragmas is on"
"UnrecognizedPragmasOn"
(Point 3 9)
"Ignore hint in this module inserts hlint ignore pragma"
"IgnoreHintAction"
(Point 2 8)
"Eta reduce"
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{- HLINT ignore "Eta reduce" -}
module IgnoreHintAction where
foo x = id x
2 changes: 2 additions & 0 deletions plugins/hls-hlint-plugin/test/testdata/IgnoreHintAction.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module IgnoreHintAction where
foo x = id x

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading