Adds support for a SHELLCHECK_OPTS environment variable.
This commit is contained in:
parent
d0029ae1d4
commit
ae4aea4530
|
@ -71,3 +71,10 @@ subRegex re input replacement = f input
|
||||||
(before, match, after) <- matchM re str :: Maybe (String, String, String)
|
(before, match, after) <- matchM re str :: Maybe (String, String, String)
|
||||||
when (null match) $ error ("Internal error: substituted empty in " ++ str)
|
when (null match) $ error ("Internal error: substituted empty in " ++ str)
|
||||||
return $ before ++ replacement ++ f after
|
return $ before ++ replacement ++ f after
|
||||||
|
|
||||||
|
-- Split a string based on a regex.
|
||||||
|
splitOn :: String -> Regex -> [String]
|
||||||
|
splitOn input re =
|
||||||
|
case matchM re input :: Maybe (String, String, String) of
|
||||||
|
Just (before, match, after) -> before : after `splitOn` re
|
||||||
|
Nothing -> [input]
|
||||||
|
|
|
@ -151,6 +151,13 @@ Valid keys are:
|
||||||
used to tell shellcheck where to look for a file whose name is determined
|
used to tell shellcheck where to look for a file whose name is determined
|
||||||
at runtime, or to skip a source by telling it to use `/dev/null`.
|
at runtime, or to skip a source by telling it to use `/dev/null`.
|
||||||
|
|
||||||
|
# ENVIRONMENT VARIABLES
|
||||||
|
The environment variable `SHELLCHECK_OPTS` can be set with default flags:
|
||||||
|
|
||||||
|
export SHELLCHECK_OPTS='--shell=bash --exclude=SC2016'
|
||||||
|
|
||||||
|
Its value will be split on spaces and prepended to the command line on each
|
||||||
|
invocation.
|
||||||
|
|
||||||
# AUTHOR
|
# AUTHOR
|
||||||
ShellCheck is written and maintained by Vidar Holen.
|
ShellCheck is written and maintained by Vidar Holen.
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
import ShellCheck.Data
|
import ShellCheck.Data
|
||||||
import ShellCheck.Checker
|
import ShellCheck.Checker
|
||||||
import ShellCheck.Interface
|
import ShellCheck.Interface
|
||||||
|
import ShellCheck.Regex
|
||||||
|
|
||||||
import ShellCheck.Formatter.Format
|
import ShellCheck.Formatter.Format
|
||||||
import qualified ShellCheck.Formatter.CheckStyle
|
import qualified ShellCheck.Formatter.CheckStyle
|
||||||
|
@ -123,8 +124,17 @@ getExclusions options =
|
||||||
|
|
||||||
toStatus = liftM (either id id) . runExceptT
|
toStatus = liftM (either id id) . runExceptT
|
||||||
|
|
||||||
|
getEnvArgs = do
|
||||||
|
opts <- getEnv "SHELLCHECK_OPTS" `catch` cantWaitForLookupEnv
|
||||||
|
return . filter (not . null) $ opts `splitOn` mkRegex " +"
|
||||||
|
where
|
||||||
|
cantWaitForLookupEnv :: IOException -> IO String
|
||||||
|
cantWaitForLookupEnv = const $ return ""
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
params <- getArgs
|
||||||
|
envOpts <- getEnvArgs
|
||||||
|
let args = envOpts ++ params
|
||||||
status <- toStatus $ do
|
status <- toStatus $ do
|
||||||
(flags, files) <- parseArguments args
|
(flags, files) <- parseArguments args
|
||||||
process flags files
|
process flags files
|
||||||
|
|
Loading…
Reference in New Issue