Skip to content

Commit cb0a0fc

Browse files
committed
[Core] Add a new finding severity - refactoring
Refactoring identifies an actionable feedback to the developer and has higher impact than a general warning.
1 parent 121992f commit cb0a0fc

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

Sources/SwiftFormatCore/Finding.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public struct Finding {
1616
public enum Severity {
1717
case warning
1818
case error
19+
case refactoring
1920
}
2021

2122
/// The file path and location in that file where a finding was encountered.

Sources/SwiftFormatCore/Rule.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extension Rule {
4646
public func diagnose<SyntaxType: SyntaxProtocol>(
4747
_ message: Finding.Message,
4848
on node: SyntaxType?,
49+
severity: Finding.Severity? = nil,
4950
leadingTriviaIndex: Trivia.Index? = nil,
5051
notes: [Finding.Note] = []
5152
) {
@@ -57,9 +58,10 @@ extension Rule {
5758
syntaxLocation = node?.startLocation(converter: context.sourceLocationConverter)
5859
}
5960

61+
let category = RuleBasedFindingCategory(ruleType: type(of: self), severity: severity)
6062
context.findingEmitter.emit(
6163
message,
62-
category: RuleBasedFindingCategory(ruleType: type(of: self)),
64+
category: category,
6365
location: syntaxLocation.flatMap(Finding.Location.init),
6466
notes: notes)
6567
}

Sources/SwiftFormatCore/RuleBasedFindingCategory.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ struct RuleBasedFindingCategory: FindingCategorizing {
2222

2323
var description: String { ruleType.ruleName }
2424

25+
var severity: Finding.Severity?
26+
2527
/// Creates a finding category that wraps the given rule type.
26-
init(ruleType: Rule.Type) {
28+
init(ruleType: Rule.Type, severity: Finding.Severity? = nil) {
2729
self.ruleType = ruleType
30+
self.severity = severity
2831
}
2932
}

Sources/swift-format/Utilities/DiagnosticsEngine.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ final class DiagnosticsEngine {
116116
switch finding.severity {
117117
case .error: severity = .error
118118
case .warning: severity = .warning
119+
case .refactoring: severity = .warning
119120
}
120121
return Diagnostic(
121122
severity: severity,

0 commit comments

Comments
 (0)