Added error for ${foo$n}
This commit is contained in:
parent
7ae5351de3
commit
e8a0fe09bf
|
@ -83,6 +83,7 @@ basicChecks = [
|
||||||
,checkGlobbedRegex
|
,checkGlobbedRegex
|
||||||
,checkTrapQuotes
|
,checkTrapQuotes
|
||||||
,checkTestRedirects
|
,checkTestRedirects
|
||||||
|
,checkIndirectExpansion
|
||||||
]
|
]
|
||||||
treeChecks = [
|
treeChecks = [
|
||||||
checkUnquotedExpansions
|
checkUnquotedExpansions
|
||||||
|
@ -870,6 +871,19 @@ checkTestRedirects (T_Redirecting id redirs@(redir:_) cmd) | cmd `isCommand` "te
|
||||||
warn (getId redir) $ "This is interpretted as a shell file redirection, not a comparison."
|
warn (getId redir) $ "This is interpretted as a shell file redirection, not a comparison."
|
||||||
checkTestRedirects _ = return ()
|
checkTestRedirects _ = return ()
|
||||||
|
|
||||||
|
prop_checkIndirectExpansion1 = verify checkIndirectExpansion "${foo$n}"
|
||||||
|
prop_checkIndirectExpansion2 = verifyNot checkIndirectExpansion "${foo//$n/lol}"
|
||||||
|
checkIndirectExpansion (T_DollarBraced id (T_NormalWord _ ((T_Literal _ s):attempt:_))) =
|
||||||
|
case attempt of T_DollarExpansion _ _ -> doit
|
||||||
|
T_DollarBraced _ _ -> doit
|
||||||
|
T_DollarArithmetic _ _ -> doit
|
||||||
|
_ -> return ()
|
||||||
|
where
|
||||||
|
doit = if all isVariableChar s
|
||||||
|
then err id "To expand via indirection, use name=\"foo$n\"; echo \"${!name}\""
|
||||||
|
else return ()
|
||||||
|
checkIndirectExpansion _ = return ()
|
||||||
|
|
||||||
--- Subshell detection
|
--- Subshell detection
|
||||||
|
|
||||||
prop_subshellAssignmentCheck = verifyFull subshellAssignmentCheck "cat foo | while read bar; do a=$bar; done; echo \"$a\""
|
prop_subshellAssignmentCheck = verifyFull subshellAssignmentCheck "cat foo | while read bar; do a=$bar; done; echo \"$a\""
|
||||||
|
|
Loading…
Reference in New Issue