-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
471 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[**@eslint-react/core**](../README.md) | ||
|
||
*** | ||
|
||
[@eslint-react/core](../README.md) / hasValidHierarchy | ||
|
||
# Function: hasValidHierarchy() | ||
|
||
> **hasValidHierarchy**(`node`, `context`, `hint`): `boolean` | ||
internal | ||
|
||
## Parameters | ||
|
||
### node | ||
|
||
[`TSESTreeFunction`](../-internal-/type-aliases/TSESTreeFunction.md) | ||
|
||
### context | ||
|
||
[`Readonly`](../-internal-/type-aliases/Readonly.md) | ||
|
||
### hint | ||
|
||
`bigint` | ||
|
||
## Returns | ||
|
||
`boolean` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[**@eslint-react/core**](../README.md) | ||
|
||
*** | ||
|
||
[@eslint-react/core](../README.md) / isFromReactLoose | ||
|
||
# Function: isFromReactLoose() | ||
|
||
> **isFromReactLoose**(`node`, `name`): `boolean` | ||
## Parameters | ||
|
||
### node | ||
|
||
[`Identifier`](../-internal-/interfaces/Identifier.md) | [`MemberExpression`](../-internal-/type-aliases/MemberExpression.md) | ||
|
||
### name | ||
|
||
`string` | ||
|
||
## Returns | ||
|
||
`boolean` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[**@eslint-react/core**](../README.md) | ||
|
||
*** | ||
|
||
[@eslint-react/core](../README.md) / isFromReactMember | ||
|
||
# Function: isFromReactMember() | ||
|
||
> **isFromReactMember**(`memberName`, `name`): (`node`, `context`) => `boolean` | ||
## Parameters | ||
|
||
### memberName | ||
|
||
`string` | ||
|
||
### name | ||
|
||
`string` | ||
|
||
## Returns | ||
|
||
`Function` | ||
|
||
### Parameters | ||
|
||
#### node | ||
|
||
[`MemberExpression`](../-internal-/type-aliases/MemberExpression.md) | ||
|
||
#### context | ||
|
||
[`Readonly`](../-internal-/type-aliases/Readonly.md) | ||
|
||
### Returns | ||
|
||
`boolean` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[**@eslint-react/core**](../README.md) | ||
|
||
*** | ||
|
||
[@eslint-react/core](../README.md) / isFromReactMemberLoose | ||
|
||
# Function: isFromReactMemberLoose() | ||
|
||
> **isFromReactMemberLoose**(`node`, `memberName`, `name`): `boolean` | ||
## Parameters | ||
|
||
### node | ||
|
||
[`MemberExpression`](../-internal-/type-aliases/MemberExpression.md) | ||
|
||
### memberName | ||
|
||
`string` | ||
|
||
### name | ||
|
||
`string` | ||
|
||
## Returns | ||
|
||
`boolean` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[**@eslint-react/core**](../README.md) | ||
|
||
*** | ||
|
||
[@eslint-react/core](../README.md) / isFromReactMemberStrict | ||
|
||
# Function: isFromReactMemberStrict() | ||
|
||
> **isFromReactMemberStrict**(`node`, `memberName`, `name`, `importSource`, `initialScope`): `boolean` | ||
## Parameters | ||
|
||
### node | ||
|
||
[`MemberExpression`](../-internal-/type-aliases/MemberExpression.md) | ||
|
||
### memberName | ||
|
||
`string` | ||
|
||
### name | ||
|
||
`string` | ||
|
||
### importSource | ||
|
||
`string` | ||
|
||
### initialScope | ||
|
||
[`Scope`](../-internal-/type-aliases/Scope.md) | ||
|
||
## Returns | ||
|
||
`boolean` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[**@eslint-react/core**](../README.md) | ||
|
||
*** | ||
|
||
[@eslint-react/core](../README.md) / isFromReactStrict | ||
|
||
# Function: isFromReactStrict() | ||
|
||
> **isFromReactStrict**(`node`, `name`, `importSource`, `initialScope`): `boolean` | ||
## Parameters | ||
|
||
### node | ||
|
||
[`Identifier`](../-internal-/interfaces/Identifier.md) | [`MemberExpression`](../-internal-/type-aliases/MemberExpression.md) | ||
|
||
### name | ||
|
||
`string` | ||
|
||
### importSource | ||
|
||
`string` | ||
|
||
### initialScope | ||
|
||
[`Scope`](../-internal-/type-aliases/Scope.md) | ||
|
||
## Returns | ||
|
||
`boolean` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable jsdoc/require-param */ | ||
import * as AST from "@eslint-react/ast"; | ||
import { type RuleContext } from "@eslint-react/shared"; | ||
import type { TSESTree } from "@typescript-eslint/types"; | ||
import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; | ||
|
||
import { isChildrenOfCreateElement } from "../element"; | ||
import { ERComponentHint } from "./component-collector-hint"; | ||
import { isFunctionOfRenderMethod } from "./component-lifecycle"; | ||
|
||
/** internal */ | ||
export function hasValidHierarchy(node: AST.TSESTreeFunction, context: RuleContext, hint: bigint) { | ||
if (isChildrenOfCreateElement(node, context) || isFunctionOfRenderMethod(node)) { | ||
return false; | ||
} | ||
if (hint & ERComponentHint.SkipMapCallback && AST.isMapCallLoose(node.parent)) { | ||
return false; | ||
} | ||
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) { | ||
return false; | ||
} | ||
if (hint & ERComponentHint.SkipClassMethod && isFunctionOfClassMethod(node.parent)) { | ||
return false; | ||
} | ||
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) { | ||
return false; | ||
} | ||
const boundaryNode = AST.findParentNode( | ||
node, | ||
AST.isOneOf([ | ||
T.JSXExpressionContainer, | ||
T.ArrowFunctionExpression, | ||
T.FunctionExpression, | ||
T.Property, | ||
T.ClassBody, | ||
]), | ||
); | ||
return boundaryNode == null || boundaryNode.type !== T.JSXExpressionContainer; | ||
} | ||
|
||
function isFunctionOfClassMethod(node: TSESTree.Node): node is | ||
| TSESTree.ArrowFunctionExpression | ||
| TSESTree.FunctionExpression | ||
{ | ||
return (node.type === T.FunctionExpression || node.type === T.ArrowFunctionExpression) | ||
&& node.parent.type === T.MethodDefinition; | ||
} | ||
|
||
function isFunctionOfClassProperty(node: TSESTree.Node): node is | ||
| TSESTree.ArrowFunctionExpression | ||
| TSESTree.FunctionExpression | ||
{ | ||
return (node.type === T.FunctionExpression || node.type === T.ArrowFunctionExpression) | ||
&& node.parent.type === T.Property; | ||
} | ||
|
||
function isFunctionOfObjectMethod(node: TSESTree.Node) { | ||
return (node.type === T.FunctionExpression || node.type === T.ArrowFunctionExpression) | ||
&& node.parent.type === T.Property | ||
&& node.parent.parent.type === T.ObjectExpression; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.