From 81956d324deb43ad5d378b352ab2e293a92d4c3e Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 5 Apr 2014 17:08:03 -0700 Subject: [PATCH] Don't warn when single quoting PROMPT_COMMAND and PS1 --- ShellCheck/Analytics.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 16afe21..fdea482 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -879,6 +879,7 @@ prop_checkSingleQuotedVariables4 = verifyNot checkSingleQuotedVariables "awk '{p prop_checkSingleQuotedVariables5 = verifyNot checkSingleQuotedVariables "trap 'echo $SECONDS' EXIT" prop_checkSingleQuotedVariables6 = verifyNot checkSingleQuotedVariables "sed -n '$p'" prop_checkSingleQuotedVariables6a= verify checkSingleQuotedVariables "sed -n '$pattern'" +prop_checkSingleQuotedVariables7 = verifyNot checkSingleQuotedVariables "PS1='$PWD \\$ '" checkSingleQuotedVariables params t@(T_SingleQuoted id s) = when (s `matches` re) $ if "sed" == commandName @@ -893,7 +894,9 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) = name <- getCommandBasename cmd return name - isProbablyOk = commandName `elem` [ + isProbablyOk = + (any isOkAssignment $ take 3 $ getPath parents t) + || commandName `elem` [ "trap" ,"sh" ,"bash" @@ -905,6 +908,12 @@ checkSingleQuotedVariables params t@(T_SingleQuoted id s) = || "awk" `isSuffixOf` 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_]" sedContra = mkRegex "\\$[dp]($|[^a-zA-Z])" checkSingleQuotedVariables _ _ = return ()