mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-07 17:03:30 +08:00
Fixed parser errors not being excluded by -e
This commit is contained in:
@@ -366,7 +366,7 @@ verifyNotTree :: (Parameters -> Token -> [Note]) -> String -> Bool
|
|||||||
verifyNotTree f s = checkTree f s == Just False
|
verifyNotTree f s = checkTree f s == Just False
|
||||||
|
|
||||||
checkNode f = checkTree (runNodeAnalysis f)
|
checkNode f = checkTree (runNodeAnalysis f)
|
||||||
checkTree f s = case parseShell "-" s of
|
checkTree f s = case parseShell defaultAnalysisOptions "-" s of
|
||||||
(ParseResult (Just (t, m)) _) -> Just . not . null $ runList defaultAnalysisOptions t [f]
|
(ParseResult (Just (t, m)) _) -> Just . not . null $ runList defaultAnalysisOptions t [f]
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@ module ShellCheck.Parser (Note(..), Severity(..), parseShell, ParseResult(..), P
|
|||||||
|
|
||||||
import ShellCheck.AST
|
import ShellCheck.AST
|
||||||
import ShellCheck.Data
|
import ShellCheck.Data
|
||||||
|
import ShellCheck.Options
|
||||||
import Text.Parsec
|
import Text.Parsec
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
@@ -2157,13 +2158,13 @@ getStringFromParsec errors =
|
|||||||
Message s -> if null s then Nothing else return $ s ++ "."
|
Message s -> if null s then Nothing else return $ s ++ "."
|
||||||
unexpected s = "Unexpected " ++ (if null s then "eof" else s) ++ "."
|
unexpected s = "Unexpected " ++ (if null s then "eof" else s) ++ "."
|
||||||
|
|
||||||
parseShell filename contents =
|
parseShell options filename contents =
|
||||||
case rp (parseWithNotes readScript) filename contents of
|
case rp (parseWithNotes readScript) filename contents of
|
||||||
(Right (script, map, notes), (parsenotes, _)) ->
|
(Right (script, map, notes), (parsenotes, _)) ->
|
||||||
ParseResult (Just (script, map)) (nub $ sortNotes $ notes ++ parsenotes)
|
ParseResult (Just (script, map)) (nub . sortNotes . excludeNotes $ notes ++ parsenotes)
|
||||||
(Left err, (p, context)) ->
|
(Left err, (p, context)) ->
|
||||||
ParseResult Nothing
|
ParseResult Nothing
|
||||||
(nub $ sortNotes $ p ++ notesForContext context ++ [makeErrorFor err])
|
(nub . sortNotes . excludeNotes $ p ++ notesForContext context ++ [makeErrorFor err])
|
||||||
where
|
where
|
||||||
isName (ContextName _ _) = True
|
isName (ContextName _ _) = True
|
||||||
isName _ = False
|
isName _ = False
|
||||||
@@ -2172,6 +2173,7 @@ parseShell filename contents =
|
|||||||
"Couldn't parse this " ++ str ++ "."
|
"Couldn't parse this " ++ str ++ "."
|
||||||
second (ContextName pos str) = ParseNote pos InfoC 1009 $
|
second (ContextName pos str) = ParseNote pos InfoC 1009 $
|
||||||
"The mentioned parser error was in this " ++ str ++ "."
|
"The mentioned parser error was in this " ++ str ++ "."
|
||||||
|
excludeNotes = filter (\c -> codeForParseNote c `notElem` optionExcludes options)
|
||||||
|
|
||||||
lt x = trace (show x) x
|
lt x = trace (show x) x
|
||||||
ltt t = trace (show t)
|
ltt t = trace (show t)
|
||||||
|
@@ -28,7 +28,7 @@ import Text.Parsec.Pos
|
|||||||
|
|
||||||
shellCheck :: AnalysisOptions -> String -> [ShellCheckComment]
|
shellCheck :: AnalysisOptions -> String -> [ShellCheckComment]
|
||||||
shellCheck options script =
|
shellCheck options script =
|
||||||
let (ParseResult result notes) = parseShell "-" script in
|
let (ParseResult result notes) = parseShell options "-" script in
|
||||||
let allNotes = notes ++ concat (maybeToList $ do
|
let allNotes = notes ++ concat (maybeToList $ do
|
||||||
(tree, posMap) <- result
|
(tree, posMap) <- result
|
||||||
let list = runAnalytics options tree
|
let list = runAnalytics options tree
|
||||||
@@ -72,6 +72,9 @@ prop_commentDisablesAnalysisIssue2 =
|
|||||||
prop_optionDisablesIssue1 =
|
prop_optionDisablesIssue1 =
|
||||||
null $ shellCheck (defaultAnalysisOptions { optionExcludes = [2086, 2148] }) "echo $1"
|
null $ shellCheck (defaultAnalysisOptions { optionExcludes = [2086, 2148] }) "echo $1"
|
||||||
|
|
||||||
|
prop_optionDisablesIssue2 =
|
||||||
|
null $ shellCheck (defaultAnalysisOptions { optionExcludes = [2148, 1037] }) "echo \"$10\""
|
||||||
|
|
||||||
return []
|
return []
|
||||||
runTests = $quickCheckAll
|
runTests = $quickCheckAll
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user