Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/ShellCheck/Analytics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ optionalTreeChecks = [
cdNegative = "[[ -e /etc/issue ]]"
}, checkRequireDoubleBracket)

,(newCheckDescription {
cdName = "require-double-equals",
cdDescription = "Require == and warn about = in Bash tests",
cdPositive = "[[ \"$x\" = \"$y\" ]]",
cdNegative = "[[ \"$x\" == \"$y\" ]]"
}, checkRequireDoubleEquals)

,(newCheckDescription {
cdName = "check-set-e-suppressed",
cdDescription = "Notify when set -e is suppressed during function invocation",
Expand Down Expand Up @@ -4718,6 +4725,22 @@ checkRequireDoubleBracket params =
_ -> False


prop_checkRequireDoubleEquals1 = verifyTree checkRequireDoubleEquals "[[ \"$x\" = \"$y\" ]]"
prop_checkRequireDoubleEquals2 = verifyTree checkRequireDoubleEquals "[ \"$x\" = \"$y\" ]"
prop_checkRequireDoubleEquals3 = verifyNotTree checkRequireDoubleEquals "[[ \"$x\" == \"$y\" ]]"
prop_checkRequireDoubleEquals4 = verifyNotTree checkRequireDoubleEquals "#!/bin/sh\n[ \"$x\" = \"$y\" ]"
prop_checkRequireDoubleEquals5 = verifyNotTree checkRequireDoubleEquals "#!/bin/ksh\n[[ \"$x\" = \"$y\" ]]"
checkRequireDoubleEquals params =
if shellType params == Bash
then nodeChecksToTreeCheck [check] params
else const []
where
check _ t = case t of
TC_Binary id _ "=" _ _ ->
style id 2337 "Prefer == over = for string comparisons in Bash tests."
_ -> return ()


prop_checkUnquotedParameterExpansionPattern1 = verify checkUnquotedParameterExpansionPattern "echo \"${var#$x}\""
prop_checkUnquotedParameterExpansionPattern2 = verify checkUnquotedParameterExpansionPattern "echo \"${var%%$(x)}\""
prop_checkUnquotedParameterExpansionPattern3 = verifyNot checkUnquotedParameterExpansionPattern "echo \"${var[#$x]}\""
Expand Down
Loading