SC2240: Warn about `. script args..` in sh/dash (fixes #1373)
This commit is contained in:
parent
de95c376ea
commit
2827b35696
|
@ -5,6 +5,7 @@
|
||||||
- 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 shen 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
|
||||||
|
|
|
@ -92,6 +92,7 @@ commandChecks = [
|
||||||
,checkWhich
|
,checkWhich
|
||||||
,checkSudoRedirect
|
,checkSudoRedirect
|
||||||
,checkSudoArgs
|
,checkSudoArgs
|
||||||
|
,checkSourceArgs
|
||||||
]
|
]
|
||||||
|
|
||||||
buildCommandMap :: [CommandCheck] -> Map.Map CommandName (Token -> Analysis)
|
buildCommandMap :: [CommandCheck] -> Map.Map CommandName (Token -> Analysis)
|
||||||
|
@ -1008,5 +1009,16 @@ checkSudoArgs = CommandCheck (Basename "sudo") f
|
||||||
-- This mess is why ShellCheck prefers not to know.
|
-- This mess is why ShellCheck prefers not to know.
|
||||||
parseOpts = getBsdOpts "vAknSbEHPa:g:h:p:u:c:T:r:"
|
parseOpts = getBsdOpts "vAknSbEHPa:g:h:p:u:c:T:r:"
|
||||||
|
|
||||||
|
prop_checkSourceArgs1 = verify checkSourceArgs "#!/bin/sh\n. script arg"
|
||||||
|
prop_checkSourceArgs2 = verifyNot checkSourceArgs "#!/bin/sh\n. script"
|
||||||
|
prop_checkSourceArgs3 = verifyNot checkSourceArgs "#!/bin/bash\n. script arg"
|
||||||
|
checkSourceArgs = CommandCheck (Exactly ".") f
|
||||||
|
where
|
||||||
|
f t = whenShell [Sh, Dash] $
|
||||||
|
case arguments t of
|
||||||
|
(file:arg1:_) -> warn (getId arg1) 2240 $
|
||||||
|
"The dot command does not support arguments in sh/dash. Set them as variables."
|
||||||
|
_ -> return ()
|
||||||
|
|
||||||
return []
|
return []
|
||||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||||
|
|
Loading…
Reference in New Issue