Merge branch 'sc2093-exec-in-loops' of https://github.com/jabberabbe/shellcheck
This commit is contained in:
commit
9c42d43e90
|
@ -1474,17 +1474,18 @@ prop_checkSpuriousExec5 = verifyNot checkSpuriousExec "exec > file; cmd"
|
||||||
prop_checkSpuriousExec6 = verify checkSpuriousExec "exec foo > file; cmd"
|
prop_checkSpuriousExec6 = verify checkSpuriousExec "exec foo > file; cmd"
|
||||||
prop_checkSpuriousExec7 = verifyNot checkSpuriousExec "exec file; echo failed; exit 3"
|
prop_checkSpuriousExec7 = verifyNot checkSpuriousExec "exec file; echo failed; exit 3"
|
||||||
prop_checkSpuriousExec8 = verifyNot checkSpuriousExec "exec {origout}>&1- >tmp.log 2>&1; bar"
|
prop_checkSpuriousExec8 = verifyNot checkSpuriousExec "exec {origout}>&1- >tmp.log 2>&1; bar"
|
||||||
|
prop_checkSpuriousExec9 = verify checkSpuriousExec "for file in rc.d/*; do exec \"$file\"; done"
|
||||||
checkSpuriousExec _ = doLists
|
checkSpuriousExec _ = doLists
|
||||||
where
|
where
|
||||||
doLists (T_Script _ _ cmds) = doList cmds
|
doLists (T_Script _ _ cmds) = doList cmds False
|
||||||
doLists (T_BraceGroup _ cmds) = doList cmds
|
doLists (T_BraceGroup _ cmds) = doList cmds False
|
||||||
doLists (T_WhileExpression _ _ cmds) = doList cmds
|
doLists (T_WhileExpression _ _ cmds) = doList cmds True
|
||||||
doLists (T_UntilExpression _ _ cmds) = doList cmds
|
doLists (T_UntilExpression _ _ cmds) = doList cmds True
|
||||||
doLists (T_ForIn _ _ _ cmds) = doList cmds
|
doLists (T_ForIn _ _ _ cmds) = doList cmds True
|
||||||
doLists (T_ForArithmetic _ _ _ _ cmds) = doList cmds
|
doLists (T_ForArithmetic _ _ _ _ cmds) = doList cmds True
|
||||||
doLists (T_IfExpression _ thens elses) = do
|
doLists (T_IfExpression _ thens elses) = do
|
||||||
mapM_ (\(_, l) -> doList l) thens
|
mapM_ (\(_, l) -> doList l False) thens
|
||||||
doList elses
|
doList elses False
|
||||||
doLists _ = return ()
|
doLists _ = return ()
|
||||||
|
|
||||||
stripCleanup = reverse . dropWhile cleanup . reverse
|
stripCleanup = reverse . dropWhile cleanup . reverse
|
||||||
|
@ -1493,10 +1494,15 @@ checkSpuriousExec _ = doLists
|
||||||
cleanup _ = False
|
cleanup _ = False
|
||||||
|
|
||||||
doList = doList' . stripCleanup
|
doList = doList' . stripCleanup
|
||||||
doList' t@(current:following:_) = do
|
-- The second parameter is True if we are in a loop
|
||||||
|
-- In that case we should emit the warning also if `exec' is the last statement
|
||||||
|
doList' t@(current:following:_) False = do
|
||||||
commentIfExec current
|
commentIfExec current
|
||||||
doList (tail t)
|
doList (tail t) False
|
||||||
doList' _ = return ()
|
doList' (current:tail) True = do
|
||||||
|
commentIfExec current
|
||||||
|
doList tail True
|
||||||
|
doList' _ _ = return ()
|
||||||
|
|
||||||
commentIfExec (T_Pipeline id _ list) =
|
commentIfExec (T_Pipeline id _ list) =
|
||||||
mapM_ commentIfExec $ take 1 list
|
mapM_ commentIfExec $ take 1 list
|
||||||
|
|
Loading…
Reference in New Issue