-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use default Equatable and Hashable implementations #2469
Use default Equatable and Hashable implementations #2469
Conversation
Here's an example of your CHANGELOG entry: * Use default Equatable and Hashable implementations.
[marcelofabri](https://github.com/marcelofabri)
[#issue_number](https://github.com/realm/SwiftLint/issues/issue_number) note: There are two invisible spaces after the entry's text. Generated by 🚫 Danger |
@@ -24,7 +24,7 @@ class RequiredEnumCaseRuleTestCase: XCTestCase { | |||
|
|||
func testRequiredCaseHashValue() { | |||
let requiredCase = RequiredCase(name: "success") | |||
XCTAssertEqual(requiredCase.hashValue, "success".hashValue) | |||
XCTAssertEqual(requiredCase.hashValue, RequiredCase(name: "success").hashValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point in testing XCTAssertEqual(RequiredCase(name: "success").hashValue, RequiredCase(name: "success").hashValue)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ideia is to make sure that hashCode
is the same for enums containing associated values.
This is now basically testing the compiler, but the fact that we're generating hashValue
automatically is an implementation detail and I don't think it hurts to test it.
Note that we can't compare to a value directly because now the hashValue
can (and will) return different values in different program runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced these tests give much value, but fine to keep if you think they do.
Tests being testRequiredCaseHashValue
, testRequiredCaseEquatableReturnsTrue
and testRequiredCaseEquatableReturnsFalseBecauseOfDifferentName
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that they're not super valuable but since they're already written I don't see why not keep them
|
||
static func == (lhs: RegexCacheKey, rhs: RegexCacheKey) -> Bool { | ||
return lhs.options == rhs.options && lhs.pattern == rhs.pattern | ||
extension NSRegularExpression.Options: Hashable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not hashable already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprisingly, it's not 😱
@@ -45,14 +45,6 @@ public struct Location: CustomStringConvertible, Comparable { | |||
} | |||
} | |||
|
|||
// MARK: Comparable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should keep this MARK
Since we now require Swift 4.2 to build, we can use the compiler-generated implementations for
Equatable
andHashable
🎉