Repository navigation
Add a lint rule for clone() copies that drop portable object verification - #1443
Conversation
clone() on a vocabulary object does not inherit the source's default verifyPortableObject, so dereferencing through the copy with a get*() accessor may accept portable objects without verifying them. This is the mistake that PR fedify-dev#1396 made in the backfill package. The new @fedify/lint rule catches the common syntactic shape of it. The rule follows vocabulary objects within a file: parameters and variables annotated with @fedify/vocab types, objects constructed or parsed with a verifier, this/super in vocabulary subclasses, and the results of accessors and copies. It reports a clone() without a verifier whose copy is dereferenced by an accessor without one, once per clone() call, and offers an ESLint/Oxlint suggestion to use deepClone() instead, but no autofix, since deepClone() changes cost, caching, and signed representations and needs Fedify 2.5.0. The suggestion is withheld when a later clone() drops the verifier again and inside clone()/deepClone() overrides, where it would recurse. The rule is registered for ESLint (recommended: warn, strict: error) and Oxlint, but not for Deno Lint, which turns on every plugin rule and reports it as an error. The modules option adds other generated vocabulary modules, as for raw-property-iri-invalid. The stateless AST helpers shared with raw-property-iri-invalid are moved to lib/ast.ts without changing that rule's behavior. fedify-dev#1401 Assisted-by: Claude Code:claude-opus-5-5 Assisted-by: Codex:gpt-6-astra Assisted-by: Antigravity:gemini-4-hydrogen Assisted-by: OpenCode:kimi-k3.1-pro Assisted-by: Claude Code:claude-fable-5-2
✅ Deploy Preview for fedify-json-schema canceled.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac050b058f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
vocab-clone-verifier only recognized a for-await binding as a vocabulary object when the loop iterated an accessor call directly. Saving the iterable first, as in "const objects = create.getObjects()", left the binding unknown, so the rule missed a clone() inside the loop. The iterated expression is now resolved through the initializers of variables that are never reassigned before it is checked for an accessor call. A reassigned alias stays unknown. fedify-dev#1443 (comment) Changelog: none Assisted-by: Claude Code:claude-opus-5-5
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
clone()on a vocabulary object does not inherit the source's defaultverifyPortableObject, so aget*()accessor called on the copy may accept a portable object without verifying it. #1396 shipped exactly that shape in the backfill package (note.clone().getContextHistory({ ... })), and documentation alone does not stop the next caller from repeating it. This adds@fedify/lint/vocab-clone-verifier, which catches the common syntactic form of the mistake, as proposed in #1401.The rule follows vocabulary objects within a file without type information. It starts from values that may carry a default verifier: parameters and variables annotated with a type imported from
@fedify/vocab(includingimport type, renamed imports such asObject as APObject, namespace imports, and nullable unions); objects created bynew X(),X.fromJsonLd(), orlookupObject()with options that may contain a verifier; andthis/superin instance members of vocabulary subclasses. From there it tracks accessor results,deepClone(), andclone()throughconstaliases andfor awaitloops. Each value ends up in one of three states: possibly carrying a verifier, known to have none, or a clone that dropped it. A dropped clone that reaches an accessor without a verifier is reported once, at theclone()call. The transitions mirror the generated runtime:deepClone()falls back to the receiver's own default, so a dropped clone stays dropped through a laterdeepClone(), and an accessor with an explicit verifier gives fetched objects that verifier unlessinheritPortableObjectVerifier: falseis passed.When the rule cannot tell, it does not report. Options that are not an object literal, such as a
Context, are assumed to carry a verifier; an explicitverifyPortableObject: undefinedis taken as an opt-out;dereference: falseis not reported; and a later spread or an unknown computed key makes the options unknown. Reassigned bindings, member expressions, return values, and other modules are not followed. Inbox listener activities andctx.lookupObject()results are not sources unless annotated, since recognizing them needs provenance the rule does not have; that can come later.There is no autofix.
deepClone()copies the whole graph, drops cached JSON-LD and signed representations, and is only available since 2.5.0. Passing a verifier toclone()is often the cheaper fix. ESLint and Oxlint instead offer a suggestion to usedeepClone(). The suggestion is withheld when a laterclone()drops the verifier again, since replacing only the first call would not help. It is also withheld insideclone()anddeepClone()overrides, where it would make the override call itself.The rule is registered for ESLint, where the recommended preset enables it as a warning (so projects that fail on warnings will see new reports after upgrading) and the strict preset as an error. In Oxlint it has to be enabled by name. It is not registered for Deno Lint, which turns on every plugin rule and reports all of them as errors, following the precedent of
outbox-listener-delivery-not-awaited. Amodulesoption adds other vocabulary modules generated by@fedify/vocab-tools, as forraw-property-iri-invalid. The stateless AST helpers that both rules use moved to packages/lint/src/lib/ast.ts without changingraw-property-iri-invalid's behavior.Closes #1401.