@@ -213,7 +213,7 @@ class Frontend {
213
213
// then try to load the configuration by inferring it based on the source file path.
214
214
if let swiftFileURL = swiftFileURL {
215
215
do {
216
- if let configuration = try configurationLoader. configuration ( forSwiftFileAt : swiftFileURL) {
216
+ if let configuration = try configurationLoader. configuration ( forPath : swiftFileURL) {
217
217
self . checkForUnrecognizedRules ( in: configuration)
218
218
return configuration
219
219
}
@@ -223,11 +223,26 @@ class Frontend {
223
223
" Unable to read configuration for \( swiftFileURL. path) : \( error. localizedDescription) " )
224
224
return nil
225
225
}
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
+ }
226
242
}
227
243
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.
231
246
return Configuration ( )
232
247
}
233
248
0 commit comments