From f8648e546595a0e44d8f8e3c46a68ec774534bde Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 9 Feb 2020 21:26:42 -0500 Subject: [PATCH] Switch getLiteralStringExt to Identity where it can never be Nothing --- src/ShellCheck/Analytics.hs | 6 ++---- src/ShellCheck/Checks/Commands.hs | 9 ++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/ShellCheck/Analytics.hs b/src/ShellCheck/Analytics.hs index 8a2902c..71743b4 100644 --- a/src/ShellCheck/Analytics.hs +++ b/src/ShellCheck/Analytics.hs @@ -1066,9 +1066,7 @@ checkNumberComparisons params (TC_Binary id typ op lhs rhs) = do checkStrings = mapM_ stringError . take 1 . filter isNonNum - isNonNum t = fromMaybe False $ do - s <- getLiteralStringExt (const $ return "") t - return . not . all numChar $ s + isNonNum t = not . all numChar . runIdentity $ getLiteralStringExt (const $ return "") t numChar x = isDigit x || x `elem` "+-. " stringError t = err (getId t) 2170 $ @@ -2595,7 +2593,7 @@ checkTildeInPath _ (T_SimpleCommand _ vars _) = warn id 2147 "Literal tilde in PATH works poorly across programs." checkVar _ = return () - hasTilde t = fromMaybe False (liftM2 elem (return '~') (getLiteralStringExt (const $ return "") t)) + hasTilde t = '~' `elem` runIdentity (getLiteralStringExt (const $ return "") t) isQuoted T_DoubleQuoted {} = True isQuoted T_SingleQuoted {} = True isQuoted _ = False diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index 869b389..a6b8d9e 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -249,13 +249,12 @@ prop_checkGrepRe23= verifyNot checkGrepRe "grep '.*' file" checkGrepRe = CommandCheck (Basename "grep") check where check cmd = f cmd (arguments cmd) -- --regex=*(extglob) doesn't work. Fixme? - skippable (Just s) = not ("--regex=" `isPrefixOf` s) && "-" `isPrefixOf` s - skippable _ = False + skippable s = not ("--regex=" `isPrefixOf` s) && "-" `isPrefixOf` s f _ [] = return () f cmd (x:r) = - let str = getLiteralStringExt (const $ return "_") x + let str = runIdentity $ getLiteralStringExt (const $ return "_") x in - if str `elem` [Just "--", Just "-e", Just "--regex"] + if str `elem` ["--", "-e", "--regex"] then checkRE cmd r -- Regex is *after* this else if skippable str @@ -366,7 +365,7 @@ checkFindExecWithSingleArgument = CommandCheck (Basename "find") (f . arguments) check (exec:arg:term:_) = do execS <- getLiteralString exec termS <- getLiteralString term - cmdS <- getLiteralStringExt (const $ return " ") arg + let cmdS = runIdentity $ getLiteralStringExt (const $ return " ") arg guard $ execS `elem` ["-exec", "-execdir"] && termS `elem` [";", "+"] guard $ cmdS `matches` commandRegex