Don't warn when single quoting PROMPT_COMMAND and PS1

This commit is contained in:
Vidar Holen 2014-04-05 17:08:03 -07:00
parent f549aad809
commit 81956d324d
1 changed files with 10 additions and 1 deletions

View File

@ -879,6 +879,7 @@ prop_checkSingleQuotedVariables4 = verifyNot checkSingleQuotedVariables "awk '{p
prop_checkSingleQuotedVariables5 = verifyNot checkSingleQuotedVariables "trap 'echo $SECONDS' EXIT" prop_checkSingleQuotedVariables5 = verifyNot checkSingleQuotedVariables "trap 'echo $SECONDS' EXIT"
prop_checkSingleQuotedVariables6 = verifyNot checkSingleQuotedVariables "sed -n '$p'" prop_checkSingleQuotedVariables6 = verifyNot checkSingleQuotedVariables "sed -n '$p'"
prop_checkSingleQuotedVariables6a= verify checkSingleQuotedVariables "sed -n '$pattern'" prop_checkSingleQuotedVariables6a= verify checkSingleQuotedVariables "sed -n '$pattern'"
prop_checkSingleQuotedVariables7 = verifyNot checkSingleQuotedVariables "PS1='$PWD \\$ '"
checkSingleQuotedVariables params t@(T_SingleQuoted id s) = checkSingleQuotedVariables params t@(T_SingleQuoted id s) =
when (s `matches` re) $ when (s `matches` re) $
if "sed" == commandName if "sed" == commandName
@ -893,7 +894,9 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) =
name <- getCommandBasename cmd name <- getCommandBasename cmd
return name return name
isProbablyOk = commandName `elem` [ isProbablyOk =
(any isOkAssignment $ take 3 $ getPath parents t)
|| commandName `elem` [
"trap" "trap"
,"sh" ,"sh"
,"bash" ,"bash"
@ -905,6 +908,12 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) =
|| "awk" `isSuffixOf` commandName || "awk" `isSuffixOf` commandName
|| "perl" `isPrefixOf` commandName || "perl" `isPrefixOf` commandName
commonlyQuoted = ["PS1", "PS2", "PS3", "PS4", "PROMPT_COMMAND"]
isOkAssignment t =
case t of
T_Assignment _ _ name _ _ -> name `elem` commonlyQuoted
otherwise -> False
re = mkRegex "\\$[{(0-9a-zA-Z_]" re = mkRegex "\\$[{(0-9a-zA-Z_]"
sedContra = mkRegex "\\$[dp]($|[^a-zA-Z])" sedContra = mkRegex "\\$[dp]($|[^a-zA-Z])"
checkSingleQuotedVariables _ _ = return () checkSingleQuotedVariables _ _ = return ()