Generalized for f in $(ls) warning, due to many edge cases.
This commit is contained in:
parent
9393e4405b
commit
f348661e7e
|
@ -468,9 +468,8 @@ checkForInLs t = try t
|
||||||
check id f x =
|
check id f x =
|
||||||
case deadSimple x of
|
case deadSimple x of
|
||||||
("ls":n) ->
|
("ls":n) ->
|
||||||
let args = (if n == [] then ["*"] else n) in
|
let warntype = if any ("-" `isPrefixOf`) n then warn else err in
|
||||||
err id $ "Don't use 'for "++f++" in $(ls " ++ (intercalate " " n)
|
warntype id $ "Iterate over globs (e.g. 'for f in */*.wav') whenever possible, as ls only works for simple, alphanumeric filenames."
|
||||||
++ ")'. Use 'for "++f++" in "++ (intercalate " " args) ++ "'."
|
|
||||||
("find":_) -> warn id $ "Don't use 'for " ++ f ++ " in $(find ...). "
|
("find":_) -> warn id $ "Don't use 'for " ++ f ++ " in $(find ...). "
|
||||||
++ "Use find -exec or a while read loop."
|
++ "Use find -exec or a while read loop."
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
|
@ -611,14 +610,14 @@ prop_checkSingleQuotedVariables3c= verifyTree checkSingleQuotedVariables "sed 's
|
||||||
prop_checkSingleQuotedVariables4 = verifyNotTree checkSingleQuotedVariables "awk '{print $1}'"
|
prop_checkSingleQuotedVariables4 = verifyNotTree checkSingleQuotedVariables "awk '{print $1}'"
|
||||||
prop_checkSingleQuotedVariables5 = verifyNotTree checkSingleQuotedVariables "trap 'echo $SECONDS' EXIT"
|
prop_checkSingleQuotedVariables5 = verifyNotTree checkSingleQuotedVariables "trap 'echo $SECONDS' EXIT"
|
||||||
checkSingleQuotedVariables t@(T_SingleQuoted id s) parents =
|
checkSingleQuotedVariables t@(T_SingleQuoted id s) parents =
|
||||||
case matchRegex checkSingleQuotedVariablesRe s of
|
case matchRegex re s of
|
||||||
Just [] -> unless (probablyOk t) $ info id $ "Expressions don't expand in single quotes, use double quotes for that."
|
Just [] -> unless (probablyOk t) $ info id $ "Expressions don't expand in single quotes, use double quotes for that."
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
where
|
where
|
||||||
probablyOk t =
|
probablyOk t =
|
||||||
isParamTo parents "awk" t || isParamTo parents "trap" t
|
any (\x -> isParamTo parents x t) ["awk", "trap"]
|
||||||
|
re = mkRegex "\\$[{(0-9a-zA-Z_]"
|
||||||
checkSingleQuotedVariables _ _ = return ()
|
checkSingleQuotedVariables _ _ = return ()
|
||||||
checkSingleQuotedVariablesRe = mkRegex "\\$[{(0-9a-zA-Z_]"
|
|
||||||
|
|
||||||
|
|
||||||
prop_checkUnquotedN = verify checkUnquotedN "if [ -n $foo ]; then echo cow; fi"
|
prop_checkUnquotedN = verify checkUnquotedN "if [ -n $foo ]; then echo cow; fi"
|
||||||
|
|
Loading…
Reference in New Issue