From ae8312791da0b11e2f91f123bce9bf560fc0e401 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Wed, 18 Nov 2026 21:59:59 +0800 Subject: [PATCH] tools: restrict defining `Symbol.[Async]Dispose` functions as aliases Signed-off-by: LiviaMedeiros PR-URL: https://github.com/nodejs/node/pull/67582 Refs: https://github.com/nodejs/node/blob/HEAD/doc/contributing/erm-guidelines.md#debuggability-of-disposer-methods Reviewed-By: James M Snell Reviewed-By: Matteo Collina --- lib/eslint.config_partial.mjs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/eslint.config_partial.mjs b/lib/eslint.config_partial.mjs index 41873397ba4..bebcd25fb3d 100644 --- a/lib/eslint.config_partial.mjs +++ b/lib/eslint.config_partial.mjs @@ -46,6 +46,16 @@ const noRestrictedSyntax = [ selector: "CallExpression:matches([callee.type='Identifier'][callee.name='FunctionPrototypeApply'], [callee.type='MemberExpression'][callee.property.type='Identifier'][callee.property.name='apply'][arguments.length=2])", message: 'Use `ReflectApply` instead of %Function.prototype.apply%', }, + { + selector: "Property[computed=true][key.name=/^SymbolDispose$/]:not([value.type=/^(Arrow)?FunctionExpression$/]):not([value.callee.name='assignFunctionName'][value.arguments.1.type=/^(Arrow)?FunctionExpression$/])," + + "AssignmentExpression[left.computed=true][left.property.name=/^SymbolDispose$/]:not([right.type=/^(Arrow)?FunctionExpression$/]):not([right.callee.name='assignFunctionName'][right.arguments.1.type=/^(Arrow)?FunctionExpression$/])", + message: 'Symbol.dispose functions should not be direct aliases, use inline function instead.', + }, + { + selector: "Property[computed=true][key.name=/^SymbolAsyncDispose$/]:not([value.type=/^(Arrow)?FunctionExpression$/]):not([value.callee.name='assignFunctionName'][value.arguments.1.type=/^(Arrow)?FunctionExpression$/])," + + "AssignmentExpression[left.computed=true][left.property.name=/^SymbolAsyncDispose$/]:not([right.type=/^(Arrow)?FunctionExpression$/]):not([right.callee.name='assignFunctionName'][right.arguments.1.type=/^(Arrow)?FunctionExpression$/])", + message: 'Symbol.asyncDispose functions should not be direct aliases, use inline function instead.', + }, ]; export default [