From 9ca7d5778048899597a1350f0c612e9e3e515b62 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Tue, 6 Nov 2012 13:26:25 -0800 Subject: [PATCH] Renamed much of the ShellCheck.Simple interface --- ShellCheck/Simple.hs | 10 +++++----- shellcheck.hs | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ShellCheck/Simple.hs b/ShellCheck/Simple.hs index 19f455c..840bc90 100644 --- a/ShellCheck/Simple.hs +++ b/ShellCheck/Simple.hs @@ -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 diff --git a/shellcheck.hs b/shellcheck.hs index dd22b3e..0b3fe2b 100644 --- a/shellcheck.hs +++ b/shellcheck.hs @@ -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