Skip to content

Commit 5b9f867

Browse files
committed
refactor: replace some _ placeholder with null or void
1 parent 05030a7 commit 5b9f867

File tree

17 files changed

+57
-59
lines changed

17 files changed

+57
-59
lines changed

packages/core/src/utils/is-initialized-from-react.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Scope } from "@typescript-eslint/scope-manager";
22
import type { TSESTree } from "@typescript-eslint/types";
33
import * as AST from "@eslint-react/ast";
4-
import { _, identity } from "@eslint-react/eff";
4+
import { identity } from "@eslint-react/eff";
55
import * as VAR from "@eslint-react/var";
66
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
77
import { match, P } from "ts-pattern";
@@ -12,12 +12,12 @@ import { match, P } from "ts-pattern";
1212
* @returns The require expression arguments or undefined if the node is not a require expression
1313
*/
1414
function getRequireExpressionArguments(node: TSESTree.Node) {
15-
return match<typeof node, TSESTree.CallExpressionArgument[] | _>(node)
15+
return match<typeof node, TSESTree.CallExpressionArgument[] | null>(node)
1616
// require("source")
1717
.with({ type: T.CallExpression, arguments: P.select(), callee: { type: T.Identifier, name: "require" } }, identity)
1818
// require("source").variable
1919
.with({ type: T.MemberExpression, object: P.select() }, getRequireExpressionArguments)
20-
.otherwise(() => _);
20+
.otherwise(() => null);
2121
}
2222

