From 25c8c011cf3a096117296c7a75f4e04c11b40020 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Jul 2026 22:15:59 +0000 Subject: [PATCH 1/2] Initial plan From 3324abd50204011e7de2069a9ae647ce593f45da Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Jul 2026 22:28:36 +0000 Subject: [PATCH 2/2] Fix require-async-entrypoint-catch TypeScript narrowing Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .../require-async-entrypoint-catch.test.ts | 25 +++++++++++++++++++ .../rules/require-async-entrypoint-catch.ts | 18 +++++-------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/eslint-factory/src/rules/require-async-entrypoint-catch.test.ts b/eslint-factory/src/rules/require-async-entrypoint-catch.test.ts index cbc2829e867..c8dbd9cabca 100644 --- a/eslint-factory/src/rules/require-async-entrypoint-catch.test.ts +++ b/eslint-factory/src/rules/require-async-entrypoint-catch.test.ts @@ -411,4 +411,29 @@ main().then(() => process.exit(0)).catch(err => { console.error(err); process.ex ], }); }); + + it("invalid: bare call to async function in multi-declarator module-scope const is flagged", () => { + cjsRuleTester.run("require-async-entrypoint-catch", requireAsyncEntrypointCatchRule, { + valid: [], + invalid: [ + { + code: `const helper = () => 1, main = async () => { return 42; }; +main();`, + errors: [ + { + messageId: "requireCatch", + data: { name: "main" }, + suggestions: [ + { + messageId: "addCatch", + output: `const helper = () => 1, main = async () => { return 42; }; +main().catch(err => { console.error(err); process.exitCode = 1; });`, + }, + ], + }, + ], + }, + ], + }); + }); }); diff --git a/eslint-factory/src/rules/require-async-entrypoint-catch.ts b/eslint-factory/src/rules/require-async-entrypoint-catch.ts index 809f4d09ed8..33bbe8be981 100644 --- a/eslint-factory/src/rules/require-async-entrypoint-catch.ts +++ b/eslint-factory/src/rules/require-async-entrypoint-catch.ts @@ -4,14 +4,8 @@ const createRule = ESLintUtils.RuleCreator(name => `https://github.com/github/gh type AsyncFuncNode = TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression; type SourceCodeScope = TSESLint.Scope.Scope; -type FunctionDeclarationDefinition = TSESLint.Scope.Definition & { - type: "FunctionName"; - node: TSESTree.FunctionDeclaration; -}; -type VariableDefinition = TSESLint.Scope.Definition & { - type: "Variable"; - node: TSESTree.VariableDeclarator; -}; +type FunctionDeclarationDefinition = TSESLint.Scope.Definitions.FunctionNameDefinition & { node: TSESTree.FunctionDeclaration }; +type VariableDefinition = TSESLint.Scope.Definitions.VariableDefinition; function isAsyncFuncNode(node: TSESTree.Node): node is AsyncFuncNode { return node.type === AST_NODE_TYPES.FunctionDeclaration || node.type === AST_NODE_TYPES.FunctionExpression || node.type === AST_NODE_TYPES.ArrowFunctionExpression; @@ -49,11 +43,11 @@ function getRootCallIdentifier(node: TSESTree.CallExpression): TSESTree.Identifi } function isFunctionDeclarationDefinition(definition: TSESLint.Scope.Definition): definition is FunctionDeclarationDefinition { - return definition.type === "FunctionName" && definition.node.type === AST_NODE_TYPES.FunctionDeclaration; + return definition.type === TSESLint.Scope.DefinitionType.FunctionName && definition.node.type === AST_NODE_TYPES.FunctionDeclaration; } function isVariableDefinition(definition: TSESLint.Scope.Definition): definition is VariableDefinition { - return definition.type === "Variable" && definition.node.type === AST_NODE_TYPES.VariableDeclarator; + return definition.type === TSESLint.Scope.DefinitionType.Variable && definition.node.type === AST_NODE_TYPES.VariableDeclarator; } function isModuleScopeVariableDeclaration(node: TSESTree.VariableDeclaration): boolean { @@ -61,8 +55,8 @@ function isModuleScopeVariableDeclaration(node: TSESTree.VariableDeclaration): b } function isAsyncVariableEntrypoint(definition: VariableDefinition): boolean { - const declaration = definition.node.parent; - if (!declaration || declaration.type !== AST_NODE_TYPES.VariableDeclaration || !isModuleScopeVariableDeclaration(declaration)) return false; + const declaration = definition.parent; + if (!declaration || !isModuleScopeVariableDeclaration(declaration)) return false; const init = definition.node.init; return (init?.type === AST_NODE_TYPES.FunctionExpression || init?.type === AST_NODE_TYPES.ArrowFunctionExpression) && init.async; }