mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-08 11:14:25 +08:00
Warn about flipped $ and " in $"(cmd)" (fixes #1517)
This commit is contained in:
@@ -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 }) ) |])
|
||||
|
Reference in New Issue
Block a user