tools: restrict defining Symbol.[Async]Dispose functions as aliases

Signed-off-by: LiviaMedeiros <livia@cirno.name>
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 <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
LiviaMedeiros authored and Node.js GitHub Bot committed 2026-11-27 06:22:21 +00:00
1 parent 4acb828ab7
commit ae8312791d
1 file changed
+10
+10
View File
@@ -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 [