Allow SC2103 to be silenced (fixes #1591)
This commit is contained in:
parent
3116ed3ae5
commit
eeb7ea01c9
|
@ -2343,27 +2343,18 @@ prop_checkCdAndBack4 = verify checkCdAndBack "cd $tmp; foo; cd -"
|
||||||
prop_checkCdAndBack5 = verifyNot checkCdAndBack "cd ..; foo; cd .."
|
prop_checkCdAndBack5 = verifyNot checkCdAndBack "cd ..; foo; cd .."
|
||||||
prop_checkCdAndBack6 = verify checkCdAndBack "for dir in */; do cd \"$dir\"; some_cmd; cd ..; done"
|
prop_checkCdAndBack6 = verify checkCdAndBack "for dir in */; do cd \"$dir\"; some_cmd; cd ..; done"
|
||||||
prop_checkCdAndBack7 = verifyNot checkCdAndBack "set -e; for dir in */; do cd \"$dir\"; some_cmd; cd ..; done"
|
prop_checkCdAndBack7 = verifyNot checkCdAndBack "set -e; for dir in */; do cd \"$dir\"; some_cmd; cd ..; done"
|
||||||
checkCdAndBack params = doLists
|
prop_checkCdAndBack8 = verifyNot checkCdAndBack "cd tmp\nfoo\n# shellcheck disable=SC2103\ncd ..\n"
|
||||||
|
checkCdAndBack params t =
|
||||||
|
unless (hasSetE params) $ mapM_ doList $ getCommandSequences t
|
||||||
where
|
where
|
||||||
shell = shellType params
|
|
||||||
doLists (T_ForIn _ _ _ cmds) = doList cmds
|
|
||||||
doLists (T_ForArithmetic _ _ _ _ cmds) = doList cmds
|
|
||||||
doLists (T_WhileExpression _ _ cmds) = doList cmds
|
|
||||||
doLists (T_UntilExpression _ _ cmds) = doList cmds
|
|
||||||
doLists (T_Script _ _ cmds) = doList cmds
|
|
||||||
doLists (T_IfExpression _ thens elses) = do
|
|
||||||
mapM_ (\(_, l) -> doList l) thens
|
|
||||||
doList elses
|
|
||||||
doLists _ = return ()
|
|
||||||
|
|
||||||
isCdRevert t =
|
isCdRevert t =
|
||||||
case oversimplify t of
|
case oversimplify t of
|
||||||
["cd", p] -> p `elem` ["..", "-"]
|
[_, p] -> p `elem` ["..", "-"]
|
||||||
_ -> False
|
_ -> False
|
||||||
|
|
||||||
getCmd (T_Annotation id _ x) = getCmd x
|
getCandidate (T_Annotation _ _ x) = getCandidate x
|
||||||
getCmd (T_Pipeline id _ [x]) = getCommandName x
|
getCandidate (T_Pipeline id _ [x]) | x `isCommand` "cd" = return x
|
||||||
getCmd _ = Nothing
|
getCandidate _ = Nothing
|
||||||
|
|
||||||
findCdPair list =
|
findCdPair list =
|
||||||
case list of
|
case list of
|
||||||
|
@ -2373,13 +2364,9 @@ checkCdAndBack params = doLists
|
||||||
else findCdPair (b:rest)
|
else findCdPair (b:rest)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
doList list =
|
doList list = potentially $ do
|
||||||
if hasSetE params
|
cd <- findCdPair $ mapMaybe getCandidate list
|
||||||
then return ()
|
return $ info cd 2103 "Use a ( subshell ) to avoid having to cd back."
|
||||||
else let cds = filter ((== Just "cd") . getCmd) list
|
|
||||||
in potentially $ do
|
|
||||||
cd <- findCdPair cds
|
|
||||||
return $ info cd 2103 "Use a ( subshell ) to avoid having to cd back."
|
|
||||||
|
|
||||||
prop_checkLoopKeywordScope1 = verify checkLoopKeywordScope "continue 2"
|
prop_checkLoopKeywordScope1 = verify checkLoopKeywordScope "continue 2"
|
||||||
prop_checkLoopKeywordScope2 = verify checkLoopKeywordScope "for f; do ( break; ); done"
|
prop_checkLoopKeywordScope2 = verify checkLoopKeywordScope "for f; do ( break; ); done"
|
||||||
|
|
Loading…
Reference in New Issue