Don't warn about sed '$d' or '$p'

This commit is contained in:
Vidar Holen 2014-01-25 14:54:05 -08:00
parent e9bba2f75a
commit 7ad0110443
1 changed files with 15 additions and 7 deletions

View File

@ -745,15 +745,22 @@ prop_checkSingleQuotedVariables3b= verifyTree checkSingleQuotedVariables "sed 's
prop_checkSingleQuotedVariables3c= verifyTree checkSingleQuotedVariables "sed 's/$((1+foo))/bar/'" prop_checkSingleQuotedVariables3c= verifyTree checkSingleQuotedVariables "sed 's/$((1+foo))/bar/'"
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"
prop_checkSingleQuotedVariables6 = verifyNotTree checkSingleQuotedVariables "sed -n '$p'"
prop_checkSingleQuotedVariables6a= verifyTree checkSingleQuotedVariables "sed -n '$pattern'"
checkSingleQuotedVariables t@(T_SingleQuoted id s) parents = checkSingleQuotedVariables t@(T_SingleQuoted id s) parents =
case matchRegex re s of when (s `matches` re) $
Just [] -> unless (probablyOk t) $ info id 2016 $ "Expressions don't expand in single quotes, use double quotes for that." if "sed" == commandName
_ -> return () then unless (s `matches` sedContra) showMessage
else unless isProbablyOk showMessage
where where
probablyOk t = fromMaybe False $ do showMessage = info id 2016 $
"Expressions don't expand in single quotes, use double quotes for that."
commandName = fromMaybe "" $ do
cmd <- getClosestCommand parents t cmd <- getClosestCommand parents t
name <- getCommandBasename cmd name <- getCommandBasename cmd
return $ name `elem` [ return name
isProbablyOk = commandName `elem` [
"trap" "trap"
,"sh" ,"sh"
,"bash" ,"bash"
@ -761,10 +768,11 @@ checkSingleQuotedVariables t@(T_SingleQuoted id s) parents =
,"zsh" ,"zsh"
,"ssh" ,"ssh"
] ]
|| "awk" `isSuffixOf` name || "awk" `isSuffixOf` commandName
|| "perl" `isPrefixOf` name || "perl" `isPrefixOf` commandName
re = mkRegex "\\$[{(0-9a-zA-Z_]" re = mkRegex "\\$[{(0-9a-zA-Z_]"
sedContra = mkRegex "\\$[dp]($|[^a-zA-Z])"
checkSingleQuotedVariables _ _ = return () checkSingleQuotedVariables _ _ = return ()