Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pkgs/eslint-plugin-local/dist/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as AST from '@eslint-react/ast';
import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
import { _ } from '@eslint-react/eff';
import { unit } from '@eslint-react/eff';
import { findVariable } from '@eslint-react/var';
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types';
import { nullThrows, NullThrowsReasons } from '@typescript-eslint/utils/eslint-utils';
Expand Down Expand Up @@ -44,7 +44,7 @@ function getRequireExpressionArguments(node) {
return getRequireExpressionArguments(node.object);
}
}
return _;
return unit;
}

// src/rules/avoid-multiline-template-expression.ts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Scope } from "@typescript-eslint/scope-manager";
import type { TSESTree } from "@typescript-eslint/types";
import * as AST from "@eslint-react/ast";
import { _ } from "@eslint-react/eff";
import { unit } from "@eslint-react/eff";
import { findVariable } from "@eslint-react/var";
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";

Expand Down Expand Up @@ -46,7 +46,7 @@ export function isInitializedFromSource(
return parent?.type === T.ImportDeclaration && parent.source.value === source;
}

function getRequireExpressionArguments(node: TSESTree.Node): TSESTree.CallExpressionArgument[] | _ {
function getRequireExpressionArguments(node: TSESTree.Node): TSESTree.CallExpressionArgument[] | unit {
switch (true) {
// require('source')
case node.type === T.CallExpression
Expand All @@ -59,5 +59,5 @@ function getRequireExpressionArguments(node: TSESTree.Node): TSESTree.CallExpres
return getRequireExpressionArguments(node.object);
}
}
return _;
return unit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@

#### getCurrentEntry()

> **getCurrentEntry**: () => `FunctionEntry` \| `_`
> **getCurrentEntry**: () => `FunctionEntry` \| `unit`

##### Returns

`FunctionEntry` \| `_`
`FunctionEntry` \| `unit`

***

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/component/component-collector-legacy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
import type { ClassComponent } from "./component-semantic-node";
import * as AST from "@eslint-react/ast";
import { _ } from "@eslint-react/eff";
import { unit } from "@eslint-react/eff";

import { getId } from "@eslint-react/shared";
import { ComponentFlag } from "./component-flag";
Expand Down Expand Up @@ -48,7 +48,7 @@ export function useComponentCollectorLegacy(): useComponentCollectorLegacy.Retur
name: id?.name,
node,
// TODO: Get displayName of class component
displayName: _,
displayName: unit,
flag,
hint: 0n,
// TODO: Get methods of class component
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/component/component-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ESLintUtils } from "@typescript-eslint/utils";
import type { ComponentDetectionHint } from "./component-detection-hint";
import type { FunctionComponent } from "./component-semantic-node";
import * as AST from "@eslint-react/ast";
import { _ } from "@eslint-react/eff";
import { unit } from "@eslint-react/eff";
import { type RuleContext, Selector as SEL } from "@eslint-react/kit";
import { getId } from "@eslint-react/shared";
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
Expand Down Expand Up @@ -33,7 +33,7 @@ export declare namespace useComponentCollector {
ctx: {
getAllComponents: (node: TSESTree.Program) => Map<string, FunctionComponent>;
getCurrentEntries: () => FunctionEntry[];
getCurrentEntry: () => FunctionEntry | _;
getCurrentEntry: () => FunctionEntry | unit;
};
listeners: ESLintUtils.RuleListener;
};
Expand Down Expand Up @@ -114,7 +114,7 @@ export function useComponentCollector(
kind: "function",
name,
node: entry.node,
displayName: _,
displayName: unit,
flag: getComponentFlagFromInitPath(initPath),
hint,
hookCalls: entry.hookCalls,
Expand All @@ -128,7 +128,7 @@ export function useComponentCollector(
if (left.type !== T.MemberExpression) return;
const componentName = left.object.type === T.Identifier
? left.object.name
: _;
: unit;
const component = [...components.values()]
.findLast(({ name }) => name != null && name === componentName);
if (component == null) return;
Expand Down Expand Up @@ -163,7 +163,7 @@ export function useComponentCollector(
kind: "function",
name,
node: entry.node,
displayName: _,
displayName: unit,
flag: getComponentFlagFromInitPath(initPath),
hint,
hookCalls: entry.hookCalls,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/component/component-id.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { RuleContext } from "@eslint-react/kit";
import type { TSESTree } from "@typescript-eslint/types";
import * as AST from "@eslint-react/ast";
import { _ } from "@eslint-react/eff";
import { unit } from "@eslint-react/eff";
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
import { isComponentWrapperCallLoose } from "./component-wrapper";

export function getFunctionComponentId(
context: RuleContext,
node: AST.TSESTreeFunction,
): TSESTree.Identifier | TSESTree.Identifier[] | _ {
): TSESTree.Identifier | TSESTree.Identifier[] | unit {
const functionId = AST.getFunctionId(node);
if (functionId != null) {
return functionId;
Expand All @@ -34,5 +34,5 @@ export function getFunctionComponentId(
) {
return parent.parent.parent.id;
}
return _;
return unit;
}
6 changes: 3 additions & 3 deletions packages/core/src/component/component-name.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as AST from "@eslint-react/ast";
import type { RuleContext } from "@eslint-react/kit";
import type { TSESTree } from "@typescript-eslint/types";
import { _ } from "@eslint-react/eff";
import { unit } from "@eslint-react/eff";
import { RegExp as RE } from "@eslint-react/kit";

import { getFunctionComponentId } from "./component-id";
Expand All @@ -14,8 +14,8 @@ export function isComponentNameLoose(name: string) {
return RE.COMPONENT_NAME_LOOSE.test(name);
}

export function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | _) {
if (id == null) return _;
export function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | unit) {
if (id == null) return unit;
return Array.isArray(id)
? id.map((n) => n.name).join(".")
: id.name;
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/component/component-semantic-node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as AST from "@eslint-react/ast";
import type { _ } from "@eslint-react/eff";
import type { unit } from "@eslint-react/eff";
import type { TSESTree } from "@typescript-eslint/types";

import type { SemanticNode } from "../semantic";
Expand All @@ -9,33 +9,33 @@ import type { ComponentFlag } from "./component-flag";
/* eslint-disable perfectionist/sort-interfaces */
export interface FunctionComponent extends SemanticNode {
id:
| _
| unit
| TSESTree.Identifier
| TSESTree.Identifier[];
kind: "function";
node: AST.TSESTreeFunction;
flag: ComponentFlag;
hint: ComponentDetectionHint;
initPath:
| _
| unit
| AST.FunctionInitPath;
hookCalls: TSESTree.CallExpression[];
displayName:
| _
| unit
| TSESTree.Expression;
}

export interface ClassComponent extends SemanticNode {
id:
| _
| unit
| TSESTree.Identifier;
kind: "class";
node: AST.TSESTreeClass;
flag: ComponentFlag;
hint: ComponentDetectionHint;
methods: AST.TSESTreeMethodOrProperty[];
displayName:
| _
| unit
| TSESTree.Expression;
}
/* eslint-enable perfectionist/sort-interfaces */
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/hook/hook-hierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { _ } from "@eslint-react/eff";
import type { unit } from "@eslint-react/eff";
import type { TSESTree } from "@typescript-eslint/types";
import * as AST from "@eslint-react/ast";
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
import { isUseEffectCallLoose } from "./hook-is";

export function isFunctionOfUseEffectSetup(node: TSESTree.Node | _) {
export function isFunctionOfUseEffectSetup(node: TSESTree.Node | unit) {
if (node == null) return false;
return node.parent?.type === T.CallExpression
&& node.parent.callee !== node
Expand All @@ -13,7 +13,7 @@ export function isFunctionOfUseEffectSetup(node: TSESTree.Node | _) {
&& isUseEffectCallLoose(node.parent);
}

export function isFunctionOfUseEffectCleanup(node: TSESTree.Node | _) {
export function isFunctionOfUseEffectCleanup(node: TSESTree.Node | unit) {
if (node == null) return false;
const pReturn = AST.findParentNode(node, AST.is(T.ReturnStatement));
const pFunction = AST.findParentNode(node, AST.isFunction); // Correctly named variable
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/hook/hook-is.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { _ } from "@eslint-react/eff";
import type { unit } from "@eslint-react/eff";
import type { RuleContext } from "@eslint-react/kit";
import type { TSESTree } from "@typescript-eslint/types";
import * as AST from "@eslint-react/ast";
Expand All @@ -9,7 +9,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
import { isInitializedFromReact } from "../utils";
import { isReactHookName } from "./hook-name";

export function isReactHook(node: AST.TSESTreeFunction | _) {
export function isReactHook(node: AST.TSESTreeFunction | unit) {
if (node == null) return false;
const id = AST.getFunctionId(node);
return id?.name != null && isReactHookName(id.name);
Expand All @@ -20,7 +20,7 @@ export function isReactHook(node: AST.TSESTreeFunction | _) {
* @param node The node to check.
* @returns `true` if the node is a React Hook call, `false` otherwise.
*/
export function isReactHookCall(node: TSESTree.Node | _) {
export function isReactHookCall(node: TSESTree.Node | unit) {
if (node == null) return false;
if (node.type !== T.CallExpression) {
return false;
Expand All @@ -35,7 +35,7 @@ export function isReactHookCall(node: TSESTree.Node | _) {
}

/* eslint-disable function/function-return-boolean */
export function isReactHookCallWithName(context: RuleContext, node: TSESTree.Node | _) {
export function isReactHookCallWithName(context: RuleContext, node: TSESTree.Node | unit) {
if (node == null || node.type !== T.CallExpression) return constFalse;
const {
importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource,
Expand All @@ -58,7 +58,7 @@ export function isReactHookCallWithName(context: RuleContext, node: TSESTree.Nod
};
}

export function isReactHookCallWithNameLoose(node: TSESTree.Node | _) {
export function isReactHookCallWithNameLoose(node: TSESTree.Node | unit) {
if (node == null || node.type !== T.CallExpression) return constFalse;
return (name: string) => {
switch (node.callee.type) {
Expand All @@ -72,7 +72,7 @@ export function isReactHookCallWithNameLoose(node: TSESTree.Node | _) {
};
}

export function isReactHookCallWithNameAlias(context: RuleContext, name: string, alias: _ | string[] = []) {
export function isReactHookCallWithNameAlias(context: RuleContext, name: string, alias: unit | string[] = []) {
const {
importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource,
skipImportCheck = true,
Expand All @@ -95,7 +95,7 @@ export function isReactHookCallWithNameAlias(context: RuleContext, name: string,
}
/* eslint-enable function/function-return-boolean */

export function isUseEffectCallLoose(node: TSESTree.Node | _) {
export function isUseEffectCallLoose(node: TSESTree.Node | unit) {
if (node == null) return false;
if (node.type !== T.CallExpression) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/hook/hook-semantic-node.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type * as AST from "@eslint-react/ast";
import type { _ } from "@eslint-react/eff";
import type { unit } from "@eslint-react/eff";
import type { TSESTree } from "@typescript-eslint/types";

import type { SemanticNode } from "../semantic";

/* eslint-disable perfectionist/sort-interfaces */
export interface Hook extends SemanticNode {
// The identifier of the hook
id: TSESTree.Identifier | _;
id: TSESTree.Identifier | unit;
// The AST node of the hook
node: AST.TSESTreeFunction;
// The name of the hook
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/jsx/jsx-attribute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { _ } from "@eslint-react/eff";
import type { unit } from "@eslint-react/eff";
import type { RuleContext } from "@eslint-react/kit";
import type { Scope } from "@typescript-eslint/scope-manager";
import type { TSESTree } from "@typescript-eslint/utils";
Expand All @@ -20,7 +20,7 @@ export function getAttribute(
name: string,
attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[],
initialScope?: Scope,
): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | _ {
): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | unit {
return attributes.findLast((attr) => {
if (attr.type === T.JSXAttribute) {
return getAttributeName(context, attr) === name;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/jsx/jsx-detection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
import type { _ } from "@eslint-react/eff";
import type { unit } from "@eslint-react/eff";
import type { Scope } from "@typescript-eslint/scope-manager";
import type { TSESTree } from "@typescript-eslint/utils";
import * as AST from "@eslint-react/ast";
Expand All @@ -12,7 +12,7 @@ import { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint } from "./jsx-detection-hi
* @param node The AST node to check
* @returns `true` if the node is a `JSXText` or a `Literal` node
*/
export function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal {
export function isJsxText(node: TSESTree.Node | null | unit): node is TSESTree.JSXText | TSESTree.Literal {
if (node == null) return false;
return node.type === T.JSXText || node.type === T.Literal;
}
Expand All @@ -27,7 +27,7 @@ export function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXT
*/
export function isJsxLike(
code: { getScope: (node: TSESTree.Node) => Scope },
node: TSESTree.Node | _ | null,
node: TSESTree.Node | unit | null,
hint: JSXDetectionHint = DEFAULT_JSX_DETECTION_HINT,
): boolean {
if (node == null) return false;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/jsx/jsx-hierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { _ } from "@eslint-react/eff";
import type { unit } from "@eslint-react/eff";
import type { TSESTree } from "@typescript-eslint/types";
import * as AST from "@eslint-react/ast";
import { constTrue } from "@eslint-react/eff";
Expand All @@ -13,7 +13,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
export function findParentAttribute(
node: TSESTree.Node,
test: (node: TSESTree.JSXAttribute) => boolean = constTrue,
): TSESTree.JSXAttribute | _ {
): TSESTree.JSXAttribute | unit {
const guard = (node: TSESTree.Node): node is TSESTree.JSXAttribute => {
return node.type === T.JSXAttribute && test(node);
};
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/jsx/jsx-is.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { _ } from "@eslint-react/eff";
import type { unit } from "@eslint-react/eff";
import type { RuleContext } from "@eslint-react/kit";
import type { Scope } from "@typescript-eslint/scope-manager";
import type { TSESTree } from "@typescript-eslint/types";
Expand All @@ -19,17 +19,17 @@ export function isKeyedElement(context: RuleContext, node: TSESTree.Node, initia

export function isFragmentElement(
context: RuleContext,
node: TSESTree.Node | null | _,
node: TSESTree.Node | null | unit,
allowJSXFragment?: false,
): node is TSESTree.JSXElement;
export function isFragmentElement(
context: RuleContext,
node: TSESTree.Node | null | _,
node: TSESTree.Node | null | unit,
allowJSXFragment?: true,
): node is TSESTree.JSXElement | TSESTree.JSXFragment;
export function isFragmentElement(
context: RuleContext,
node: TSESTree.Node | null | _,
node: TSESTree.Node | null | unit,
allowJSXFragment = false,
): node is TSESTree.JSXElement | TSESTree.JSXFragment {
if (node == null) return false;
Expand Down
Loading
Loading