Fix redundantEquatable incorrectly removing custom == on Strideable types#2417
Fix redundantEquatable incorrectly removing custom == on Strideable types#2417
redundantEquatable incorrectly removing custom == on Strideable types#2417Conversation
|
@copilot, also add a mention about this to Known Issues in the README. We can only detect this if the Equatable and Strideable conformances are in the same file. |
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
redundantEquatable incorrectly removing custom == on Strideable types
…le conformances Co-authored-by: calda <1811727+calda@users.noreply.github.com>
Added in bf4ccf1. The Known Issues entry notes that the rule will correctly preserve |
README.md
Outdated
|
|
||
| * The `propertyTypes` rule can cause a build failure in cases like `let foo = Foo.bar` where the value is a static member that doesn't return the same time. For example, `let foo: Foo = .bar` would be invalid if the `bar` property was defined as `static var bar: Bar`. As a workaround you can write the name of the type explicitly, like `let foo: Bar = Foo.bar`, or exclude the type name and/or property name with `--preserve-symbols Bar,bar,etc`. | ||
|
|
||
| * The `redundantEquatable` rule will not remove a custom `==` implementation if the type also conforms to `Strideable` *in the same file*. If the `Strideable` conformance is defined in a different file, SwiftFormat cannot detect it, and may incorrectly remove a `==` implementation that intentionally overrides the default one provided by `Strideable`. As a workaround you can use the `// swiftformat:disable:next redundantEquatable` comment directive to disable the rule for the affected type (or just disable the `redundantEquatable` rule completely). |
There was a problem hiding this comment.
@copilot: This also applies to types other than Strideable that potentially add defaulted == implementations. Broaden this, and mention that we do handle it for Stridable conformance in the same file as the ==.
There was a problem hiding this comment.
Updated in a29f15e. The Known Issues entry now mentions that any protocol providing a default == can cause this problem, with Strideable as the concrete example, and explicitly states that SwiftFormat handles the Strideable-in-same-file case correctly.
…ension Co-authored-by: calda <1811727+calda@users.noreply.github.com>
…er protocols beyond Strideable Co-authored-by: calda <1811727+calda@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2417 +/- ##
===========================================
- Coverage 95.22% 95.20% -0.02%
===========================================
Files 161 161
Lines 24181 24188 +7
===========================================
+ Hits 23026 23029 +3
- Misses 1155 1159 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Strideableprovides a default==implementation derived fromdistance(to:). A type conforming toStrideablemay intentionally override this with a custom==, and theredundantEquatablerule was removing it — silently restoring theStrideabledefault and changing runtime behavior.Changes
Sources/Rules/RedundantEquatable.swift: InmanuallyImplementedEquatableTypes, track fully-qualified names of types with aStrideableconformance (across primary declarations and extensions). Exclude those types from==removal.Tests/Rules/RedundantEquatableTests.swift: Add four test cases covering all combinations of where the conformances can appear:StrideableandEquatabledeclared inline on the typeStrideableinline,Equatable(with==) in a separate extensionEquatable(with==) inline,Strideablein a separate extensionREADME.md: Added a Known Issues entry noting that theredundantEquatablerule may incorrectly remove a==implementation that intentionally overrides a default==provided by any protocol (not justStrideable). The entry explicitly notes that SwiftFormat does handle theStrideable-in-same-file case correctly, but cannot detectStrideableconformances in a different file or default==implementations from other protocols. The recommended workaround is to use// swiftformat:disable:next redundantEquatableor disable the rule entirely.Example
Original prompt
redundantEquatableremoves non-redundant==#2416💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.