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"