From 48fd793581e3eb92c467c94478f28f068095d4e1 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Tue, 27 Oct 2015 22:07:29 -0700 Subject: [PATCH] Update getFlag function to also return non-flags. --- ShellCheck/ASTLib.hs | 11 +++++++---- ShellCheck/Analytics.hs | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ShellCheck/ASTLib.hs b/ShellCheck/ASTLib.hs index cd5e8f1..9ef29b5 100644 --- a/ShellCheck/ASTLib.hs +++ b/ShellCheck/ASTLib.hs @@ -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 -- diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 3b539b4..f8df27a 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -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"