mirror of
				https://github.com/koalaman/shellcheck.git
				synced 2025-10-26 02:29:26 +08:00 
			
		
		
		
	Use maybe instead of fromMaybe and fmap
This commit is contained in:
		| @@ -409,7 +409,7 @@ prop_checkArithmeticOpCommand1 = verify checkArithmeticOpCommand "i=i + 1" | |||||||
| prop_checkArithmeticOpCommand2 = verify checkArithmeticOpCommand "foo=bar * 2" | prop_checkArithmeticOpCommand2 = verify checkArithmeticOpCommand "foo=bar * 2" | ||||||
| prop_checkArithmeticOpCommand3 = verifyNot checkArithmeticOpCommand "foo + opts" | prop_checkArithmeticOpCommand3 = verifyNot checkArithmeticOpCommand "foo + opts" | ||||||
| checkArithmeticOpCommand _ (T_SimpleCommand id [T_Assignment {}] (firstWord:_)) = | checkArithmeticOpCommand _ (T_SimpleCommand id [T_Assignment {}] (firstWord:_)) = | ||||||
|     fromMaybe (return ()) $ check <$> getGlobOrLiteralString firstWord |     maybe (return ()) check $ getGlobOrLiteralString firstWord | ||||||
|   where |   where | ||||||
|     check op = |     check op = | ||||||
|         when (op `elem` ["+", "-", "*", "/"]) $ |         when (op `elem` ["+", "-", "*", "/"]) $ | ||||||
| @@ -493,8 +493,8 @@ checkPipePitfalls _ (T_Pipeline id _ commands) = do | |||||||
|  |  | ||||||
|     for ["grep", "wc"] $ |     for ["grep", "wc"] $ | ||||||
|         \(grep:wc:_) -> |         \(grep:wc:_) -> | ||||||
|             let flagsGrep = fromMaybe [] $ map snd . getAllFlags <$> getCommand grep |             let flagsGrep = maybe [] (map snd . getAllFlags) $ getCommand grep | ||||||
|                 flagsWc = fromMaybe [] $ map snd . getAllFlags <$> getCommand wc |                 flagsWc = maybe [] (map snd . getAllFlags) $ getCommand wc | ||||||
|             in |             in | ||||||
|                 unless (any (`elem` ["o", "only-matching", "r", "R", "recursive"]) flagsGrep || any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc || null flagsWc) $ |                 unless (any (`elem` ["o", "only-matching", "r", "R", "recursive"]) flagsGrep || any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc || null flagsWc) $ | ||||||
|                     style (getId grep) 2126 "Consider using grep -c instead of grep|wc -l." |                     style (getId grep) 2126 "Consider using grep -c instead of grep|wc -l." | ||||||
| @@ -3140,9 +3140,9 @@ checkSubshellAsTest _ t = | |||||||
|  |  | ||||||
|  |  | ||||||
|     checkParams id first second = do |     checkParams id first second = do | ||||||
|         when (fromMaybe False $ (`elem` unaryTestOps) <$> getLiteralString first) $ |         when (maybe False (`elem` unaryTestOps) $ getLiteralString first) $ | ||||||
|             err id 2204 "(..) is a subshell. Did you mean [ .. ], a test expression?" |             err id 2204 "(..) is a subshell. Did you mean [ .. ], a test expression?" | ||||||
|         when (fromMaybe False $ (`elem` binaryTestOps) <$> getLiteralString second) $ |         when (maybe False (`elem` binaryTestOps) $ getLiteralString second) $ | ||||||
|             warn id 2205 "(..) is a subshell. Did you mean [ .. ], a test expression?" |             warn id 2205 "(..) is a subshell. Did you mean [ .. ], a test expression?" | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -784,8 +784,8 @@ isCommand token str = isCommandMatch token (\cmd -> cmd  == str || ('/' : str) ` | |||||||
| -- Compare a command to a literal. Like above, but checks full path. | -- Compare a command to a literal. Like above, but checks full path. | ||||||
| isUnqualifiedCommand token str = isCommandMatch token (== str) | isUnqualifiedCommand token str = isCommandMatch token (== str) | ||||||
|  |  | ||||||
| isCommandMatch token matcher = fromMaybe False $ | isCommandMatch token matcher = maybe False | ||||||
|     fmap matcher (getCommandName token) |     matcher (getCommandName token) | ||||||
|  |  | ||||||
| -- Does this regex look like it was intended as a glob? | -- Does this regex look like it was intended as a glob? | ||||||
| -- True:  *foo* | -- True:  *foo* | ||||||
|   | |||||||
| @@ -88,9 +88,9 @@ checkScript sys spec = do | |||||||
|                     asOptionalChecks = csOptionalChecks spec |                     asOptionalChecks = csOptionalChecks spec | ||||||
|                 } where as = newAnalysisSpec root |                 } where as = newAnalysisSpec root | ||||||
|         let analysisMessages = |         let analysisMessages = | ||||||
|                 fromMaybe [] $ |                 maybe [] | ||||||
|                     (arComments . analyzeScript . analysisSpec) |                     (arComments . analyzeScript . analysisSpec) | ||||||
|                         <$> prRoot result |                         $ prRoot result | ||||||
|         let translator = tokenToPosition tokenPositions |         let translator = tokenToPosition tokenPositions | ||||||
|         return . nub . sortMessages . filter shouldInclude $ |         return . nub . sortMessages . filter shouldInclude $ | ||||||
|             (parseMessages ++ map translator analysisMessages) |             (parseMessages ++ map translator analysisMessages) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user