mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-08 10:12:50 +08:00
Added cute simplified API plus a CLI frontend
This commit is contained in:
@@ -9,7 +9,7 @@ import Debug.Trace
|
||||
|
||||
checks = map runBasicAnalysis basicChecks
|
||||
|
||||
checkAll = checkList checks
|
||||
runAllAnalytics = checkList checks
|
||||
checkList l t m = foldl (\x f -> f t x) m l
|
||||
|
||||
runBasicAnalysis f t m = snd $ runState (doAnalysis f t) m
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{-# LANGUAGE NoMonomorphismRestriction #-}
|
||||
|
||||
module Shpell.Parser (Token(..), Note(..), Severity(..), parseShell, ParseResult(..), notesFromMap, Metadata(..), doAnalysis, doTransform) where
|
||||
module Shpell.Parser (Token(..), Note(..), Severity(..), parseShell, ParseResult(..), ParseNote(..), notesFromMap, Metadata(..), doAnalysis, doTransform, sortNotes) where
|
||||
|
||||
import Text.Parsec
|
||||
import Text.Parsec.Pos (initialPos)
|
||||
|
32
Shpell/Simple.hs
Normal file
32
Shpell/Simple.hs
Normal file
@@ -0,0 +1,32 @@
|
||||
module Shpell.Simple (shpellCheck, ShpellComment, shpellLine, shpellColumn, shpellSeverity, shpellComment) where
|
||||
|
||||
import Shpell.Parser
|
||||
import Shpell.Analytics
|
||||
import Data.Maybe
|
||||
import Text.Parsec.Pos
|
||||
|
||||
data ShpellComment = ShpellComment { shpellLine :: Int, shpellColumn :: Int, shpellSeverity :: String, shpellComment :: String }
|
||||
|
||||
|
||||
instance Show ShpellComment where
|
||||
show c = concat ["(", show $ shpellLine c, ",", show $ shpellColumn c, ") ", shpellSeverity c, ": ", shpellComment c]
|
||||
|
||||
shpellCheck script =
|
||||
let (ParseResult result notes) = parseShell "-" script in
|
||||
let allNotes = notes ++ (concat $ maybeToList $ do
|
||||
(tree, map) <- result
|
||||
let newMap = runAllAnalytics tree map
|
||||
return $ notesFromMap newMap
|
||||
)
|
||||
in
|
||||
map formatNote $ sortNotes allNotes
|
||||
|
||||
|
||||
severityToString s =
|
||||
case s of
|
||||
ErrorC -> "error"
|
||||
WarningC -> "warning"
|
||||
InfoC -> "info"
|
||||
StyleC -> "style"
|
||||
|
||||
formatNote (ParseNote pos severity text) = ShpellComment (sourceLine pos) (sourceColumn pos) (severityToString severity) text
|
Reference in New Issue
Block a user