Skip to content

Commit 3211abd

Browse files
committed
refactor: replace returnTrue/returnFalse with constTrue/constFalse for consistency
1 parent 701899b commit 3211abd

File tree

6 files changed

+16
-27
lines changed

6 files changed

+16
-27
lines changed

packages/core/src/hook/is.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as AST from "@eslint-react/ast";
2-
import { _, flip, returnFalse } from "@eslint-react/eff";
2+
import { _, constFalse, flip } from "@eslint-react/eff";
33
import type { RuleContext } from "@eslint-react/shared";
44
import { unsafeDecodeSettings } from "@eslint-react/shared";
55
import type { TSESTree } from "@typescript-eslint/types";
@@ -34,7 +34,7 @@ export function isReactHookCall(node: TSESTree.Node | _) {
3434
}
3535

3636
export function isReactHookCallWithName(node: TSESTree.CallExpression | _, context: RuleContext) {
37-
if (node == null) return returnFalse;
37+
if (node == null) return constFalse;
3838
const settings = unsafeDecodeSettings(context.settings);
3939
const importSource = settings.importSource ?? "react";
4040
const initialScope = context.sourceCode.getScope(node);
@@ -59,7 +59,7 @@ export function isReactHookCallWithName(node: TSESTree.CallExpression | _, conte
5959
}
6060

6161
export function isReactHookCallWithNameLoose(node: TSESTree.CallExpression | _) {
62-
if (node == null) return returnFalse;
62+
if (node == null) return constFalse;
6363
return (name: string) => {
6464
switch (node.callee.type) {
6565
case T.Identifier:

packages/plugins/eslint-plugin-react-hooks-extra/src/utils/is-from-hook-call.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isReactHookCallWithNameAlias } from "@eslint-react/core";
2-
import { returnTrue } from "@eslint-react/eff";
2+
import { constTrue } from "@eslint-react/eff";
33
import type { ESLintReactSettingsNormalized, REACT_BUILD_IN_HOOKS, RuleContext } from "@eslint-react/shared";
44
import * as VAR from "@eslint-react/var";
55
import type { TSESTree } from "@typescript-eslint/types";
@@ -9,7 +9,7 @@ export function isFromHookCall(
99
name: (typeof REACT_BUILD_IN_HOOKS)[number],
1010
context: RuleContext,
1111
settings: ESLintReactSettingsNormalized,
12-
predicate: (topLevelId: TSESTree.Identifier, call: TSESTree.CallExpression) => boolean = returnTrue,
12+
predicate: (topLevelId: TSESTree.Identifier, call: TSESTree.CallExpression) => boolean = constTrue,
1313
) {
1414
const hookAlias = settings.additionalHooks[name] ?? [];
1515
return (topLevelId: TSESTree.Identifier) => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as AST from "@eslint-react/ast";
22
import { useComponentCollector, useComponentCollectorLegacy } from "@eslint-react/core";
33
import type { _ } from "@eslint-react/eff";
4-
import { returnFalse } from "@eslint-react/eff";
4+
import { constFalse } from "@eslint-react/eff";
55
import * as JSX from "@eslint-react/jsx";
66
import type { RuleFeature } from "@eslint-react/shared";
77
import { RE_CONSTANT_CASE, RE_PASCAL_CASE } from "@eslint-react/shared";
@@ -113,7 +113,7 @@ function validate(name: string | _, options: ReturnType<typeof normalizeOptions>
113113
}
114114
return RE_PASCAL_CASE.test(normalized);
115115
})
116-
.otherwise(returnFalse);
116+
.otherwise(constFalse);
117117
}
118118

119119
export default createRule<Options, MessageID>({
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { returnFalse, returnTrue } from "@eslint-react/eff";
1+
import { constFalse, constTrue } from "@eslint-react/eff";
22
import type { TSESTree } from "@typescript-eslint/types";
33
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
44
import { match } from "ts-pattern";
@@ -8,8 +8,8 @@ export function isKeyLiteralLike(
88
property: TSESTree.Node,
99
) {
1010
return match(property)
11-
.with({ type: T.Literal }, returnTrue)
12-
.with({ type: T.TemplateLiteral, expressions: [] }, returnTrue)
11+
.with({ type: T.Literal }, constTrue)
12+
.with({ type: T.TemplateLiteral, expressions: [] }, constTrue)
1313
.with({ type: T.Identifier }, () => !node.computed)
14-
.otherwise(returnFalse);
14+
.otherwise(constFalse);
1515
}

packages/utilities/eff/src/index.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,17 @@ export function identity<T>(x: T): T {
3838
/**
3939
* Do nothing and return void
4040
*/
41-
export function returnVoid(): void {}
41+
export const constVoid = () => {};
4242

4343
/**
4444
* Do nothing and return true
4545
*/
46-
export function returnTrue(): true {
47-
return true;
48-
}
46+
export const constTrue = () => true as const;
4947

5048
/**
5149
* Do nothing and return false
5250
*/
53-
export function returnFalse(): false {
54-
return false;
55-
}
56-
57-
/**
58-
* Do nothing and return undefined
59-
*/
60-
export function returnUndefined(): undefined {
61-
return undefined;
62-
}
51+
export const constFalse = () => false as const;
6352

6453
// Ported from https://github.com/Effect-TS/effect/blob/main/packages/effect/src/Function.ts
6554
/**

packages/utilities/jsx/src/find-parent-attribute.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 type { _ } from "@eslint-react/eff";
3-
import { returnTrue } from "@eslint-react/eff";
3+
import { constTrue } from "@eslint-react/eff";
44
import type { TSESTree } from "@typescript-eslint/types";
55
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
66

@@ -12,7 +12,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
1212
*/
1313
export function findParentAttribute(
1414
node: TSESTree.Node,
15-
test: (node: TSESTree.JSXAttribute) => boolean = returnTrue,
15+
test: (node: TSESTree.JSXAttribute) => boolean = constTrue,
1616
): TSESTree.JSXAttribute | _ {
1717
const guard = (node: TSESTree.Node): node is TSESTree.JSXAttribute => {
1818
return node.type === T.JSXAttribute && test(node);

0 commit comments

Comments
 (0)