Skip to content

feat(DEP0206): remove redundant Hmac.digest() calls - #574

Open
vishalrajofficial wants to merge 2 commits into
nodejs:mainfrom
vishalrajofficial:feat-dep0206-hmac-digest
Open

vishalrajofficial wants to merge 2 commits into
nodejs:mainfrom
vishalrajofficial:feat-dep0206-hmac-digest

Conversation

@vishalrajofficial

Copy link
Copy Markdown

Fixes #557

Description

This PR implements the @nodejs/crypto-hmac-digest-redundant codemod recipe to address DEP0206.

In Node.js, Hmac.prototype.digest() finalizes the HMAC context. Subsequent argument-free calls to digest() on the same instance are redundant when their return value is unused and can be safely removed.

Changes

  • Added @nodejs/crypto-hmac-digest-redundant recipe in recipes/crypto-hmac-digest-redundant.
  • Detects createHmac initializations from node:crypto and crypto (both ESM and CommonJS).
  • Validates straight-line execution and removes standalone, argument-free hmac.digest() expression statements that occur after the instance has already been finalized by a previous digest() call.
  • Preserves calls if the Hmac instance is passed as an argument, reassigned, returned, involved in conditional branching, invoked with arguments (such as encoding strings), or if the return value is captured or consumed.
  • Added comprehensive unit test fixtures covering adjacent calls, multiple redundant calls, CommonJS requires, imported aliases, consumed return values, encoding arguments, control-flow branching, and shadowed bindings.

Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
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.

feat(DEP0206): remove provably redundant Hmac.digest() calls

2 participants