From 57632017e4c89d4a2db3894049d736391f5e4fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Tue, 17 Oct 2023 18:55:02 +0200 Subject: [PATCH] Introduce parent class for rewriters (#5282) --- .../Helpers/LegacyFunctionRuleHelper.swift | 8 ++----- .../Rules/Idiomatic/ExplicitInitRule.swift | 11 +-------- .../JoinedDefaultParameterRule.swift | 11 +-------- .../Rules/Idiomatic/LegacyConstantRule.swift | 11 +-------- .../Idiomatic/LegacyConstructorRule.swift | 11 +-------- .../PreferZeroOverExplicitInitRule.swift | 11 +-------- .../PrivateOverFilePrivateRule.swift | 8 ++----- .../RedundantNilCoalescingRule.swift | 11 +-------- .../RedundantOptionalInitializationRule.swift | 11 +-------- .../ShorthandOptionalBindingRule.swift | 11 +-------- .../Rules/Idiomatic/ToggleBoolRule.swift | 11 +-------- .../Idiomatic/TrailingSemicolonRule.swift | 11 +-------- .../Idiomatic/UnneededBreakInSwitchRule.swift | 11 +-------- .../UnneededSynthesizedInitializerRule.swift | 11 +-------- .../Idiomatic/UntypedErrorInCatchRule.swift | 11 +-------- .../Rules/Lint/AnyObjectProtocolRule.swift | 11 +-------- .../Rules/Lint/LowerACLThanParentRule.swift | 11 +-------- .../Rules/Lint/PrivateUnitTestRule.swift | 8 ++----- .../Rules/Lint/StrongIBOutletRule.swift | 11 +-------- .../Rules/Lint/UnneededOverrideRule.swift | 11 +-------- .../Lint/UnusedClosureParameterRule.swift | 11 +-------- .../Lint/UnusedControlFlowLabelRule.swift | 11 +-------- .../Rules/Style/ClosingBraceRule.swift | 11 +-------- .../Rules/Style/ClosureSpacingRule.swift | 11 +-------- .../Rules/Style/ControlStatementRule.swift | 11 +-------- .../Rules/Style/DirectReturnRule.swift | 11 +-------- .../Rules/Style/EmptyEnumArgumentsRule.swift | 11 +-------- .../Rules/Style/EmptyParametersRule.swift | 11 +-------- ...tyParenthesesWithTrailingClosureRule.swift | 11 +-------- .../Rules/Style/NoSpaceInMethodCallRule.swift | 11 +-------- .../Rules/Style/NumberSeparatorRule.swift | 8 ++----- .../Style/OptionalEnumCaseMatchingRule.swift | 11 +-------- .../PreferSelfTypeOverTypeOfSelfRule.swift | 11 +-------- .../ProtocolPropertyAccessorsOrderRule.swift | 11 +-------- .../Style/RedundantDiscardableLetRule.swift | 11 +-------- .../Rules/Style/SelfBindingRule.swift | 8 ++----- .../Rules/Style/TrailingCommaRule.swift | 8 ++----- ...ededParenthesesInClosureArgumentRule.swift | 11 +-------- .../SwiftSyntaxCorrectableRule.swift | 23 ++++++++++++++----- 39 files changed, 61 insertions(+), 362 deletions(-) diff --git a/Source/SwiftLintBuiltInRules/Helpers/LegacyFunctionRuleHelper.swift b/Source/SwiftLintBuiltInRules/Helpers/LegacyFunctionRuleHelper.swift index 53f47e3148..009a7a747d 100644 --- a/Source/SwiftLintBuiltInRules/Helpers/LegacyFunctionRuleHelper.swift +++ b/Source/SwiftLintBuiltInRules/Helpers/LegacyFunctionRuleHelper.swift @@ -35,10 +35,7 @@ enum LegacyFunctionRuleHelper { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - private let locationConverter: SourceLocationConverter - private let disabledRegions: [SourceRange] + final class Rewriter: ViolationsSyntaxRewriter { private let legacyFunctions: [String: RewriteStrategy] init( @@ -47,8 +44,7 @@ enum LegacyFunctionRuleHelper { disabledRegions: [SourceRange] ) { self.legacyFunctions = legacyFunctions - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions + super.init(locationConverter: locationConverter, disabledRegions: disabledRegions) } override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax { diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ExplicitInitRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ExplicitInitRule.swift index 4ef85c0e46..1e951ad20c 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ExplicitInitRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ExplicitInitRule.swift @@ -193,16 +193,7 @@ private extension ExplicitInitRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax { guard let calledExpression = node.calledExpression.as(MemberAccessExprSyntax.self), diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/JoinedDefaultParameterRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/JoinedDefaultParameterRule.swift index f5ddf7f848..39524b4fa8 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/JoinedDefaultParameterRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/JoinedDefaultParameterRule.swift @@ -54,16 +54,7 @@ private extension JoinedDefaultParameterRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - private let locationConverter: SourceLocationConverter - private let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax { guard let violationPosition = node.violationPosition, !node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else { diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyConstantRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyConstantRule.swift index dada4d77e6..fcec11de56 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyConstantRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyConstantRule.swift @@ -38,16 +38,7 @@ private extension LegacyConstantRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: DeclReferenceExprSyntax) -> ExprSyntax { guard let correction = LegacyConstantRuleExamples.patterns[node.baseName.text], diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyConstructorRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyConstructorRule.swift index b138e3106d..c7d8419722 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyConstructorRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyConstructorRule.swift @@ -141,16 +141,7 @@ private extension LegacyConstructorRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax { guard let identifierExpr = node.calledExpression.as(DeclReferenceExprSyntax.self), case let identifier = identifierExpr.baseName.text, diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/PreferZeroOverExplicitInitRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/PreferZeroOverExplicitInitRule.swift index 39bb2611e5..5ec76319ce 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/PreferZeroOverExplicitInitRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/PreferZeroOverExplicitInitRule.swift @@ -52,16 +52,7 @@ private extension PreferZeroOverExplicitInitRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax { guard node.hasViolation, let name = node.name, diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/PrivateOverFilePrivateRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/PrivateOverFilePrivateRule.swift index 7bd51fbca1..033cdc501b 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/PrivateOverFilePrivateRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/PrivateOverFilePrivateRule.swift @@ -123,16 +123,12 @@ private extension PrivateOverFilePrivateRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] + final class Rewriter: ViolationsSyntaxRewriter { private let validateExtensions: Bool - private let locationConverter: SourceLocationConverter - private let disabledRegions: [SourceRange] init(validateExtensions: Bool, locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { self.validateExtensions = validateExtensions - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions + super.init(locationConverter: locationConverter, disabledRegions: disabledRegions) } // don't call super in any of the `visit` methods to avoid digging into the children diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantNilCoalescingRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantNilCoalescingRule.swift index 899de59960..f6405a5894 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantNilCoalescingRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantNilCoalescingRule.swift @@ -40,16 +40,7 @@ private extension RedundantNilCoalescingRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: ExprListSyntax) -> ExprListSyntax { guard node.count > 2, diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantOptionalInitializationRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantOptionalInitializationRule.swift index 0370782129..d0ed2a3dff 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantOptionalInitializationRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantOptionalInitializationRule.swift @@ -125,16 +125,7 @@ private extension RedundantOptionalInitializationRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - private let locationConverter: SourceLocationConverter - private let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: VariableDeclSyntax) -> DeclSyntax { guard node.bindingSpecifier.tokenKind == .keyword(.var), !node.modifiers.contains(keyword: .lazy) else { diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ShorthandOptionalBindingRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ShorthandOptionalBindingRule.swift index a8fe9142cc..14b3e4a930 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ShorthandOptionalBindingRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ShorthandOptionalBindingRule.swift @@ -97,16 +97,7 @@ private extension ShorthandOptionalBindingRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - private let locationConverter: SourceLocationConverter - private let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: OptionalBindingConditionSyntax) -> OptionalBindingConditionSyntax { guard node.isShadowingOptionalBinding, diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ToggleBoolRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ToggleBoolRule.swift index 4c6fb4d38a..67b083949b 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ToggleBoolRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ToggleBoolRule.swift @@ -47,16 +47,7 @@ private extension ToggleBoolRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: ExprListSyntax) -> ExprListSyntax { guard node.hasToggleBoolViolation, !node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter), diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/TrailingSemicolonRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/TrailingSemicolonRule.swift index ffad7c87f7..98ee862fb4 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/TrailingSemicolonRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/TrailingSemicolonRule.swift @@ -42,16 +42,7 @@ private extension TrailingSemicolonRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: TokenSyntax) -> TokenSyntax { guard node.isTrailingSemicolon, diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededBreakInSwitchRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededBreakInSwitchRule.swift index fc35a80ab2..a346978a48 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededBreakInSwitchRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededBreakInSwitchRule.swift @@ -106,16 +106,7 @@ private extension UnneededBreakInSwitchRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [SwiftSyntax.AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: SwitchCaseSyntax) -> SwitchCaseSyntax { let stmts = CodeBlockItemListSyntax(node.statements.dropLast()) diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift index 8f57ff2005..dfad96f4f7 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift @@ -53,18 +53,9 @@ private extension UnneededSynthesizedInitializerRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - var correctionPositions: [AbsolutePosition] = [] + final class Rewriter: ViolationsSyntaxRewriter { private var unneededInitializers: [InitializerDeclSyntax] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - override func visit(_ node: StructDeclSyntax) -> DeclSyntax { unneededInitializers = node.unneededInitializers.filter { !$0.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UntypedErrorInCatchRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UntypedErrorInCatchRule.swift index 35e9f1a7a5..6a9f10b0f2 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UntypedErrorInCatchRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UntypedErrorInCatchRule.swift @@ -126,16 +126,7 @@ private extension UntypedErrorInCatchRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: CatchClauseSyntax) -> CatchClauseSyntax { guard let item = node.catchItems.onlyElement, diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/AnyObjectProtocolRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/AnyObjectProtocolRule.swift index 50ff5b8b88..14c5ba8f78 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/AnyObjectProtocolRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/AnyObjectProtocolRule.swift @@ -58,16 +58,7 @@ private extension AnyObjectProtocolRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: InheritedTypeSyntax) -> InheritedTypeSyntax { let typeName = node.type guard diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/LowerACLThanParentRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/LowerACLThanParentRule.swift index 5a11b66ab6..1f9e45149a 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/LowerACLThanParentRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/LowerACLThanParentRule.swift @@ -98,16 +98,7 @@ private extension LowerACLThanParentRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: DeclModifierSyntax) -> DeclModifierSyntax { guard node.isHigherACLThanParent, diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/PrivateUnitTestRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/PrivateUnitTestRule.swift index 3cb8394abe..8d427bd7d1 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/PrivateUnitTestRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/PrivateUnitTestRule.swift @@ -156,18 +156,14 @@ private extension PrivateUnitTestRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] + final class Rewriter: ViolationsSyntaxRewriter { private let configuration: PrivateUnitTestConfiguration - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] init(configuration: PrivateUnitTestConfiguration, locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { self.configuration = configuration - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions + super.init(locationConverter: locationConverter, disabledRegions: disabledRegions) } override func visit(_ node: ClassDeclSyntax) -> DeclSyntax { diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/StrongIBOutletRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/StrongIBOutletRule.swift index 41cc168e4a..43204869d5 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/StrongIBOutletRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/StrongIBOutletRule.swift @@ -45,16 +45,7 @@ private extension StrongIBOutletRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: VariableDeclSyntax) -> DeclSyntax { guard let violationPosition = node.violationPosition, let weakOrUnownedModifier = node.weakOrUnownedModifier, diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/UnneededOverrideRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/UnneededOverrideRule.swift index 8f9282b3d8..d0870d5840 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/UnneededOverrideRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/UnneededOverrideRule.swift @@ -66,16 +66,7 @@ private extension UnneededOverrideRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: FunctionDeclSyntax) -> DeclSyntax { if isUnneededOverride(node) && !node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) { diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedClosureParameterRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedClosureParameterRule.swift index d2ba6679b0..f56d280488 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedClosureParameterRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedClosureParameterRule.swift @@ -40,16 +40,7 @@ private extension UnusedClosureParameterRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: ClosureExprSyntax) -> ExprSyntax { guard node.namedParameters.isNotEmpty, diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedControlFlowLabelRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedControlFlowLabelRule.swift index 7fc81134ef..e23730bb10 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedControlFlowLabelRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedControlFlowLabelRule.swift @@ -101,16 +101,7 @@ private extension UnusedControlFlowLabelRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: LabeledStmtSyntax) -> StmtSyntax { guard let violationPosition = node.violationPosition, !node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else { diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/ClosingBraceRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/ClosingBraceRule.swift index 7cf3af0455..2b34fc8f6d 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/ClosingBraceRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/ClosingBraceRule.swift @@ -39,16 +39,7 @@ private extension ClosingBraceRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: TokenSyntax) -> TokenSyntax { guard node.hasClosingBraceViolation, diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/ClosureSpacingRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/ClosureSpacingRule.swift index 14e8aca15e..e1e6570048 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/ClosureSpacingRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/ClosureSpacingRule.swift @@ -63,16 +63,7 @@ private extension ClosureSpacingRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: ClosureExprSyntax) -> ExprSyntax { var node = node node.statements = visit(node.statements) diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/ControlStatementRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/ControlStatementRule.swift index 1e609bc7bc..a60b2c2fea 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/ControlStatementRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/ControlStatementRule.swift @@ -115,16 +115,7 @@ private extension ControlStatementRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: CatchClauseSyntax) -> CatchClauseSyntax { guard !node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter), case let items = node.catchItems, items.containSuperfluousParens == true else { diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/DirectReturnRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/DirectReturnRule.swift index aeef7faa9c..ccee8fd158 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/DirectReturnRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/DirectReturnRule.swift @@ -198,16 +198,7 @@ private extension DirectReturnRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ statements: CodeBlockItemListSyntax) -> CodeBlockItemListSyntax { guard let (binding, returnStmt) = statements.violation, !binding.isContainedIn(regions: disabledRegions, locationConverter: locationConverter), diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/EmptyEnumArgumentsRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/EmptyEnumArgumentsRule.swift index 4d26e6876d..b6fa1c10d8 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/EmptyEnumArgumentsRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/EmptyEnumArgumentsRule.swift @@ -135,16 +135,7 @@ private extension EmptyEnumArgumentsRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: SwitchCaseItemSyntax) -> SwitchCaseItemSyntax { guard let (violationPosition, newPattern) = node.pattern.emptyEnumArgumentsViolation(rewrite: true), diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/EmptyParametersRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/EmptyParametersRule.swift index 60da21f95a..b384e7e956 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/EmptyParametersRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/EmptyParametersRule.swift @@ -51,16 +51,7 @@ private extension EmptyParametersRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: FunctionTypeSyntax) -> TypeSyntax { guard let violationPosition = node.emptyParametersViolationPosition, diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/EmptyParenthesesWithTrailingClosureRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/EmptyParenthesesWithTrailingClosureRule.swift index 6b71c89077..bfa366969e 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/EmptyParenthesesWithTrailingClosureRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/EmptyParenthesesWithTrailingClosureRule.swift @@ -64,16 +64,7 @@ private extension EmptyParenthesesWithTrailingClosureRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax { guard let violationPosition = node.violationPosition, diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/NoSpaceInMethodCallRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/NoSpaceInMethodCallRule.swift index bc9ea8420a..6bf68495e7 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/NoSpaceInMethodCallRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/NoSpaceInMethodCallRule.swift @@ -63,16 +63,7 @@ private extension NoSpaceInMethodCallRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax { guard node.hasNoSpaceInMethodCallViolation, diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/NumberSeparatorRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/NumberSeparatorRule.swift index 351e50ff7e..a046953a27 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/NumberSeparatorRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/NumberSeparatorRule.swift @@ -50,18 +50,14 @@ private extension NumberSeparatorRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter, NumberSeparatorValidator { - private(set) var correctionPositions: [AbsolutePosition] = [] + final class Rewriter: ViolationsSyntaxRewriter, NumberSeparatorValidator { let configuration: NumberSeparatorConfiguration - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] init(configuration: NumberSeparatorConfiguration, locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { self.configuration = configuration - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions + super.init(locationConverter: locationConverter, disabledRegions: disabledRegions) } override func visit(_ node: FloatLiteralExprSyntax) -> ExprSyntax { diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/OptionalEnumCaseMatchingRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/OptionalEnumCaseMatchingRule.swift index 8ce5a4b75f..572e211d52 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/OptionalEnumCaseMatchingRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/OptionalEnumCaseMatchingRule.swift @@ -181,16 +181,7 @@ private extension OptionalEnumCaseMatchingRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: SwitchCaseItemSyntax) -> SwitchCaseItemSyntax { guard let pattern = node.pattern.as(ExpressionPatternSyntax.self), diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/PreferSelfTypeOverTypeOfSelfRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/PreferSelfTypeOverTypeOfSelfRule.swift index 4714a76e4c..85787be336 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/PreferSelfTypeOverTypeOfSelfRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/PreferSelfTypeOverTypeOfSelfRule.swift @@ -123,16 +123,7 @@ private extension PreferSelfTypeOverTypeOfSelfRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: MemberAccessExprSyntax) -> ExprSyntax { guard let function = node.base?.as(FunctionCallExprSyntax.self), function.hasViolation, diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/ProtocolPropertyAccessorsOrderRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/ProtocolPropertyAccessorsOrderRule.swift index 72604cc38b..7b7cc31e73 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/ProtocolPropertyAccessorsOrderRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/ProtocolPropertyAccessorsOrderRule.swift @@ -46,16 +46,7 @@ private extension ProtocolPropertyAccessorsOrderRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: AccessorBlockSyntax) -> AccessorBlockSyntax { guard node.hasViolation, diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/RedundantDiscardableLetRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/RedundantDiscardableLetRule.swift index a92e6e5ef0..2dd68059e4 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/RedundantDiscardableLetRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/RedundantDiscardableLetRule.swift @@ -44,16 +44,7 @@ private extension RedundantDiscardableLetRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: VariableDeclSyntax) -> DeclSyntax { guard node.hasRedundantDiscardableLetViolation, diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/SelfBindingRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/SelfBindingRule.swift index b54cbd719c..5d37797ac2 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/SelfBindingRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/SelfBindingRule.swift @@ -80,16 +80,12 @@ private extension SelfBindingRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] + final class Rewriter: ViolationsSyntaxRewriter { private let bindIdentifier: String - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] init(bindIdentifier: String, locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { self.bindIdentifier = bindIdentifier - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions + super.init(locationConverter: locationConverter, disabledRegions: disabledRegions) } override func visit(_ node: OptionalBindingConditionSyntax) -> OptionalBindingConditionSyntax { diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/TrailingCommaRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/TrailingCommaRule.swift index 40d28b6a32..c974080ddd 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/TrailingCommaRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/TrailingCommaRule.swift @@ -97,16 +97,12 @@ private extension TrailingCommaRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] + final class Rewriter: ViolationsSyntaxRewriter { private let mandatoryComma: Bool - private let locationConverter: SourceLocationConverter - private let disabledRegions: [SourceRange] init(mandatoryComma: Bool, locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { self.mandatoryComma = mandatoryComma - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions + super.init(locationConverter: locationConverter, disabledRegions: disabledRegions) } override func visit(_ node: DictionaryElementListSyntax) -> DictionaryElementListSyntax { diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/UnneededParenthesesInClosureArgumentRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/UnneededParenthesesInClosureArgumentRule.swift index 0c94ade3ab..c5e726c278 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/UnneededParenthesesInClosureArgumentRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/UnneededParenthesesInClosureArgumentRule.swift @@ -94,16 +94,7 @@ private extension UnneededParenthesesInClosureArgumentRule { } } - final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - private(set) var correctionPositions: [AbsolutePosition] = [] - let locationConverter: SourceLocationConverter - let disabledRegions: [SourceRange] - - init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { - self.locationConverter = locationConverter - self.disabledRegions = disabledRegions - } - + final class Rewriter: ViolationsSyntaxRewriter { override func visit(_ node: ClosureSignatureSyntax) -> ClosureSignatureSyntax { guard let clause = node.parameterClause?.as(ClosureParameterClauseSyntax.self), diff --git a/Source/SwiftLintCore/Protocols/SwiftSyntaxCorrectableRule.swift b/Source/SwiftLintCore/Protocols/SwiftSyntaxCorrectableRule.swift index 55f32030b4..bb109f1d6c 100644 --- a/Source/SwiftLintCore/Protocols/SwiftSyntaxCorrectableRule.swift +++ b/Source/SwiftLintCore/Protocols/SwiftSyntaxCorrectableRule.swift @@ -16,7 +16,7 @@ public protocol SwiftSyntaxCorrectableRule: SwiftSyntaxRule, CorrectableRule { public extension SwiftSyntaxCorrectableRule { func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? { - nil as NoOpRewriter? + nil as ViolationsSyntaxRewriter? } func correct(file: SwiftLintFile) -> [Correction] { @@ -66,11 +66,22 @@ public extension SwiftSyntaxCorrectableRule { } /// A SwiftSyntax `SyntaxRewriter` that produces absolute positions where corrections were applied. -public protocol ViolationsSyntaxRewriter: SyntaxRewriter { +open class ViolationsSyntaxRewriter: SyntaxRewriter { + /// A converter of positions in the traversed source file. + public let locationConverter: SourceLocationConverter + /// The regions in the traversed file that are disabled by a command. + public let disabledRegions: [SourceRange] + /// Positions in a source file where corrections were applied. - var correctionPositions: [AbsolutePosition] { get } -} + public var correctionPositions = [AbsolutePosition]() -private class NoOpRewriter: SyntaxRewriter, ViolationsSyntaxRewriter { - var correctionPositions = [AbsolutePosition]() + /// Initilizer for a ``ViolationsSyntaxRewriter``. + /// + /// - Parameters: + /// - locationConverter: Converter for positions in the source file being rewritten. + /// - disabledRegions: Regions in the to be rewritten file that are disabled by a command. + public init(locationConverter: SourceLocationConverter, disabledRegions: [SourceRange]) { + self.locationConverter = locationConverter + self.disabledRegions = disabledRegions + } }