SC2245: Warn that Ksh [ -f * ] only applies to first (Fixes #1452)
This commit is contained in:
parent
ec6f9e4d49
commit
1835ebd3a0
|
@ -1,6 +1,7 @@
|
||||||
## Since previous release
|
## Since previous release
|
||||||
### Added
|
### Added
|
||||||
- Preliminary support for fix suggestions
|
- Preliminary support for fix suggestions
|
||||||
|
- SC2245: Warn that Ksh ignores all but the first glob result in `[`
|
||||||
- SC2243/SC2244: Suggest using explicit -n for `[ $foo ]`
|
- SC2243/SC2244: Suggest using explicit -n for `[ $foo ]`
|
||||||
|
|
||||||
## v0.6.0 - 2018-12-02
|
## v0.6.0 - 2018-12-02
|
||||||
|
|
|
@ -2466,8 +2466,10 @@ prop_checkTestArgumentSplitting13 = verify checkTestArgumentSplitting "[ \"$@\"
|
||||||
prop_checkTestArgumentSplitting14 = verify checkTestArgumentSplitting "[[ \"$@\" == \"\" ]]"
|
prop_checkTestArgumentSplitting14 = verify checkTestArgumentSplitting "[[ \"$@\" == \"\" ]]"
|
||||||
prop_checkTestArgumentSplitting15 = verifyNot checkTestArgumentSplitting "[[ \"$*\" == \"\" ]]"
|
prop_checkTestArgumentSplitting15 = verifyNot checkTestArgumentSplitting "[[ \"$*\" == \"\" ]]"
|
||||||
prop_checkTestArgumentSplitting16 = verifyNot checkTestArgumentSplitting "[[ -v foo[123] ]]"
|
prop_checkTestArgumentSplitting16 = verifyNot checkTestArgumentSplitting "[[ -v foo[123] ]]"
|
||||||
|
prop_checkTestArgumentSplitting17 = verifyNot checkTestArgumentSplitting "#!/bin/ksh\n[ -e foo* ]"
|
||||||
|
prop_checkTestArgumentSplitting18 = verify checkTestArgumentSplitting "#!/bin/ksh\n[ -d foo* ]"
|
||||||
checkTestArgumentSplitting :: Parameters -> Token -> Writer [TokenComment] ()
|
checkTestArgumentSplitting :: Parameters -> Token -> Writer [TokenComment] ()
|
||||||
checkTestArgumentSplitting _ t =
|
checkTestArgumentSplitting params t =
|
||||||
case t of
|
case t of
|
||||||
(TC_Unary _ typ op token) | isGlob token ->
|
(TC_Unary _ typ op token) | isGlob token ->
|
||||||
if op == "-v"
|
if op == "-v"
|
||||||
|
@ -2475,6 +2477,14 @@ checkTestArgumentSplitting _ t =
|
||||||
when (typ == SingleBracket) $
|
when (typ == SingleBracket) $
|
||||||
err (getId token) 2208 $
|
err (getId token) 2208 $
|
||||||
"Use [[ ]] or quote arguments to -v to avoid glob expansion."
|
"Use [[ ]] or quote arguments to -v to avoid glob expansion."
|
||||||
|
else
|
||||||
|
if (typ == SingleBracket && shellType params == Ksh)
|
||||||
|
then
|
||||||
|
-- Ksh appears to stop processing after unrecognized tokens, so operators
|
||||||
|
-- will effectively work with globs, but only the first match.
|
||||||
|
when (op `elem` ['-':c:[] | c <- "bcdfgkprsuwxLhNOGRS" ]) $
|
||||||
|
warn (getId token) 2245 $
|
||||||
|
op ++ " only applies to the first expansion of this glob. Use a loop to check any/all."
|
||||||
else
|
else
|
||||||
err (getId token) 2144 $
|
err (getId token) 2144 $
|
||||||
op ++ " doesn't work with globs. Use a for loop."
|
op ++ " doesn't work with globs. Use a for loop."
|
||||||
|
|
Loading…
Reference in New Issue