Skip to content

Commit 6ea5a2a

Browse files
CopilotFreed-Wu
andcommitted
Add --file-name option for stdin EditorConfig resolution
Co-authored-by: Freed-Wu <32936898+Freed-Wu@users.noreply.github.com>
1 parent 1531473 commit 6ea5a2a

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

shellcheck.1.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ not warn at all, as `ksh` supports decimals in arithmetic contexts.
139139
read the list from standard input. This option is processed in addition to
140140
any files specified on the command line.
141141

142+
**--file-name** *FILE*
143+
144+
: When checking standard input (`-`), use *FILE* as the filename to resolve
145+
`.shellcheckrc` and EditorConfig configuration, instead of `-`. This has no
146+
effect when checking regular files.
147+
142148

143149
# FORMATS
144150

shellcheck.hs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ data Options = Options {
7878
sourcePaths :: [FilePath],
7979
formatterOptions :: FormatterOptions,
8080
minSeverity :: Severity,
81-
rcfile :: Maybe FilePath
81+
rcfile :: Maybe FilePath,
82+
fileNameOverride :: Maybe FilePath
8283
}
8384

8485
defaultOptions = Options {
@@ -89,7 +90,8 @@ defaultOptions = Options {
8990
foColorOption = ColorAuto
9091
},
9192
minSeverity = StyleC,
92-
rcfile = Nothing
93+
rcfile = Nothing,
94+
fileNameOverride = Nothing
9395
}
9496

9597
usageHeader = "Usage: shellcheck [OPTIONS...] FILES..."
@@ -138,7 +140,10 @@ options = [
138140
(NoArg $ Flag "help" "true") "Show this usage summary and exit",
139141
Option "" ["files-from"]
140142
(ReqArg (Flag "files-from") "FILE")
141-
"Read input files from FILE (one per line, or '-' for stdin)"
143+
"Read input files from FILE (one per line, or '-' for stdin)",
144+
Option "" ["file-name"]
145+
(ReqArg (Flag "file-name") "FILE")
146+
"Use FILE as the filename for parsing EditorConfig configuration when input is stdin"
142147
]
143148
getUsageInfo = usageInfo usageHeader options
144149

@@ -421,6 +426,11 @@ parseOption flag options =
421426
rcfile = Just str
422427
}
423428

429+
Flag "file-name" str -> do
430+
return options {
431+
fileNameOverride = Just str
432+
}
433+
424434
Flag "enable" value ->
425435
let cs = checkSpec options in return options {
426436
checkSpec = cs {
@@ -519,8 +529,12 @@ ioInterface options files = do
519529
-- merged with any shellcheck.* directives found in applicable
520530
-- EditorConfig files.
521531
getConfig cache filename = do
522-
rcResult <- getRcConfig cache filename
523-
ecResult <- getEditorConfig filename
532+
let configFilename =
533+
if filename == "-"
534+
then fromMaybe filename (fileNameOverride options)
535+
else filename
536+
rcResult <- getRcConfig cache configFilename
537+
ecResult <- getEditorConfig configFilename
524538
return $ mergeConfigs filename rcResult ecResult
525539

526540
mergeConfigs filename rcResult ecResult =

0 commit comments

Comments
 (0)