Skip to content

add implement the Hashable & Equatable to SmartIgnored#113

Closed
faimin wants to merge 1 commit into
iAmMccc:mainfrom
faimin:main
Closed

add implement the Hashable & Equatable to SmartIgnored#113
faimin wants to merge 1 commit into
iAmMccc:mainfrom
faimin:main

Conversation

@faimin
Copy link
Copy Markdown
Contributor

@faimin faimin commented Sep 15, 2025

问题

在使用NSDiffableDataSourceSnapshot 时,snapshot要求Item遵守Hashable协议,假如 Item中的某个属性被@SmartIgnored标记,会因为@SmartIgnored未实现Hashable协议而编译失败。

当然使用者也可以自己解决,比如不用 @SmartIgnored , 或者项目中自己对 SmartIgnored 添加 Hashable extetion。不过我感觉这是一个比较常见的业务场景,所以提了这个MR

Code

struct RewardModel: Hashable, SmartCodable {
    // MARK: Properties

    var rewardId: Int = 0
    var rewardName: String = ""
    var rewardIcon: String = ""
    var unitText: String = ""

    @SmartIgnored
    var contributeLevel: ContributeLevel = .none
}

// MARK: - ContributeLevel

enum ContributeLevel: Int, Hashable, SmartCaseDefaultable {
    case none = 0, low, high, top1
}

Summary by CodeRabbit

  • New Features
    • SmartIgnored now conforms to Equatable and Hashable when its wrapped type does, allowing direct comparisons and hashing. This enables use in sets, as dictionary keys, and simplifies testing and state diffs. Improves interoperability with Swift collections and algorithms without requiring workarounds. No behavior changes for non-Equatable/Hashable types. Backwards compatible. No API removals.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 15, 2025

Walkthrough

Added conditional Equatable and Hashable conformances to the SmartIgnored property wrapper by delegating comparison and hashing to wrappedValue when T meets those protocols.

Changes

Cohort / File(s) Summary
Property wrapper protocol conformances
Sources/SmartCodable/Core/PropertyWrapper/SmartIgnored.swift
Added extension SmartIgnored: Equatable where T: Equatable with == comparing wrappedValue, and extension SmartIgnored: Hashable where T: Hashable with hash(into:) delegating to wrappedValue.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I twitch my nose at tidy code,
New equals, hashes on the road.
Wrapped values whisper, “Compare me true!”
The hasher hums a crunchy chew.
I thump, approve, then softly scoot—
Small hops make sturdy, stable fruit. 🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title directly and specifically describes the primary change—adding Equatable and Hashable conformance to SmartIgnored—so it accurately reflects the main changes in the diff; however the phrasing is slightly awkward ("add implement") which reduces clarity.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Sources/SmartCodable/Core/PropertyWrapper/SmartIgnored.swift (1)

71-75: LGTM: Hashable conformance; minor nits

Implementation is correct. Two small nits:

  • Verify that excluding isEncodable from hashing is intentional.
  • Consider marking these tiny methods @inlinable for cross‑module performance, or move public to the extension (public extension) for consistency.

Apply if you agree:

-extension SmartIgnored: Equatable where T: Equatable {
-    public static func == (lhs: Self, rhs: Self) -> Bool {
+public extension SmartIgnored where T: Equatable {
+    @inlinable
+    static func == (lhs: Self, rhs: Self) -> Bool {
         return lhs.wrappedValue == rhs.wrappedValue
     }
 }
 
-extension SmartIgnored: Hashable where T: Hashable {
-    public func hash(into hasher: inout Hasher) {
+public extension SmartIgnored where T: Hashable {
+    @inlinable
+    func hash(into hasher: inout Hasher) {
         wrappedValue.hash(into: &hasher)
     }
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1eae39a and aaf67ab.

📒 Files selected for processing (1)
  • Sources/SmartCodable/Core/PropertyWrapper/SmartIgnored.swift (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
Sources/SmartCodable/Core/PropertyWrapper/SmartIgnored.swift (1)

65-69: LGTM: Equatable conformance via wrappedValue; confirm synthesized semantics on owners

This is correct and unblocks synthesized Equatable on types containing @SmartIgnored. Note this makes the wrapped value participate in owners’ synthesized equality; confirm that’s the intended behavior for an “ignored” property (ignore only for coding, not for identity).

@iAmMccc
Copy link
Copy Markdown
Owner

iAmMccc commented Sep 28, 2025

V5.1.3已支持

@iAmMccc iAmMccc closed this Sep 28, 2025
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.

2 participants