Warn about array assignments for /bin/sh
This commit is contained in:
parent
75d51087c8
commit
19e1bdf11f
|
@ -506,29 +506,29 @@ prop_checkBashisms17= verify checkBashisms "echo $((RANDOM%6+1))"
|
||||||
prop_checkBashisms18= verify checkBashisms "foo &> /dev/null"
|
prop_checkBashisms18= verify checkBashisms "foo &> /dev/null"
|
||||||
checkBashisms _ = bashism
|
checkBashisms _ = bashism
|
||||||
where
|
where
|
||||||
errMsg id s = err id 2040 $ "#!/bin/sh was specified, so " ++ s ++ " is not supported, even when sh is actually bash."
|
errMsg id s = err id 2040 $ "#!/bin/sh was specified, so " ++ s ++ " not supported, even when sh is actually bash."
|
||||||
warnMsg id s = warn id 2039 $ "#!/bin/sh was specified, but " ++ s ++ " is not standard."
|
warnMsg id s = warn id 2039 $ "#!/bin/sh was specified, but " ++ s ++ " not standard."
|
||||||
bashism (T_ProcSub id _ _) = errMsg id "process substitution"
|
bashism (T_ProcSub id _ _) = errMsg id "process substitution is"
|
||||||
bashism (T_Extglob id _ _) = warnMsg id "extglob"
|
bashism (T_Extglob id _ _) = warnMsg id "extglob is"
|
||||||
bashism (T_DollarSingleQuoted id _) = warnMsg id "$'..'"
|
bashism (T_DollarSingleQuoted id _) = warnMsg id "$'..' is"
|
||||||
bashism (T_DollarDoubleQuoted id _) = warnMsg id "$\"..\""
|
bashism (T_DollarDoubleQuoted id _) = warnMsg id "$\"..\" is"
|
||||||
bashism (T_ForArithmetic id _ _ _ _) = warnMsg id "arithmetic for loop"
|
bashism (T_ForArithmetic id _ _ _ _) = warnMsg id "arithmetic for loops are"
|
||||||
bashism (T_Arithmetic id _) = warnMsg id "standalone ((..))"
|
bashism (T_Arithmetic id _) = warnMsg id "standalone ((..)) is"
|
||||||
bashism (T_DollarBracket id _) = warnMsg id "$[..] in place of $((..))"
|
bashism (T_DollarBracket id _) = warnMsg id "$[..] in place of $((..)) is"
|
||||||
bashism (T_SelectIn id _ _ _) = warnMsg id "select loop"
|
bashism (T_SelectIn id _ _ _) = warnMsg id "select loops are"
|
||||||
bashism (T_BraceExpansion id _) = warnMsg id "brace expansion"
|
bashism (T_BraceExpansion id _) = warnMsg id "brace expansion is"
|
||||||
bashism (T_Condition id DoubleBracket _) = warnMsg id "[[ ]]"
|
bashism (T_Condition id DoubleBracket _) = warnMsg id "[[ ]] is"
|
||||||
bashism (T_HereString id _) = warnMsg id "here-string"
|
bashism (T_HereString id _) = warnMsg id "here-strings are"
|
||||||
bashism (TC_Binary id SingleBracket op _ _)
|
bashism (TC_Binary id SingleBracket op _ _)
|
||||||
| op `elem` [ "-nt", "-ef", "\\<", "\\>", "==" ] =
|
| op `elem` [ "-nt", "-ef", "\\<", "\\>", "==" ] =
|
||||||
warnMsg id op
|
warnMsg id $ op ++ " is"
|
||||||
bashism (TA_Unary id op _)
|
bashism (TA_Unary id op _)
|
||||||
| op `elem` [ "|++", "|--", "++|", "--|"] =
|
| op `elem` [ "|++", "|--", "++|", "--|"] =
|
||||||
warnMsg id (filter (/= '|') op)
|
warnMsg id $ (filter (/= '|') op) ++ " is"
|
||||||
bashism t@(T_SimpleCommand id _ _)
|
bashism t@(T_SimpleCommand id _ _)
|
||||||
| t `isCommand` "source" =
|
| t `isCommand` "source" =
|
||||||
warnMsg id "'source' in place of '.'"
|
warnMsg id "'source' in place of '.' is"
|
||||||
bashism (T_FdRedirect id "&" (T_IoFile _ (T_Greater _) _)) = warnMsg id "&>"
|
bashism (T_FdRedirect id "&" (T_IoFile _ (T_Greater _) _)) = warnMsg id "&> is"
|
||||||
bashism (T_DollarBraced id token) =
|
bashism (T_DollarBraced id token) =
|
||||||
mapM_ check expansion
|
mapM_ check expansion
|
||||||
where
|
where
|
||||||
|
@ -539,28 +539,30 @@ checkBashisms _ = bashism
|
||||||
bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
|
bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
|
||||||
| t `isCommand` "echo" && "-" `isPrefixOf` argString =
|
| t `isCommand` "echo" && "-" `isPrefixOf` argString =
|
||||||
unless ("--" `isPrefixOf` argString) $ -- echo "-------"
|
unless ("--" `isPrefixOf` argString) $ -- echo "-------"
|
||||||
warnMsg (getId arg) "echo flag"
|
warnMsg (getId arg) "echo flags are"
|
||||||
where argString = (concat $ deadSimple arg)
|
where argString = (concat $ deadSimple arg)
|
||||||
bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
|
bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
|
||||||
| t `isCommand` "exec" && "-" `isPrefixOf` (concat $ deadSimple arg) =
|
| t `isCommand` "exec" && "-" `isPrefixOf` (concat $ deadSimple arg) =
|
||||||
warnMsg (getId arg) "exec flag"
|
warnMsg (getId arg) "exec flags are"
|
||||||
bashism t@(T_SimpleCommand id _ _)
|
bashism t@(T_SimpleCommand id _ _)
|
||||||
| t `isCommand` "let" = warnMsg id "'let'"
|
| t `isCommand` "let" = warnMsg id "'let' is"
|
||||||
bashism t@(TA_Variable id "RANDOM") =
|
bashism t@(TA_Variable id "RANDOM") =
|
||||||
warnMsg id "RANDOM"
|
warnMsg id "RANDOM is"
|
||||||
bashism t@(T_Pipe id "|&") =
|
bashism t@(T_Pipe id "|&") =
|
||||||
warnMsg id "|& in place of 2>&1 |"
|
warnMsg id "|& in place of 2>&1 | is"
|
||||||
|
bashism (T_Array id _) =
|
||||||
|
warnMsg id "arrays are"
|
||||||
|
|
||||||
bashism _ = return()
|
bashism _ = return()
|
||||||
|
|
||||||
varChars="_0-9a-zA-Z"
|
varChars="_0-9a-zA-Z"
|
||||||
expansion = let re = mkRegex in [
|
expansion = let re = mkRegex in [
|
||||||
(re $ "^[" ++ varChars ++ "]+\\[.*\\]$", "array references"),
|
(re $ "^[" ++ varChars ++ "]+\\[.*\\]$", "array references are"),
|
||||||
(re $ "^![" ++ varChars ++ "]+\\[[*@]]$", "array key expansion"),
|
(re $ "^![" ++ varChars ++ "]+\\[[*@]]$", "array key expansion is"),
|
||||||
(re $ "^![" ++ varChars ++ "]+[*@]$", "name matching prefix"),
|
(re $ "^![" ++ varChars ++ "]+[*@]$", "name matching prefixes are"),
|
||||||
(re $ "^[" ++ varChars ++ "]+:[^-=?+]", "string indexing"),
|
(re $ "^[" ++ varChars ++ "]+:[^-=?+]", "string indexing is"),
|
||||||
(re $ "^[" ++ varChars ++ "]+(\\[.*\\])?/", "string replacement"),
|
(re $ "^[" ++ varChars ++ "]+(\\[.*\\])?/", "string replacement is"),
|
||||||
(re $ "^RANDOM$", "$RANDOM")
|
(re $ "^RANDOM$", "$RANDOM is")
|
||||||
]
|
]
|
||||||
|
|
||||||
prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done"
|
prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done"
|
||||||
|
|
Loading…
Reference in New Issue