mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-09 16:31:51 +08:00
Use the Identity monad to avoid unnecessary uses of fromJust
This commit is contained in:
@@ -34,6 +34,7 @@ import ShellCheck.Regex
|
||||
import Control.Monad
|
||||
import Control.Monad.RWS
|
||||
import Data.Char
|
||||
import Data.Functor.Identity
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import qualified Data.Map.Strict as Map
|
||||
@@ -348,7 +349,7 @@ returnOrExit multi invalid = (f . arguments)
|
||||
isInvalid s = null s || any (not . isDigit) s || length s > 5
|
||||
|| let value = (read s :: Integer) in value > 255
|
||||
|
||||
literal token = fromJust $ getLiteralStringExt lit token
|
||||
literal token = runIdentity $ getLiteralStringExt lit token
|
||||
lit (T_DollarBraced {}) = return "0"
|
||||
lit (T_DollarArithmetic {}) = return "0"
|
||||
lit (T_DollarExpansion {}) = return "0"
|
||||
@@ -735,7 +736,7 @@ checkAliasesUsesArgs = CommandCheck (Exactly "alias") (f . arguments)
|
||||
re = mkRegex "\\$\\{?[0-9*@]"
|
||||
f = mapM_ checkArg
|
||||
checkArg arg =
|
||||
let string = fromJust $ getLiteralStringExt (const $ return "_") arg in
|
||||
let string = runIdentity $ getLiteralStringExt (const $ return "_") arg in
|
||||
when ('=' `elem` string && string `matches` re) $
|
||||
err (getId arg) 2142
|
||||
"Aliases can't use positional parameters. Use a function."
|
||||
@@ -781,7 +782,7 @@ checkFindWithoutPath = CommandCheck (Basename "find") f
|
||||
-- path. We assume that all the pre-path flags are single characters from a
|
||||
-- list of GNU and macOS flags.
|
||||
hasPath (first:rest) =
|
||||
let flag = fromJust $ getLiteralStringExt (const $ return "___") first in
|
||||
let flag = runIdentity $ getLiteralStringExt (const $ return "___") first in
|
||||
not ("-" `isPrefixOf` flag) || isLeadingFlag flag && hasPath rest
|
||||
hasPath [] = False
|
||||
isLeadingFlag flag = length flag <= 2 || all (`elem` leadingFlagChars) flag
|
||||
|
Reference in New Issue
Block a user