Skip to content

Commit fb98989

Browse files
committed
Refinements to Diagnostics type based on SE-0303 amendment review modifications.
Mark the Severity as public and add a method that takes it as a parameter.
1 parent 0a246fe commit fb98989

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Sources/PackagePlugin/Implementation.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ struct PrebuildCommand: Encodable {
102102
}
103103

104104
struct Diagnostic: Encodable {
105-
enum Severity: String, Encodable {
106-
case error, warning, remark
107-
}
108-
let severity: Severity
105+
let severity: Diagnostics.Severity
109106
let message: String
110107
let file: Path?
111108
let line: Int?

Sources/PackagePlugin/PublicAPI/Diagnostics.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@
1111
/// Emits errors, warnings, and remarks to be shown as a result of running the
1212
/// plugin. After emitting one or more errors, the plugin should return a
1313
/// non-zero exit code.
14-
public final class Diagnostics {
14+
public struct Diagnostics {
1515

1616
// This prevents a Diagnostics from being instantiated by the script.
1717
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+
}
1828

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.
2030
public static func error(_ message: String, file: Path? = nil, line: Int? = nil) {
2131
output.diagnostics.append(Diagnostic(severity: .error, message: message, file: file, line: line))
2232
}
2333

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.
2535
public static func warning(_ message: String, file: Path? = nil, line: Int? = nil) {
2636
output.diagnostics.append(Diagnostic(severity: .warning, message: message, file: file, line: line))
2737
}
2838

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.
3040
public static func remark(_ message: String, file: Path? = nil, line: Int? = nil) {
3141
output.diagnostics.append(Diagnostic(severity: .remark, message: message, file: file, line: line))
3242
}

0 commit comments

Comments
 (0)