From f6f05234bf90136bdb864f2a03fb92d23a725f68 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 25 Jan 2013 20:15:42 -0800 Subject: [PATCH] Warn on for f in 1,2,3 and for f in ls; --- ShellCheck/Analytics.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 66f3185..f98e4c9 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -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"