Skip to content

Commit 38da7e5

Browse files
committed
refactor: improve collector function naming semantics
1 parent 9417641 commit 38da7e5

24 files changed

+124
-124
lines changed

packages/core/docs/README.md

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@
3333

3434
### Functions
3535

36-
- [componentCollector](README.md#componentcollector)
37-
- [componentCollectorLegacy](README.md#componentcollectorlegacy)
3836
- [constructionDetector](README.md#constructiondetector)
3937
- [getComponentInitPath](README.md#getcomponentinitpath)
4038
- [getComponentNameFromIdentifier](README.md#getcomponentnamefromidentifier)
4139
- [getFunctionComponentIdentifier](README.md#getfunctioncomponentidentifier)
4240
- [getParentClassComponent](README.md#getparentclasscomponent)
4341
- [hasCallInInitPath](README.md#hascallininitpath)
4442
- [hasNoneOrValidComponentName](README.md#hasnoneorvalidcomponentname)
45-
- [hookCollector](README.md#hookcollector)
4643
- [isChildrenCount](README.md#ischildrencount)
4744
- [isChildrenCountCall](README.md#ischildrencountcall)
4845
- [isChildrenForEach](README.md#ischildrenforeach)
@@ -97,6 +94,9 @@
9794
- [unsafeIsDeclaredInRenderProp](README.md#unsafeisdeclaredinrenderprop)
9895
- [unsafeIsRenderFunction](README.md#unsafeisrenderfunction)
9996
- [unsafeIsRenderProp](README.md#unsafeisrenderprop)
97+
- [useComponentCollector](README.md#usecomponentcollector)
98+
- [useComponentCollectorLegacy](README.md#usecomponentcollectorlegacy)
99+
- [useHookCollector](README.md#usehookcollector)
100100

101101
## Type Aliases
102102

@@ -238,64 +238,6 @@ ___
238238

239239
## Functions
240240

241-
### componentCollector
242-
243-
**componentCollector**(`context`, `hint?`, `pragma?`): `Object`
244-
245-
#### Parameters
246-
247-
| Name | Type | Default value |
248-
| :------ | :------ | :------ |
249-
| `context` | `Readonly`\<`RuleContext`\<`string`, readonly `unknown`[]\>\> | `undefined` |
250-
| `hint` | `bigint` | `DEFAULT_COMPONENT_COLLECTOR_HINT` |
251-
| `pragma` | `string` | `undefined` |
252-
253-
#### Returns
254-
255-
`Object`
256-
257-
| Name | Type |
258-
| :------ | :------ |
259-
| `ctx` | \{ `getCurrentFunction`: () => `Option`\<[`TSESTreeFunction`, `boolean`, `CallExpression`[]]\> ; `getAllComponents`: (`_`: `Program`) => `Map`\<`string`, [`ERFunctionComponent`](interfaces/ERFunctionComponent.md)\> ; `getCurrentComponents`: () => `Map`\<`string`, [`ERFunctionComponent`](interfaces/ERFunctionComponent.md)\> ; `getCurrentFunctionStack`: () => [`TSESTreeFunction`, `boolean`, `CallExpression`[]][] } |
260-
| `ctx.getCurrentFunction` | () => `Option`\<[`TSESTreeFunction`, `boolean`, `CallExpression`[]]\> |
261-
| `ctx.getAllComponents` | [object Object] |
262-
| `ctx.getCurrentComponents` | [object Object] |
263-
| `ctx.getCurrentFunctionStack` | [object Object] |
264-
| `listeners` | \{ `:function`: (`node`: `TSESTreeFunction`) => `MutableList`\<[`TSESTreeFunction`, `boolean`, `CallExpression`[]]\> = onFunctionEnter; `:function:exit`: () => `undefined` \| [`TSESTreeFunction`, `boolean`, `CallExpression`[]] = onFunctionExit; `ArrowFunctionExpression[body.type!='BlockStatement']`: () => `void` ; `AssignmentExpression[operator='='][left.type='MemberExpression'][left.property.name='displayName']`: (`node`: `AssignmentExpression`) => `void` ; `CallExpression:exit`: (`node`: `CallExpression`) => `void` ; `ReturnStatement`: (`node`: `ReturnStatement`) => `void` } |
265-
| `listeners.:function` | (`node`: `TSESTreeFunction`) => `MutableList`\<[`TSESTreeFunction`, `boolean`, `CallExpression`[]]\> |
266-
| `listeners.:function:exit` | () => `undefined` \| [`TSESTreeFunction`, `boolean`, `CallExpression`[]] |
267-
| `listeners.ArrowFunctionExpression[body.type!='BlockStatement']` | [object Object] |
268-
| `listeners.AssignmentExpression[operator='='][left.type='MemberExpression'][left.property.name='displayName']` | [object Object] |
269-
| `listeners.CallExpression:exit` | [object Object] |
270-
| `listeners.ReturnStatement` | [object Object] |
271-
272-
___
273-
274-
### componentCollectorLegacy
275-
276-
**componentCollectorLegacy**(`context`): `Object`
277-
278-
#### Parameters
279-
280-
| Name | Type |
281-
| :------ | :------ |
282-
| `context` | `Readonly`\<`RuleContext`\<`string`, readonly `unknown`[]\>\> |
283-
284-
#### Returns
285-
286-
`Object`
287-
288-
| Name | Type |
289-
| :------ | :------ |
290-
| `ctx` | \{ `getAllComponents`: (`_`: `Program`) => `Map`\<`string`, [`ERClassComponent`](interfaces/ERClassComponent.md)\> ; `getCurrentComponents`: () => `Map`\<`string`, [`ERClassComponent`](interfaces/ERClassComponent.md)\> } |
291-
| `ctx.getAllComponents` | [object Object] |
292-
| `ctx.getCurrentComponents` | [object Object] |
293-
| `listeners` | \{ `ClassDeclaration`: (`node`: `TSESTreeClass`) => `void` = collect; `ClassExpression`: (`node`: `TSESTreeClass`) => `void` = collect } |
294-
| `listeners.ClassDeclaration` | (`node`: `TSESTreeClass`) => `void` |
295-
| `listeners.ClassExpression` | (`node`: `TSESTreeClass`) => `void` |
296-
297-
___
298-
299241
### constructionDetector
300242

301243
**constructionDetector**\<`T`\>(`context`): (`node`: `TSESTree.Node`) => [`ERConstruction`](README.md#erconstruction-1)
@@ -450,23 +392,6 @@ ___
450392

451393
___
452394

453-
### hookCollector
454-
455-
**hookCollector**(): `Object`
456-
457-
#### Returns
458-
459-
`Object`
460-
461-
| Name | Type |
462-
| :------ | :------ |
463-
| `ctx` | \{ `getAllHooks`: (`_`: `Program`) => `Map`\<`string`, [`ERHook`](interfaces/ERHook.md)\> ; `getCurrentHooks`: () => `Map`\<`string`, [`ERHook`](interfaces/ERHook.md)\> } |
464-
| `ctx.getAllHooks` | [object Object] |
465-
| `ctx.getCurrentHooks` | [object Object] |
466-
| `listeners` | `ESLintUtils.RuleListener` |
467-
468-
___
469-
470395
### isChildrenCount
471396

472397
**isChildrenCount**(`node`, `context`, `pragma?`): `boolean`
@@ -1493,3 +1418,78 @@ _ = <Component renderRow={() => <div />} />
14931418
`boolean`
14941419

14951420
`true` if node is a render prop, `false` if not
1421+
1422+
___
1423+
1424+
### useComponentCollector
1425+
1426+
**useComponentCollector**(`context`, `hint?`, `pragma?`): `Object`
1427+
1428+
#### Parameters
1429+
1430+
| Name | Type | Default value |
1431+
| :------ | :------ | :------ |
1432+
| `context` | `Readonly`\<`RuleContext`\<`string`, readonly `unknown`[]\>\> | `undefined` |
1433+
| `hint` | `bigint` | `DEFAULT_COMPONENT_COLLECTOR_HINT` |
1434+
| `pragma` | `string` | `undefined` |
1435+
1436+
#### Returns
1437+
1438+
`Object`
1439+
1440+
| Name | Type |
1441+
| :------ | :------ |
1442+
| `ctx` | \{ `getCurrentFunction`: () => `Option`\<[`TSESTreeFunction`, `boolean`, `CallExpression`[]]\> ; `getAllComponents`: (`_`: `Program`) => `Map`\<`string`, [`ERFunctionComponent`](interfaces/ERFunctionComponent.md)\> ; `getCurrentComponents`: () => `Map`\<`string`, [`ERFunctionComponent`](interfaces/ERFunctionComponent.md)\> ; `getCurrentFunctionStack`: () => [`TSESTreeFunction`, `boolean`, `CallExpression`[]][] } |
1443+
| `ctx.getCurrentFunction` | () => `Option`\<[`TSESTreeFunction`, `boolean`, `CallExpression`[]]\> |
1444+
| `ctx.getAllComponents` | [object Object] |
1445+
| `ctx.getCurrentComponents` | [object Object] |
1446+
| `ctx.getCurrentFunctionStack` | [object Object] |
1447+
| `listeners` | \{ `:function`: (`node`: `TSESTreeFunction`) => `MutableList`\<[`TSESTreeFunction`, `boolean`, `CallExpression`[]]\> = onFunctionEnter; `:function:exit`: () => `undefined` \| [`TSESTreeFunction`, `boolean`, `CallExpression`[]] = onFunctionExit; `ArrowFunctionExpression[body.type!='BlockStatement']`: () => `void` ; `AssignmentExpression[operator='='][left.type='MemberExpression'][left.property.name='displayName']`: (`node`: `AssignmentExpression`) => `void` ; `CallExpression:exit`: (`node`: `CallExpression`) => `void` ; `ReturnStatement`: (`node`: `ReturnStatement`) => `void` } |
1448+
| `listeners.:function` | (`node`: `TSESTreeFunction`) => `MutableList`\<[`TSESTreeFunction`, `boolean`, `CallExpression`[]]\> |
1449+
| `listeners.:function:exit` | () => `undefined` \| [`TSESTreeFunction`, `boolean`, `CallExpression`[]] |
1450+
| `listeners.ArrowFunctionExpression[body.type!='BlockStatement']` | [object Object] |
1451+
| `listeners.AssignmentExpression[operator='='][left.type='MemberExpression'][left.property.name='displayName']` | [object Object] |
1452+
| `listeners.CallExpression:exit` | [object Object] |
1453+
| `listeners.ReturnStatement` | [object Object] |
1454+
1455+
___
1456+
1457+
### useComponentCollectorLegacy
1458+
1459+
**useComponentCollectorLegacy**(`context`): `Object`
1460+
1461+
#### Parameters
1462+
1463+
| Name | Type |
1464+
| :------ | :------ |
1465+
| `context` | `Readonly`\<`RuleContext`\<`string`, readonly `unknown`[]\>\> |
1466+
1467+
#### Returns
1468+
1469+
`Object`
1470+
1471+
| Name | Type |
1472+
| :------ | :------ |
1473+
| `ctx` | \{ `getAllComponents`: (`_`: `Program`) => `Map`\<`string`, [`ERClassComponent`](interfaces/ERClassComponent.md)\> ; `getCurrentComponents`: () => `Map`\<`string`, [`ERClassComponent`](interfaces/ERClassComponent.md)\> } |
1474+
| `ctx.getAllComponents` | [object Object] |
1475+
| `ctx.getCurrentComponents` | [object Object] |
1476+
| `listeners` | \{ `ClassDeclaration`: (`node`: `TSESTreeClass`) => `void` = collect; `ClassExpression`: (`node`: `TSESTreeClass`) => `void` = collect } |
1477+
| `listeners.ClassDeclaration` | (`node`: `TSESTreeClass`) => `void` |
1478+
| `listeners.ClassExpression` | (`node`: `TSESTreeClass`) => `void` |
1479+
1480+
___
1481+
1482+
### useHookCollector
1483+
1484+
**useHookCollector**(): `Object`
1485+
1486+
#### Returns
1487+
1488+
`Object`
1489+
1490+
| Name | Type |
1491+
| :------ | :------ |
1492+
| `ctx` | \{ `getAllHooks`: (`_`: `Program`) => `Map`\<`string`, [`ERHook`](interfaces/ERHook.md)\> ; `getCurrentHooks`: () => `Map`\<`string`, [`ERHook`](interfaces/ERHook.md)\> } |
1493+
| `ctx.getAllHooks` | [object Object] |
1494+
| `ctx.getCurrentHooks` | [object Object] |
1495+
| `listeners` | `ESLintUtils.RuleListener` |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function isPureComponent(node: TSESTree.Node, context: RuleContext) {
5656
return false;
5757
}
5858

59-
export function componentCollectorLegacy(context: RuleContext) {
59+
export function useComponentCollectorLegacy(context: RuleContext) {
6060
const components = new Map<string, ERClassComponent>();
6161

6262
const ctx = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function getComponentFlag(initPath: ERFunctionComponent["initPath"], pragma: str
7878
return MutRef.get(flagRef);
7979
}
8080

81-
export function componentCollector(
81+
export function useComponentCollector(
8282
context: RuleContext,
8383
hint: bigint = DEFAULT_COMPONENT_COLLECTOR_HINT,
8484
pragma = getPragmaFromContext(context),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { isReactHookCall } from "./is";
99

1010
const uid = new ShortUniqueId({ length: 10 });
1111

12-
export function hookCollector(): {
12+
export function useHookCollector(): {
1313
// manually specify the return type here to avoid @typescript-eslint/utils's TS2742 error
1414
ctx: {
1515
getAllHooks(_: TSESTree.Program): Map<string, ERHook>;

packages/plugins/eslint-plugin-debug/src/rules/class-component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { componentCollectorLegacy } from "@eslint-react/core";
1+
import { useComponentCollectorLegacy } from "@eslint-react/core";
22
import { F, O } from "@eslint-react/tools";
33
import type { ESLintUtils } from "@typescript-eslint/utils";
44

@@ -23,7 +23,7 @@ export default createRule<[], MessageID>({
2323
},
2424
defaultOptions: [],
2525
create(context) {
26-
const { ctx, listeners } = componentCollectorLegacy(context);
26+
const { ctx, listeners } = useComponentCollectorLegacy(context);
2727

2828
return {
2929
...listeners,

packages/plugins/eslint-plugin-debug/src/rules/function-component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { componentCollector, ERFunctionComponentFlag } from "@eslint-react/core";
1+
import { ERFunctionComponentFlag, useComponentCollector } from "@eslint-react/core";
22
import { F, O } from "@eslint-react/tools";
33
import type { ESLintUtils } from "@typescript-eslint/utils";
44
import { type ConstantCase } from "string-ts";
@@ -25,7 +25,7 @@ export default createRule<[], MessageID>({
2525
},
2626
defaultOptions: [],
2727
create(context) {
28-
const { ctx, listeners } = componentCollector(context);
28+
const { ctx, listeners } = useComponentCollector(context);
2929

3030
return {
3131
...listeners,

packages/plugins/eslint-plugin-debug/src/rules/react-hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hookCollector } from "@eslint-react/core";
1+
import { useHookCollector } from "@eslint-react/core";
22
import type { ESLintUtils } from "@typescript-eslint/utils";
33
import type { ConstantCase } from "string-ts";
44

@@ -22,7 +22,7 @@ export default createRule<[], MessageID>({
2222
},
2323
defaultOptions: [],
2424
create(context) {
25-
const { ctx, listeners } = hookCollector();
25+
const { ctx, listeners } = useHookCollector();
2626

2727
return {
2828
...listeners,

packages/plugins/eslint-plugin-naming-convention/src/rules/component-name.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getClassIdentifier, getFunctionIdentifier } from "@eslint-react/ast";
2-
import { componentCollector, componentCollectorLegacy } from "@eslint-react/core";
2+
import { useComponentCollector, useComponentCollectorLegacy } from "@eslint-react/core";
33
import { elementType } from "@eslint-react/jsx";
44
import { getCaseValidator } from "@eslint-react/shared";
55
import { _, O } from "@eslint-react/tools";
@@ -81,8 +81,8 @@ export default createRule<Options, MessageID>({
8181
const validator = getCaseValidator(rule, [...excepts]);
8282
const validate = (name: string) => validator.validate(name);
8383

84-
const collector = componentCollector(context);
85-
const collectorLegacy = componentCollectorLegacy(context);
84+
const collector = useComponentCollector(context);
85+
const collectorLegacy = useComponentCollectorLegacy(context);
8686

8787
return {
8888
...collector.listeners,

packages/plugins/eslint-plugin-naming-convention/src/rules/use-state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NodeType } from "@eslint-react/ast";
2-
import { componentCollector, isUseStateCall } from "@eslint-react/core";
2+
import { isUseStateCall, useComponentCollector } from "@eslint-react/core";
33
import { getPragmaFromContext } from "@eslint-react/jsx";
44
import { _, F, O } from "@eslint-react/tools";
55
import type { ESLintUtils } from "@typescript-eslint/utils";
@@ -36,7 +36,7 @@ export default createRule<[], MessageID>({
3636
},
3737
defaultOptions: [],
3838
create(context) {
39-
const { ctx, listeners } = componentCollector(context);
39+
const { ctx, listeners } = useComponentCollector(context);
4040

4141
return {
4242
...listeners,

packages/plugins/eslint-plugin-react-hooks/src/rules/ensure-custom-hooks-using-other-hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hookCollector } from "@eslint-react/core";
1+
import { useHookCollector } from "@eslint-react/core";
22
import type { ESLintUtils } from "@typescript-eslint/utils";
33
import { type ConstantCase } from "string-ts";
44

@@ -23,7 +23,7 @@ export default createRule<[], MessageID>({
2323
},
2424
defaultOptions: [],
2525
create(context) {
26-
const { ctx, listeners } = hookCollector();
26+
const { ctx, listeners } = useHookCollector();
2727

2828
return {
2929
...listeners,

packages/plugins/eslint-plugin-react/src/rules/no-class-component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { componentCollectorLegacy } from "@eslint-react/core";
1+
import { useComponentCollectorLegacy } from "@eslint-react/core";
22
import { F, O } from "@eslint-react/tools";
33
import type { ESLintUtils } from "@typescript-eslint/utils";
44
import { type ConstantCase } from "string-ts";
@@ -23,7 +23,7 @@ export default createRule<[], MessageID>({
2323
},
2424
defaultOptions: [],
2525
create(context) {
26-
const { ctx, listeners } = componentCollectorLegacy(context);
26+
const { ctx, listeners } = useComponentCollectorLegacy(context);
2727

2828
return {
2929
...listeners,

packages/plugins/eslint-plugin-react/src/rules/no-component-will-mount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isOneOf, NodeType } from "@eslint-react/ast";
2-
import { componentCollectorLegacy } from "@eslint-react/core";
2+
import { useComponentCollectorLegacy } from "@eslint-react/core";
33
import type { TSESTree } from "@typescript-eslint/utils";
44
import type { ESLintUtils } from "@typescript-eslint/utils";
55
import type { ConstantCase } from "string-ts";
@@ -32,7 +32,7 @@ export default createRule<[], MessageID>({
3232
},
3333
defaultOptions: [],
3434
create(context) {
35-
const { ctx, listeners } = componentCollectorLegacy(context);
35+
const { ctx, listeners } = useComponentCollectorLegacy(context);
3636

3737
return {
3838
...listeners,

packages/plugins/eslint-plugin-react/src/rules/no-component-will-receive-props.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isOneOf, NodeType } from "@eslint-react/ast";
2-
import { componentCollectorLegacy } from "@eslint-react/core";
2+
import { useComponentCollectorLegacy } from "@eslint-react/core";
33
import type { TSESTree } from "@typescript-eslint/utils";
44
import type { ESLintUtils } from "@typescript-eslint/utils";
55
import type { ConstantCase } from "string-ts";
@@ -32,7 +32,7 @@ export default createRule<[], MessageID>({
3232
},
3333
defaultOptions: [],
3434
create(context) {
35-
const { ctx, listeners } = componentCollectorLegacy(context);
35+
const { ctx, listeners } = useComponentCollectorLegacy(context);
3636

3737
return {
3838
...listeners,

packages/plugins/eslint-plugin-react/src/rules/no-component-will-update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isOneOf, NodeType } from "@eslint-react/ast";
2-
import { componentCollectorLegacy } from "@eslint-react/core";
2+
import { useComponentCollectorLegacy } from "@eslint-react/core";
33
import type { TSESTree } from "@typescript-eslint/utils";
44
import type { ESLintUtils } from "@typescript-eslint/utils";
55
import type { ConstantCase } from "string-ts";
@@ -32,7 +32,7 @@ export default createRule<[], MessageID>({
3232
},
3333
defaultOptions: [],
3434
create(context) {
35-
const { ctx, listeners } = componentCollectorLegacy(context);
35+
const { ctx, listeners } = useComponentCollectorLegacy(context);
3636

3737
return {
3838
...listeners,

packages/plugins/eslint-plugin-react/src/rules/no-constructed-context-value.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NodeType, type TSESTreeFunction } from "@eslint-react/ast";
2-
import { componentCollector, constructionDetector, type ERConstruction } from "@eslint-react/core";
2+
import { constructionDetector, type ERConstruction, useComponentCollector } from "@eslint-react/core";
33
import { O } from "@eslint-react/tools";
44
import type { ESLintUtils } from "@typescript-eslint/utils";
55

@@ -33,7 +33,7 @@ export default createRule<[], MessageID>({
3333
},
3434
defaultOptions: [],
3535
create(context) {
36-
const { ctx, listeners } = componentCollector(context);
36+
const { ctx, listeners } = useComponentCollector(context);
3737
const detectConstruction = constructionDetector(context);
3838
const possibleValueConstructions = new Map<TSESTreeFunction, ERConstruction>();
3939

0 commit comments

Comments
 (0)