mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-11 07:36:29 -07:00
Have SC2155 trigger on 'typeset' as well (fixes #2262)
This commit is contained in:
parent
364c33395e
commit
44471b73cc
3 changed files with 63 additions and 31 deletions
|
@ -169,7 +169,6 @@ nodeChecks = [
|
|||
,checkTestArgumentSplitting
|
||||
,checkConcatenatedDollarAt
|
||||
,checkTildeInPath
|
||||
,checkMaskedReturns
|
||||
,checkReadWithoutR
|
||||
,checkLoopVariableReassignment
|
||||
,checkTrailingBracket
|
||||
|
@ -2970,31 +2969,6 @@ checkTestArgumentSplitting params t =
|
|||
err (getId token) 2255 "[ ] does not apply arithmetic evaluation. Evaluate with $((..)) for numbers, or use string comparator for strings."
|
||||
|
||||
|
||||
prop_checkMaskedReturns1 = verify checkMaskedReturns "f() { local a=$(false); }"
|
||||
prop_checkMaskedReturns2 = verify checkMaskedReturns "declare a=$(false)"
|
||||
prop_checkMaskedReturns3 = verify checkMaskedReturns "declare a=\"`false`\""
|
||||
prop_checkMaskedReturns4 = verify checkMaskedReturns "readonly a=$(false)"
|
||||
prop_checkMaskedReturns5 = verify checkMaskedReturns "readonly a=\"`false`\""
|
||||
prop_checkMaskedReturns6 = verifyNot checkMaskedReturns "declare a; a=$(false)"
|
||||
prop_checkMaskedReturns7 = verifyNot checkMaskedReturns "f() { local -r a=$(false); }"
|
||||
prop_checkMaskedReturns8 = verifyNot checkMaskedReturns "a=$(false); readonly a"
|
||||
checkMaskedReturns _ t@(T_SimpleCommand id _ (cmd:rest)) = sequence_ $ do
|
||||
name <- getCommandName t
|
||||
guard $ name `elem` ["declare", "export", "readonly"]
|
||||
|| name == "local" && "r" `notElem` map snd (getAllFlags t)
|
||||
return $ mapM_ checkArgs rest
|
||||
where
|
||||
checkArgs (T_Assignment id _ _ _ word) | any hasReturn $ getWordParts word =
|
||||
warn id 2155 "Declare and assign separately to avoid masking return values."
|
||||
checkArgs _ = return ()
|
||||
|
||||
hasReturn t = case t of
|
||||
T_Backticked {} -> True
|
||||
T_DollarExpansion {} -> True
|
||||
_ -> False
|
||||
checkMaskedReturns _ _ = return ()
|
||||
|
||||
|
||||
prop_checkReadWithoutR1 = verify checkReadWithoutR "read -a foo"
|
||||
prop_checkReadWithoutR2 = verifyNot checkReadWithoutR "read -ar foo"
|
||||
prop_checkReadWithoutR3 = verifyNot checkReadWithoutR "read -t 0"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue