Renamed much of the ShellCheck.Simple interface

This commit is contained in:
Vidar Holen 2012-11-06 13:26:25 -08:00
parent e264f64266
commit 9ca7d57780
2 changed files with 11 additions and 11 deletions

View File

@ -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.Parser
import ShellCheck.Analytics import ShellCheck.Analytics
@ -6,8 +6,8 @@ import Data.Maybe
import Text.Parsec.Pos import Text.Parsec.Pos
import Data.List import Data.List
shellcheckCheck :: String -> [ShellCheckComment] shellCheck :: String -> [ShellCheckComment]
shellcheckCheck script = shellCheck script =
let (ParseResult result notes) = parseShell "-" script in let (ParseResult result notes) = parseShell "-" script in
let allNotes = notes ++ (concat $ maybeToList $ do let allNotes = notes ++ (concat $ maybeToList $ do
(tree, map) <- result (tree, map) <- result
@ -17,11 +17,11 @@ shellcheckCheck script =
in in
map formatNote $ nub $ sortNotes allNotes 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 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 = severityToString s =
case s of case s of

View File

@ -33,25 +33,25 @@ doFile path colorFunc = do
doInput filename contents colorFunc = do doInput filename contents colorFunc = do
let fileLines = lines contents let fileLines = lines contents
let lineCount = length fileLines let lineCount = length fileLines
let comments = shellcheckCheck contents let comments = shellCheck contents
let groups = groupWith shellcheckLine comments let groups = groupWith scLine comments
if not $ null comments then do if not $ null comments then do
mapM_ (\x -> do mapM_ (\x -> do
let lineNum = shellcheckLine (head x) let lineNum = scLine (head x)
let line = if lineNum < 1 || lineNum > lineCount let line = if lineNum < 1 || lineNum > lineCount
then "" then ""
else fileLines !! (lineNum - 1) else fileLines !! (lineNum - 1)
putStrLn "" putStrLn ""
putStrLn $ colorFunc "message" ("In " ++ filename ++" line " ++ (show $ lineNum) ++ ":") putStrLn $ colorFunc "message" ("In " ++ filename ++" line " ++ (show $ lineNum) ++ ":")
putStrLn (colorFunc "source" line) putStrLn (colorFunc "source" line)
mapM (\c -> putStrLn (colorFunc (shellcheckSeverity c) $ cuteIndent c)) x mapM (\c -> putStrLn (colorFunc (scSeverity c) $ cuteIndent c)) x
putStrLn "" putStrLn ""
) groups ) groups
else do else do
putStrLn ("No comments for " ++ filename) putStrLn ("No comments for " ++ filename)
cuteIndent comment = cuteIndent comment =
(replicate ((shellcheckColumn comment) - 1) ' ') ++ "^-- " ++ (shellcheckComment comment) (replicate ((scColumn comment) - 1) ' ') ++ "^-- " ++ (scMessage comment)
getColorFunc = do getColorFunc = do
term <- hIsTerminalDevice stdout term <- hIsTerminalDevice stdout
@ -61,7 +61,7 @@ main = do
args <- getArgs args <- getArgs
colors <- getColorFunc colors <- getColorFunc
if null args then do 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..." hPutStrLn stderr "Usage: shellcheck filenames..."
exitFailure exitFailure
else else