mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-16 10:03:08 -07:00
SC2324: Warn when x+=1 appends.
This commit is contained in:
parent
c9e27c2470
commit
372c0b667e
4 changed files with 64 additions and 0 deletions
|
@ -59,6 +59,8 @@ module ShellCheck.CFGAnalysis (
|
|||
,getIncomingState
|
||||
,getOutgoingState
|
||||
,doesPostDominate
|
||||
,variableMayBeDeclaredInteger
|
||||
,variableMayBeAssignedInteger
|
||||
,ShellCheck.CFGAnalysis.runTests -- STRIP
|
||||
) where
|
||||
|
||||
|
@ -153,6 +155,20 @@ doesPostDominate analysis target base = fromMaybe False $ do
|
|||
(targetStart, _) <- M.lookup target $ tokenToRange analysis
|
||||
return $ targetStart `elem` (postDominators analysis ! baseEnd)
|
||||
|
||||
-- See if any execution path results in the variable containing a state
|
||||
variableMayHaveState :: ProgramState -> String -> CFVariableProp -> Maybe Bool
|
||||
variableMayHaveState state var property = do
|
||||
value <- M.lookup var $ variablesInScope state
|
||||
return $ any (S.member property) $ variableProperties value
|
||||
|
||||
-- See if any execution path declares the variable an integer (declare -i).
|
||||
variableMayBeDeclaredInteger state var = variableMayHaveState state var CFVPInteger
|
||||
|
||||
-- See if any execution path suggests the variable may contain an integer value
|
||||
variableMayBeAssignedInteger state var = do
|
||||
value <- M.lookup var $ variablesInScope state
|
||||
return $ (numericalStatus $ variableValue value) >= NumericalStatusMaybe
|
||||
|
||||
getDataForNode analysis node = M.lookup node $ nodeToData analysis
|
||||
|
||||
-- The current state of data flow at a point in the program, potentially as a diff
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue