mirror of
				https://github.com/koalaman/shellcheck.git
				synced 2025-10-31 06:29:20 +08:00 
			
		
		
		
	Don't trigger SC2222 for fallthrough case branches (fixes #1044)
This commit is contained in:
		| @@ -5,6 +5,7 @@ | |||||||
| - SC1117 about unknown double-quoted escape sequences has been retired | - SC1117 about unknown double-quoted escape sequences has been retired | ||||||
| ### Fixed | ### Fixed | ||||||
| - SC2021 no longer triggers for equivalence classes like '[=e=]' | - SC2021 no longer triggers for equivalence classes like '[=e=]' | ||||||
|  | - SC2221/SC2222 no longer mistriggers on fall-through case branches | ||||||
|  |  | ||||||
| ## v0.5.0 - 2018-05-31 | ## v0.5.0 - 2018-05-31 | ||||||
| ### Added | ### Added | ||||||
|   | |||||||
| @@ -2686,26 +2686,31 @@ prop_checkUnmatchableCases5 = verify checkUnmatchableCases "case $f in *.txt) tr | |||||||
| prop_checkUnmatchableCases6 = verifyNot checkUnmatchableCases "case $f in ?*) true;; *) false;; esac" | prop_checkUnmatchableCases6 = verifyNot checkUnmatchableCases "case $f in ?*) true;; *) false;; esac" | ||||||
| prop_checkUnmatchableCases7 = verifyNot checkUnmatchableCases "case $f in $(x)) true;; asdf) false;; esac" | prop_checkUnmatchableCases7 = verifyNot checkUnmatchableCases "case $f in $(x)) true;; asdf) false;; esac" | ||||||
| prop_checkUnmatchableCases8 = verify checkUnmatchableCases "case $f in cow) true;; bar|cow) false;; esac" | prop_checkUnmatchableCases8 = verify checkUnmatchableCases "case $f in cow) true;; bar|cow) false;; esac" | ||||||
|  | prop_checkUnmatchableCases9 = verifyNot checkUnmatchableCases "case $f in x) true;;& x) false;; esac" | ||||||
| checkUnmatchableCases _ t = | checkUnmatchableCases _ t = | ||||||
|     case t of |     case t of | ||||||
|         T_CaseExpression _ word list -> do |         T_CaseExpression _ word list -> do | ||||||
|             let patterns = concatMap snd3 list |             -- Check all patterns for whether they can ever match | ||||||
|  |             let allpatterns  = concatMap snd3 list | ||||||
|  |             -- Check only the non-fallthrough branches for shadowing | ||||||
|  |             let breakpatterns = concatMap snd3 $ filter (\x -> fst3 x == CaseBreak) list | ||||||
|  |  | ||||||
|             if isConstant word |             if isConstant word | ||||||
|                 then warn (getId word) 2194 |                 then warn (getId word) 2194 | ||||||
|                         "This word is constant. Did you forget the $ on a variable?" |                         "This word is constant. Did you forget the $ on a variable?" | ||||||
|                 else  potentially $ do |                 else  potentially $ do | ||||||
|                     pg <- wordToPseudoGlob word |                     pg <- wordToPseudoGlob word | ||||||
|                     return $ mapM_ (check pg) patterns |                     return $ mapM_ (check pg) allpatterns | ||||||
|  |  | ||||||
|             let exactGlobs = tupMap wordToExactPseudoGlob patterns |             let exactGlobs = tupMap wordToExactPseudoGlob breakpatterns | ||||||
|             let fuzzyGlobs = tupMap wordToPseudoGlob patterns |             let fuzzyGlobs = tupMap wordToPseudoGlob breakpatterns | ||||||
|             let dominators = zip exactGlobs (tails $ drop 1 fuzzyGlobs) |             let dominators = zip exactGlobs (tails $ drop 1 fuzzyGlobs) | ||||||
|  |  | ||||||
|             mapM_ checkDoms dominators |             mapM_ checkDoms dominators | ||||||
|  |  | ||||||
|         _ -> return () |         _ -> return () | ||||||
|   where |   where | ||||||
|  |     fst3 (x,_,_) = x | ||||||
|     snd3 (_,x,_) = x |     snd3 (_,x,_) = x | ||||||
|     check target candidate = potentially $ do |     check target candidate = potentially $ do | ||||||
|         candidateGlob <- wordToPseudoGlob candidate |         candidateGlob <- wordToPseudoGlob candidate | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user