Simplify checkWhileReadPitfalls

* Clean up usage of not
* Use a case match instead of sequence_ and a do block
This commit is contained in:
Joseph C. Sible 2020-03-16 00:12:19 -04:00
parent acee69676b
commit 9d5363377e
1 changed files with 6 additions and 6 deletions

View File

@ -2341,18 +2341,18 @@ checkWhileReadPitfalls params (T_WhileExpression id [command] contents)
let plaintext = oversimplify cmd let plaintext = oversimplify cmd
in headOrDefault "" plaintext == "read" in headOrDefault "" plaintext == "read"
&& ("-u" `notElem` plaintext) && ("-u" `notElem` plaintext)
&& all (not . stdinRedirect) redirs && not (any stdinRedirect redirs)
isStdinReadCommand _ = False isStdinReadCommand _ = False
checkMuncher :: Token -> Writer [TokenComment] () checkMuncher :: Token -> Writer [TokenComment] ()
checkMuncher (T_Pipeline _ _ (T_Redirecting _ redirs cmd:_)) = do checkMuncher (T_Pipeline _ _ (T_Redirecting _ redirs cmd:_)) = do
-- Check command substitutions regardless of the command -- Check command substitutions regardless of the command
sequence_ $ do case cmd of
(T_SimpleCommand _ vars args) <- Just cmd T_SimpleCommand _ vars args ->
let words = concat $ concatMap getCommandSequences $ concatMap getWords $ vars ++ args mapM_ checkMuncher $ concat $ concatMap getCommandSequences $ concatMap getWords $ vars ++ args
return $ mapM_ checkMuncher words _ -> return ()
when (not $ any stdinRedirect redirs) $ do unless (any stdinRedirect redirs) $ do
-- Recurse into ifs/loops/groups/etc if this doesn't redirect -- Recurse into ifs/loops/groups/etc if this doesn't redirect
mapM_ checkMuncher $ concat $ getCommandSequences cmd mapM_ checkMuncher $ concat $ getCommandSequences cmd