Skip to content

Commit

Permalink
feat: no-top-level-arrow-function only report when the function bod…
Browse files Browse the repository at this point in the history
…y is `BlockStatement`
  • Loading branch information
zanminkian committed Jan 22, 2025
1 parent 0c3b8f0 commit ae6cb40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-snakes-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fenge/eslint-plugin": minor
---

feat: `no-top-level-arrow-function` only report when the function body is `BlockStatement`
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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":
Expand Down

0 comments on commit ae6cb40

Please sign in to comment.