Add command-line option -S/--severity

Specifies the maximum severity of errors to handle.  For example,
specifying "-S warning" means that errors of severity "info" and
"style" are ignored.

Signed-off-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Martin Schwenke 2018-08-12 21:28:48 +10:00 committed by Vidar Holen
parent 15aaacf715
commit b16da4b242
4 changed files with 33 additions and 5 deletions

View File

@ -56,6 +56,11 @@ not warn at all, as `ksh` supports decimals in arithmetic contexts.
standard output. Subsequent **-f** options are ignored, see **FORMATS**
below for more information.
**-S**\ *SEVERITY*,\ **--severity=***severity*
: Specify maximum severity of errors to consider. Valid values are *error*,
*warning*, *info* and *style*. The default is *style*.
**-s**\ *shell*,\ **--shell=***shell*
: Specify Bourne shell dialect. Valid values are *sh*, *bash*, *dash* and *ksh*.

View File

@ -67,7 +67,8 @@ instance Monoid Status where
data Options = Options {
checkSpec :: CheckSpec,
externalSources :: Bool,
formatterOptions :: FormatterOptions
formatterOptions :: FormatterOptions,
maxSeverity :: Severity
}
defaultOptions = Options {
@ -75,7 +76,8 @@ defaultOptions = Options {
externalSources = False,
formatterOptions = FormatterOptions {
foColorOption = ColorAuto
}
},
maxSeverity = StyleC
}
usageHeader = "Usage: shellcheck [OPTIONS...] FILES..."
@ -93,6 +95,9 @@ options = [
Option "s" ["shell"]
(ReqArg (Flag "shell") "SHELLNAME")
"Specify dialect (sh, bash, dash, ksh)",
Option "S" ["severity"]
(ReqArg (Flag "severity") "SEVERITY")
"Maximum severity of errors to consider (error, warning, info, style)",
Option "V" ["version"]
(NoArg $ Flag "version" "true") "Print version information",
Option "x" ["external-sources"]
@ -223,6 +228,14 @@ parseColorOption colorOption =
"never" -> ColorNever
_ -> error $ "Bad value for --color `" ++ colorOption ++ "'"
parseSeverityOption severityOption =
case severityOption of
"error" -> ErrorC
"warning" -> WarningC
"info" -> InfoC
"style" -> StyleC
_ -> error $ "Bad value for --severity `" ++ severityOption ++ "'"
parseOption flag options =
case flag of
Flag "shell" str ->
@ -266,6 +279,13 @@ parseOption flag options =
}
}
Flag "severity" severity ->
return options {
checkSpec = (checkSpec options) {
csMaxSeverity = parseSeverityOption severity
}
}
_ -> return options
where
die s = do

View File

@ -67,7 +67,8 @@ checkScript sys spec = do
return . nub . sortMessages . filter shouldInclude $
(parseMessages ++ map translator analysisMessages)
shouldInclude (PositionedComment _ _ (Comment _ code _)) =
shouldInclude (PositionedComment _ _ (Comment severity code _)) =
severity <= csMaxSeverity spec &&
code `notElem` csExcludedWarnings spec
sortMessages = sortBy (comparing order)

View File

@ -35,7 +35,8 @@ data CheckSpec = CheckSpec {
csScript :: String,
csCheckSourced :: Bool,
csExcludedWarnings :: [Integer],
csShellTypeOverride :: Maybe Shell
csShellTypeOverride :: Maybe Shell,
csMaxSeverity :: Severity
} deriving (Show, Eq)
data CheckResult = CheckResult {
@ -49,7 +50,8 @@ emptyCheckSpec = CheckSpec {
csScript = "",
csCheckSourced = False,
csExcludedWarnings = [],
csShellTypeOverride = Nothing
csShellTypeOverride = Nothing,
csMaxSeverity = StyleC
}
newParseSpec :: ParseSpec