mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-09 06:12:13 +08:00
Change definition of Replacement, add ToJSON instance for it
This commit is contained in:
@@ -39,6 +39,19 @@ format = do
|
||||
footer = finish ref
|
||||
}
|
||||
|
||||
instance ToJSON Replacement where
|
||||
toJSON replacement =
|
||||
let start = repStartPos replacement
|
||||
end = repEndPos replacement
|
||||
str = repString replacement in
|
||||
object [
|
||||
"line" .= posLine start,
|
||||
"endLine" .= posLine end,
|
||||
"column" .= posColumn start,
|
||||
"endColumn" .= posColumn end,
|
||||
"replaceWith" .= str
|
||||
]
|
||||
|
||||
instance ToJSON (PositionedComment) where
|
||||
toJSON comment =
|
||||
let start = pcStartPos comment
|
||||
@@ -52,7 +65,8 @@ instance ToJSON (PositionedComment) where
|
||||
"endColumn" .= posColumn end,
|
||||
"level" .= severityText comment,
|
||||
"code" .= cCode c,
|
||||
"message" .= cMessage c
|
||||
"message" .= cMessage c,
|
||||
"fix" .= pcFix comment
|
||||
]
|
||||
|
||||
toEncoding comment =
|
||||
@@ -68,6 +82,7 @@ instance ToJSON (PositionedComment) where
|
||||
<> "level" .= severityText comment
|
||||
<> "code" .= cCode c
|
||||
<> "message" .= cMessage c
|
||||
<> "replaceWith" .= pcFix comment
|
||||
)
|
||||
|
||||
outputError file msg = hPutStrLn stderr $ file ++ ": " ++ msg
|
||||
@@ -77,4 +92,3 @@ collectResult ref result _ =
|
||||
finish ref = do
|
||||
list <- readIORef ref
|
||||
BL.putStrLn $ encode list
|
||||
|
||||
|
@@ -142,11 +142,12 @@ fixedString comment line =
|
||||
apply_replacement rs line 0
|
||||
where
|
||||
apply_replacement [] s _ = s
|
||||
apply_replacement ((R startp endp r):xs) s offset =
|
||||
let start = posColumn startp
|
||||
end = posColumn endp
|
||||
z = do_replace start end s r
|
||||
len_r = (fromIntegral . length) r in
|
||||
apply_replacement (rep:xs) s offset =
|
||||
let replacementString = repString rep
|
||||
start = (posColumn . repStartPos) rep
|
||||
end = (posColumn . repEndPos) rep
|
||||
z = do_replace start end s replacementString
|
||||
len_r = (fromIntegral . length) replacementString in
|
||||
apply_replacement xs z (offset + (end - start) + len_r)
|
||||
|
||||
-- start and end comes from pos, which is 1 based
|
||||
|
Reference in New Issue
Block a user