Skip to content

Commit ae4aea4

Browse files
committed
Adds support for a SHELLCHECK_OPTS environment variable.
1 parent d0029ae commit ae4aea4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

ShellCheck/Regex.hs

+7
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,10 @@ subRegex re input replacement = f input
7171
(before, match, after) <- matchM re str :: Maybe (String, String, String)
7272
when (null match) $ error ("Internal error: substituted empty in " ++ str)
7373
return $ before ++ replacement ++ f after
74+
75+
-- Split a string based on a regex.
76+
splitOn :: String -> Regex -> [String]
77+
splitOn input re =
78+
case matchM re input :: Maybe (String, String, String) of
79+
Just (before, match, after) -> before : after `splitOn` re
80+
Nothing -> [input]

shellcheck.1.md

+7
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ Valid keys are:
151151
used to tell shellcheck where to look for a file whose name is determined
152152
at runtime, or to skip a source by telling it to use `/dev/null`.
153153

154+
# ENVIRONMENT VARIABLES
155+
The environment variable `SHELLCHECK_OPTS` can be set with default flags:
156+
157+
export SHELLCHECK_OPTS='--shell=bash --exclude=SC2016'
158+
159+
Its value will be split on spaces and prepended to the command line on each
160+
invocation.
154161

155162
# AUTHOR
156163
ShellCheck is written and maintained by Vidar Holen.

shellcheck.hs

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import ShellCheck.Data
2121
import ShellCheck.Checker
2222
import ShellCheck.Interface
23+
import ShellCheck.Regex
2324

2425
import ShellCheck.Formatter.Format
2526
import qualified ShellCheck.Formatter.CheckStyle
@@ -123,8 +124,17 @@ getExclusions options =
123124

124125
toStatus = liftM (either id id) . runExceptT
125126

127+
getEnvArgs = do
128+
opts <- getEnv "SHELLCHECK_OPTS" `catch` cantWaitForLookupEnv
129+
return . filter (not . null) $ opts `splitOn` mkRegex " +"
130+
where
131+
cantWaitForLookupEnv :: IOException -> IO String
132+
cantWaitForLookupEnv = const $ return ""
133+
126134
main = do
127-
args <- getArgs
135+
params <- getArgs
136+
envOpts <- getEnvArgs
137+
let args = envOpts ++ params
128138
status <- toStatus $ do
129139
(flags, files) <- parseArguments args
130140
process flags files

0 commit comments

Comments
 (0)