From cc44c989b7e5f2df2deb89dadeae9547338413fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sun, 8 Jan 2023 16:37:32 +0100 Subject: [PATCH] Check every used internal violation reason for a pending period --- .sourcery/PrimaryRuleList.stencil | 8 ++++++-- .../SwiftLintFramework/Models/PrimaryRuleList.swift | 10 +++++++--- .../SwiftLintFramework/Models/StyleViolation.swift | 12 +++++++++++- Tests/GeneratedTests/GeneratedTests.swift | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.sourcery/PrimaryRuleList.stencil b/.sourcery/PrimaryRuleList.stencil index 42f3cfe94..2386e44e2 100644 --- a/.sourcery/PrimaryRuleList.stencil +++ b/.sourcery/PrimaryRuleList.stencil @@ -1,4 +1,8 @@ + /// The rule list containing all available rules built into SwiftLint. -public let primaryRuleList = RuleList(rules: [ +let builtInRules: [Rule.Type] = [ {% for rule in types.structs where rule.name|hasSuffix:"Rule" or rule.name|hasSuffix:"Rules" %} {{ rule.name }}.self{% if not forloop.last %},{% endif %} -{% endfor %}] + extraRules()) +{% endfor %}] + +/// The rule list containing all available rules built into SwiftLint as well as native custom rules. +public let primaryRuleList = RuleList(rules: builtInRules + extraRules()) diff --git a/Source/SwiftLintFramework/Models/PrimaryRuleList.swift b/Source/SwiftLintFramework/Models/PrimaryRuleList.swift index cd725956f..0bd9af4b3 100644 --- a/Source/SwiftLintFramework/Models/PrimaryRuleList.swift +++ b/Source/SwiftLintFramework/Models/PrimaryRuleList.swift @@ -1,7 +1,8 @@ -// Generated using Sourcery 1.9.0 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 1.9.2 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT + /// The rule list containing all available rules built into SwiftLint. -public let primaryRuleList = RuleList(rules: [ +let builtInRules: [Rule.Type] = [ AccessibilityLabelForImageRule.self, AccessibilityTraitForButtonRule.self, AnonymousArgumentInMultilineClosureRule.self, @@ -223,4 +224,7 @@ public let primaryRuleList = RuleList(rules: [ XCTFailMessageRule.self, XCTSpecificMatcherRule.self, YodaConditionRule.self -] + extraRules()) +] + +/// The rule list containing all available rules built into SwiftLint as well as native custom rules. +public let primaryRuleList = RuleList(rules: builtInRules + extraRules()) diff --git a/Source/SwiftLintFramework/Models/StyleViolation.swift b/Source/SwiftLintFramework/Models/StyleViolation.swift index 8a6eda0d4..b7e77de21 100644 --- a/Source/SwiftLintFramework/Models/StyleViolation.swift +++ b/Source/SwiftLintFramework/Models/StyleViolation.swift @@ -28,7 +28,8 @@ public struct StyleViolation: CustomStringConvertible, Equatable, Codable { /// - parameter ruleDescription: The description of the rule that generated this violation. /// - parameter severity: The severity of this violation. /// - parameter location: The location of this violation. - /// - parameter reason: The justification for this violation. + /// - parameter reason: The justification for this violation. If not specified the rule's description will + /// be used. public init(ruleDescription: RuleDescription, severity: ViolationSeverity = .warning, location: Location, @@ -39,6 +40,15 @@ public struct StyleViolation: CustomStringConvertible, Equatable, Codable { self.severity = severity self.location = location self.reason = reason ?? ruleDescription.description + #if DEBUG + if self.reason.trimmingTrailingCharacters(in: .whitespaces).last == ".", + builtInRules.contains(where: { rule in rule.description.identifier == self.ruleIdentifier }) { + queuedFatalError(""" + Reasons shall not end with a period. Got "\(self.reason)". Either rewrite the rule's description \ + or set a custom reason in the StyleViolation's constructor. + """) + } + #endif } /// Returns the same violation, but with the `severity` that is passed in diff --git a/Tests/GeneratedTests/GeneratedTests.swift b/Tests/GeneratedTests/GeneratedTests.swift index 20bfea51e..ef0ffde72 100644 --- a/Tests/GeneratedTests/GeneratedTests.swift +++ b/Tests/GeneratedTests/GeneratedTests.swift @@ -1,4 +1,4 @@ -// Generated using Sourcery 1.9.0 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 1.9.2 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT @_spi(TestHelper) @testable import SwiftLintFramework