Skip to content

Commit c1d2309

Browse files
committed
Prefix annotated errors and warnings in DiagnosticsFormatter to improve accessibility
1 parent 90ae449 commit c1d2309

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Sources/SwiftDiagnostics/DiagnosticsFormatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ public struct DiagnosticsFormatter {
179179
switch message.severity {
180180
case .error:
181181
let annotation = ANSIAnnotation(color: .red, trait: .bold)
182-
return annotation.applied(to: message.message)
182+
return annotation.applied(to: "error: \(message.message)")
183183
case .warning:
184184
let annotation = ANSIAnnotation(color: .yellow)
185-
return annotation.applied(to: message.message)
185+
return annotation.applied(to: "warning: \(message.message)")
186186
case .note:
187187
return message.message
188188
}

Tests/SwiftDiagnosticsTest/DiagnosticsFormatterTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ final class DiagnosticsFormatterTests: XCTestCase {
101101

102102
let expectedOutput = """
103103
1 │ var foo = bar +
104-
∣ ╰─ \u{001B}[1;31mexpected expression in variable\u{001B}[0;0m
104+
∣ ╰─ \u{001B}[1;31merror: expected expression in variable\u{001B}[0;0m
105105
106106
"""
107107
AssertStringsEqualWithDiff(expectedOutput, annotate(source: source, colorize: true))
@@ -113,9 +113,9 @@ final class DiagnosticsFormatterTests: XCTestCase {
113113
"""
114114
let expectedOutput = """
115115
1 │ foo.[].[].[]
116-
∣ │ │ ╰─ \u{001B}[1;31mexpected name in member access\u{001B}[0;0m
117-
∣ │ ╰─ \u{001B}[1;31mexpected name in member access\u{001B}[0;0m
118-
∣ ╰─ \u{001B}[1;31mexpected name in member access\u{001B}[0;0m
116+
∣ │ │ ╰─ \u{001B}[1;31merror: expected name in member access\u{001B}[0;0m
117+
∣ │ ╰─ \u{001B}[1;31merror: expected name in member access\u{001B}[0;0m
118+
∣ ╰─ \u{001B}[1;31merror: expected name in member access\u{001B}[0;0m
119119
120120
"""
121121
AssertStringsEqualWithDiff(expectedOutput, annotate(source: source, colorize: true))

0 commit comments

Comments
 (0)