Skip to content

Commit 4e44fac

Browse files
authored
refactor: move regular expressions and selectors to dedicated namespace (#1046)
1 parent 6fd4676 commit 4e44fac

File tree

73 files changed

+468
-567
lines changed

Some content is hidden

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

73 files changed

+468
-567
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"tinyexec": "^1.0.1",
8585
"tinyglobby": "^0.2.12",
8686
"ts-pattern": "^5.7.0",
87+
"tslib": "^2.8.1",
8788
"tsup": "^8.4.0",
8889
"tsx": "^4.19.3",
8990
"type-fest": "^4.39.1",
@@ -117,6 +118,7 @@
117118
"react": "^19.1.0",
118119
"react-dom": "^19.1.0",
119120
"ts-api-utils": "^2.1.0",
121+
"tslib": "^2.8.1",
120122
"typescript": "^5.8.3"
121123
}
122124
}

packages/core/docs/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
- [ComponentFlag](variables/ComponentFlag.md)
3838
- [ComponentPhaseRelevance](variables/ComponentPhaseRelevance.md)
3939
- [DEFAULT\_COMPONENT\_DETECTION\_HINT](variables/DEFAULT_COMPONENT_DETECTION_HINT.md)
40-
- [DISPLAY\_NAME\_ASSIGNMENT\_SELECTOR](variables/DISPLAY_NAME_ASSIGNMENT_SELECTOR.md)
4140
- [isChildrenCount](variables/isChildrenCount.md)
4241
- [isChildrenCountCall](variables/isChildrenCountCall.md)
4342
- [isChildrenForEach](variables/isChildrenForEach.md)
@@ -80,9 +79,6 @@
8079
- [isUseStateCall](variables/isUseStateCall.md)
8180
- [isUseSyncExternalStoreCall](variables/isUseSyncExternalStoreCall.md)
8281
- [isUseTransitionCall](variables/isUseTransitionCall.md)
83-
- [RE\_COMPONENT\_NAME](variables/RE_COMPONENT_NAME.md)
84-
- [RE\_COMPONENT\_NAME\_LOOSE](variables/RE_COMPONENT_NAME_LOOSE.md)
85-
- [RE\_HOOK\_NAME](variables/RE_HOOK_NAME.md)
8682

8783
## Functions
8884

@@ -128,7 +124,6 @@
128124
- [isReactHookCallWithNameAlias](functions/isReactHookCallWithNameAlias.md)
129125
- [isReactHookCallWithNameLoose](functions/isReactHookCallWithNameLoose.md)
130126
- [isReactHookName](functions/isReactHookName.md)
131-
- [isReactHookNameLoose](functions/isReactHookNameLoose.md)
132127
- [isRenderFunctionLoose](functions/isRenderFunctionLoose.md)
133128
- [isRenderLike](functions/isRenderLike.md)
134129
- [isRenderMethodLike](functions/isRenderMethodLike.md)

packages/core/docs/functions/isReactHookNameLoose.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/core/docs/variables/DISPLAY_NAME_ASSIGNMENT_SELECTOR.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/core/docs/variables/RE_COMPONENT_NAME.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/core/docs/variables/RE_COMPONENT_NAME_LOOSE.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/core/docs/variables/RE_HOOK_NAME.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import type { RuleContext } from "@eslint-react/kit";
21
import type { TSESTree } from "@typescript-eslint/types";
32
import type { ESLintUtils } from "@typescript-eslint/utils";
43
import type { ComponentDetectionHint } from "./component-detection-hint";
54
import type { FunctionComponent } from "./component-semantic-node";
65
import * as AST from "@eslint-react/ast";
76
import { _ } from "@eslint-react/eff";
87
import * as JSX from "@eslint-react/jsx";
8+
import { type RuleContext, SEL } from "@eslint-react/kit";
99
import { getId } from "@eslint-react/shared";
1010
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
1111

12-
import { DISPLAY_NAME_ASSIGNMENT_SELECTOR } from "../constants";
1312
import { isReactHookCall } from "../hook";
1413
import { isValidComponentDefinition } from "./component-definition";
1514
import { DEFAULT_COMPONENT_DETECTION_HINT } from "./component-detection-hint";
@@ -96,7 +95,7 @@ export function useComponentCollector(
9695
const listeners = {
9796
":function[type]": onFunctionEnter,
9897
":function[type]:exit": onFunctionExit,
99-
"ArrowFunctionExpression[type][body.type!='BlockStatement']"() {
98+
"ArrowFunctionExpression[body.type!='BlockStatement']"() {
10099
const entry = getCurrentEntry();
101100
if (entry == null) return;
102101
const { body } = entry.node;
@@ -123,7 +122,7 @@ export function useComponentCollector(
123122
},
124123
...collectDisplayName
125124
? {
126-
[DISPLAY_NAME_ASSIGNMENT_SELECTOR](node: TSESTree.AssignmentExpression) {
125+
[SEL.DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node: TSESTree.AssignmentExpression) {
127126
const { left, right } = node;
128127
if (left.type !== T.MemberExpression) return;
129128
const componentName = left.object.type === T.Identifier

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ import type * as AST from "@eslint-react/ast";
22
import type { RuleContext } from "@eslint-react/kit";
33
import type { TSESTree } from "@typescript-eslint/types";
44
import { _ } from "@eslint-react/eff";
5+
import { RE } from "@eslint-react/kit";
56

67
import { getFunctionComponentId } from "./component-id";
78

8-
export const RE_COMPONENT_NAME = /^[A-Z]/u;
9-
10-
export const RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
11-
129
export function isComponentName(name: string) {
13-
return RE_COMPONENT_NAME.test(name);
10+
return RE.COMPONENT_NAME.test(name);
1411
}
1512

1613
export function isComponentNameLoose(name: string) {
17-
return RE_COMPONENT_NAME_LOOSE.test(name);
14+
return RE.COMPONENT_NAME_LOOSE.test(name);
1815
}
1916

2017
export function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | _) {

packages/core/src/constants.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)