Skip to content

Commit 1782000

Browse files
authored
Replace star imports with direct imports (#1241)
1 parent 7e371b1 commit 1782000

File tree

84 files changed

+427
-389
lines changed

Some content is hidden

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

84 files changed

+427
-389
lines changed

packages/core/src/jsx/jsx-attribute.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type * as AST from "@eslint-react/ast";
22
import type { RuleContext } from "@eslint-react/kit";
3-
import * as VAR from "@eslint-react/var";
3+
import { findProperty, findVariable, getVariableDefinitionNode } from "@eslint-react/var";
44
import type { Scope } from "@typescript-eslint/scope-manager";
5-
65
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
6+
77
import { getAttributeName } from "./jsx-attribute-name";
88

99
export function getAttribute(context: RuleContext, attributes: AST.TSESTreeJSXAttributeLike[], initialScope?: Scope) {
@@ -18,16 +18,16 @@ export function getAttribute(context: RuleContext, attributes: AST.TSESTreeJSXAt
1818
switch (attr.argument.type) {
1919
// Case 2: Spread from variable (e.g., {...props})
2020
case T.Identifier: {
21-
const variable = VAR.findVariable(attr.argument.name, initialScope);
22-
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
21+
const variable = findVariable(attr.argument.name, initialScope);
22+
const variableNode = getVariableDefinitionNode(variable, 0);
2323
if (variableNode?.type === T.ObjectExpression) {
24-
return VAR.findProperty(name, variableNode.properties, initialScope) != null;
24+
return findProperty(name, variableNode.properties, initialScope) != null;
2525
}
2626
return false;
2727
}
2828
// Case 3: Spread from object literal (e.g., {{...{prop: value}}})
2929
case T.ObjectExpression:
30-
return VAR.findProperty(name, attr.argument.properties, initialScope) != null;
30+
return findProperty(name, attr.argument.properties, initialScope) != null;
3131
}
3232
return false;
3333
});

packages/core/src/jsx/jsx-detection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
22
import * as AST from "@eslint-react/ast";
33
import type { unit } from "@eslint-react/eff";
4-
import * as VAR from "@eslint-react/var";
4+
import { findVariable, getVariableDefinitionNode } from "@eslint-react/var";
55
import type { Scope } from "@typescript-eslint/scope-manager";
66
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
77
import type { TSESTree } from "@typescript-eslint/utils";
@@ -185,9 +185,9 @@ export function isJsxLike(
185185
return true;
186186
}
187187
// Resolve variables to their values and check if they're JSX-like
188-
const variable = VAR.findVariable(name, code.getScope(node));
188+
const variable = findVariable(name, code.getScope(node));
189189
const variableNode = variable
190-
&& VAR.getVariableDefinitionNode(variable, 0);
190+
&& getVariableDefinitionNode(variable, 0);
191191
return !!variableNode
192192
&& isJsxLike(code, variableNode, hint);
193193
}