2323
/**

packages/plugins/eslint-plugin-react-hooks-extra/src/hooks/use-no-direct-set-state-in-use-effect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
33
import type { Scope } from "@typescript-eslint/utils/ts-eslint";
44
import * as AST from "@eslint-react/ast";
55
import * as ER from "@eslint-react/core";
6-
import { _, getOrUpdate } from "@eslint-react/eff";
6+
import { constVoid, getOrUpdate } from "@eslint-react/eff";
77
import { getSettingsFromContext } from "@eslint-react/shared";
88
import * as VAR from "@eslint-react/var";
99
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
@@ -143,7 +143,7 @@ export function useNoDirectSetStateInUseEffect<Ctx extends RuleContext>(
143143
if (pEntry.node !== setupFunction) return;
144144
indFunctionCalls.push(node);
145145
})
146-
.otherwise(() => _);
146+
.otherwise(constVoid);
147147
},
148148
Identifier(node) {
149149
if (node.parent.type === T.CallExpression && node.parent.callee === node) {

packages/plugins/eslint-plugin-react-hooks-extra/src/rules/no-unnecessary-use-callback.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
8686
const variable = VAR.findVariable(n.name, initialScope);
8787
const variableNode = VAR.getVariableInitNode(variable, 0);
8888
if (variableNode?.type !== T.ArrowFunctionExpression && variableNode?.type !== T.FunctionExpression) {
89-
return _;
89+
return null;
9090
}
9191
return variableNode;
9292
})
93-
.otherwise(() => _);
93+
.otherwise(() => null);
9494
if (arg0Node == null) return;
9595

9696
const arg0NodeScope = context.sourceCode.getScope(arg0Node);

packages/plugins/eslint-plugin-react-hooks-extra/src/rules/no-unnecessary-use-memo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
33
import type { CamelCase } from "string-ts";
44
import * as AST from "@eslint-react/ast";
55
import * as ER from "@eslint-react/core";
6-
import { _, identity } from "@eslint-react/eff";
6+
import { identity } from "@eslint-react/eff";
77
import { getSettingsFromContext } from "@eslint-react/shared";
88
import * as VAR from "@eslint-react/var";
99
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
@@ -91,11 +91,11 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
9191
const variable = VAR.findVariable(n.name, initialScope);
9292
const variableNode = VAR.getVariableInitNode(variable, 0);
9393
if (variableNode?.type !== T.ArrowFunctionExpression && variableNode?.type !== T.FunctionExpression) {
94-
return _;
94+
return null;
9595
}
9696
return variableNode;
9797
})
98-
.otherwise(() => _);
98+
.otherwise(() => null);
9999
if (arg0Node == null) return;
100100

101101
const arg0NodeScope = context.sourceCode.getScope(arg0Node);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
3939
const name = match(id)
4040
.with({ type: T.Identifier, name: P.select() }, identity)
4141
.with({ type: T.MemberExpression, property: { name: P.select(P.string) } }, identity)
42-
.otherwise(() => _);
42+
.otherwise(() => null);
4343
if (name != null && ER.isComponentName(name) && name.endsWith("Context")) return;
4444
context.report({
4545
messageId: "invalid",

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { RuleContext, RuleFeature } from "@eslint-react/kit";
22
import type { TSESTree } from "@typescript-eslint/types";
33
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
44
import * as ER from "@eslint-react/core";
5-
import { _ } from "@eslint-react/eff";
65
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
76
import { snakeCase } from "string-ts";
87
import { match } from "ts-pattern";
@@ -54,7 +53,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
5453
}
5554
const setterName = match(setter)
5655
.with({ type: T.Identifier }, (id) => id.name)
57-
.otherwise(() => _);
56+
.otherwise(() => null);
5857
if (setterName == null || !setterName.startsWith("set")) {
5958
context.report({ messageId: "invalidSetterNaming", node });
6059
return;
@@ -70,7 +69,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
7069
}, []);
7170
return values.join("_");
7271
})
73-
.otherwise(() => _);
72+
.otherwise(() => null);
7473
if (valueName == null || `set_${valueName}` !== snakeCase(setterName)) {
7574
context.report({ messageId: "invalidSetterNaming", node });
7675
return;

packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
277277
.with("abort", () => {
278278
abortedSignals.push(node.callee);
279279
})
280-
.otherwise(() => _);
280+
.otherwise(() => null);
281281
},
282282
["Program:exit"]() {
283283
for (const aEntry of aEntries) {

packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-resize-observer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import type { _ } from "@eslint-react/eff";
12
import type { RuleContext, RuleFeature } from "@eslint-react/kit";
23
import type { TSESTree } from "@typescript-eslint/utils";
34
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
45
import type { ObserverEntry, ObserverMethod } from "../types";
56
import * as AST from "@eslint-react/ast";
67
import * as ER from "@eslint-react/core";
7-
import { _, or } from "@eslint-react/eff";
8+
import { or } from "@eslint-react/eff";
89
import * as VAR from "@eslint-react/var";
910
import { AST_NODE_TYPES as T } from "@typescript-eslint/utils";
1011

@@ -176,7 +177,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
176177
phase: fKind,
177178
});
178179
})
179-
.otherwise(() => _);
180+
.otherwise(() => null);
180181
},
181182
["NewExpression"](node) {
182183
const fEntry = fEntries.findLast((x) => x.kind !== "other");
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type * as AST from "@eslint-react/ast";
22
import * as ER from "@eslint-react/core";
3-
import { _ } from "@eslint-react/eff";
43
import { match } from "ts-pattern";
54

65
export function getPhaseKindOfFunction(node: AST.TSESTreeFunction) {
7-
return match<AST.TSESTreeFunction, ER.ComponentPhaseKind | _>(node)
6+
return match<AST.TSESTreeFunction, ER.ComponentPhaseKind | null>(node)
87
.when(ER.isFunctionOfUseEffectSetup, () => "setup")
98
.when(ER.isFunctionOfUseEffectCleanup, () => "cleanup")
109
.when(ER.isFunctionOfComponentDidMount, () => "mount")
1110
.when(ER.isFunctionOfComponentWillUnmount, () => "unmount")
12-
.otherwise(() => _);
11+
.otherwise(() => null);
1312
}

packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-boolean.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export default createRule<[], MessageID>({
3333
export function create(context: RuleContext<MessageID, []>): RuleListener {
3434
return {
3535
JSXAttribute(node) {
36-
// eslint-disable-next-line local/prefer-eqeq-nullish-comparison
37-
if (node.value === null) {
36+
if (node.value == null) {
3837
context.report({
3938
messageId: "avoidShorthandBoolean",
4039
node,

0 commit comments

Comments
 (0)