Renamed much of the ShellCheck.Simple interface
This commit is contained in:
parent
e264f64266
commit
9ca7d57780
|
@ -1,4 +1,4 @@
|
|||
module ShellCheck.Simple (shellcheckCheck, ShellCheckComment, shellcheckLine, shellcheckColumn, shellcheckSeverity, shellcheckComment) where
|
||||
module ShellCheck.Simple (shellCheck, ShellCheckComment, scLine, scColumn, scSeverity, scMessage) where
|
||||
|
||||
import ShellCheck.Parser
|
||||
import ShellCheck.Analytics
|
||||
|
@ -6,8 +6,8 @@ import Data.Maybe
|
|||
import Text.Parsec.Pos
|
||||
import Data.List
|
||||
|
||||
shellcheckCheck :: String -> [ShellCheckComment]
|
||||
shellcheckCheck script =
|
||||
shellCheck :: String -> [ShellCheckComment]
|
||||
shellCheck script =
|
||||
let (ParseResult result notes) = parseShell "-" script in
|
||||
let allNotes = notes ++ (concat $ maybeToList $ do
|
||||
(tree, map) <- result
|
||||
|
@ -17,11 +17,11 @@ shellcheckCheck script =
|
|||
in
|
||||
map formatNote $ nub $ sortNotes allNotes
|
||||
|
||||
data ShellCheckComment = ShellCheckComment { shellcheckLine :: Int, shellcheckColumn :: Int, shellcheckSeverity :: String, shellcheckComment :: String }
|
||||
data ShellCheckComment = ShellCheckComment { scLine :: Int, scColumn :: Int, scSeverity :: String, scMessage :: String }
|
||||
|
||||
|
||||
instance Show ShellCheckComment where
|
||||
show c = concat ["(", show $ shellcheckLine c, ",", show $ shellcheckColumn c, ") ", shellcheckSeverity c, ": ", shellcheckComment c]
|
||||
show c = concat ["(", show $ scLine c, ",", show $ scColumn c, ") ", scSeverity c, ": ", scMessage c]
|
||||
|
||||
severityToString s =
|
||||
case s of
|
||||
|
|
|
@ -33,25 +33,25 @@ doFile path colorFunc = do
|
|||
doInput filename contents colorFunc = do
|
||||
let fileLines = lines contents
|
||||
let lineCount = length fileLines
|
||||
let comments = shellcheckCheck contents
|
||||
let groups = groupWith shellcheckLine comments
|
||||
let comments = shellCheck contents
|
||||
let groups = groupWith scLine comments
|
||||
if not $ null comments then do
|
||||
mapM_ (\x -> do
|
||||
let lineNum = shellcheckLine (head x)
|
||||
let lineNum = scLine (head x)
|
||||
let line = if lineNum < 1 || lineNum > lineCount
|
||||
then ""
|
||||
else fileLines !! (lineNum - 1)
|
||||
putStrLn ""
|
||||
putStrLn $ colorFunc "message" ("In " ++ filename ++" line " ++ (show $ lineNum) ++ ":")
|
||||
putStrLn (colorFunc "source" line)
|
||||
mapM (\c -> putStrLn (colorFunc (shellcheckSeverity c) $ cuteIndent c)) x
|
||||
mapM (\c -> putStrLn (colorFunc (scSeverity c) $ cuteIndent c)) x
|
||||
putStrLn ""
|
||||
) groups
|
||||
else do
|
||||
putStrLn ("No comments for " ++ filename)
|
||||
|
||||
cuteIndent comment =
|
||||
(replicate ((shellcheckColumn comment) - 1) ' ') ++ "^-- " ++ (shellcheckComment comment)
|
||||
(replicate ((scColumn comment) - 1) ' ') ++ "^-- " ++ (scMessage comment)
|
||||
|
||||
getColorFunc = do
|
||||
term <- hIsTerminalDevice stdout
|
||||
|
@ -61,7 +61,7 @@ main = do
|
|||
args <- getArgs
|
||||
colors <- getColorFunc
|
||||
if null args then do
|
||||
hPutStrLn stderr "shellcheck -- bash/sh shell script static analysis tool"
|
||||
hPutStrLn stderr "shellcheck -- bash/sh script static analysis tool"
|
||||
hPutStrLn stderr "Usage: shellcheck filenames..."
|
||||
exitFailure
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue