mirror of
				https://github.com/koalaman/shellcheck.git
				synced 2025-10-31 06:29:20 +08:00 
			
		
		
		
	Update getFlag function to also return non-flags.
This commit is contained in:
		| @@ -93,14 +93,17 @@ oversimplify token = | ||||
|  | ||||
|  | ||||
| -- Turn a SimpleCommand foo -avz --bar=baz into args "a", "v", "z", "bar", | ||||
| -- each in a tuple of (token, stringFlag). | ||||
| -- each in a tuple of (token, stringFlag). Non-flag arguments are added with | ||||
| -- stringFlag == "". | ||||
| getFlagsUntil stopCondition (T_SimpleCommand _ _ (_:args)) = | ||||
|     let textArgs = takeWhile (not . stopCondition . snd) $ map (\x -> (x, concat $ oversimplify x)) args in | ||||
|         concatMap flag textArgs | ||||
|     let tokenAndText = map (\x -> (x, concat $ oversimplify x)) args | ||||
|         (flagArgs, rest) = break (stopCondition . snd) tokenAndText | ||||
|     in | ||||
|         concatMap flag flagArgs ++ map (\(t, _) -> (t, "")) rest | ||||
|   where | ||||
|     flag (x, '-':'-':arg) = [ (x, takeWhile (/= '=') arg) ] | ||||
|     flag (x, '-':args) = map (\v -> (x, [v])) args | ||||
|     flag _ = [] | ||||
|     flag (x, _) = [ (x, "") ] | ||||
| getFlagsUntil _ _ = error "Internal shellcheck error, please report! (getFlags on non-command)" | ||||
|  | ||||
| -- Get all flags in a GNU way, up until -- | ||||
|   | ||||
| @@ -689,7 +689,8 @@ checkBashisms params = bashism | ||||
|                 warnMsg id $ "'" ++ name ++ "' is" | ||||
|             potentially $ do | ||||
|                 allowed <- Map.lookup name allowedFlags | ||||
|                 (word, flag) <- listToMaybe $ filter (\x -> snd x `notElem` allowed) flags | ||||
|                 (word, flag) <- listToMaybe $ | ||||
|                     filter (\x -> (not . null . snd $ x) && snd x `notElem` allowed) flags | ||||
|                 return . warnMsg (getId word) $ name ++ " -" ++ flag ++ " is" | ||||
|  | ||||
|             when (name == "source") $ warnMsg id "'source' in place of '.' is" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user