Skip to content

Commit 3594003

Browse files
committed
Don't propagate the diagnostic engine when formatting.
This supresses printing diagnostic messages when using the format mode. When formatting, the issues in the source are either going to be fixed or they can't be fixed automatically. In either case, the formatter should be quiet about it. Linting continues to use the `DiagnosticEngine` so that lint findings are displayed as before.
1 parent 70a543a commit 3594003

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/swift-format/Run.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ func formatMain(
7777
configuration: Configuration, sourceFile: FileHandle, assumingFilename: String?, inPlace: Bool,
7878
debugOptions: DebugOptions, diagnosticEngine: DiagnosticEngine
7979
) -> Int {
80-
let formatter = SwiftFormatter(configuration: configuration, diagnosticEngine: diagnosticEngine)
80+
// Even though `diagnosticEngine` is defined, it's use is reserved for fatal messages. Pass nil
81+
// to the formatter to suppress other messages since they will be fixed or can't be automatically
82+
// fixed anyway.
83+
let formatter = SwiftFormatter(configuration: configuration, diagnosticEngine: nil)
8184
formatter.debugOptions = debugOptions
8285
let assumingFileURL = URL(fileURLWithPath: assumingFilename ?? "<stdin>")
8386

0 commit comments

Comments
 (0)