mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-29 19:19:10 -07:00
Improved bad indirection detection
This commit is contained in:
parent
73c6202842
commit
a20a3499ed
1 changed files with 19 additions and 9 deletions
|
@ -1096,16 +1096,26 @@ checkBackticks _ = return ()
|
||||||
|
|
||||||
prop_checkIndirectExpansion1 = verify checkIndirectExpansion "${foo$n}"
|
prop_checkIndirectExpansion1 = verify checkIndirectExpansion "${foo$n}"
|
||||||
prop_checkIndirectExpansion2 = verifyNot checkIndirectExpansion "${foo//$n/lol}"
|
prop_checkIndirectExpansion2 = verifyNot checkIndirectExpansion "${foo//$n/lol}"
|
||||||
checkIndirectExpansion (T_DollarBraced id (T_NormalWord _ ((T_Literal _ s):attempt:_))) =
|
prop_checkIndirectExpansion3 = verify checkIndirectExpansion "${$#}"
|
||||||
case attempt of T_DollarExpansion _ _ -> doit
|
prop_checkIndirectExpansion4 = verify checkIndirectExpansion "${var${n}_$((i%2))}"
|
||||||
T_Backticked _ _ -> doit
|
prop_checkIndirectExpansion5 = verifyNot checkIndirectExpansion "${bar}"
|
||||||
T_DollarBraced _ _ -> doit
|
checkIndirectExpansion (T_DollarBraced i (T_NormalWord _ contents)) =
|
||||||
T_DollarArithmetic _ _ -> doit
|
when (isIndirection contents) $
|
||||||
_ -> return ()
|
err i "To expand via indirection, use name=\"foo$n\"; echo \"${!name}\"."
|
||||||
where
|
where
|
||||||
doit = if all isVariableChar s
|
isIndirection vars =
|
||||||
then err id "To expand via indirection, use name=\"foo$n\"; echo \"${!name}\""
|
let list = catMaybes (map isIndirectionPart vars) in
|
||||||
else return ()
|
not (null list) && all id list
|
||||||
|
isIndirectionPart t =
|
||||||
|
case t of T_DollarExpansion _ _ -> Just True
|
||||||
|
T_Backticked _ _ -> Just True
|
||||||
|
T_DollarBraced _ _ -> Just True
|
||||||
|
T_DollarArithmetic _ _ -> Just True
|
||||||
|
T_Literal _ s -> if all isVariableChar s
|
||||||
|
then Nothing
|
||||||
|
else Just False
|
||||||
|
_ -> Just False
|
||||||
|
|
||||||
checkIndirectExpansion _ = return ()
|
checkIndirectExpansion _ = return ()
|
||||||
|
|
||||||
prop_checkInexplicablyUnquoted1 = verify checkInexplicablyUnquoted "echo 'var='value';'"
|
prop_checkInexplicablyUnquoted1 = verify checkInexplicablyUnquoted "echo 'var='value';'"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue