File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
packages/ast/src/function Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 22
33### Release Notes
44
5+ #### Reduce false positives in rule ` react/no-unstable-nested-components `
6+
7+ #### Reduce false positives in rule ` debug/function-component `
8+
59---
610
11+ #### 🏠 Internal
12+
13+ - ` @eslint-react/ast `
14+ - Refactor ` getFunctionIdentifier ` function to follow spec convention for ` IsAnonymousFunctionDefinition() ` usage in ECMAScript spec.
15+ - Improve module structure.
16+
17+ - ` @eslint-react/core `
18+ - Move construction detection from ` @eslint-react/ast ` to ` @eslint-react/core ` .
19+
720#### Authors: 1
821
922- Eva1ent ([ @Rel1cx ] ( https://github.com/Rel1cx ) )
Original file line number Diff line number Diff line change 1010import { O } from "@eslint-react/tools" ;
1111import type { TSESTree } from "@typescript-eslint/types" ;
1212
13- import { NodeType , type TSESTreeFunction } from "../node" ;
13+ import { isOneOf , NodeType , type TSESTreeFunction } from "../node" ;
1414
1515export function getFunctionIdentifier ( node : TSESTreeFunction ) : O . Option < TSESTree . Identifier > {
1616 if ( node . id ) {
@@ -47,13 +47,16 @@ export function getFunctionIdentifier(node: TSESTreeFunction): O.Option<TSESTree
4747 // {useHook: () => {}}
4848 // {useHook() {}}
4949 return O . some ( node . parent . key ) ;
50+ }
5051
51- // NOTE: We could also support `ClassProperty` and `MethodDefinition`
52- // here to be pedantic. However, hooks in a class are an anti-pattern. So
53- // we don't allow it to error early.
54- //
52+ if (
53+ isOneOf ( [ NodeType . MethodDefinition , NodeType . PropertyDefinition ] ) ( node . parent )
54+ && node . parent . value === node
55+ && node . parent . key . type === NodeType . Identifier
56+ ) {
5557 // class {useHook = () => {}}
5658 // class {useHook() {}}
59+ return O . some ( node . parent . key ) ;
5760 }
5861
5962 if (
You can’t perform that action at this time.
0 commit comments