Skip to content

Commit aca7a05

Browse files
authored
Merge pull request #578 from xedin/upstream-refactoring-and-warning-severity
[Core] Add new finding severity kinds - `refactoring` and `convention`
2 parents 24efe7f + 21c122f commit aca7a05

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

Sources/SwiftFormatCore/Finding.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public struct Finding {
1616
public enum Severity {
1717
case warning
1818
case error
19+
case refactoring
20+
case convention
1921
}
2022

2123
/// 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ final class DiagnosticsEngine {
116116
switch finding.severity {
117117
case .error: severity = .error
118118
case .warning: severity = .warning
119+
case .refactoring: severity = .warning
120+
case .convention: severity = .warning
119121
}
120122
return Diagnostic(
121123
severity: severity,

0 commit comments

Comments
 (0)