mirror of
				https://github.com/koalaman/shellcheck.git
				synced 2025-10-31 22:52:50 +08:00 
			
		
		
		
	Try to parse the inside of traps (fixes #2584)
This commit is contained in:
		| @@ -2112,6 +2112,7 @@ prop_readSimpleCommand11 = isOk readSimpleCommand "/\\* foo" | |||||||
| prop_readSimpleCommand12 = isWarning readSimpleCommand "elsif foo" | prop_readSimpleCommand12 = isWarning readSimpleCommand "elsif foo" | ||||||
| prop_readSimpleCommand13 = isWarning readSimpleCommand "ElseIf foo" | prop_readSimpleCommand13 = isWarning readSimpleCommand "ElseIf foo" | ||||||
| prop_readSimpleCommand14 = isWarning readSimpleCommand "elseif[$i==2]" | prop_readSimpleCommand14 = isWarning readSimpleCommand "elseif[$i==2]" | ||||||
|  | prop_readSimpleCommand15 = isWarning readSimpleCommand "trap 'foo\"bar' INT" | ||||||
| readSimpleCommand = called "simple command" $ do | readSimpleCommand = called "simple command" $ do | ||||||
|     prefix <- option [] readCmdPrefix |     prefix <- option [] readCmdPrefix | ||||||
|     skipAnnotationAndWarn |     skipAnnotationAndWarn | ||||||
| @@ -2141,9 +2142,12 @@ readSimpleCommand = called "simple command" $ do | |||||||
|             id2 <- getNewIdFor id1 |             id2 <- getNewIdFor id1 | ||||||
|  |  | ||||||
|             let result = makeSimpleCommand id1 id2 prefix [cmd] suffix |             let result = makeSimpleCommand id1 id2 prefix [cmd] suffix | ||||||
|             if isCommand ["source", "."] cmd |             case () of | ||||||
|                 then readSource result |                 _ | isCommand ["source", "."] cmd -> readSource result | ||||||
|                 else return result |                 _ | isCommand ["trap"] cmd -> do | ||||||
|  |                         syntaxCheckTrap result | ||||||
|  |                         return result | ||||||
|  |                 _ -> return result | ||||||
|   where |   where | ||||||
|     isCommand strings (T_NormalWord _ [T_Literal _ s]) = s `elem` strings |     isCommand strings (T_NormalWord _ [T_Literal _ s]) = s `elem` strings | ||||||
|     isCommand _ _ = False |     isCommand _ _ = False | ||||||
| @@ -2163,6 +2167,17 @@ readSimpleCommand = called "simple command" $ do | |||||||
|                     parseProblemAtId (getId cmd) ErrorC 1131 "Use 'elif' to start another branch." |                     parseProblemAtId (getId cmd) ErrorC 1131 "Use 'elif' to start another branch." | ||||||
|             _ -> return () |             _ -> return () | ||||||
|  |  | ||||||
|  |     syntaxCheckTrap cmd = | ||||||
|  |         case cmd of | ||||||
|  |             (T_Redirecting _ _ (T_SimpleCommand _ _ (cmd:arg:_))) -> checkArg arg (getLiteralString arg) | ||||||
|  |             _ -> return () | ||||||
|  |       where | ||||||
|  |         checkArg _ Nothing = return () | ||||||
|  |         checkArg arg (Just ('-':_)) = return () | ||||||
|  |         checkArg arg (Just str) = do | ||||||
|  |             (start,end) <- getSpanForId (getId arg) | ||||||
|  |             subParse start (tryWithErrors (readCompoundListOrEmpty >> verifyEof) <|> return ()) str | ||||||
|  |  | ||||||
|     commentWarning id = |     commentWarning id = | ||||||
|         parseProblemAtId id ErrorC 1127 "Was this intended as a comment? Use # in sh." |         parseProblemAtId id ErrorC 1127 "Was this intended as a comment? Use # in sh." | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user