Skip to content

Explicit Codable Hooks#23

Merged
WendellXY merged 3 commits intomainfrom
feature/v2-explicit-codable-hooks
Dec 31, 2025
Merged

Explicit Codable Hooks#23
WendellXY merged 3 commits intomainfrom
feature/v2-explicit-codable-hooks

Conversation

@WendellXY
Copy link
Copy Markdown
Owner

This pull request introduces breaking changes to how Codable lifecycle hooks are detected and invoked in CodableKit v2. Hooks are now explicit: only methods annotated with @CodableHook will be recognized and invoked, and using conventional method names without the annotation will result in a compile-time error. The documentation and tests have been updated to reflect this new behavior, and migration guidance has been added.

Codable Hook Detection Changes:

  • Removed fallback for detecting hook methods by conventional names (didDecode, willEncode, didEncode, willDecode); only @CodableHook-annotated methods are now invoked. [1] [2]
  • Added compile-time diagnostics: if a conventional hook method is present without @CodableHook, a clear error is emitted indicating the method will not be invoked.

Documentation Updates:

  • Added a new MIGRATION.md file detailing the breaking changes and providing migration steps for upgrading from v1 to v2.
  • Updated README.md to clarify that hooks are now explicit and to direct users to the migration guide. [1] [2]

Test Suite Updates:

  • Updated and expanded tests to check for the new diagnostics when conventional hook methods are used without annotation, ensuring the new error messages are emitted as expected. [1] [2] [3] [4]

- Remove conventional-name fallback hook detection; only @CodableHook is invoked.

- Warn when conventional hook methods exist without @CodableHook.

- Update README and macro expansion tests.
Document that hooks are annotation-only in v2 and provide before/after examples.
Conventional hook method names are no longer invoked in v2; make this a compile-time error and update docs/tests.
@WendellXY WendellXY added this to the v2 milestone Dec 31, 2025
Copilot AI review requested due to automatic review settings December 31, 2025 08:25
@WendellXY WendellXY self-assigned this Dec 31, 2025
@WendellXY WendellXY changed the title Feature: Explicit Codable Hooks Explicit Codable Hooks Dec 31, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a breaking change to CodableKit v2 that makes lifecycle hooks explicit: only methods annotated with @CodableHook will be recognized and invoked. The macro now emits compile-time errors when conventional hook method names are detected without the required annotation.

  • Removed implicit hook detection by conventional method names (willDecode, didDecode, willEncode, didEncode)
  • Added compile-time diagnostics to catch unannotated conventional hooks
  • Updated documentation and added migration guide for v1 to v2 upgrades

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Sources/CodableKitMacros/CodeGenCore.swift Removed fallback logic for conventional hook names; added diagnostic generation for unannotated hooks with conventional names
Tests/EncodableKitTests/CodableMacroTests+hooks.swift Added diagnostic expectations for unannotated willEncode and didEncode methods
Tests/DecodableKitTests/CodableMacroTests+hooks.swift Added diagnostic expectation for unannotated didDecode method
Tests/CodableKitTests/CodableMacroTests+class_hooks.swift Added diagnostic expectations for three unannotated hook methods in class context
README.md Updated hook documentation to clarify explicit annotation requirement; added reference to migration guide
MIGRATION.md New file providing comprehensive migration guidance from v1 to v2 with examples for each hook type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@WendellXY WendellXY merged commit 0a9087a into main Dec 31, 2025
14 checks passed
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