Warn about flipped $ and " in $"(cmd)" (fixes #1517)

This commit is contained in:
Vidar Holen 2019-03-20 22:10:04 -07:00
parent c53c8a5ead
commit f514f5f735
2 changed files with 15 additions and 0 deletions

View File

@ -3,6 +3,7 @@
- Preliminary support for fix suggestions - Preliminary support for fix suggestions
- Files containing Bats tests can now be checked - Files containing Bats tests can now be checked
- Directory wide directives can now be placed in a `.shellcheckrc` - Directory wide directives can now be placed in a `.shellcheckrc`
- SC2247: Warn about $"(cmd)" and $"{var}"
- SC2246: Warn if a shebang's interpreter ends with / - SC2246: Warn if a shebang's interpreter ends with /
- SC2245: Warn that Ksh ignores all but the first glob result in `[` - SC2245: Warn that Ksh ignores all but the first glob result in `[`
- SC2243/SC2244: Suggest using explicit -n for `[ $foo ]` - SC2243/SC2244: Suggest using explicit -n for `[ $foo ]`

View File

@ -171,6 +171,7 @@ nodeChecks = [
,checkInvertedStringTest ,checkInvertedStringTest
,checkRedirectionToCommand ,checkRedirectionToCommand
,checkNullaryExpansionTest ,checkNullaryExpansionTest
,checkDollarQuoteParen
] ]
@ -3169,5 +3170,18 @@ checkNullaryExpansionTest params t =
fix = fixWith [replaceStart id params 0 "-n "] fix = fixWith [replaceStart id params 0 "-n "]
_ -> return () _ -> return ()
prop_checkDollarQuoteParen1 = verify checkDollarQuoteParen "$\"(foo)\""
prop_checkDollarQuoteParen2 = verify checkDollarQuoteParen "$\"{foo}\""
prop_checkDollarQuoteParen3 = verifyNot checkDollarQuoteParen "\"$(foo)\""
prop_checkDollarQuoteParen4 = verifyNot checkDollarQuoteParen "$\"..\""
checkDollarQuoteParen params t =
case t of
T_DollarDoubleQuoted id ((T_Literal _ (c:_)):_) | c `elem` "({" ->
warnWithFix id 2247 "Flip leading $ and \" if this should be a quoted substitution." (fix id)
_ -> return ()
where
fix id = fixWith [replaceStart id params 2 "\"$"]
return [] return []
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |]) runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])