Added check for echo $a | sed s/foo/bar/g
This commit is contained in:
parent
aae87fc030
commit
aaf5ac6f8f
|
@ -61,6 +61,7 @@ basicChecks = [
|
||||||
,checkPrintfVar
|
,checkPrintfVar
|
||||||
,checkCommarrays
|
,checkCommarrays
|
||||||
,checkOrNeq
|
,checkOrNeq
|
||||||
|
,checkEchoSed
|
||||||
]
|
]
|
||||||
|
|
||||||
modifyMap = modify
|
modifyMap = modify
|
||||||
|
@ -88,7 +89,7 @@ makeSimple t = t
|
||||||
simplify = doTransform makeSimple
|
simplify = doTransform makeSimple
|
||||||
|
|
||||||
deadSimple (T_NormalWord _ l) = [concat (concatMap (deadSimple) l)]
|
deadSimple (T_NormalWord _ l) = [concat (concatMap (deadSimple) l)]
|
||||||
deadSimple (T_DoubleQuoted _ l) = ["\"" ++(concat (concatMap (deadSimple) l)) ++ "\""]
|
deadSimple (T_DoubleQuoted _ l) = [(concat (concatMap (deadSimple) l))]
|
||||||
deadSimple (T_SingleQuoted _ s) = [s]
|
deadSimple (T_SingleQuoted _ s) = [s]
|
||||||
deadSimple (T_DollarBraced _ _) = ["${VAR}"]
|
deadSimple (T_DollarBraced _ _) = ["${VAR}"]
|
||||||
deadSimple (T_DollarArithmetic _ _) = ["${VAR}"]
|
deadSimple (T_DollarArithmetic _ _) = ["${VAR}"]
|
||||||
|
@ -110,6 +111,23 @@ checkFull f s = case parseShell "-" s of
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
|
|
||||||
|
prop_checkEchoSed1 = verify checkEchoSed "FOO=$(echo \"$cow\" | sed 's/foo/bar/g')"
|
||||||
|
prop_checkEchoSed2 = verify checkEchoSed "rm $(echo $cow | sed -e 's,foo,bar,')"
|
||||||
|
checkEchoSed (T_Pipeline id [a, b]) =
|
||||||
|
when (acmd == ["echo", "${VAR}"]) $
|
||||||
|
case bcmd of
|
||||||
|
["sed", v] -> checkIn v
|
||||||
|
["sed", "-e", v] -> checkIn v
|
||||||
|
_ -> return ()
|
||||||
|
where
|
||||||
|
acmd = deadSimple a
|
||||||
|
bcmd = deadSimple b
|
||||||
|
checkIn s =
|
||||||
|
case matchRegex checkEchoSedRe s of
|
||||||
|
Just _ -> style id $ "See if you can use ${variable//search/replace} instead."
|
||||||
|
_ -> return ()
|
||||||
|
checkEchoSed _ = return ()
|
||||||
|
checkEchoSedRe = mkRegex "^s(.)(.*)\\1(.*)\\1g?$"
|
||||||
|
|
||||||
prop_checkUuoc = verify checkUuoc "cat foo | grep bar"
|
prop_checkUuoc = verify checkUuoc "cat foo | grep bar"
|
||||||
checkUuoc (T_Pipeline _ (T_Redirecting _ _ f@(T_SimpleCommand id _ _):_:_)) =
|
checkUuoc (T_Pipeline _ (T_Redirecting _ _ f@(T_SimpleCommand id _ _):_:_)) =
|
||||||
|
@ -397,6 +415,7 @@ checkPrintfVar = checkCommand "printf" f where
|
||||||
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 ()
|
||||||
|
|
||||||
|
|
||||||
--- 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