Warn on for f in 1,2,3 and for f in ls;
This commit is contained in:
parent
0d3dded238
commit
f6f05234bf
|
@ -269,12 +269,19 @@ checkUndeclaredBash t@(T_Script id sb _) m =
|
|||
|
||||
prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done"
|
||||
prop_checkForInQuoted2 = verifyNot checkForInQuoted "for f in \"$@\"; do echo foo; done"
|
||||
prop_checkForInQuoted2a = verifyNot checkForInQuoted "for f in *.mp3; do echo foo; done"
|
||||
prop_checkForInQuoted3 = verify checkForInQuoted "for f in 'find /'; do true; done"
|
||||
prop_checkForInQuoted4 = verify checkForInQuoted "for f in 1,2,3; do true; done"
|
||||
prop_checkForInQuoted5 = verify checkForInQuoted "for f in ls; do true; done"
|
||||
checkForInQuoted (T_ForIn _ f [T_NormalWord _ [T_DoubleQuoted id list]] _) =
|
||||
when (any (\x -> willSplit x && not (isMagicInQuotes x)) list) $
|
||||
err id $ "Since you double quoted this, it will not word split, and the loop will only run once."
|
||||
checkForInQuoted (T_ForIn _ f [T_NormalWord _ [T_SingleQuoted id s]] _) =
|
||||
warn id $ "This is a literal string. To run as a command, use $(" ++ s ++ ")."
|
||||
checkForInQuoted (T_ForIn _ f [T_NormalWord _ [T_Literal id s]] _) =
|
||||
if ',' `elem` s
|
||||
then warn id $ "Use spaces, not commas, to separate loop elements."
|
||||
else warn id $ "This loop will only run once, with " ++ f ++ "='" ++ s ++ "'."
|
||||
checkForInQuoted _ = return ()
|
||||
|
||||
prop_checkForInCat1 = verify checkForInCat "for f in $(cat foo); do stuff; done"
|
||||
|
|
Loading…
Reference in New Issue