mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-06 21:11:35 -07:00
Suggest quoting expansions in for loop globs
This commit is contained in:
parent
c3b606c68a
commit
764b242f1b
3 changed files with 25 additions and 0 deletions
|
@ -166,6 +166,7 @@ nodeChecks = [
|
|||
,checkFlagAsCommand
|
||||
,checkEmptyCondition
|
||||
,checkPipeToNowhere
|
||||
,checkForLoopGlobVariables
|
||||
]
|
||||
|
||||
|
||||
|
@ -2908,5 +2909,19 @@ checkUseBeforeDefinition _ t =
|
|||
then [x]
|
||||
else concatMap recursiveSequences list
|
||||
|
||||
prop_checkForLoopGlobVariables1 = verify checkForLoopGlobVariables "for i in $var/*.txt; do true; done"
|
||||
prop_checkForLoopGlobVariables2 = verifyNot checkForLoopGlobVariables "for i in \"$var\"/*.txt; do true; done"
|
||||
prop_checkForLoopGlobVariables3 = verifyNot checkForLoopGlobVariables "for i in $var; do true; done"
|
||||
checkForLoopGlobVariables _ t =
|
||||
case t of
|
||||
T_ForIn _ _ words _ -> mapM_ check words
|
||||
_ -> return ()
|
||||
where
|
||||
check (T_NormalWord _ parts) =
|
||||
when (any isGlob parts) $
|
||||
mapM_ suggest $ filter isQuoteableExpansion parts
|
||||
suggest t = info (getId t) 2231
|
||||
"Quote expansions in this for loop glob to prevent wordsplitting, e.g. \"$dir\"/*.txt ."
|
||||
|
||||
return []
|
||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue