Remove unnecessary uses of head
This commit is contained in:
parent
c95914f9b3
commit
6d06103cab
|
@ -2293,7 +2293,7 @@ checkWhileReadPitfalls _ (T_WhileExpression id [command] contents)
|
||||||
|
|
||||||
isStdinReadCommand (T_Pipeline _ _ [T_Redirecting id redirs cmd]) =
|
isStdinReadCommand (T_Pipeline _ _ [T_Redirecting id redirs cmd]) =
|
||||||
let plaintext = oversimplify cmd
|
let plaintext = oversimplify cmd
|
||||||
in head (plaintext ++ [""]) == "read"
|
in headOrDefault "" plaintext == "read"
|
||||||
&& ("-u" `notElem` plaintext)
|
&& ("-u" `notElem` plaintext)
|
||||||
&& all (not . stdinRedirect) redirs
|
&& all (not . stdinRedirect) redirs
|
||||||
isStdinReadCommand _ = False
|
isStdinReadCommand _ = False
|
||||||
|
|
|
@ -255,7 +255,7 @@ determineShell fallbackShell t = fromMaybe Bash $
|
||||||
executableFromShebang :: String -> String
|
executableFromShebang :: String -> String
|
||||||
executableFromShebang = shellFor
|
executableFromShebang = shellFor
|
||||||
where
|
where
|
||||||
shellFor s | "/env " `isInfixOf` s = head (drop 1 (words s)++[""])
|
shellFor s | "/env " `isInfixOf` s = headOrDefault "" (drop 1 $ words s)
|
||||||
shellFor s | ' ' `elem` s = shellFor $ takeWhile (/= ' ') s
|
shellFor s | ' ' `elem` s = shellFor $ takeWhile (/= ' ') s
|
||||||
shellFor s = reverse . takeWhile (/= '/') . reverse $ s
|
shellFor s = reverse . takeWhile (/= '/') . reverse $ s
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ isQuoteFree = isQuoteFreeNode False
|
||||||
|
|
||||||
isQuoteFreeNode strict tree t =
|
isQuoteFreeNode strict tree t =
|
||||||
(isQuoteFreeElement t == Just True) ||
|
(isQuoteFreeElement t == Just True) ||
|
||||||
head (mapMaybe isQuoteFreeContext (drop 1 $ getPath tree t) ++ [False])
|
headOrDefault False (mapMaybe isQuoteFreeContext (drop 1 $ getPath tree t))
|
||||||
where
|
where
|
||||||
-- Is this node self-quoting in itself?
|
-- Is this node self-quoting in itself?
|
||||||
isQuoteFreeElement t =
|
isQuoteFreeElement t =
|
||||||
|
@ -758,9 +758,8 @@ getReferencedVariables parents t =
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
getIfReference context token = maybeToList $ do
|
getIfReference context token = maybeToList $ do
|
||||||
str <- getLiteralStringExt literalizer token
|
str@(h:_) <- getLiteralStringExt literalizer token
|
||||||
guard . not $ null str
|
when (isDigit h) $ fail "is a number"
|
||||||
when (isDigit $ head str) $ fail "is a number"
|
|
||||||
return (context, token, getBracedReference str)
|
return (context, token, getBracedReference str)
|
||||||
|
|
||||||
isDereferencing = (`elem` ["-eq", "-ne", "-lt", "-le", "-gt", "-ge"])
|
isDereferencing = (`elem` ["-eq", "-ne", "-lt", "-le", "-gt", "-ge"])
|
||||||
|
|
|
@ -279,10 +279,10 @@ checkGrepRe = CommandCheck (Basename "grep") check where
|
||||||
grepGlobFlags = ["fixed-strings", "F", "include", "exclude", "exclude-dir", "o", "only-matching"]
|
grepGlobFlags = ["fixed-strings", "F", "include", "exclude", "exclude-dir", "o", "only-matching"]
|
||||||
|
|
||||||
wordStartingWith c =
|
wordStartingWith c =
|
||||||
head . filter ([c] `isPrefixOf`) $ candidates
|
headOrDefault (c:"test") . filter ([c] `isPrefixOf`) $ candidates
|
||||||
where
|
where
|
||||||
candidates =
|
candidates =
|
||||||
sampleWords ++ map (\(x:r) -> toUpper x : r) sampleWords ++ [c:"test"]
|
sampleWords ++ map (\(x:r) -> toUpper x : r) sampleWords
|
||||||
|
|
||||||
getSuspiciousRegexWildcard str =
|
getSuspiciousRegexWildcard str =
|
||||||
if not $ str `matches` contra
|
if not $ str `matches` contra
|
||||||
|
|
|
@ -457,8 +457,8 @@ checkEchoSed = ForShell [Bash, Ksh] f
|
||||||
-- This should have used backreferences, but TDFA doesn't support them
|
-- This should have used backreferences, but TDFA doesn't support them
|
||||||
sedRe = mkRegex "^s(.)([^\n]*)g?$"
|
sedRe = mkRegex "^s(.)([^\n]*)g?$"
|
||||||
isSimpleSed s = fromMaybe False $ do
|
isSimpleSed s = fromMaybe False $ do
|
||||||
[first,rest] <- matchRegex sedRe s
|
[h:_,rest] <- matchRegex sedRe s
|
||||||
let delimiters = filter (== head first) rest
|
let delimiters = filter (== h) rest
|
||||||
guard $ length delimiters == 2
|
guard $ length delimiters == 2
|
||||||
return True
|
return True
|
||||||
checkIn id s =
|
checkIn id s =
|
||||||
|
|
|
@ -186,12 +186,12 @@ getNextIdSpanningTokens startTok endTok = do
|
||||||
|
|
||||||
-- Get an ID starting from the first token of the list, and ending after the last
|
-- Get an ID starting from the first token of the list, and ending after the last
|
||||||
getNextIdSpanningTokenList list =
|
getNextIdSpanningTokenList list =
|
||||||
if null list
|
case list of
|
||||||
then do
|
[] -> do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
getNextIdBetween pos pos
|
getNextIdBetween pos pos
|
||||||
else
|
(h:_) ->
|
||||||
getNextIdSpanningTokens (head list) (last list)
|
getNextIdSpanningTokens h (last list)
|
||||||
|
|
||||||
-- Get the span covered by an id
|
-- Get the span covered by an id
|
||||||
getSpanForId :: Monad m => Id -> SCParser m (SourcePos, SourcePos)
|
getSpanForId :: Monad m => Id -> SCParser m (SourcePos, SourcePos)
|
||||||
|
@ -1826,7 +1826,7 @@ readPendingHereDocs = do
|
||||||
let thereIsNoTrailer = null trailingSpace && null trailer
|
let thereIsNoTrailer = null trailingSpace && null trailer
|
||||||
let leaderIsOk = null leadingSpace
|
let leaderIsOk = null leadingSpace
|
||||||
|| dashed == Dashed && leadingSpacesAreTabs
|
|| dashed == Dashed && leadingSpacesAreTabs
|
||||||
let trailerStart = if null trailer then '\0' else head trailer
|
let trailerStart = case trailer of [] -> '\0'; (h:_) -> h
|
||||||
let hasTrailingSpace = not $ null trailingSpace
|
let hasTrailingSpace = not $ null trailingSpace
|
||||||
let hasTrailer = not $ null trailer
|
let hasTrailer = not $ null trailer
|
||||||
let ppt = parseProblemAt trailerPos ErrorC
|
let ppt = parseProblemAt trailerPos ErrorC
|
||||||
|
|
Loading…
Reference in New Issue