Skip to content

Commit feee406

Browse files
committed
Update local function rules
1 parent 3217a74 commit feee406

File tree

12 files changed

+181
-153
lines changed

12 files changed

+181
-153
lines changed

.pkgs/configs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@stylistic/eslint-plugin": "^5.5.0",
2424
"eslint-plugin-de-morgan": "^2.0.0",
2525
"eslint-plugin-function": "^0.0.33",
26-
"eslint-plugin-function-rule": "^0.0.7",
26+
"eslint-plugin-function-rule": "^0.0.9",
2727
"eslint-plugin-jsdoc": "^61.1.12",
2828
"eslint-plugin-perfectionist": "^4.15.1",
2929
"eslint-plugin-regexp": "^2.10.0",

.pkgs/function-rules/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from "./rules/nullishComparison";
1+
export * from "./rules/nullish-comparison";
2+
export * from "./rules/template-expression";

.pkgs/function-rules/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"lint:publish": "publint",
2121
"lint:ts": "tsc --noEmit"
2222
},
23+
"dependencies": {
24+
"eslint-plugin-function-rule": "^0.0.9"
25+
},
2326
"devDependencies": {
2427
"eslint": "^9.39.1",
2528
"tsdown": "^0.16.1"

.pkgs/function-rules/rules/nullishComparison.ts renamed to .pkgs/function-rules/rules/nullish-comparison.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export interface nullishComparisonOptions {
99

1010
// TODO: Implement different enforce options
1111
export function nullishComparison(options?: nullishComparisonOptions) {
12-
return (context: Rule.RuleContext): Rule.RuleListener => {
13-
return defineRuleListener({
12+
return (context: Rule.RuleContext) =>
13+
defineRuleListener({
1414
BinaryExpression(node): void {
1515
if (node.operator === "===" || node.operator === "!==") {
1616
const offendingChild = [node.left, node.right].find(
@@ -65,5 +65,4 @@ export function nullishComparison(options?: nullishComparisonOptions) {
6565
}
6666
},
6767
});
68-
};
6968
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Rule } from "eslint";
2+
import { defineRuleListener } from "eslint-plugin-function-rule";
3+
4+
export interface templateExpressionOptions {
5+
allowMultiline: boolean;
6+
}
7+
8+
export function templateExpression(options?: templateExpressionOptions) {
9+
const allowMultiline = options?.allowMultiline ?? false;
10+
return (context: Rule.RuleContext) =>
11+
defineRuleListener({
12+
TemplateLiteral(node) {
13+
if (!allowMultiline && node.loc?.start.line !== node.loc?.end.line) {
14+
context.report({
15+
node,
16+
message: "Avoid multiline template expressions.",
17+
});
18+
}
19+
},
20+
});
21+
}

eslint.config.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
disableTypeChecked,
1212
strictTypeChecked,
1313
} from "@local/configs/eslint";
14-
import { nullishComparison } from "@local/function-rules";
14+
import { nullishComparison, templateExpression } from "@local/function-rules";
1515
import { recommended as fastImportRecommended } from "eslint-plugin-fast-import";
16-
import functionRule from "eslint-plugin-function-rule";
16+
import { functionRule } from "eslint-plugin-function-rule";
1717
import pluginVitest from "eslint-plugin-vitest";
1818
import { defineConfig, globalIgnores } from "eslint/config";
1919
import tseslint from "typescript-eslint";
@@ -26,8 +26,6 @@ const packagesTsConfigs = [
2626
"packages/*/*/tsconfig.json",
2727
];
2828

29-
const nullishComparisonRule = nullishComparison();
30-
3129
export default defineConfig([
3230
includeIgnoreFile(gitignore, "Imported .gitignore patterns") as never,
3331
globalIgnores([
@@ -55,21 +53,23 @@ export default defineConfig([
5553
},
5654
},
5755
plugins: {
58-
"function-rule": functionRule((context) => ({
59-
...nullishComparisonRule(context),
60-
TemplateLiteral(node) {
61-
if (node.loc?.start.line !== node.loc?.end.line) {
62-
context.report({
63-
node,
64-
message: "Avoid multiline template expressions.",
65-
});
66-
}
67-
},
68-
})),
56+
"nullish-comparison": functionRule("v1", nullishComparison()),
57+
"template-expression": functionRule("v1", templateExpression()),
58+
// "template-expression": functionRule("v1", (context) => ({
59+
// TemplateLiteral(node) {
60+
// if (node.loc?.start.line !== node.loc?.end.line) {
61+
// context.report({
62+
// node,
63+
// message: "Avoid multiline template expressions.",
64+
// });
65+
// }
66+
// },
67+
// })),
6968
},
7069
rules: {
7170
"fast-import/no-unused-exports": "off",
72-
"function-rule/function-rule": "error",
71+
"nullish-comparison/v1": "error",
72+
"template-expression/v1": "warn",
7373
},
7474
},
7575
{
@@ -107,7 +107,8 @@ export default defineConfig([
107107
},
108108
rules: {
109109
"@typescript-eslint/no-empty-function": ["error", { allow: ["arrowFunctions"] }],
110-
"function-rule/function-rule": "off",
110+
"nullish-comparison/v1": "off",
111+
"template-expression/v1": "off",
111112
},
112113
},
113114
disableProblematicEslintJsRules,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"effect": "^3.19.3",
7575
"eslint": "^9.39.1",
7676
"eslint-plugin-fast-import": "^1.5.3",
77-
"eslint-plugin-function-rule": "^0.0.7",
77+
"eslint-plugin-function-rule": "^0.0.9",
7878
"eslint-plugin-vitest": "^0.5.4",
7979
"mdxlint": "^1.0.0",
8080
"publint": "^0.3.15",
@@ -111,7 +111,7 @@
111111
"@eslint/js": "9.39.1",
112112
"@types/react": "^19.2.2",
113113
"@types/react-dom": "^19.2.2",
114-
"esbuild": "^0.26.0",
114+
"esbuild": "^0.27.0",
115115
"eslint": "9.39.1",
116116
"fumadocs-core": "15.8.5",
117117
"fumadocs-docgen": "3.0.2",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function create(context: RuleContext<MessageID, Options>): RuleListener {
7575
}
7676
// Enforce explicit `={true}` for boolean attributes (e.g., `prop={true}` instead of `prop`)
7777
case policy === -1
78-
// eslint-disable-next-line function-rule/function-rule
78+
// eslint-disable-next-line nullish-comparison/v1
7979
&& value === null: {
8080
context.report({
8181
messageId: "jsxShorthandBoolean",

packages/utilities/ast/src/literal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function isLiteral(node: TSESTree.Node, type?: LiteralType) {
2121
case "boolean":
2222
return typeof node.value === "boolean";
2323
case "null":
24-
// eslint-disable-next-line function-rule/function-rule
24+
// eslint-disable-next-line nullish-comparison/v1
2525
return node.value === null;
2626
case "number":
2727
return typeof node.value === "number";

packages/utilities/ast/src/node-format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { delimiterCase, replace, toLowerCase } from "string-ts";
66
import { isJSX } from "./node-is";
77

88
function getLiteralValueType(input: bigint | boolean | null | number | string | symbol) {
9-
// eslint-disable-next-line function-rule/function-rule
9+
// eslint-disable-next-line nullish-comparison/v1
1010
if (input === null) return "null";
1111
return typeof input;
1212
}

0 commit comments

Comments
 (0)