diff --git a/CHANGELOG.md b/CHANGELOG.md index 194b8df81d..376c93f074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,11 @@ [SimplyDanny](https://github.com/SimplyDanny) [#5592](https://github.com/realm/SwiftLint/issues/5592) +* Keep initializers with attributed parameters in + `unneeded_synthesized_initializer` rule. + [SimplyDanny](https://github.com/SimplyDanny) + [#5153](https://github.com/realm/SwiftLint/issues/5153) + ## 0.55.1: Universal Washing Powder #### Breaking diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift index d40aa8b977..dd789bae62 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift @@ -132,7 +132,7 @@ private extension StructDeclSyntax { } for (idx, parameter) in initializerParameters.enumerated() { - guard parameter.secondName == nil else { + guard parameter.secondName == nil, parameter.attributes.isEmpty else { return false } let property = storedProperties[idx] diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRuleExamples.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRuleExamples.swift index 868022aa67..507ade2774 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRuleExamples.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRuleExamples.swift @@ -198,6 +198,15 @@ enum UnneededSynthesizedInitializerRuleExamples { } } """), + Example(""" + struct Foo { + var bar: Int + + init(@Clamped bar: Int) { + self.bar = bar + } + } + """), Example(""" struct Foo { let bar: Int