packages/core/src/utils/is-from-react.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 { identity } from "@eslint-react/eff";
3-
import * as VAR from "@eslint-react/var";
3+
import { findVariable } from "@eslint-react/var";
44
import type { Scope } from "@typescript-eslint/scope-manager";
55
import type { TSESTree } from "@typescript-eslint/types";
66
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
@@ -34,7 +34,7 @@ export function isInitializedFromReact(
3434
initialScope: Scope,
3535
): boolean {
3636
if (name.toLowerCase() === "react") return true;
37-
const latestDef = VAR.findVariable(name, initialScope)?.defs.at(-1);
37+
const latestDef = findVariable(name, initialScope)?.defs.at(-1);
3838
if (latestDef == null) return false;
3939
const { node, parent } = latestDef;
4040
if (node.type === T.VariableDeclarator && node.init != null) {

packages/core/src/utils/is-instance-id-equal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-disable jsdoc/require-param */
22
import * as AST from "@eslint-react/ast";
33
import type { RuleContext } from "@eslint-react/kit";
4-
import * as VAR from "@eslint-react/var";
4+
import { isNodeValueEqual } from "@eslint-react/var";
55
import type { TSESTree } from "@typescript-eslint/types";
66

77
/** @internal */
88
export function isInstanceIdEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node) {
9-
return AST.isNodeEqual(a, b) || VAR.isNodeValueEqual(a, b, [
9+
return AST.isNodeEqual(a, b) || isNodeValueEqual(a, b, [
1010
context.sourceCode.getScope(a),
1111
context.sourceCode.getScope(b),
1212
]);

packages/plugins/eslint-plugin-react-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 * as ER from "@eslint-react/core";
1+
import { useComponentCollectorLegacy } from "@eslint-react/core";
22
import type { RuleContext, RuleFeature } from "@eslint-react/kit";
33
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
44
import type { CamelCase } from "string-ts";
@@ -31,7 +31,7 @@ export default createRule<[], MessageID>({
3131
});
3232

3333
export function create(context: RuleContext<MessageID, []>): RuleListener {
34-
const { ctx, listeners } = ER.useComponentCollectorLegacy();
34+
const { ctx, listeners } = useComponentCollectorLegacy();
3535
return {
3636
...listeners,
3737
"Program:exit"(program) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ER from "@eslint-react/core";
1+
import { ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, useComponentCollector } from "@eslint-react/core";
22
import type { RuleContext, RuleFeature } from "@eslint-react/kit";
33
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
44
import type { CamelCase } from "string-ts";
@@ -32,12 +32,12 @@ export default createRule<[], MessageID>({
3232
});
3333

3434
export function create(context: RuleContext<MessageID, []>): RuleListener {
35-
const { ctx, listeners } = ER.useComponentCollector(
35+
const { ctx, listeners } = useComponentCollector(
3636
context,
3737
{
3838
collectDisplayName: true,
3939
collectHookCalls: true,
40-
hint: ER.DEFAULT_COMPONENT_DETECTION_HINT,
40+
hint: DEFAULT_COMPONENT_DETECTION_HINT,
4141
},
4242
);
4343
return {
@@ -54,9 +54,9 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
5454
displayName: displayName == null
5555
? "none"
5656
: context.sourceCode.getText(displayName),
57-
forwardRef: (flag & ER.ComponentFlag.ForwardRef) > 0n,
57+
forwardRef: (flag & ComponentFlag.ForwardRef) > 0n,
5858
hookCalls: hookCalls.length,
59-
memo: (flag & ER.ComponentFlag.Memo) > 0n,
59+
memo: (flag & ComponentFlag.Memo) > 0n,
6060
}),
6161
},
6262
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ER from "@eslint-react/core";
1+
import { useHookCollector } from "@eslint-react/core";
22
import type { RuleContext, RuleFeature } from "@eslint-react/kit";
33
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
44
import type { CamelCase } from "string-ts";
@@ -31,7 +31,7 @@ export default createRule<[], MessageID>({
3131
});
3232

3333
export function create(context: RuleContext<MessageID, []>): RuleListener {
34-
const { ctx, listeners } = ER.useHookCollector();
34+
const { ctx, listeners } = useHookCollector();
3535

3636
return {
3737
...listeners,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ER from "@eslint-react/core";
1+
import { isInitializedFromReact } from "@eslint-react/core";
22
import type { RuleContext, RuleFeature } from "@eslint-react/kit";
33
import { getSettingsFromContext } from "@eslint-react/shared";
44
import type { Scope } from "@typescript-eslint/scope-manager";
@@ -79,12 +79,12 @@ function isFromReact(
7979
case node.parent.type === T.MemberExpression
8080
&& node.parent.property === node
8181
&& node.parent.object.type === T.Identifier:
82-
return ER.isInitializedFromReact(node.parent.object.name, importSource, initialScope);
82+
return isInitializedFromReact(node.parent.object.name, importSource, initialScope);
8383
case node.parent.type === T.JSXMemberExpression
8484
&& node.parent.property === node
8585
&& node.parent.object.type === T.JSXIdentifier:
86-
return ER.isInitializedFromReact(node.parent.object.name, importSource, initialScope);
86+
return isInitializedFromReact(node.parent.object.name, importSource, initialScope);
8787
default:
88-
return ER.isInitializedFromReact(name, importSource, initialScope);
88+
return isInitializedFromReact(name, importSource, initialScope);
8989
}
9090
}

packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml-with-children.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as ER from "@eslint-react/core";
1+
import { hasAttribute, isJsxText } from "@eslint-react/core";
22
import type { RuleContext, RuleFeature } from "@eslint-react/kit";
3+
import { AST_NODE_TYPES, type TSESTree } from "@typescript-eslint/types";
34
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
45
import type { CamelCase } from "string-ts";
56

6-
import { AST_NODE_TYPES, type TSESTree } from "@typescript-eslint/types";
77
import { createRule } from "../utils";
88

99
export const RULE_NAME = "no-dangerously-set-innerhtml-with-children";
@@ -40,8 +40,8 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
4040
const attributes = node.openingElement.attributes;
4141
const initialScope = context.sourceCode.getScope(node);
4242
const hasChildren = node.children.some(isSignificantChildren)
43-
|| ER.hasAttribute(context, "children", attributes, initialScope);
44-
if (hasChildren && ER.hasAttribute(context, dangerouslySetInnerHTML, attributes, initialScope)) {
43+
|| hasAttribute(context, "children", attributes, initialScope);
44+
if (hasChildren && hasAttribute(context, dangerouslySetInnerHTML, attributes, initialScope)) {
4545
context.report({
4646
messageId: "noDangerouslySetInnerhtmlWithChildren",
4747
node,
@@ -66,7 +66,7 @@ function isWhiteSpace(node: TSESTree.JSXText | TSESTree.Literal) {
6666
* @returns boolean
6767
*/
6868
function isPaddingSpaces(node: TSESTree.Node) {
69-
return ER.isJsxText(node)
69+
return isJsxText(node)
7070
&& isWhiteSpace(node)
7171
&& node.raw.includes("\n");
7272
}

packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ER from "@eslint-react/core";
1+
import { getAttribute } from "@eslint-react/core";
22
import type { RuleContext, RuleFeature } from "@eslint-react/kit";
33
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
44
import type { CamelCase } from "string-ts";
@@ -35,8 +35,8 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
3535
if (!context.sourceCode.text.includes(dangerouslySetInnerHTML)) return {};
3636
return {
3737
JSXElement(node) {
38-
const getAttribute = ER.getAttribute(context, node.openingElement.attributes, context.sourceCode.getScope(node));
39-
const attribute = getAttribute(dangerouslySetInnerHTML);
38+
const getAttributeEx = getAttribute(context, node.openingElement.attributes, context.sourceCode.getScope(node));
39+
const attribute = getAttributeEx(dangerouslySetInnerHTML);
4040
if (attribute == null) return;
4141
context.report({
4242
messageId: "noDangerouslySetInnerhtml",

0 commit comments

Comments
 (0)