@@ -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
8485defaultOptions = 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
9597usageHeader = " 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 ]
143148getUsageInfo = 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