Warn about flipped $ and " in $"(cmd)" (fixes #1517)
This commit is contained in:
parent
c53c8a5ead
commit
f514f5f735
|
@ -3,6 +3,7 @@
|
|||
- Preliminary support for fix suggestions
|
||||
- Files containing Bats tests can now be checked
|
||||
- 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 /
|
||||
- SC2245: Warn that Ksh ignores all but the first glob result in `[`
|
||||
- SC2243/SC2244: Suggest using explicit -n for `[ $foo ]`
|
||||
|
|
|
@ -171,6 +171,7 @@ nodeChecks = [
|
|||
,checkInvertedStringTest
|
||||
,checkRedirectionToCommand
|
||||
,checkNullaryExpansionTest
|
||||
,checkDollarQuoteParen
|
||||
]
|
||||
|
||||
|
||||
|
@ -3169,5 +3170,18 @@ checkNullaryExpansionTest params t =
|
|||
fix = fixWith [replaceStart id params 0 "-n "]
|
||||
_ -> 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 []
|
||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||
|
|
Loading…
Reference in New Issue