@@ -213,7 +213,7 @@ class Frontend {
213213 // then try to load the configuration by inferring it based on the source file path.
214214 if let swiftFileURL = swiftFileURL {
215215 do {
216- if let configuration = try configurationLoader. configuration ( forSwiftFileAt : swiftFileURL) {
216+ if let configuration = try configurationLoader. configuration ( forPath : swiftFileURL) {
217217 self . checkForUnrecognizedRules ( in: configuration)
218218 return configuration
219219 }
@@ -223,11 +223,26 @@ class Frontend {
223223 " Unable to read configuration for \( swiftFileURL. path) : \( error. localizedDescription) " )
224224 return nil
225225 }
226+ } else {
227+ // If reading from stdin and no explicit configuration file was given,
228+ // walk up the file tree from the cwd to find a config.
229+
230+ let cwd = URL ( fileURLWithPath: FileManager . default. currentDirectoryPath)
231+ // Definitely a Swift file. Definitely not a directory. Shhhhhh.
232+ do {
233+ if let configuration = try configurationLoader. configuration ( forPath: cwd) {
234+ self . checkForUnrecognizedRules ( in: configuration)
235+ return configuration
236+ }
237+ } catch {
238+ diagnosticsEngine. emitError (
239+ " Unable to read configuration for \( cwd) : \( error. localizedDescription) " )
240+ return nil
241+ }
226242 }
227243
228- // If neither path was given (for example, formatting standard input with no assumed filename)
229- // or if there was no configuration found by inferring it from the source file path, return the
230- // default configuration.
244+ // An explicit configuration has not been given, and one cannot be found.
245+ // Return the default configuration.
231246 return Configuration ( )
232247 }
233248
0 commit comments