Change to aeson (fixes #1085)

Adds bytestring as a dependency for putStrLn encoded values.
This commit is contained in:
Ng Zhi An 2018-05-06 16:07:53 -07:00
parent ef6a5b97b9
commit 08235a1cb2
2 changed files with 35 additions and 19 deletions

View File

@ -49,10 +49,11 @@ library
build-depends:
-- GHC 7.6.3 (base 4.6.0.1) is buggy (#1131, #1119) in optimized mode.
-- Just disable that version entirely to fail fast.
aeson,
base > 4.6.0.1 && < 5,
bytestring,
containers >= 0.5,
directory,
json,
mtl >= 2.2.1,
parsec,
regex-tdfa,
@ -85,11 +86,12 @@ executable shellcheck
build-depends:
semigroups
build-depends:
aeson,
base >= 4 && < 5,
bytestring,
ShellCheck,
containers,
directory,
json >= 0.3.6,
mtl >= 2.2.1,
parsec >= 3.0,
QuickCheck >= 2.7.4,
@ -99,11 +101,12 @@ executable shellcheck
test-suite test-shellcheck
type: exitcode-stdio-1.0
build-depends:
aeson,
base >= 4 && < 5,
bytestring,
ShellCheck,
containers,
directory,
json,
mtl >= 2.2.1,
parsec,
QuickCheck >= 2.7.4,

View File

@ -1,3 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
{-
Copyright 2012-2015 Vidar Holen
@ -22,10 +23,11 @@ module ShellCheck.Formatter.JSON (format) where
import ShellCheck.Interface
import ShellCheck.Formatter.Format
import Data.Aeson
import Data.IORef
import GHC.Exts
import System.IO
import Text.JSON
import qualified Data.ByteString.Lazy.Char8 as BL
format = do
ref <- newIORef []
@ -36,19 +38,30 @@ format = do
footer = finish ref
}
instance JSON (PositionedComment) where
showJSON comment@(PositionedComment start end (Comment level code string)) = makeObj [
("file", showJSON $ posFile start),
("line", showJSON $ posLine start),
("endLine", showJSON $ posLine end),
("column", showJSON $ posColumn start),
("endColumn", showJSON $ posColumn end),
("level", showJSON $ severityText comment),
("code", showJSON code),
("message", showJSON string)
]
instance ToJSON (PositionedComment) where
toJSON comment@(PositionedComment start end (Comment level code string)) =
object [
"file" .= posFile start,
"line" .= posLine start,
"endLine" .= posLine end,
"column" .= posColumn start,
"endColumn" .= posColumn end,
"level" .= severityText comment,
"code" .= code,
"message" .= string
]
readJSON = undefined
toEncoding comment@(PositionedComment start end (Comment level code string)) =
pairs (
"file" .= posFile start
<> "line" .= posLine start
<> "endLine" .= posLine end
<> "column" .= posColumn start
<> "endColumn" .= posColumn end
<> "level" .= severityText comment
<> "code" .= code
<> "message" .= string
)
outputError file msg = hPutStrLn stderr $ file ++ ": " ++ msg
collectResult ref result _ =
@ -56,5 +69,5 @@ collectResult ref result _ =
finish ref = do
list <- readIORef ref
putStrLn $ encodeStrict list
BL.putStrLn $ encode list