From 2a9aa0d7dde420528ac912512bcaefb4db1bcaec Mon Sep 17 00:00:00 2001 From: Vishal Raj <9031842908.vk@gmail.com> Date: Tue, 17 Nov 2026 10:18:31 +0530 Subject: [PATCH 1/2] feat(DEP0206): remove redundant Hmac.digest() calls Signed-off-by: Vishal Raj <9031842908.vk@gmail.com> --- package-lock.json | 13 ++ .../crypto-hmac-digest-redundant/README.md | 51 +++++ .../crypto-hmac-digest-redundant/codemod.yaml | 25 +++ .../crypto-hmac-digest-redundant/package.json | 13 ++ .../src/workflow.ts | 207 ++++++++++++++++++ .../tests/adjacent-calls/expected.js | 6 + .../tests/adjacent-calls/input.js | 7 + .../tests/aliases/expected.js | 4 + .../tests/aliases/input.js | 5 + .../tests/branches/expected.js | 8 + .../tests/branches/input.js | 8 + .../tests/commonjs/expected.js | 4 + .../tests/commonjs/input.js | 5 + .../tests/consumed-results/expected.js | 6 + .../tests/consumed-results/input.js | 6 + .../tests/invalid-encodings/expected.js | 5 + .../tests/invalid-encodings/input.js | 5 + .../multiple-redundant-calls/expected.js | 5 + .../tests/multiple-redundant-calls/input.js | 7 + .../tests/shadowed-bindings/expected.js | 8 + .../tests/shadowed-bindings/input.js | 8 + .../workflow.yaml | 25 +++ 22 files changed, 431 insertions(+) create mode 100644 recipes/crypto-hmac-digest-redundant/README.md create mode 100644 recipes/crypto-hmac-digest-redundant/codemod.yaml create mode 100644 recipes/crypto-hmac-digest-redundant/package.json create mode 100644 recipes/crypto-hmac-digest-redundant/src/workflow.ts create mode 100644 recipes/crypto-hmac-digest-redundant/tests/adjacent-calls/expected.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/adjacent-calls/input.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/aliases/expected.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/aliases/input.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/branches/expected.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/branches/input.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/commonjs/expected.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/commonjs/input.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/consumed-results/expected.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/consumed-results/input.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/invalid-encodings/expected.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/invalid-encodings/input.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/multiple-redundant-calls/expected.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/multiple-redundant-calls/input.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/shadowed-bindings/expected.js create mode 100644 recipes/crypto-hmac-digest-redundant/tests/shadowed-bindings/input.js create mode 100644 recipes/crypto-hmac-digest-redundant/workflow.yaml diff --git a/package-lock.json b/package-lock.json index 287f3675..9defa7d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -505,6 +505,10 @@ "resolved": "recipes/crypto-fips-to-getFips", "link": true }, + "node_modules/@nodejs/crypto-hmac-digest-redundant": { + "resolved": "recipes/crypto-hmac-digest-redundant", + "link": true + }, "node_modules/@nodejs/crypto-rsa-pss-update": { "resolved": "recipes/crypto-rsa-pss-update", "link": true @@ -1114,6 +1118,15 @@ "@codemod.com/jssg-types": "^1.6.3" } }, + "recipes/crypto-hmac-digest-redundant": { + "name": "@nodejs/crypto-hmac-digest-redundant", + "dependencies": { + "@nodejs/codemod-utils": "*" + }, + "devDependencies": { + "@codemod.com/jssg-types": "^1.6.3" + } + }, "recipes/crypto-rsa-pss-update": { "name": "@nodejs/crypto-rsa-pss-update", "dependencies": { diff --git a/recipes/crypto-hmac-digest-redundant/README.md b/recipes/crypto-hmac-digest-redundant/README.md new file mode 100644 index 00000000..ed5942f7 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/README.md @@ -0,0 +1,51 @@ +--- +authors: vishalrajofficial +--- + +# DEP0206: Remove Provably Redundant `Hmac.digest()` Calls + +Removes redundant, standalone argument-free `hmac.digest()` expression statements on already-finalized Hmac instances created through `crypto.createHmac()`. Supports CommonJS and ESM imports, aliases, and both `crypto` and `node:crypto` specifiers. See [DEP0206](https://nodejs.org/api/deprecations.html#DEP0206). + +## Usage + +Run this codemod with: + +```sh +npx codemod @nodejs/crypto-hmac-digest-redundant +``` + +## Examples + +### Example 1 + +Adjacent redundant `hmac.digest()` call after finalizing the instance: + +```diff + import { createHmac } from 'node:crypto'; + + const hmac = createHmac('sha256', 'secret'); + hmac.update('message'); + const digest = hmac.digest('hex'); +-hmac.digest(); + console.log(digest); +``` + +### Example 2 + +CommonJS and aliased `createHmac` with standalone calls: + +```diff + const { createHmac: makeHmac } = require('node:crypto'); + + const hmac = makeHmac('sha256', 'secret'); + hmac.digest('hex'); +-hmac.digest(); +``` + +## Notes + +### Limitations + +- Only argument-free `hmac.digest()` calls on stable, unescaped local bindings in straight-line code are automatically removed. +- Calls where the return value is consumed (e.g. assigned to a variable or passed as an argument) are left unchanged for manual review, as reusing the first digest changes behavior. +- Repeated calls with arguments or calls occurring across different branches are not modified. diff --git a/recipes/crypto-hmac-digest-redundant/codemod.yaml b/recipes/crypto-hmac-digest-redundant/codemod.yaml new file mode 100644 index 00000000..fa5e95a0 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/codemod.yaml @@ -0,0 +1,25 @@ +schema_version: "1.0" +name: "@nodejs/crypto-hmac-digest-redundant" +version: "1.0.0" +description: Handle DEP0206 by removing redundant, argument-free Hmac.digest() calls on finalized instances. +author: Vishal Raj +license: MIT +workflow: workflow.yaml +category: migration +repository: https://github.com/nodejs/userland-migrations + +targets: + languages: + - javascript + - typescript + +keywords: + - transformation + - migration + - nodejs + - DEP0206 + - crypto + +registry: + access: public + visibility: public diff --git a/recipes/crypto-hmac-digest-redundant/package.json b/recipes/crypto-hmac-digest-redundant/package.json new file mode 100644 index 00000000..5ac4f07a --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/package.json @@ -0,0 +1,13 @@ +{ + "name": "@nodejs/crypto-hmac-digest-redundant", + "type": "module", + "scripts": { + "test": "npx codemod jssg test -l typescript ./src/workflow.ts" + }, + "devDependencies": { + "@codemod.com/jssg-types": "^1.6.3" + }, + "dependencies": { + "@nodejs/codemod-utils": "*" + } +} diff --git a/recipes/crypto-hmac-digest-redundant/src/workflow.ts b/recipes/crypto-hmac-digest-redundant/src/workflow.ts new file mode 100644 index 00000000..9d048c37 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/src/workflow.ts @@ -0,0 +1,207 @@ +import type { Range, SgNode, SgRoot } from '@codemod.com/jssg-types/main'; +import type Js from '@codemod.com/jssg-types/langs/javascript'; +import { getModuleDependencies } from '@nodejs/codemod-utils/ast-grep/module-dependencies'; +import { resolveBindingPath } from '@nodejs/codemod-utils/ast-grep/resolve-binding-path'; +import { removeLines } from '@nodejs/codemod-utils/ast-grep/remove-lines'; +import { getScope } from '@nodejs/codemod-utils/ast-grep/get-scope'; + +const BRANCH_KINDS = [ + 'if_statement', + 'for_statement', + 'for_in_statement', + 'while_statement', + 'do_statement', + 'switch_statement', + 'try_statement', +] as const; + +/** + * Transforms code by removing provably redundant argument-free Hmac.digest() calls + * on already-finalized Hmac instances (DEP0206). + */ +export default function transform(root: SgRoot): string | null { + const rootNode = root.root(); + const cryptoDeps = getModuleDependencies(root, 'crypto'); + if (cryptoDeps.length === 0) return null; + + const createHmacCallees = new Set(); + for (const dep of cryptoDeps) { + const resolved = resolveBindingPath(dep, '$.createHmac'); + if (resolved) { + createHmacCallees.add(resolved); + } + } + + if (createHmacCallees.size === 0) return null; + + const linesToRemove: Range[] = []; + const declarators = rootNode.findAll({ + rule: { kind: 'variable_declarator' }, + }); + + for (const decl of declarators) { + const nameNode = decl.field('name'); + const valueNode = decl.field('value'); + + if ( + nameNode?.kind() !== 'identifier' || + valueNode?.kind() !== 'call_expression' + ) { + continue; + } + + const fnNode = valueNode.field('function'); + if (!fnNode || !createHmacCallees.has(fnNode.text())) { + continue; + } + + const hmacName = nameNode.text(); + const scopeNode = getScope(decl); + if (!scopeNode) continue; + + if (!isSafeHmac(decl, hmacName, scopeNode)) { + continue; + } + + const redundantStmts = findRedundantCalls(scopeNode, decl, hmacName); + for (const stmt of redundantStmts) { + linesToRemove.push(stmt.range()); + } + } + + if (linesToRemove.length === 0) return null; + + return removeLines(rootNode.text(), linesToRemove); +} + +function isSafeHmac( + declNode: SgNode, + hmacName: string, + scopeNode: SgNode, +): boolean { + // 1. Check for reassignments to hmacName or property mutations on hmacName + const assignments = scopeNode.findAll({ + rule: { kind: 'assignment_expression' }, + }); + + for (const assign of assignments) { + const left = assign.field('left'); + if (left?.kind() === 'identifier' && left.text() === hmacName) { + return false; + } + if ( + left?.kind() === 'member_expression' && + left.field('object')?.text() === hmacName + ) { + return false; + } + } + + // 2. Check for update expressions (e.g. hmac++) + const updates = scopeNode.findAll({ rule: { kind: 'update_expression' } }); + for (const update of updates) { + if (update.field('argument')?.text() === hmacName) { + return false; + } + } + + // 3. Check all identifier occurrences to verify hmac does not escape + const identifiers = scopeNode.findAll({ + rule: { + kind: 'identifier', + pattern: hmacName, + }, + }); + + const declNameId = declNode.field('name')?.id(); + + for (const id of identifiers) { + if (id.id() === declNameId) continue; + + const parent = id.parent(); + if ( + parent?.kind() === 'member_expression' && + parent.field('object')?.id() === id.id() + ) { + const prop = parent.field('property')?.text(); + if (prop !== 'update' && prop !== 'digest') { + return false; + } + + const grandParent = parent.parent(); + if ( + grandParent?.kind() === 'call_expression' && + grandParent.field('function')?.id() === parent.id() + ) { + continue; + } + + return false; + } + + return false; + } + + return true; +} + +function findRedundantCalls( + scopeNode: SgNode, + declNode: SgNode, + hmacName: string, +): SgNode[] { + const declLine = declNode.range().start.line; + const statements = scopeNode.children().filter((c) => { + const k = c.kind(); + return k.endsWith('_statement') || k.endsWith('_declaration'); + }); + + let finalized = false; + const redundant: SgNode[] = []; + + for (const stmt of statements) { + if (stmt.range().start.line <= declLine) continue; + + const hasBranch = + BRANCH_KINDS.some((k) => k === stmt.kind()) || + stmt.find({ + rule: { + any: BRANCH_KINDS.map((k) => ({ kind: k })), + }, + }); + + if (hasBranch) { + const referencesHmac = stmt.find({ + rule: { kind: 'identifier', pattern: hmacName }, + }); + if (referencesHmac) { + return []; + } + } + + const digestCalls = stmt.findAll({ + rule: { + pattern: `${hmacName}.digest($$$ARGS)`, + }, + }); + + if (digestCalls.length === 0) continue; + + for (const call of digestCalls) { + if (!finalized) { + finalized = true; + } else { + const isStandaloneExpr = stmt.kind() === 'expression_statement'; + const args = call.field('arguments'); + const isArgFree = + args?.children().length === 2 || args?.text().trim() === '()'; + + if (isStandaloneExpr && isArgFree) { + redundant.push(stmt); + } + } + } + } + + return redundant; +} diff --git a/recipes/crypto-hmac-digest-redundant/tests/adjacent-calls/expected.js b/recipes/crypto-hmac-digest-redundant/tests/adjacent-calls/expected.js new file mode 100644 index 00000000..ca9b40b1 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/adjacent-calls/expected.js @@ -0,0 +1,6 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'secret'); +hmac.update('message'); +const digest = hmac.digest('hex'); +console.log(digest); diff --git a/recipes/crypto-hmac-digest-redundant/tests/adjacent-calls/input.js b/recipes/crypto-hmac-digest-redundant/tests/adjacent-calls/input.js new file mode 100644 index 00000000..af32a12f --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/adjacent-calls/input.js @@ -0,0 +1,7 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'secret'); +hmac.update('message'); +const digest = hmac.digest('hex'); +hmac.digest(); +console.log(digest); diff --git a/recipes/crypto-hmac-digest-redundant/tests/aliases/expected.js b/recipes/crypto-hmac-digest-redundant/tests/aliases/expected.js new file mode 100644 index 00000000..189b2e1b --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/aliases/expected.js @@ -0,0 +1,4 @@ +import { createHmac as myHmac } from 'crypto'; + +const hmac = myHmac('sha256', 'secret'); +const digest = hmac.digest('hex'); diff --git a/recipes/crypto-hmac-digest-redundant/tests/aliases/input.js b/recipes/crypto-hmac-digest-redundant/tests/aliases/input.js new file mode 100644 index 00000000..16f9e3ac --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/aliases/input.js @@ -0,0 +1,5 @@ +import { createHmac as myHmac } from 'crypto'; + +const hmac = myHmac('sha256', 'secret'); +const digest = hmac.digest('hex'); +hmac.digest(); diff --git a/recipes/crypto-hmac-digest-redundant/tests/branches/expected.js b/recipes/crypto-hmac-digest-redundant/tests/branches/expected.js new file mode 100644 index 00000000..8e74d0a4 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/branches/expected.js @@ -0,0 +1,8 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'secret'); +if (condition) { + hmac.digest('hex'); +} else { + hmac.digest(); +} diff --git a/recipes/crypto-hmac-digest-redundant/tests/branches/input.js b/recipes/crypto-hmac-digest-redundant/tests/branches/input.js new file mode 100644 index 00000000..8e74d0a4 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/branches/input.js @@ -0,0 +1,8 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'secret'); +if (condition) { + hmac.digest('hex'); +} else { + hmac.digest(); +} diff --git a/recipes/crypto-hmac-digest-redundant/tests/commonjs/expected.js b/recipes/crypto-hmac-digest-redundant/tests/commonjs/expected.js new file mode 100644 index 00000000..849bce72 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/commonjs/expected.js @@ -0,0 +1,4 @@ +const crypto = require('node:crypto'); + +const hmac = crypto.createHmac('sha256', 'secret'); +hmac.digest('hex'); diff --git a/recipes/crypto-hmac-digest-redundant/tests/commonjs/input.js b/recipes/crypto-hmac-digest-redundant/tests/commonjs/input.js new file mode 100644 index 00000000..ed493516 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/commonjs/input.js @@ -0,0 +1,5 @@ +const crypto = require('node:crypto'); + +const hmac = crypto.createHmac('sha256', 'secret'); +hmac.digest('hex'); +hmac.digest(); diff --git a/recipes/crypto-hmac-digest-redundant/tests/consumed-results/expected.js b/recipes/crypto-hmac-digest-redundant/tests/consumed-results/expected.js new file mode 100644 index 00000000..cd251d6f --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/consumed-results/expected.js @@ -0,0 +1,6 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'secret'); +const first = hmac.digest('hex'); +const second = hmac.digest('hex'); +consume(first, second); diff --git a/recipes/crypto-hmac-digest-redundant/tests/consumed-results/input.js b/recipes/crypto-hmac-digest-redundant/tests/consumed-results/input.js new file mode 100644 index 00000000..cd251d6f --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/consumed-results/input.js @@ -0,0 +1,6 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'secret'); +const first = hmac.digest('hex'); +const second = hmac.digest('hex'); +consume(first, second); diff --git a/recipes/crypto-hmac-digest-redundant/tests/invalid-encodings/expected.js b/recipes/crypto-hmac-digest-redundant/tests/invalid-encodings/expected.js new file mode 100644 index 00000000..b024f88d --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/invalid-encodings/expected.js @@ -0,0 +1,5 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'secret'); +hmac.digest('hex'); +hmac.digest('invalid-encoding'); diff --git a/recipes/crypto-hmac-digest-redundant/tests/invalid-encodings/input.js b/recipes/crypto-hmac-digest-redundant/tests/invalid-encodings/input.js new file mode 100644 index 00000000..b024f88d --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/invalid-encodings/input.js @@ -0,0 +1,5 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'secret'); +hmac.digest('hex'); +hmac.digest('invalid-encoding'); diff --git a/recipes/crypto-hmac-digest-redundant/tests/multiple-redundant-calls/expected.js b/recipes/crypto-hmac-digest-redundant/tests/multiple-redundant-calls/expected.js new file mode 100644 index 00000000..0ed426df --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/multiple-redundant-calls/expected.js @@ -0,0 +1,5 @@ +import crypto from "node:crypto"; + +const hmac = crypto.createHmac("sha256", "secret"); +hmac.update("data"); +const buf = hmac.digest(); diff --git a/recipes/crypto-hmac-digest-redundant/tests/multiple-redundant-calls/input.js b/recipes/crypto-hmac-digest-redundant/tests/multiple-redundant-calls/input.js new file mode 100644 index 00000000..856291a4 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/multiple-redundant-calls/input.js @@ -0,0 +1,7 @@ +import crypto from "node:crypto"; + +const hmac = crypto.createHmac("sha256", "secret"); +hmac.update("data"); +const buf = hmac.digest(); +hmac.digest(); +hmac.digest(); diff --git a/recipes/crypto-hmac-digest-redundant/tests/shadowed-bindings/expected.js b/recipes/crypto-hmac-digest-redundant/tests/shadowed-bindings/expected.js new file mode 100644 index 00000000..779a1d35 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/shadowed-bindings/expected.js @@ -0,0 +1,8 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'outer'); +{ + const hmac = createHmac('sha256', 'inner'); + hmac.digest('hex'); +} +hmac.digest(); diff --git a/recipes/crypto-hmac-digest-redundant/tests/shadowed-bindings/input.js b/recipes/crypto-hmac-digest-redundant/tests/shadowed-bindings/input.js new file mode 100644 index 00000000..779a1d35 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/tests/shadowed-bindings/input.js @@ -0,0 +1,8 @@ +import { createHmac } from 'node:crypto'; + +const hmac = createHmac('sha256', 'outer'); +{ + const hmac = createHmac('sha256', 'inner'); + hmac.digest('hex'); +} +hmac.digest(); diff --git a/recipes/crypto-hmac-digest-redundant/workflow.yaml b/recipes/crypto-hmac-digest-redundant/workflow.yaml new file mode 100644 index 00000000..74dd4297 --- /dev/null +++ b/recipes/crypto-hmac-digest-redundant/workflow.yaml @@ -0,0 +1,25 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/codemod-com/codemod/refs/heads/main/schemas/workflow.json + +version: "1" + +nodes: + - id: apply-transforms + name: Apply AST Transformations + type: automatic + steps: + - name: Handle DEP0206 by removing redundant Hmac.digest() calls + js-ast-grep: + js_file: src/workflow.ts + base_path: . + include: + - "**/*.cjs" + - "**/*.cts" + - "**/*.js" + - "**/*.jsx" + - "**/*.mjs" + - "**/*.mts" + - "**/*.ts" + - "**/*.tsx" + exclude: + - "**/node_modules/**" + language: typescript From 071c09166ddcea66f304c2d70266be45333d746a Mon Sep 17 00:00:00 2001 From: Vishal Raj <9031842908.vk@gmail.com> Date: Tue, 17 Nov 2026 20:11:46 +0530 Subject: [PATCH 2/2] style(DEP0206): apply review suggestions Signed-off-by: Vishal Raj <9031842908.vk@gmail.com> --- .../src/workflow.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/recipes/crypto-hmac-digest-redundant/src/workflow.ts b/recipes/crypto-hmac-digest-redundant/src/workflow.ts index 9d048c37..7ba826af 100644 --- a/recipes/crypto-hmac-digest-redundant/src/workflow.ts +++ b/recipes/crypto-hmac-digest-redundant/src/workflow.ts @@ -22,17 +22,18 @@ const BRANCH_KINDS = [ export default function transform(root: SgRoot): string | null { const rootNode = root.root(); const cryptoDeps = getModuleDependencies(root, 'crypto'); - if (cryptoDeps.length === 0) return null; + if (!cryptoDeps.length) return null; const createHmacCallees = new Set(); for (const dep of cryptoDeps) { + const resolved = resolveBindingPath(dep, '$.createHmac'); if (resolved) { createHmacCallees.add(resolved); } } - if (createHmacCallees.size === 0) return null; + if (!createHmacCallees.size) return null; const linesToRemove: Range[] = []; const declarators = rootNode.findAll({ @@ -44,8 +45,8 @@ export default function transform(root: SgRoot): string | null { const valueNode = decl.field('value'); if ( - nameNode?.kind() !== 'identifier' || - valueNode?.kind() !== 'call_expression' + !nameNode?.is('identifier') || + !valueNode?.is('call_expression') ) { continue; } @@ -69,7 +70,7 @@ export default function transform(root: SgRoot): string | null { } } - if (linesToRemove.length === 0) return null; + if (!linesToRemove.length) return null; return removeLines(rootNode.text(), linesToRemove); } @@ -86,11 +87,11 @@ function isSafeHmac( for (const assign of assignments) { const left = assign.field('left'); - if (left?.kind() === 'identifier' && left.text() === hmacName) { + if (left?.is('identifier') && left.text() === hmacName) { return false; } if ( - left?.kind() === 'member_expression' && + left?.is('member_expression') && left.field('object')?.text() === hmacName ) { return false; @@ -120,7 +121,7 @@ function isSafeHmac( const parent = id.parent(); if ( - parent?.kind() === 'member_expression' && + parent?.is('member_expression') && parent.field('object')?.id() === id.id() ) { const prop = parent.field('property')?.text();