Modernize SC2028 echo escape test
This commit is contained in:
parent
afada43978
commit
5ef4229f61
|
@ -325,26 +325,18 @@ prop_checkUnusedEchoEscapes2 = verifyNot checkUnusedEchoEscapes "echo -e 'foi\\n
|
||||||
prop_checkUnusedEchoEscapes3 = verify checkUnusedEchoEscapes "echo \"n:\\t42\""
|
prop_checkUnusedEchoEscapes3 = verify checkUnusedEchoEscapes "echo \"n:\\t42\""
|
||||||
prop_checkUnusedEchoEscapes4 = verifyNot checkUnusedEchoEscapes "echo lol"
|
prop_checkUnusedEchoEscapes4 = verifyNot checkUnusedEchoEscapes "echo lol"
|
||||||
prop_checkUnusedEchoEscapes5 = verifyNot checkUnusedEchoEscapes "echo -n -e '\n'"
|
prop_checkUnusedEchoEscapes5 = verifyNot checkUnusedEchoEscapes "echo -n -e '\n'"
|
||||||
checkUnusedEchoEscapes = CommandCheck (Basename "echo") (f . arguments)
|
checkUnusedEchoEscapes = CommandCheck (Basename "echo") f
|
||||||
where
|
where
|
||||||
isDashE = mkRegex "^-.*e"
|
|
||||||
hasEscapes = mkRegex "\\\\[rnt]"
|
hasEscapes = mkRegex "\\\\[rnt]"
|
||||||
f args | concat (concatMap oversimplify allButLast) `matches` isDashE =
|
f cmd =
|
||||||
return ()
|
whenShell [Sh, Bash, Ksh] $
|
||||||
where allButLast = reverse . drop 1 . reverse $ args
|
unless (cmd `hasFlag` "e") $
|
||||||
f args = mapM_ checkEscapes args
|
mapM_ examine $ arguments cmd
|
||||||
|
|
||||||
checkEscapes (T_NormalWord _ args) =
|
examine token = do
|
||||||
mapM_ checkEscapes args
|
let str = onlyLiteralString token
|
||||||
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) $
|
when (str `matches` hasEscapes) $
|
||||||
info id 2028 "echo won't expand escape sequences. Consider printf."
|
info (getId token) 2028 "echo may not expand escape sequences. Use printf."
|
||||||
|
|
||||||
|
|
||||||
prop_checkInjectableFindSh1 = verify checkInjectableFindSh "find . -exec sh -c 'echo {}' \\;"
|
prop_checkInjectableFindSh1 = verify checkInjectableFindSh "find . -exec sh -c 'echo {}' \\;"
|
||||||
|
|
Loading…
Reference in New Issue