Stop 2164 and 2103 about 'cd foo || exit' from overlapping.
This commit is contained in:
parent
f653362b18
commit
54b2d14847
|
@ -85,7 +85,7 @@ checksFor Bash = [
|
||||||
|
|
||||||
runAnalytics :: AnalysisSpec -> AnalysisResult
|
runAnalytics :: AnalysisSpec -> AnalysisResult
|
||||||
runAnalytics options = AnalysisResult {
|
runAnalytics options = AnalysisResult {
|
||||||
arComments =
|
arComments =
|
||||||
nub . filterByAnnotation (asScript options) $
|
nub . filterByAnnotation (asScript options) $
|
||||||
runList options treeChecks
|
runList options treeChecks
|
||||||
}
|
}
|
||||||
|
@ -3014,12 +3014,9 @@ checkCdAndBack params = doLists
|
||||||
doList list =
|
doList list =
|
||||||
let cds = filter ((== Just "cd") . getCmd) list in
|
let cds = filter ((== Just "cd") . getCmd) list in
|
||||||
when (length cds >= 2 && isCdRevert (last cds)) $
|
when (length cds >= 2 && isCdRevert (last cds)) $
|
||||||
warn (getId $ head cds) 2103 message
|
info (getId $ last cds) 2103 message
|
||||||
|
|
||||||
message =
|
message = "Use a ( subshell ) to avoid having to cd back."
|
||||||
if shell == Bash
|
|
||||||
then "Consider using ( subshell ), 'cd foo||exit', or pushd/popd instead."
|
|
||||||
else "Consider using ( subshell ) or 'cd foo||exit' instead."
|
|
||||||
|
|
||||||
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"
|
||||||
|
@ -3545,13 +3542,17 @@ prop_checkUncheckedCd2 = verifyNotTree checkUncheckedCd "cd ~/src || exit; rm -r
|
||||||
prop_checkUncheckedCd3 = verifyNotTree checkUncheckedCd "set -e; cd ~/src; rm -r foo"
|
prop_checkUncheckedCd3 = verifyNotTree checkUncheckedCd "set -e; cd ~/src; rm -r foo"
|
||||||
prop_checkUncheckedCd4 = verifyNotTree checkUncheckedCd "if cd foo; then rm foo; fi"
|
prop_checkUncheckedCd4 = verifyNotTree checkUncheckedCd "if cd foo; then rm foo; fi"
|
||||||
prop_checkUncheckedCd5 = verifyTree checkUncheckedCd "if true; then cd foo; fi"
|
prop_checkUncheckedCd5 = verifyTree checkUncheckedCd "if true; then cd foo; fi"
|
||||||
|
prop_checkUncheckedCd6 = verifyNotTree checkUncheckedCd "cd .."
|
||||||
checkUncheckedCd params root =
|
checkUncheckedCd params root =
|
||||||
if hasSetE then [] else execWriter $ doAnalysis checkElement root
|
if hasSetE then [] else execWriter $ doAnalysis checkElement root
|
||||||
where
|
where
|
||||||
checkElement t@(T_SimpleCommand {}) =
|
checkElement t@(T_SimpleCommand {}) =
|
||||||
when(t `isUnqualifiedCommand` "cd" && not (isCondition $ getPath (parentMap params) t)) $
|
when(t `isUnqualifiedCommand` "cd"
|
||||||
warn (getId t) 2164 "Use cd ... || exit in case cd fails."
|
&& not (isCdDotDot t)
|
||||||
|
&& not (isCondition $ getPath (parentMap params) t)) $
|
||||||
|
warn (getId t) 2164 "Use cd ... || exit in case cd fails."
|
||||||
checkElement _ = return ()
|
checkElement _ = return ()
|
||||||
|
isCdDotDot t = deadSimple t == ["cd", ".."]
|
||||||
hasSetE = isNothing $ doAnalysis (guard . not . isSetE) root
|
hasSetE = isNothing $ doAnalysis (guard . not . isSetE) root
|
||||||
isSetE t =
|
isSetE t =
|
||||||
case t of
|
case t of
|
||||||
|
|
Loading…
Reference in New Issue