ndmitchell/hlint

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

開放

#1,446 建立於 2023年1月27日

 (5 則留言) (0 個反應) (0 位負責人)Haskell (208 個分叉)batch import
buggood first issue

倉庫指標

星標
 (1,602 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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

貢獻者指南