From ae6cb404d8305e147f6297be60ac6d79034dea8f Mon Sep 17 00:00:00 2001 From: zanminkian Date: Wed, 22 Jan 2025 06:50:07 +0000 Subject: [PATCH] feat: `no-top-level-arrow-function` only report when the function body is `BlockStatement` --- .changeset/spicy-snakes-mate.md | 5 +++++ .../src/rules/no-top-level-arrow-function.ts | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/spicy-snakes-mate.md diff --git a/.changeset/spicy-snakes-mate.md b/.changeset/spicy-snakes-mate.md new file mode 100644 index 00000000..db1f5587 --- /dev/null +++ b/.changeset/spicy-snakes-mate.md @@ -0,0 +1,5 @@ +--- +"@fenge/eslint-plugin": minor +--- + +feat: `no-top-level-arrow-function` only report when the function body is `BlockStatement` diff --git a/packages/eslint-plugin/src/rules/no-top-level-arrow-function.ts b/packages/eslint-plugin/src/rules/no-top-level-arrow-function.ts index 510dfb1c..40b9cce9 100644 --- a/packages/eslint-plugin/src/rules/no-top-level-arrow-function.ts +++ b/packages/eslint-plugin/src/rules/no-top-level-arrow-function.ts @@ -1,5 +1,5 @@ import type { Rule } from "eslint"; -import type { Node } from "estree"; +import type { ArrowFunctionExpression } from "estree"; import { getRuleName } from "../utils.ts"; const name = getRuleName(import.meta.url); @@ -15,9 +15,10 @@ const rule: Rule.RuleModule = { }, }, create: (context) => { - const handle = (node: Node) => { - if (node.loc?.start.line === node.loc?.end.line) return; - context.report({ node, messageId: `${name}/error` }); + const handle = (node: ArrowFunctionExpression) => { + if (node.body.type === "BlockStatement") { + context.report({ node, messageId: `${name}/error` }); + } }; return { "VariableDeclaration[parent.type='Program'] > VariableDeclarator > ArrowFunctionExpression":