From b42f6ffe77159aed1060bf607212a0410c7623b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 17 May 2024 23:06:09 +0200 Subject: [PATCH] Keep initializers with attributed parameters in `unneeded_synthesized_initializer` rule (#5594) --- CHANGELOG.md | 5 +++++ .../Idiomatic/UnneededSynthesizedInitializerRule.swift | 2 +- .../UnneededSynthesizedInitializerRuleExamples.swift | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) 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