Skip to content

Commit

Permalink
Merge branch 'tacerus-config'
Browse files Browse the repository at this point in the history
  • Loading branch information
koalaman committed Feb 3, 2024
2 parents b1b95c2 + 6a44a19 commit f5758e1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
5 changes: 5 additions & 0 deletions shellcheck.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ not warn at all, as `ksh` supports decimals in arithmetic contexts.

: Don't try to look for .shellcheckrc configuration files.

--rcfile\ RCFILE

: Prefer the specified configuration file over searching for one
in the default locations.

**-o**\ *NAME1*[,*NAME2*...],\ **--enable=***NAME1*[,*NAME2*...]

: Enable optional checks. The special name *all* enables all of them.
Expand Down
53 changes: 39 additions & 14 deletions shellcheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ data Options = Options {
externalSources :: Bool,
sourcePaths :: [FilePath],
formatterOptions :: FormatterOptions,
minSeverity :: Severity
minSeverity :: Severity,
rcfile :: Maybe FilePath
}

defaultOptions = Options {
Expand All @@ -86,7 +87,8 @@ defaultOptions = Options {
formatterOptions = newFormatterOptions {
foColorOption = ColorAuto
},
minSeverity = StyleC
minSeverity = StyleC,
rcfile = Nothing
}

usageHeader = "Usage: shellcheck [OPTIONS...] FILES..."
Expand All @@ -107,6 +109,9 @@ options = [
(NoArg $ Flag "list-optional" "true") "List checks disabled by default",
Option "" ["norc"]
(NoArg $ Flag "norc" "true") "Don't look for .shellcheckrc files",
Option "" ["rcfile"]
(ReqArg (Flag "rcfile") "RCFILE")
"Prefer the specified configuration file over searching for one",
Option "o" ["enable"]
(ReqArg (Flag "enable") "check1,check2..")
"List of optional checks to enable (or 'all')",
Expand Down Expand Up @@ -367,6 +372,11 @@ parseOption flag options =
}
}

Flag "rcfile" str -> do
return options {
rcfile = Just str
}

Flag "enable" value ->
let cs = checkSpec options in return options {
checkSpec = cs {
Expand Down Expand Up @@ -441,18 +451,33 @@ ioInterface options files = do
fallback :: FilePath -> IOException -> IO FilePath
fallback path _ = return path


-- Returns the name and contents of .shellcheckrc for the given file
getConfig cache filename = do
path <- normalize filename
let dir = takeDirectory path
(previousPath, result) <- readIORef cache
if dir == previousPath
then return result
else do
paths <- getConfigPaths dir
result <- findConfig paths
writeIORef cache (dir, result)
return result
getConfig cache filename =
case rcfile options of
Just file -> do
-- We have a specified rcfile. Ignore normal rcfile resolution.
(path, result) <- readIORef cache
if path == "/"
then return result
else do
result <- readConfig file
when (isNothing result) $
hPutStrLn stderr $ "Warning: unable to read --rcfile " ++ file
writeIORef cache ("/", result)
return result

Nothing -> do
path <- normalize filename
let dir = takeDirectory path
(previousPath, result) <- readIORef cache
if dir == previousPath
then return result
else do
paths <- getConfigPaths dir
result <- findConfig paths
writeIORef cache (dir, result)
return result

findConfig paths =
case paths of
Expand Down Expand Up @@ -490,7 +515,7 @@ ioInterface options files = do
where
handler :: FilePath -> IOException -> IO (String, Bool)
handler file err = do
putStrLn $ file ++ ": " ++ show err
hPutStrLn stderr $ file ++ ": " ++ show err
return ("", True)

andM a b arg = do
Expand Down

0 comments on commit f5758e1

Please sign in to comment.