Skip to content
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

Merged
merged 2 commits into from
Nov 20, 2018
Merged

Use default Equatable and Hashable implementations #2469

merged 2 commits into from
Nov 20, 2018

Conversation

marcelofabri
Copy link
Collaborator

Since we now require Swift 4.2 to build, we can use the compiler-generated implementations for Equatable and Hashable 🎉

@SwiftLintBot
Copy link

SwiftLintBot commented Nov 19, 2018

1 Warning
⚠️ Please include a CHANGELOG entry to credit yourself!
You can find it at CHANGELOG.md.
12 Messages
📖 Linting Aerial with this PR took 2.05s vs 2.61s on master (21% faster)
📖 Linting Alamofire with this PR took 4.85s vs 5.57s on master (12% faster)
📖 Linting Firefox with this PR took 18.69s vs 19.42s on master (3% faster)
📖 Linting Kickstarter with this PR took 34.01s vs 24.25s on master (40% slower)
📖 Linting Moya with this PR took 3.57s vs 2.15s on master (66% slower)
📖 Linting Nimble with this PR took 3.75s vs 2.0s on master (87% slower)
📖 Linting Quick with this PR took 0.93s vs 0.64s on master (45% slower)
📖 Linting Realm with this PR took 5.92s vs 3.95s on master (49% slower)
📖 Linting SourceKitten with this PR took 1.96s vs 1.36s on master (44% slower)
📖 Linting Sourcery with this PR took 8.13s vs 6.52s on master (24% slower)
📖 Linting Swift with this PR took 44.9s vs 31.65s on master (41% slower)
📖 Linting WordPress with this PR took 33.13s vs 22.59s on master (46% slower)

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)
Copy link
Contributor

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)?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should keep this MARK

@marcelofabri marcelofabri merged commit d1dbc31 into realm:master Nov 20, 2018
@marcelofabri marcelofabri deleted the use-default-equatable-implementation branch November 20, 2018 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants