提交 e264f642 编写于 作者: V Vidar Holen

Renamed from codename Shpell to final name ShellCheck.

上级 45b98f40
all: shpell .tests
all: shellcheck .tests
: Done
shpell: regardless
: Conditionally compiling shpell
ghc --make shpell
shellcheck: regardless
: Conditionally compiling shellcheck
ghc --make shellcheck
.tests: *.hs */*.hs
: Running unit tests
./test/runQuack && touch .tests
clean:
rm -f .tests shpell *.hi *.o Shpell/*.hi Shpell/*.o
rm -f .tests shellcheck *.hi *.o ShellCheck/*.hi ShellCheck/*.o
regardless:
module Shpell.Analytics where
module ShellCheck.Analytics where
import Shpell.Parser
import ShellCheck.Parser
import Control.Monad
import Control.Monad.State
import qualified Data.Map as Map
......
{-# LANGUAGE NoMonomorphismRestriction #-}
module Shpell.Parser (Token(..), Id(..), Note(..), Severity(..), parseShell, ParseResult(..), ParseNote(..), notesFromMap, Metadata(..), doAnalysis, doStackAnalysis, doTransform, sortNotes) where
module ShellCheck.Parser (Token(..), Id(..), Note(..), Severity(..), parseShell, ParseResult(..), ParseNote(..), notesFromMap, Metadata(..), doAnalysis, doStackAnalysis, doTransform, sortNotes) where
import Text.Parsec
import Debug.Trace
......
module Shpell.Simple (shpellCheck, ShpellComment, shpellLine, shpellColumn, shpellSeverity, shpellComment) where
module ShellCheck.Simple (shellcheckCheck, ShellCheckComment, shellcheckLine, shellcheckColumn, shellcheckSeverity, shellcheckComment) where
import Shpell.Parser
import Shpell.Analytics
import ShellCheck.Parser
import ShellCheck.Analytics
import Data.Maybe
import Text.Parsec.Pos
import Data.List
shpellCheck :: String -> [ShpellComment]
shpellCheck script =
shellcheckCheck :: String -> [ShellCheckComment]
shellcheckCheck script =
let (ParseResult result notes) = parseShell "-" script in
let allNotes = notes ++ (concat $ maybeToList $ do
(tree, map) <- result
......@@ -17,11 +17,11 @@ shpellCheck script =
in
map formatNote $ nub $ sortNotes allNotes
data ShpellComment = ShpellComment { shpellLine :: Int, shpellColumn :: Int, shpellSeverity :: String, shpellComment :: String }
data ShellCheckComment = ShellCheckComment { shellcheckLine :: Int, shellcheckColumn :: Int, shellcheckSeverity :: String, shellcheckComment :: String }
instance Show ShpellComment where
show c = concat ["(", show $ shpellLine c, ",", show $ shpellColumn c, ") ", shpellSeverity c, ": ", shpellComment c]
instance Show ShellCheckComment where
show c = concat ["(", show $ shellcheckLine c, ",", show $ shellcheckColumn c, ") ", shellcheckSeverity c, ": ", shellcheckComment c]
severityToString s =
case s of
......@@ -30,4 +30,4 @@ severityToString s =
InfoC -> "info"
StyleC -> "style"
formatNote (ParseNote pos severity text) = ShpellComment (sourceLine pos) (sourceColumn pos) (severityToString severity) text
formatNote (ParseNote pos severity text) = ShellCheckComment (sourceLine pos) (sourceColumn pos) (severityToString severity) text
import Control.Monad
import GHC.Exts
import GHC.IO.Device
import Shpell.Simple
import ShellCheck.Simple
import System.Directory
import System.Environment
import System.Exit
......@@ -33,25 +33,25 @@ doFile path colorFunc = do
doInput filename contents colorFunc = do
let fileLines = lines contents
let lineCount = length fileLines
let comments = shpellCheck contents
let groups = groupWith shpellLine comments
let comments = shellcheckCheck contents
let groups = groupWith shellcheckLine comments
if not $ null comments then do
mapM_ (\x -> do
let lineNum = shpellLine (head x)
let lineNum = shellcheckLine (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 (shpellSeverity c) $ cuteIndent c)) x
mapM (\c -> putStrLn (colorFunc (shellcheckSeverity c) $ cuteIndent c)) x
putStrLn ""
) groups
else do
putStrLn ("No comments for " ++ filename)
cuteIndent comment =
(replicate ((shpellColumn comment) - 1) ' ') ++ "^-- " ++ (shpellComment comment)
(replicate ((shellcheckColumn comment) - 1) ' ') ++ "^-- " ++ (shellcheckComment comment)
getColorFunc = do
term <- hIsTerminalDevice stdout
......@@ -61,8 +61,8 @@ main = do
args <- getArgs
colors <- getColorFunc
if null args then do
hPutStrLn stderr "shpell -- bash/sh shell script static analysis tool"
hPutStrLn stderr "Usage: shpell filenames..."
hPutStrLn stderr "shellcheck -- bash/sh shell script static analysis tool"
hPutStrLn stderr "Usage: shellcheck filenames..."
exitFailure
else
mapM (\f -> doFile f colors) args
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册