Check for 'echo "\n"'.
This commit is contained in:
parent
fc3045232f
commit
af4d24c6f6
|
@ -126,6 +126,7 @@ basicChecks = [
|
||||||
,checkLonelyDotDash
|
,checkLonelyDotDash
|
||||||
,checkSpuriousExec
|
,checkSpuriousExec
|
||||||
,checkSpuriousExpansion
|
,checkSpuriousExpansion
|
||||||
|
,checkUnusedEchoEscapes
|
||||||
]
|
]
|
||||||
treeChecks = [
|
treeChecks = [
|
||||||
checkUnquotedExpansions
|
checkUnquotedExpansions
|
||||||
|
@ -172,6 +173,8 @@ isPotentiallyConfusedGlobRegex =
|
||||||
let re = mkRegex "[a-z1-9]\\*" in
|
let re = mkRegex "[a-z1-9]\\*" in
|
||||||
isJust . matchRegex re
|
isJust . matchRegex re
|
||||||
|
|
||||||
|
matches string regex = isJust $ matchRegex regex string
|
||||||
|
|
||||||
isConstant token =
|
isConstant token =
|
||||||
case token of
|
case token of
|
||||||
T_NormalWord _ l -> all isConstant l
|
T_NormalWord _ l -> all isConstant l
|
||||||
|
@ -904,7 +907,7 @@ checkPrintfVar = checkUnqualifiedCommand "printf" f where
|
||||||
f _ = return ()
|
f _ = return ()
|
||||||
check format =
|
check format =
|
||||||
if not $ isLiteral format
|
if not $ isLiteral format
|
||||||
then warn (getId format) $ "Don't use variables in the printf format string. Use printf \"%s\" \"$foo\"."
|
then warn (getId format) $ "Don't use variables in the printf format string. Use printf \"..%s..\" \"$foo\"."
|
||||||
else return ()
|
else return ()
|
||||||
|
|
||||||
prop_checkUuoe1 = verify checkUuoe "echo $(date)"
|
prop_checkUuoe1 = verify checkUuoe "echo $(date)"
|
||||||
|
@ -1188,6 +1191,30 @@ checkSpuriousExpansion (T_SimpleCommand _ _ [T_NormalWord _ [word]]) = check wor
|
||||||
checkSpuriousExpansion _ = return ()
|
checkSpuriousExpansion _ = return ()
|
||||||
|
|
||||||
|
|
||||||
|
prop_checkUnusedEchoEscapes1 = verify checkUnusedEchoEscapes "echo 'foo\\nbar\\n'"
|
||||||
|
prop_checkUnusedEchoEscapes2 = verifyNot checkUnusedEchoEscapes "echo -e 'foi\\nbar'"
|
||||||
|
prop_checkUnusedEchoEscapes3 = verify checkUnusedEchoEscapes "echo \"n:\\t42\""
|
||||||
|
prop_checkUnusedEchoEscapes4 = verifyNot checkUnusedEchoEscapes "echo lol"
|
||||||
|
checkUnusedEchoEscapes = checkCommand "echo" f
|
||||||
|
where
|
||||||
|
isDashE = mkRegex "^-.*e"
|
||||||
|
hasEscapes = mkRegex "\\\\[rnt]"
|
||||||
|
f (arg:_) | (concat $ deadSimple arg) `matches` isDashE = return ()
|
||||||
|
f args = mapM_ checkEscapes args
|
||||||
|
|
||||||
|
checkEscapes (T_NormalWord _ args) =
|
||||||
|
mapM_ checkEscapes args
|
||||||
|
checkEscapes (T_DoubleQuoted id args) =
|
||||||
|
mapM_ checkEscapes args
|
||||||
|
checkEscapes (T_Literal id str) = examine id str
|
||||||
|
checkEscapes (T_SingleQuoted id str) = examine id str
|
||||||
|
checkEscapes _ = return ()
|
||||||
|
|
||||||
|
examine id str =
|
||||||
|
when (str `matches` hasEscapes) $
|
||||||
|
info id "echo won't expand escape sequences. Consider printf."
|
||||||
|
|
||||||
|
|
||||||
--- Subshell detection
|
--- Subshell detection
|
||||||
|
|
||||||
prop_subshellAssignmentCheck = verifyFull subshellAssignmentCheck "cat foo | while read bar; do a=$bar; done; echo \"$a\""
|
prop_subshellAssignmentCheck = verifyFull subshellAssignmentCheck "cat foo | while read bar; do a=$bar; done; echo \"$a\""
|
||||||
|
|
Loading…
Reference in New Issue