Skip to content

Commit

Permalink
refactor: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Rel1cx committed Dec 19, 2023
1 parent 10e1ced commit 1818a07
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 149 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
"@typescript-eslint/eslint-plugin": "6.15.0",
"@typescript-eslint/parser": ">=6.15.0",
"@typescript-eslint/rule-tester": "6.15.0",
"@vitest/ui": "1.0.4",
"@vitest/ui": "1.1.0",
"bun": "1.0.18",
"bun-types": "1.0.18-canary.20231218T214637",
"bun-types": "1.0.18-canary.20231219T140126",
"cspell": "8.1.3",
"dedent": "1.5.1",
"dprint": "0.44.0",
Expand All @@ -85,7 +85,7 @@
"eslint-plugin-vitest": "0.3.18",
"fast-equals": "5.0.1",
"husky": "8.0.3",
"knip": "3.8.2",
"knip": "3.8.3",
"markdownlint": "0.32.1",
"pathe": "1.1.1",
"publint": "0.2.6",
Expand All @@ -105,7 +105,7 @@
"typedoc-plugin-mermaid": "1.10.0",
"typedoc-plugin-rename-defaults": "0.7.0",
"typescript": ">=5.3.3",
"vitest": "1.0.4"
"vitest": "1.1.0"
},
"peerDependencies": {
"@typescript-eslint/parser": ">=6.15.0",
Expand Down
41 changes: 0 additions & 41 deletions packages/core/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
- [ERFunctionComponentFlag](README.md#erfunctioncomponentflag-1)
- [RE\_COMPONENT\_NAME](README.md#re_component_name)
- [RE\_HOOK\_NAME](README.md#re_hook_name)
- [uid](README.md#uid)

### Functions

Expand Down Expand Up @@ -68,7 +67,6 @@
- [isFunctionOfRenderMethod](README.md#isfunctionofrendermethod)
- [isInsideReactHook](README.md#isinsidereacthook)
- [isInsideRenderMethod](README.md#isinsiderendermethod)
- [isMemberExpressionOfReactMember](README.md#ismemberexpressionofreactmember)
- [isMemo](README.md#ismemo)
- [isMemoCall](README.md#ismemocall)
- [isPureComponent](README.md#ispurecomponent)
Expand Down Expand Up @@ -240,12 +238,6 @@ ___

`Const` **RE\_HOOK\_NAME**: `RegExp`

___

### uid

`Const` **uid**: `default`

## Functions

### componentCollector
Expand Down Expand Up @@ -914,39 +906,6 @@ It will be removed in the future

___

### isMemberExpressionOfReactMember

**isMemberExpressionOfReactMember**(`pragmaMemberName`, `memberName`): (`node`: `TSESTree.MemberExpression`, `context`: `RuleContext`, `pragma?`: `string`) => `boolean`

#### Parameters

| Name | Type |
| :------ | :------ |
| `pragmaMemberName` | `string` |
| `memberName` | `string` |

#### Returns

`fn`

A function that checks if a given node is a member expression of a Pragma member.

▸ (`node`, `context`, `pragma?`): `boolean`

##### Parameters

| Name | Type |
| :------ | :------ |
| `node` | `TSESTree.MemberExpression` |
| `context` | `RuleContext` |
| `pragma?` | `string` |

##### Returns

`boolean`

___

### isMemo

**isMemo**(`node`, `context`): `boolean`
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/api/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/component/component-Identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { O } from "@eslint-react/tools";
import type { RuleContext } from "@eslint-react/types";
import type { TSESTree } from "@typescript-eslint/types";

import { isForwardRefCall, isMemoCall } from "../api";
import { isForwardRefCall, isMemoCall } from "../react-api";

function isMemoOrForwardRefCall(node: TSESTree.Node, context: RuleContext) {
if (node.type !== NodeType.CallExpression) {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/component/component-collector-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { getPragmaFromContext } from "@eslint-react/jsx";
import { O } from "@eslint-react/tools";
import type { RuleContext } from "@eslint-react/types";
import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
import ShortUniqueId from "short-unique-id";
import { match, P } from "ts-pattern";

import { uid } from "../utils";
import type { ERClassComponent } from "./component";
import { ERClassComponentFlag } from "./component-flag";

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

/**
* Check if a node is a React class component
* @param node The AST node to check
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/component/component-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { F, MutList, MutRef, O } from "@eslint-react/tools";
import type { RuleContext } from "@eslint-react/types";
import { type TSESTree } from "@typescript-eslint/types";
import type { ESLintUtils } from "@typescript-eslint/utils";
import ShortUniqueId from "short-unique-id";
import { match } from "ts-pattern";

import { unsafeIsReactHookCall } from "../hook";
import { uid } from "../utils";
import type { ERFunctionComponent } from "./component";
import { DEFAULT_COMPONENT_COLLECTOR_HINT, ERComponentCollectorHint } from "./component-collector-hint";
import { ERFunctionComponentFlag } from "./component-flag";
Expand All @@ -26,6 +26,8 @@ import { getComponentInitPath, hasCallInInitPath } from "./component-init-path";
import { getComponentNameFromIdentifier, hasNoneOrValidComponentName } from "./component-name";
import { isFunctionOfRenderMethod } from "./component-render-method";

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

function hasValidHierarchy(node: TSESTreeFunction, context: RuleContext, hint: bigint) {
if (isChildrenOfCreateElement(node, context) || isFunctionOfRenderMethod(node, context)) {
return false;
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/hook/hook-collector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { getFunctionIdentifier, type TSESTreeFunction } from "@eslint-react/ast";
import { O } from "@eslint-react/tools";
import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
import ShortUniqueId from "short-unique-id";

import { uid } from "../utils";
import type { ERHook } from "./hook";
import { unsafeIsReactHookCall } from "./hook-call";
import { isValidReactHookName } from "./hook-name";

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

export function hookCollector(): {
// manually specify the return type here to avoid @typescript-eslint/utils's TS2742 error
ctx: {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./api";
export * from "./component";
export * from "./construction";
export * from "./hook";
export * from "./internal";
export * from "./react-api";
export * from "./render-prop";
export * from "./utils";
1 change: 0 additions & 1 deletion packages/core/src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./analyzer-node";
export * from "./is-member-expression-of-react-member";
export * from "./is-react-api";
48 changes: 0 additions & 48 deletions packages/core/src/internal/is-member-expression-of-react-member.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RuleContext } from "@eslint-react/types";
import type { TSESTree } from "@typescript-eslint/types";

import { isReactAPI, isReactAPICall } from "../internal";
import { isReactAPI, isReactAPICall } from "./internal";

// Workaround for @typescript-eslint/utils's TS2742 error.
type A = (node: TSESTree.Identifier | TSESTree.MemberExpression, context: RuleContext) => boolean;
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/utils/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/src/utils/uid.ts

This file was deleted.

Loading

0 comments on commit 1818a07

Please sign in to comment.