Issue 837 flag to include only certain warnings

Issue https://github.com/koalaman/shellcheck/issues/837

Add an --include option, which creates a whitelist of warnings to report
on, the opposite of --exclude.
This commit is contained in:
Gandalf- 2019-01-18 20:15:52 -08:00
parent a621eba6d3
commit 59c47f2266
4 changed files with 52 additions and 5 deletions

View file

@ -94,11 +94,13 @@ checkScript sys spec = do
(parseMessages ++ map translator analysisMessages)
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)
in
code `notElem` csExcludedWarnings spec &&
severity <= csMinSeverity spec
sortMessages = sortBy (comparing order)
order pc =
@ -137,6 +139,13 @@ checkRecursive includes src =
csCheckSourced = True
}
checkOptionIncludes includes src =
checkWithSpec [] emptyCheckSpec {
csScript = src,
csIncludedWarnings = includes,
csCheckSourced = True
}
prop_findsParseIssue = check "echo \"$12\"" == [1037]
prop_commentDisablesParseIssue1 =
@ -274,6 +283,21 @@ prop_sourcedFileUsesOriginalShellExtension = result == [2079]
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 []
runTests = $quickCheckAll