Skip to content

Commit af83bb1

Browse files
Rel1cxCopilot
andauthored
refactor: cleanup utilities (#1231)
Signed-off-by: REL1CX <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent b60ff88 commit af83bb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+394
-271
lines changed

packages/core/docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [ClassComponent](interfaces/ClassComponent.md)
1818
- [FunctionComponent](interfaces/FunctionComponent.md)
1919
- [Hook](interfaces/Hook.md)
20+
- [JsxConfig](interfaces/JsxConfig.md)
2021
- [SemanticEntry](interfaces/SemanticEntry.md)
2122
- [SemanticNode](interfaces/SemanticNode.md)
2223

@@ -107,6 +108,7 @@
107108
- [isUseSyncExternalStoreCall](variables/isUseSyncExternalStoreCall.md)
108109
- [isUseTransitionCall](variables/isUseTransitionCall.md)
109110
- [JSXDetectionHint](variables/JSXDetectionHint.md)
111+
- [JsxEmit](variables/JsxEmit.md)
110112
- [REACT\_BUILTIN\_HOOK\_NAMES](variables/REACT_BUILTIN_HOOK_NAMES.md)
111113

112114
## Functions
@@ -118,6 +120,8 @@
118120
- [getComponentNameFromId](functions/getComponentNameFromId.md)
119121
- [getElementType](functions/getElementType.md)
120122
- [getFunctionComponentId](functions/getFunctionComponentId.md)
123+
- [getJsxConfigFromAnnotation](functions/getJsxConfigFromAnnotation.md)
124+
- [getJsxConfigFromContext](functions/getJsxConfigFromContext.md)
121125
- [hasAnyAttribute](functions/hasAnyAttribute.md)
122126
- [hasAttribute](functions/hasAttribute.md)
123127
- [hasEveryAttribute](functions/hasEveryAttribute.md)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / getJsxConfigFromAnnotation
6+
7+
# Function: getJsxConfigFromAnnotation()
8+
9+
> **getJsxConfigFromAnnotation**(`context`): [`JsxConfig`](../interfaces/JsxConfig.md)
10+
11+
Get JsxConfig from pragma comments (annotations) in the source code.
12+
13+
## Parameters
14+
15+
### context
16+
17+
`RuleContext`
18+
19+
The RuleContext.
20+
21+
## Returns
22+
23+
[`JsxConfig`](../interfaces/JsxConfig.md)
24+
25+
JsxConfig derived from pragma comments.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / getJsxConfigFromContext
6+
7+
# Function: getJsxConfigFromContext()
8+
9+
> **getJsxConfigFromContext**(`context`): `object`
10+
11+
Get JsxConfig from the rule context by reading compiler options.
12+
13+
## Parameters
14+
15+
### context
16+
17+
`RuleContext`
18+
19+
The RuleContext.
20+
21+
## Returns
22+
23+
`object`
24+
25+
JsxConfig derived from compiler options.
26+
27+
### jsx
28+
29+
> **jsx**: `4` \| `JsxEmit`
30+
31+
### jsxFactory
32+
33+
> **jsxFactory**: `string`
34+
35+
### jsxFragmentFactory
36+
37+
> **jsxFragmentFactory**: `string`
38+
39+
### jsxImportSource
40+
41+
> **jsxImportSource**: `string`

packages/core/docs/functions/hasNoneOrLooseComponentName.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Function: hasNoneOrLooseComponentName()
88

9-
> **hasNoneOrLooseComponentName**(`context`, `fn`): `any`
9+
> **hasNoneOrLooseComponentName**(`context`, `fn`): `boolean`
1010
1111
## Parameters
1212

@@ -20,4 +20,4 @@
2020

2121
## Returns
2222

23-
`any`
23+
`boolean`

packages/core/docs/functions/isComponentName.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Function: isComponentName()
88

9-
> **isComponentName**(`name`): `any`
9+
> **isComponentName**(`name`): `boolean`
1010
1111
## Parameters
1212

@@ -16,4 +16,4 @@
1616

1717
## Returns
1818

19-
`any`
19+
`boolean`

packages/core/docs/functions/isComponentNameLoose.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Function: isComponentNameLoose()
88

9-
> **isComponentNameLoose**(`name`): `any`
9+
> **isComponentNameLoose**(`name`): `boolean`
1010
1111
## Parameters
1212

@@ -16,4 +16,4 @@
1616

1717
## Returns
1818

19-
`any`
19+
`boolean`
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / JsxConfig
6+
7+
# Interface: JsxConfig
8+
9+
## Properties
10+
11+
### jsx?
12+
13+
> `optional` **jsx**: `number`
14+
15+
***
16+
17+
### jsxFactory?
18+
19+
> `optional` **jsxFactory**: `string`
20+
21+
***
22+
23+
### jsxFragmentFactory?
24+
25+
> `optional` **jsxFragmentFactory**: `string`
26+
27+
***
28+
29+
### jsxImportSource?
30+
31+
> `optional` **jsxImportSource**: `string`
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / JsxEmit
6+
7+
# Variable: JsxEmit
8+
9+
> `const` **JsxEmit**: `object`
10+
11+
## Type Declaration
12+
13+
### None
14+
15+
> `readonly` **None**: `0` = `0`
16+
17+
### Preserve
18+
19+
> `readonly` **Preserve**: `1` = `1`
20+
21+
### React
22+
23+
> `readonly` **React**: `2` = `2`
24+
25+
### ReactJSX
26+
27+
> `readonly` **ReactJSX**: `4` = `4`
28+
29+
### ReactJSXDev
30+
31+
> `readonly` **ReactJSXDev**: `5` = `5`
32+
33+
### ReactNative
34+
35+
> `readonly` **ReactNative**: `3` = `3`

packages/core/src/component/component-collector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as AST from "@eslint-react/ast";
22
import { unit } from "@eslint-react/eff";
3-
import { type RuleContext, Selector as SEL } from "@eslint-react/kit";
3+
import { type RuleContext, SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION } from "@eslint-react/kit";
44
import { getId } from "@eslint-react/shared";
55
import type { TSESTree } from "@typescript-eslint/types";
66
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
@@ -123,7 +123,7 @@ export function useComponentCollector(
123123
},
124124
...collectDisplayName
125125
? {
126-
[SEL.DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node: TSESTree.AssignmentExpression) {
126+
[SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node: TSESTree.AssignmentExpression) {
127127
const { left, right } = node;
128128
if (left.type !== T.MemberExpression) return;
129129
const componentName = left.object.type === T.Identifier

packages/core/src/component/component-name.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import type * as AST from "@eslint-react/ast";
22
import { unit } from "@eslint-react/eff";
3-
import type { RuleContext } from "@eslint-react/kit";
4-
import { RegExp as RE } from "@eslint-react/kit";
3+
import { RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, type RuleContext } from "@eslint-react/kit";
54
import type { TSESTree } from "@typescript-eslint/types";
65

76
import { getFunctionComponentId } from "./component-id";
87

98
export function isComponentName(name: string) {
10-
return RE.COMPONENT_NAME.test(name);
9+
return RE_COMPONENT_NAME.test(name);
1110
}
1211

1312
export function isComponentNameLoose(name: string) {
14-
return RE.COMPONENT_NAME_LOOSE.test(name);
13+
return RE_COMPONENT_NAME_LOOSE.test(name);
1514
}
1615

1716
export function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | unit) {

0 commit comments

Comments
 (0)