module ShellCheck.Formatter.GCC (format) where
import ShellCheck.Interface
import ShellCheck.Formatter.Format
import Data.List
import GHC.Exts
import System.IO
format :: IO Formatter
format :: IO Formatter
format = forall (m :: * -> *) a. Monad m => a -> m a
return Formatter {
header :: IO ()
header = forall (m :: * -> *) a. Monad m => a -> m a
return (),
footer :: IO ()
footer = forall (m :: * -> *) a. Monad m => a -> m a
return (),
onFailure :: FilePath -> FilePath -> IO ()
onFailure = FilePath -> FilePath -> IO ()
outputError,
onResult :: CheckResult -> SystemInterface IO -> IO ()
onResult = CheckResult -> SystemInterface IO -> IO ()
outputAll
}
outputError :: FilePath -> FilePath -> IO ()
outputError FilePath
file FilePath
error = Handle -> FilePath -> IO ()
hPutStrLn Handle
stderr forall a b. (a -> b) -> a -> b
$ FilePath
file forall a. [a] -> [a] -> [a]
++ FilePath
": " forall a. [a] -> [a] -> [a]
++ FilePath
error
outputAll :: CheckResult -> SystemInterface IO -> IO ()
outputAll CheckResult
cr SystemInterface IO
sys = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ [PositionedComment] -> IO ()
f [[PositionedComment]]
groups
where
comments :: [PositionedComment]
comments = CheckResult -> [PositionedComment]
crComments CheckResult
cr
groups :: [[PositionedComment]]
groups = forall b a. Ord b => (a -> b) -> [a] -> [[a]]
groupWith PositionedComment -> FilePath
sourceFile [PositionedComment]
comments
f :: [PositionedComment] -> IO ()
f :: [PositionedComment] -> IO ()
f [PositionedComment]
group = do
let filename :: FilePath
filename = PositionedComment -> FilePath
sourceFile (forall a. [a] -> a
head [PositionedComment]
group)
Either FilePath FilePath
result <- forall (m :: * -> *).
SystemInterface m
-> Maybe Bool -> FilePath -> m (Either FilePath FilePath)
siReadFile SystemInterface IO
sys (forall a. a -> Maybe a
Just Bool
True) FilePath
filename
let contents :: FilePath
contents = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const FilePath
"") forall a. a -> a
id Either FilePath FilePath
result
FilePath -> FilePath -> [PositionedComment] -> IO ()
outputResult FilePath
filename FilePath
contents [PositionedComment]
group
outputResult :: FilePath -> FilePath -> [PositionedComment] -> IO ()
outputResult FilePath
filename FilePath
contents [PositionedComment]
warnings = do
let comments :: [PositionedComment]
comments = [PositionedComment] -> FilePath -> [PositionedComment]
makeNonVirtual [PositionedComment]
warnings FilePath
contents
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (FilePath -> IO ()
putStrLn forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> PositionedComment -> FilePath
formatComment FilePath
filename) [PositionedComment]
comments
FilePath
filename PositionedComment
c = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [
FilePath
filename, FilePath
":",
forall a. Show a => a -> FilePath
show forall a b. (a -> b) -> a -> b
$ PositionedComment -> Integer
lineNo PositionedComment
c, FilePath
":",
forall a. Show a => a -> FilePath
show forall a b. (a -> b) -> a -> b
$ PositionedComment -> Integer
colNo PositionedComment
c, FilePath
": ",
case PositionedComment -> FilePath
severityText PositionedComment
c of
FilePath
"error" -> FilePath
"error"
FilePath
"warning" -> FilePath
"warning"
FilePath
_ -> FilePath
"note",
FilePath
": ",
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> [FilePath]
lines forall a b. (a -> b) -> a -> b
$ PositionedComment -> FilePath
messageText PositionedComment
c,
FilePath
" [SC", forall a. Show a => a -> FilePath
show forall a b. (a -> b) -> a -> b
$ PositionedComment -> Integer
codeNo PositionedComment
c, FilePath
"]"
]