Simplify checkVariableBraces

This commit is contained in:
Joseph C. Sible 2020-04-05 17:07:05 -04:00
parent 1eac0d7340
commit 8a7497c4f0
1 changed files with 6 additions and 9 deletions

View File

@ -1955,19 +1955,16 @@ prop_CheckVariableBraces1 = verify checkVariableBraces "a='123'; echo $a"
prop_CheckVariableBraces2 = verifyNot checkVariableBraces "a='123'; echo ${a}"
prop_CheckVariableBraces3 = verifyNot checkVariableBraces "#shellcheck disable=SC2016\necho '$a'"
prop_CheckVariableBraces4 = verifyNot checkVariableBraces "echo $* $1"
checkVariableBraces params t =
case t of
T_DollarBraced id False _
| name `notElem` unbracedVariables ->
checkVariableBraces params t@(T_DollarBraced id False _)
| name `notElem` unbracedVariables =
styleWithFix id 2250
"Prefer putting braces around variable references even when not strictly required."
(fixFor t)
_ -> return ()
where
name = getBracedReference $ bracedString t
fixFor token = fixWith [replaceStart (getId token) params 1 "${"
,replaceEnd (getId token) params 0 "}"]
checkVariableBraces _ _ = return ()
prop_checkQuotesInLiterals1 = verifyTree checkQuotesInLiterals "param='--foo=\"bar\"'; app $param"
prop_checkQuotesInLiterals1a= verifyTree checkQuotesInLiterals "param=\"--foo='lolbar'\"; app $param"