Skip to content

Commit d5307db

Browse files
committed
Remove severity
Instead of making the severity configurable, this patch removes severity all together and treats every finding as an error. Issue: #879
1 parent eeb2850 commit d5307db

25 files changed

+289
-137
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
.swiftpm/
33
swift-format.xcodeproj/
44
Package.resolved
5-
5+
.index-build

Documentation/RuleDocumentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Use the rules below in the `rules` block of your `.swift-format`
66
configuration file, as described in
7-
[Configuration](Configuration.md). All of these rules can be
7+
[Configuration](Documentation/Configuration.md). All of these rules can be
88
applied in the linter, but only some of them can format your source code
99
automatically.
1010

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ var targets: [Target] = [
113113
dependencies: [
114114
"SwiftFormat",
115115
"_SwiftFormatTestSupport",
116+
"swift-format",
116117
.product(name: "Markdown", package: "swift-markdown"),
117118
] + swiftSyntaxDependencies(["SwiftOperators", "SwiftParser", "SwiftSyntax", "SwiftSyntaxBuilder"])
118119
),

Sources/SwiftFormat/API/Finding.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212

1313
/// A problem with the style or syntax of the source code discovered during linting or formatting.
1414
public struct Finding {
15-
/// The severity of a finding.
16-
public enum Severity {
17-
case warning
18-
case error
19-
case refactoring
20-
case convention
21-
}
2215

2316
/// The file path and location in that file where a finding was encountered.
2417
public struct Location {
@@ -83,9 +76,6 @@ public struct Finding {
8376
/// The finding's message.
8477
public let message: Message
8578

86-
/// The severity of the finding.
87-
public let severity: Severity
88-
8979
/// The optional location of the finding.
9080
public let location: Location?
9181

@@ -97,13 +87,11 @@ public struct Finding {
9787
init(
9888
category: FindingCategorizing,
9989
message: Message,
100-
severity: Finding.Severity,
10190
location: Location? = nil,
10291
notes: [Note] = []
10392
) {
10493
self.category = category
10594
self.message = message
106-
self.severity = severity
10795
self.location = location
10896
self.notes = notes
10997
}

Sources/SwiftFormat/API/FindingCategorizing.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,5 @@
1717
/// to be displayed as part of the diagnostic message when the finding is presented to the user.
1818
/// For example, the category `Indentation` in the message `[Indentation] Indent by 2 spaces`.
1919
public protocol FindingCategorizing: CustomStringConvertible {
20-
/// The default severity of findings emitted in this category.
21-
///
22-
/// By default, all findings are warnings. Individual categories may choose to override this to
23-
/// make the findings in those categories more severe.
24-
var defaultSeverity: Finding.Severity { get }
25-
}
2620

27-
extension FindingCategorizing {
28-
public var defaultSeverity: Finding.Severity { .warning }
2921
}

Sources/SwiftFormat/Core/FindingEmitter.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ final class FindingEmitter {
5454
Finding(
5555
category: category,
5656
message: message,
57-
severity: category.defaultSeverity,
5857
location: location,
5958
notes: notes
6059
)

Sources/SwiftFormat/Core/Rule.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ extension Rule {
6262
public func diagnose<SyntaxType: SyntaxProtocol>(
6363
_ message: Finding.Message,
6464
on node: SyntaxType?,
65-
severity: Finding.Severity? = nil,
6665
anchor: FindingAnchor = .start,
6766
notes: [Finding.Note] = []
6867
) {
@@ -86,7 +85,7 @@ extension Rule {
8685
syntaxLocation = nil
8786
}
8887

89-
let category = RuleBasedFindingCategory(ruleType: type(of: self), severity: severity)
88+
let category = RuleBasedFindingCategory(ruleType: type(of: self))
9089
context.findingEmitter.emit(
9190
message,
9291
category: category,

Sources/SwiftFormat/Core/RuleBasedFindingCategory.swift

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

2323
var description: String { ruleType.ruleName }
2424

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

Sources/SwiftFormat/Core/RuleRegistry+Generated.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,14 @@
5757
"UseTripleSlashForDocumentationComments": true,
5858
"UseWhereClausesInForLoops": false,
5959
"ValidateDocumentationComments": false,
60+
"AddLines": true,
61+
"EndOfLineComment": true,
62+
"Indentation": true,
63+
"LineLength": true,
64+
"RemoveLine": true,
65+
"Spacing": true,
66+
"SpacingCharacter": true,
67+
"TrailingComma": true,
68+
"TrailingWhitespace": true,
6069
]
6170
}

Sources/SwiftFormat/Rules/OmitExplicitReturns.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class OmitExplicitReturns: SyntaxFormatRule {
3434
}
3535

3636
funcDecl.body?.statements = rewrapReturnedExpression(returnStmt)
37-
diagnose(.omitReturnStatement, on: returnStmt, severity: .refactoring)
37+
diagnose(.omitReturnStatement, on: returnStmt)
3838
return DeclSyntax(funcDecl)
3939
}
4040

@@ -78,7 +78,7 @@ public final class OmitExplicitReturns: SyntaxFormatRule {
7878
}
7979

8080
closureExpr.statements = rewrapReturnedExpression(returnStmt)
81-
diagnose(.omitReturnStatement, on: returnStmt, severity: .refactoring)
81+
diagnose(.omitReturnStatement, on: returnStmt)
8282
return ExprSyntax(closureExpr)
8383
}
8484

@@ -111,7 +111,7 @@ public final class OmitExplicitReturns: SyntaxFormatRule {
111111

112112
getter.body?.statements = rewrapReturnedExpression(returnStmt)
113113

114-
diagnose(.omitReturnStatement, on: returnStmt, severity: .refactoring)
114+
diagnose(.omitReturnStatement, on: returnStmt)
115115

116116
accessors[getterAt] = getter
117117
var newBlock = accessorBlock
@@ -123,7 +123,7 @@ public final class OmitExplicitReturns: SyntaxFormatRule {
123123
return nil
124124
}
125125

126-
diagnose(.omitReturnStatement, on: returnStmt, severity: .refactoring)
126+
diagnose(.omitReturnStatement, on: returnStmt)
127127

128128
var newBlock = accessorBlock
129129
newBlock.accessors = .getter(rewrapReturnedExpression(returnStmt))

0 commit comments

Comments
 (0)