Merge branch 'issue_837_opposite_of_exclude_option' of https://github.com/Gandalf-/shellcheck
This commit is contained in:
commit
a404efab65
|
@ -44,6 +44,13 @@ not warn at all, as `ksh` supports decimals in arithmetic contexts.
|
||||||
is *auto*. **--color** without an argument is equivalent to
|
is *auto*. **--color** without an argument is equivalent to
|
||||||
**--color=always**.
|
**--color=always**.
|
||||||
|
|
||||||
|
**-i**\ *CODE1*[,*CODE2*...],\ **--include=***CODE1*[,*CODE2*...]
|
||||||
|
|
||||||
|
: Explicitly include only the specified codes in the report. Subsequent **-i**
|
||||||
|
options are cumulative, but all the codes can be specified at once,
|
||||||
|
comma-separated as a single argument. Include options override any provided
|
||||||
|
exclude options.
|
||||||
|
|
||||||
**-e**\ *CODE1*[,*CODE2*...],\ **--exclude=***CODE1*[,*CODE2*...]
|
**-e**\ *CODE1*[,*CODE2*...],\ **--exclude=***CODE1*[,*CODE2*...]
|
||||||
|
|
||||||
: Explicitly exclude the specified codes from the report. Subsequent **-e**
|
: Explicitly exclude the specified codes from the report. Subsequent **-e**
|
||||||
|
|
|
@ -88,6 +88,8 @@ options = [
|
||||||
Option "C" ["color"]
|
Option "C" ["color"]
|
||||||
(OptArg (maybe (Flag "color" "always") (Flag "color")) "WHEN")
|
(OptArg (maybe (Flag "color" "always") (Flag "color")) "WHEN")
|
||||||
"Use color (auto, always, never)",
|
"Use color (auto, always, never)",
|
||||||
|
Option "i" ["include"]
|
||||||
|
(ReqArg (Flag "include") "CODE1,CODE2..") "Consider only given types of warnings",
|
||||||
Option "e" ["exclude"]
|
Option "e" ["exclude"]
|
||||||
(ReqArg (Flag "exclude") "CODE1,CODE2..") "Exclude types of warnings",
|
(ReqArg (Flag "exclude") "CODE1,CODE2..") "Exclude types of warnings",
|
||||||
Option "f" ["format"]
|
Option "f" ["format"]
|
||||||
|
@ -272,6 +274,18 @@ parseOption flag options =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Flag "include" str -> do
|
||||||
|
new <- mapM parseNum $ filter (not . null) $ split ',' str
|
||||||
|
let old = csIncludedWarnings . checkSpec $ options
|
||||||
|
return options {
|
||||||
|
checkSpec = (checkSpec options) {
|
||||||
|
csIncludedWarnings =
|
||||||
|
if null new
|
||||||
|
then old
|
||||||
|
else Just new `mappend` old
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Flag "version" _ -> do
|
Flag "version" _ -> do
|
||||||
liftIO printVersion
|
liftIO printVersion
|
||||||
throwError NoProblems
|
throwError NoProblems
|
||||||
|
|
|
@ -94,11 +94,13 @@ checkScript sys spec = do
|
||||||
(parseMessages ++ map translator analysisMessages)
|
(parseMessages ++ map translator analysisMessages)
|
||||||
|
|
||||||
shouldInclude pc =
|
shouldInclude pc =
|
||||||
let code = cCode (pcComment pc)
|
severity <= csMinSeverity spec &&
|
||||||
|
case csIncludedWarnings spec of
|
||||||
|
Nothing -> code `notElem` csExcludedWarnings spec
|
||||||
|
Just includedWarnings -> code `elem` includedWarnings
|
||||||
|
where
|
||||||
|
code = cCode (pcComment pc)
|
||||||
severity = cSeverity (pcComment pc)
|
severity = cSeverity (pcComment pc)
|
||||||
in
|
|
||||||
code `notElem` csExcludedWarnings spec &&
|
|
||||||
severity <= csMinSeverity spec
|
|
||||||
|
|
||||||
sortMessages = sortBy (comparing order)
|
sortMessages = sortBy (comparing order)
|
||||||
order pc =
|
order pc =
|
||||||
|
@ -137,6 +139,13 @@ checkRecursive includes src =
|
||||||
csCheckSourced = True
|
csCheckSourced = True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkOptionIncludes includes src =
|
||||||
|
checkWithSpec [] emptyCheckSpec {
|
||||||
|
csScript = src,
|
||||||
|
csIncludedWarnings = includes,
|
||||||
|
csCheckSourced = True
|
||||||
|
}
|
||||||
|
|
||||||
prop_findsParseIssue = check "echo \"$12\"" == [1037]
|
prop_findsParseIssue = check "echo \"$12\"" == [1037]
|
||||||
|
|
||||||
prop_commentDisablesParseIssue1 =
|
prop_commentDisablesParseIssue1 =
|
||||||
|
@ -274,6 +283,21 @@ prop_sourcedFileUsesOriginalShellExtension = result == [2079]
|
||||||
csCheckSourced = True
|
csCheckSourced = True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prop_optionIncludes1 =
|
||||||
|
-- expect 2086, but not included, so not reported
|
||||||
|
null $ checkOptionIncludes (Just [2080]) "#!/bin/sh\n var='a b'\n echo $var"
|
||||||
|
|
||||||
|
prop_optionIncludes2 =
|
||||||
|
-- expect 2086, included, so its reported
|
||||||
|
[2086] == checkOptionIncludes (Just [2086]) "#!/bin/sh\n var='a b'\n echo $var"
|
||||||
|
|
||||||
|
prop_optionIncludes3 =
|
||||||
|
-- expect 2086, no inclusions provided, so its reported
|
||||||
|
[2086] == checkOptionIncludes Nothing "#!/bin/sh\n var='a b'\n echo $var"
|
||||||
|
|
||||||
|
prop_optionIncludes4 =
|
||||||
|
-- expect 2086 & 2154, only 2154 included, so only its reported
|
||||||
|
[2154] == checkOptionIncludes (Just [2154]) "#!/bin/sh\n var='a b'\n echo $var\n echo $bar"
|
||||||
|
|
||||||
return []
|
return []
|
||||||
runTests = $quickCheckAll
|
runTests = $quickCheckAll
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
module ShellCheck.Interface
|
module ShellCheck.Interface
|
||||||
(
|
(
|
||||||
SystemInterface(..)
|
SystemInterface(..)
|
||||||
, CheckSpec(csFilename, csScript, csCheckSourced, csExcludedWarnings, csShellTypeOverride, csMinSeverity)
|
, CheckSpec(csFilename, csScript, csCheckSourced, csIncludedWarnings, csExcludedWarnings, csShellTypeOverride, csMinSeverity)
|
||||||
, CheckResult(crFilename, crComments)
|
, CheckResult(crFilename, crComments)
|
||||||
, ParseSpec(psFilename, psScript, psCheckSourced, psShellTypeOverride)
|
, ParseSpec(psFilename, psScript, psCheckSourced, psShellTypeOverride)
|
||||||
, ParseResult(prComments, prTokenPositions, prRoot)
|
, ParseResult(prComments, prTokenPositions, prRoot)
|
||||||
|
@ -80,6 +80,7 @@ data CheckSpec = CheckSpec {
|
||||||
csScript :: String,
|
csScript :: String,
|
||||||
csCheckSourced :: Bool,
|
csCheckSourced :: Bool,
|
||||||
csExcludedWarnings :: [Integer],
|
csExcludedWarnings :: [Integer],
|
||||||
|
csIncludedWarnings :: Maybe [Integer],
|
||||||
csShellTypeOverride :: Maybe Shell,
|
csShellTypeOverride :: Maybe Shell,
|
||||||
csMinSeverity :: Severity
|
csMinSeverity :: Severity
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
@ -101,6 +102,7 @@ emptyCheckSpec = CheckSpec {
|
||||||
csScript = "",
|
csScript = "",
|
||||||
csCheckSourced = False,
|
csCheckSourced = False,
|
||||||
csExcludedWarnings = [],
|
csExcludedWarnings = [],
|
||||||
|
csIncludedWarnings = Nothing,
|
||||||
csShellTypeOverride = Nothing,
|
csShellTypeOverride = Nothing,
|
||||||
csMinSeverity = StyleC
|
csMinSeverity = StyleC
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue