ndmitchell/hlint

for redundant parens from and to fields do not match the start/end line/column .. sometimes

Open

#1,446 opened on Jan 27, 2023

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Haskell (1,594 stars) (208 forks)batch import
buggood first issue

Description

for the following example

main = do
  print $ (\((Just a), b) -> show a) (Just 1, 2)

hlint suggests

Main.hs:2:14-21: Suggestion: Redundant bracket
Found:
  ((Just a), b)
Perhaps:
  (Just a, b)

1 hint

and the json output is as follows

[
  {
    "module": [
      "Main"
    ],
    "decl": [
      "main"
    ],
    "severity": "Suggestion",
    "hint": "Redundant bracket",
    "file": "Main.hs",
    "startLine": 2,
    "startColumn": 14,
    "endLine": 2,
    "endColumn": 22,
    "from": "((Just a), b)",
    "to": "(Just a, b)",
    "note": [],
    "refactorings": "[Replace {rtype = Pattern, pos = SrcSpan {startLine = 2, startCol = 14, endLine = 2, endCol = 22}, subts = [(\"x\",SrcSpan {startLine = 2, startCol = 15, endLine = 2, endCol = 21})], orig = \"x\"}]"
  }
]

the issue I'm having is that if you take the location information and replace that range in the file with the suggestion you get a bad outcome of

main = do
  print $ (\((Just a, b), b) -> show a) (Just 1, 2)

the output says the bad text is in the range 14 to 22 but the from text is actually from columns 13 to 28. the to is a valid replacement for the from but not the range.

this doesn't happen with simpler redundant parens print $ (\((a), b) -> show a) (Just 1, 2) correctly suggests the right columns and a matching replacement

i kind of feel like it should be saying from (Just a) to Just a and then the column info is correct, this is also minimal since the b section is not related

Contributor guide