Add warnings for 'exit' similar to 'return' (fixes #1388)
This commit is contained in:
parent
705e476e4c
commit
cb76951ad2
|
@ -2,14 +2,17 @@
|
||||||
### Added
|
### Added
|
||||||
- Command line option --severity/-S for filtering by minimum severity
|
- Command line option --severity/-S for filtering by minimum severity
|
||||||
- Command line option --wiki-link-count/-W for showing wiki links
|
- Command line option --wiki-link-count/-W for showing wiki links
|
||||||
|
- SC2152/SC2151: Warn about bad `exit` values like `1234` and `"foo"`
|
||||||
- SC2236/SC2237: Suggest -n/-z instead of ! -z/-n
|
- SC2236/SC2237: Suggest -n/-z instead of ! -z/-n
|
||||||
- SC2238: Warn when redirecting to a known command name, e.g. ls > rm
|
- SC2238: Warn when redirecting to a known command name, e.g. ls > rm
|
||||||
- SC2239: Warn if the shebang is not an absolute path, e.g. #!bin/sh
|
- SC2239: Warn if the shebang is not an absolute path, e.g. #!bin/sh
|
||||||
- SC2240: Warn when passing additional arguments to dot (.) in sh/dash
|
- SC2240: Warn when passing additional arguments to dot (.) in sh/dash
|
||||||
- SC1133: Better diagnostics when starting a line with |/||/&&
|
- SC1133: Better diagnostics when starting a line with |/||/&&
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Most warnings now have useful end positions
|
- Most warnings now have useful end positions
|
||||||
- SC1117 about unknown double-quoted escape sequences has been retired
|
- SC1117 about unknown double-quoted escape sequences has been retired
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- SC2021 no longer triggers for equivalence classes like '[=e=]'
|
- SC2021 no longer triggers for equivalence classes like '[=e=]'
|
||||||
- SC2221/SC2222 no longer mistriggers on fall-through case branches
|
- SC2221/SC2222 no longer mistriggers on fall-through case branches
|
||||||
|
|
|
@ -61,6 +61,7 @@ commandChecks = [
|
||||||
,checkGrepRe
|
,checkGrepRe
|
||||||
,checkTrapQuotes
|
,checkTrapQuotes
|
||||||
,checkReturn
|
,checkReturn
|
||||||
|
,checkExit
|
||||||
,checkFindExecWithSingleArgument
|
,checkFindExecWithSingleArgument
|
||||||
,checkUnusedEchoEscapes
|
,checkUnusedEchoEscapes
|
||||||
,checkInjectableFindSh
|
,checkInjectableFindSh
|
||||||
|
@ -281,15 +282,28 @@ prop_checkReturn4 = verifyNot checkReturn "return $((a|b))"
|
||||||
prop_checkReturn5 = verify checkReturn "return -1"
|
prop_checkReturn5 = verify checkReturn "return -1"
|
||||||
prop_checkReturn6 = verify checkReturn "return 1000"
|
prop_checkReturn6 = verify checkReturn "return 1000"
|
||||||
prop_checkReturn7 = verify checkReturn "return 'hello world'"
|
prop_checkReturn7 = verify checkReturn "return 'hello world'"
|
||||||
checkReturn = CommandCheck (Exactly "return") (f . arguments)
|
checkReturn = CommandCheck (Exactly "return") (returnOrExit
|
||||||
|
(\c -> err c 2151 "Only one integer 0-255 can be returned. Use stdout for other data.")
|
||||||
|
(\c -> err c 2152 "Can only return 0-255. Other data should be written to stdout."))
|
||||||
|
|
||||||
|
prop_checkExit1 = verifyNot checkExit "exit"
|
||||||
|
prop_checkExit2 = verifyNot checkExit "exit 1"
|
||||||
|
prop_checkExit3 = verifyNot checkExit "exit $var"
|
||||||
|
prop_checkExit4 = verifyNot checkExit "exit $((a|b))"
|
||||||
|
prop_checkExit5 = verify checkExit "exit -1"
|
||||||
|
prop_checkExit6 = verify checkExit "exit 1000"
|
||||||
|
prop_checkExit7 = verify checkExit "exit 'hello world'"
|
||||||
|
checkExit = CommandCheck (Exactly "exit") (returnOrExit
|
||||||
|
(\c -> err c 2241 "The exit status can only be one integer 0-255. Use stdout for other data.")
|
||||||
|
(\c -> err c 2242 "Can only exit with status 0-255. Other data should be written to stdout/stderr."))
|
||||||
|
|
||||||
|
returnOrExit multi invalid = (f . arguments)
|
||||||
where
|
where
|
||||||
f (first:second:_) =
|
f (first:second:_) =
|
||||||
err (getId second) 2151
|
multi (getId first)
|
||||||
"Only one integer 0-255 can be returned. Use stdout for other data."
|
|
||||||
f [value] =
|
f [value] =
|
||||||
when (isInvalid $ literal value) $
|
when (isInvalid $ literal value) $
|
||||||
err (getId value) 2152
|
invalid (getId value)
|
||||||
"Can only return 0-255. Other data should be written to stdout."
|
|
||||||
f _ = return ()
|
f _ = return ()
|
||||||
|
|
||||||
isInvalid s = s == "" || any (not . isDigit) s || length s > 5
|
isInvalid s = s == "" || any (not . isDigit) s || length s > 5
|
||||||
|
|
Loading…
Reference in New Issue