|
11 | 11 | /// Emits errors, warnings, and remarks to be shown as a result of running the
|
12 | 12 | /// plugin. After emitting one or more errors, the plugin should return a
|
13 | 13 | /// non-zero exit code.
|
14 |
| -public final class Diagnostics { |
| 14 | +public struct Diagnostics { |
15 | 15 |
|
16 | 16 | // This prevents a Diagnostics from being instantiated by the script.
|
17 | 17 | internal init() {}
|
| 18 | + |
| 19 | + /// Severity of the diagnostic. |
| 20 | + public enum Severity: String, Encodable { |
| 21 | + case error, warning, remark |
| 22 | + } |
| 23 | + |
| 24 | + /// Emits an error with a specified severity and message, and optional file path and line number. |
| 25 | + public static func emit(_ severity: Severity, _ message: String, file: Path? = #file, line: Int? = #line) { |
| 26 | + output.diagnostics.append(Diagnostic(severity: severity, message: message, file: file, line: line)) |
| 27 | + } |
18 | 28 |
|
19 |
| - /// Emits an error with the specified message and optional file path and line number.. |
| 29 | + /// Emits an error with the specified message, and optional file path and line number. |
20 | 30 | public static func error(_ message: String, file: Path? = nil, line: Int? = nil) {
|
21 | 31 | output.diagnostics.append(Diagnostic(severity: .error, message: message, file: file, line: line))
|
22 | 32 | }
|
23 | 33 |
|
24 |
| - /// Emits a warning with the specified message and optional file path and line number.. |
| 34 | + /// Emits a warning with the specified message, and optional file path and line number. |
25 | 35 | public static func warning(_ message: String, file: Path? = nil, line: Int? = nil) {
|
26 | 36 | output.diagnostics.append(Diagnostic(severity: .warning, message: message, file: file, line: line))
|
27 | 37 | }
|
28 | 38 |
|
29 |
| - /// Emits a remark with the specified message and optional file path and line number.. |
| 39 | + /// Emits a remark with the specified message, and optional file path and line number. |
30 | 40 | public static func remark(_ message: String, file: Path? = nil, line: Int? = nil) {
|
31 | 41 | output.diagnostics.append(Diagnostic(severity: .remark, message: message, file: file, line: line))
|
32 | 42 | }
|
|
0 commit comments