Skip to content

Commit d31db5b

Browse files
authored
style: update code style to follow 'curly' and 'curly-newline' (#909)
1 parent 6f563be commit d31db5b

File tree

124 files changed

+1347
-570
lines changed

Some content is hidden

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

124 files changed

+1347
-570
lines changed

eslint.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import url from "node:url";
33

44
import eslintJs from "@eslint/js";
55
import eslintMarkdown from "@eslint/markdown";
6+
import eslintStylistic from "@stylistic/eslint-plugin";
67
import eslintPluginImport from "eslint-plugin-import-x";
78
import eslintPluginJsdoc from "eslint-plugin-jsdoc";
89
import eslintPluginLocal from "@workspace/eslint-plugin-local";
@@ -128,6 +129,7 @@ export default tseslint.config(
128129
},
129130
},
130131
plugins: {
132+
["@stylistic"]: eslintStylistic,
131133
["@susisu/safe-typescript"]: eslintPluginSafeTypeScript,
132134
["local"]: eslintPluginLocal,
133135
["simple-import-sort"]: eslintPluginSimpleImportSort,
@@ -137,6 +139,7 @@ export default tseslint.config(
137139
{
138140
files: [...GLOB_JS, ...GLOB_TS],
139141
rules: {
142+
curly: "warn",
140143
eqeqeq: ["error", "always"],
141144
"no-console": "error",
142145
"no-else-return": "error",
@@ -195,6 +198,8 @@ export default tseslint.config(
195198
// Part: simple-import-sort rules
196199
"simple-import-sort/exports": "warn",
197200
"simple-import-sort/imports": "warn",
201+
// Part: stylistic rules
202+
"@stylistic/curly-newline": ["warn", "always"],
198203
// Part: perfectionist rules
199204
"perfectionist/sort-exports": "off",
200205
"perfectionist/sort-imports": "off",

examples/dual-react-dom-lib/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@examples/dual-react-dom-lib",
33
"version": "0.0.0",
44
"license": "MIT",
5+
"sideEffects": false,
56
"exports": {
67
".": {
78
"import": {
@@ -16,6 +17,7 @@
1617
"./package.json": "./package.json"
1718
},
1819
"main": "dist/index.js",
20+
"module": "dist/index.mjs",
1921
"types": "dist/index.d.ts",
2022
"files": [
2123
"dist",
@@ -29,7 +31,7 @@
2931
"prepare": "pnpm run build"
3032
},
3133
"devDependencies": {
32-
"@eslint-react/eslint-plugin": "^1.23.1",
34+
"@eslint-react/eslint-plugin": "^1.23.2",
3335
"@eslint/js": "^9.17.0",
3436
"@tsconfig/node22": "^22.0.0",
3537
"@tsconfig/strictest": "^2.0.5",
@@ -46,10 +48,8 @@
4648
"peerDependencies": {
4749
"react": "^19.0.0"
4850
},
51+
"packageManager": "[email protected]",
4952
"engines": {
5053
"node": ">=18.18.0"
51-
},
52-
"sideEffects": false,
53-
"module": "dist/index.mjs",
54-
"packageManager": "[email protected]"
54+
}
5555
}

examples/next-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"react-dom": "latest"
1717
},
1818
"devDependencies": {
19-
"@eslint-react/eslint-plugin": "^1.23.1",
19+
"@eslint-react/eslint-plugin": "^1.23.2",
2020
"@eslint/config-inspector": "^0.7.0",
2121
"@eslint/js": "^9.17.0",
2222
"@next/eslint-plugin-next": "^15.1.3",

examples/vite-react-dom-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"react-dom": "^19.0.0"
1616
},
1717
"devDependencies": {
18-
"@eslint-react/eslint-plugin": "^1.23.1",
18+
"@eslint-react/eslint-plugin": "^1.23.2",
1919
"@eslint/config-inspector": "^0.7.0",
2020
"@eslint/js": "^9.17.0",
2121
"@tsconfig/node22": "^22.0.0",

examples/vite-react-dom-js-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"react-dom": "^19.0.0"
1616
},
1717
"devDependencies": {
18-
"@eslint-react/eslint-plugin": "^1.23.1",
18+
"@eslint-react/eslint-plugin": "^1.23.2",
1919
"@eslint/config-inspector": "^0.7.0",
2020
"@eslint/js": "^9.17.0",
2121
"@types/react": "^19.0.3",

examples/vite-react-dom-js-with-babel-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@babel/eslint-parser": "^7.25.9",
2020
"@babel/preset-env": "^7.26.0",
2121
"@babel/preset-react": "^7.26.3",
22-
"@eslint-react/eslint-plugin": "^1.23.1",
22+
"@eslint-react/eslint-plugin": "^1.23.2",
2323
"@eslint/config-inspector": "^0.7.0",
2424
"@eslint/js": "^9.17.0",
2525
"@types/babel__core": "~7.20.5",

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"license": "MIT",
1515
"author": "Eva1ent<[email protected]>",
16+
"sideEffects": false,
1617
"exports": {
1718
".": {
1819
"import": {
@@ -27,6 +28,7 @@
2728
"./package.json": "./package.json"
2829
},
2930
"main": "dist/index.js",
31+
"module": "dist/index.mjs",
3032
"types": "dist/index.d.ts",
3133
"files": [
3234
"dist",
@@ -59,7 +61,5 @@
5961
"engines": {
6062
"bun": ">=1.0.15",
6163
"node": ">=18.18.0"
62-
},
63-
"sideEffects": false,
64-
"module": "dist/index.mjs"
64+
}
6565
}

packages/core/src/component/component-collector-legacy.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import { ERClassComponentFlag } from "./component-flag";
1414
* @returns `true` if the node is a class component, `false` otherwise
1515
*/
1616
export function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClass {
17-
if (!("superClass" in node && node.superClass)) return false;
17+
if (!("superClass" in node && node.superClass)) {
18+
return false;
19+
}
1820
const { superClass } = node;
1921
return match(superClass)
2022
.with({
@@ -87,7 +89,9 @@ export function useComponentCollectorLegacy() {
8789
} as const;
8890

8991
const collect = (node: AST.TSESTreeClass) => {
90-
if (!isClassComponent(node)) return;
92+
if (!isClassComponent(node)) {
93+
return;
94+
}
9195
const id = AST.getClassIdentifier(node);
9296
const key = getId();
9397
const flag = isPureComponent(node)

packages/core/src/component/component-collector.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export function useComponentCollector(
7979
};
8080
const onFunctionExit = () => {
8181
const { key, node, isComponent } = functionEntries.at(-1) ?? {};
82-
if (!key || !node || !isComponent) return functionEntries.pop();
82+
if (!key || !node || !isComponent) {
83+
return functionEntries.pop();
84+
}
8385
const shouldDrop = AST.getNestedReturnStatements(node.body)
8486
.slice()
8587
.reverse()
@@ -88,7 +90,9 @@ export function useComponentCollector(
8890
&& r.argument !== null
8991
&& !JSX.isJSXValue(r.argument, jsxCtx, hint);
9092
});
91-
if (shouldDrop) components.delete(key);
93+
if (shouldDrop) {
94+
components.delete(key);
95+
}
9296
return functionEntries.pop();
9397
};
9498

@@ -107,13 +111,17 @@ export function useComponentCollector(
107111
":function[type]:exit": onFunctionExit,
108112
"ArrowFunctionExpression[type][body.type!='BlockStatement']"() {
109113
const mbEntry = getCurrentFunction();
110-
if (O.isNone(mbEntry)) return;
114+
if (O.isNone(mbEntry)) {
115+
return;
116+
}
111117
const entry = mbEntry.value;
112118
const { body } = entry.node;
113119
const isComponent = hasNoneOrValidComponentName(entry.node, context)
114120
&& JSX.isJSXValue(body, jsxCtx, hint)
115121
&& hasValidHierarchy(entry.node, context, hint);
116-
if (!isComponent) return;
122+
if (!isComponent) {
123+
return;
124+
}
117125
const initPath = AST.getFunctionInitPath(entry.node);
118126
const id = getFunctionComponentIdentifier(entry.node, context);
119127
const name = O.flatMapNullable(id, getComponentNameFromIdentifier);
@@ -138,33 +146,45 @@ export function useComponentCollector(
138146
const mbComponentName = match(left.object)
139147
.with({ type: T.Identifier }, n => O.some(n.name))
140148
.otherwise(O.none);
141-
if (O.isNone(mbComponentName)) return;
149+
if (O.isNone(mbComponentName)) {
150+
return;
151+
}
142152
const componentName = mbComponentName.value;
143153
const component = Array
144154
.from(components.values())
145155
.findLast(({ name }) => O.exists(name, n => n === componentName));
146-
if (!component) return;
156+
if (!component) {
157+
return;
158+
}
147159
components.set(component._, {
148160
...component,
149161
displayName: O.some(right),
150162
});
151163
},
152164
"CallExpression[type]:exit"(node: TSESTree.CallExpression) {
153-
if (!isReactHookCall(node)) return;
165+
if (!isReactHookCall(node)) {
166+
return;
167+
}
154168
const mbEntry = getCurrentFunction();
155-
if (O.isNone(mbEntry)) return;
169+
if (O.isNone(mbEntry)) {
170+
return;
171+
}
156172
const entry = mbEntry.value;
157173
functionEntries.pop();
158174
functionEntries.push({ ...entry, hookCalls: [...entry.hookCalls, node] });
159175
},
160176
"ReturnStatement[type]"(node: TSESTree.ReturnStatement) {
161177
const mbEntry = getCurrentFunction();
162-
if (O.isNone(mbEntry)) return;
178+
if (O.isNone(mbEntry)) {
179+
return;
180+
}
163181
const entry = mbEntry.value;
164182
const isComponent = hasNoneOrValidComponentName(entry.node, context)
165183
&& JSX.isJSXValue(node.argument, jsxCtx, hint)
166184
&& hasValidHierarchy(entry.node, context, hint);
167-
if (!isComponent) return;
185+
if (!isComponent) {
186+
return;
187+
}
168188
functionEntries.pop();
169189
functionEntries.push({ ...entry, isComponent });
170190
const initPath = AST.getFunctionInitPath(entry.node);

packages/core/src/component/component-id.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { isReactHookCallWithNameLoose } from "../hook";
88
import { isForwardRefCall, isMemoCall } from "../utils";
99

1010
function isComponentWrapperCall(node: TSESTree.Node, context: RuleContext) {
11-
if (node.type !== T.CallExpression) return false;
11+
if (node.type !== T.CallExpression) {
12+
return false;
13+
}
1214
return isMemoCall(node, context)
1315
|| isForwardRefCall(node, context)
1416
|| isReactHookCallWithNameLoose(node)("useCallback");
@@ -19,7 +21,9 @@ export function getFunctionComponentIdentifier(
1921
context: RuleContext,
2022
): O.Option<TSESTree.Identifier | TSESTree.Identifier[]> {
2123
const functionId = AST.getFunctionIdentifier(node);
22-
if (O.isSome(functionId)) return functionId;
24+
if (O.isSome(functionId)) {
25+
return functionId;
26+
}
2327
const { parent } = node;
2428
// Get function component identifier from `const Component = memo(() => {});`
2529
if (

0 commit comments

Comments
 (0)