Merge pull request #1456 from contivero/issue-667

Silence SC2103 when using 'set -e' (fixes #667)
This commit is contained in:
Vidar Holen 2019-01-20 14:54:29 -08:00 committed by GitHub
commit a621eba6d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

@ -2145,6 +2145,8 @@ prop_checkCdAndBack2 = verifyNot checkCdAndBack "for f in *; do cd $f || continu
prop_checkCdAndBack3 = verifyNot checkCdAndBack "while [[ $PWD != / ]]; do cd ..; done" prop_checkCdAndBack3 = verifyNot checkCdAndBack "while [[ $PWD != / ]]; do cd ..; done"
prop_checkCdAndBack4 = verify checkCdAndBack "cd $tmp; foo; cd -" 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_checkCdAndBack7 = verifyNot checkCdAndBack "set -e; for dir in */; do cd \"$dir\"; some_cmd; cd ..; done"
checkCdAndBack params = doLists checkCdAndBack params = doLists
where where
shell = shellType params shell = shellType params
@ -2175,14 +2177,13 @@ checkCdAndBack params = doLists
else findCdPair (b:rest) else findCdPair (b:rest)
_ -> Nothing _ -> Nothing
doList list = doList list =
let cds = filter ((== Just "cd") . getCmd) list in if hasSetE params
potentially $ do then return ()
cd <- findCdPair cds else let cds = filter ((== Just "cd") . getCmd) list
return $ info cd 2103 message in potentially $ do
cd <- findCdPair cds
message = "Use a ( subshell ) to avoid having to cd back." 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"