Update getFlag function to also return non-flags.
This commit is contained in:
parent
ffb9578a98
commit
48fd793581
|
@ -93,14 +93,17 @@ oversimplify token =
|
||||||
|
|
||||||
|
|
||||||
-- Turn a SimpleCommand foo -avz --bar=baz into args "a", "v", "z", "bar",
|
-- 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)) =
|
getFlagsUntil stopCondition (T_SimpleCommand _ _ (_:args)) =
|
||||||
let textArgs = takeWhile (not . stopCondition . snd) $ map (\x -> (x, concat $ oversimplify x)) args in
|
let tokenAndText = map (\x -> (x, concat $ oversimplify x)) args
|
||||||
concatMap flag textArgs
|
(flagArgs, rest) = break (stopCondition . snd) tokenAndText
|
||||||
|
in
|
||||||
|
concatMap flag flagArgs ++ map (\(t, _) -> (t, "")) rest
|
||||||
where
|
where
|
||||||
flag (x, '-':'-':arg) = [ (x, takeWhile (/= '=') arg) ]
|
flag (x, '-':'-':arg) = [ (x, takeWhile (/= '=') arg) ]
|
||||||
flag (x, '-':args) = map (\v -> (x, [v])) args
|
flag (x, '-':args) = map (\v -> (x, [v])) args
|
||||||
flag _ = []
|
flag (x, _) = [ (x, "") ]
|
||||||
getFlagsUntil _ _ = error "Internal shellcheck error, please report! (getFlags on non-command)"
|
getFlagsUntil _ _ = error "Internal shellcheck error, please report! (getFlags on non-command)"
|
||||||
|
|
||||||
-- Get all flags in a GNU way, up until --
|
-- Get all flags in a GNU way, up until --
|
||||||
|
|
|
@ -689,7 +689,8 @@ checkBashisms params = bashism
|
||||||
warnMsg id $ "'" ++ name ++ "' is"
|
warnMsg id $ "'" ++ name ++ "' is"
|
||||||
potentially $ do
|
potentially $ do
|
||||||
allowed <- Map.lookup name allowedFlags
|
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"
|
return . warnMsg (getId word) $ name ++ " -" ++ flag ++ " is"
|
||||||
|
|
||||||
when (name == "source") $ warnMsg id "'source' in place of '.' is"
|
when (name == "source") $ warnMsg id "'source' in place of '.' is"
|
||||||
|
|
Loading…
Reference in New Issue