Skip to content

Commit d35f90a

Browse files
committed
Add react compiler
1 parent 553bdb2 commit d35f90a

File tree

4 files changed

+174
-52
lines changed

4 files changed

+174
-52
lines changed

eslint.config.mjs

Lines changed: 98 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,121 @@
1-
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
2-
import react from "eslint-plugin-react";
3-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
4-
import tsParser from "@typescript-eslint/parser";
5-
import path from "node:path";
6-
import { fileURLToPath } from "node:url";
7-
import js from "@eslint/js";
8-
import { FlatCompat } from "@eslint/eslintrc";
1+
// @ts-check
92

10-
const __filename = fileURLToPath(import.meta.url);
11-
const __dirname = path.dirname(__filename);
12-
const compat = new FlatCompat({
13-
baseDirectory: __dirname,
14-
recommendedConfig: js.configs.recommended,
15-
allConfig: js.configs.all,
16-
});
3+
import eslint from "@eslint/js";
4+
import eslintConfigPrettier from "eslint-config-prettier";
175

18-
export default [
19-
...fixupConfigRules(
20-
compat.extends(
21-
"eslint:recommended",
22-
"plugin:@typescript-eslint/recommended",
23-
"plugin:react/recommended",
24-
"plugin:react-hooks/recommended",
25-
"plugin:prettier/recommended",
26-
),
27-
),
6+
import reactPlugin from "eslint-plugin-react";
7+
import pluginReactCompiler from "eslint-plugin-react-compiler";
8+
import reactHooksPlugin from "eslint-plugin-react-hooks";
9+
import vitestPlugin from "eslint-plugin-vitest";
10+
import tseslint from "typescript-eslint";
11+
12+
import compilerOptions from "./compilerOptions.js";
13+
14+
export default tseslint.config(
15+
eslint.configs.recommended,
16+
...tseslint.configs.recommended,
17+
eslintConfigPrettier,
18+
// @ts-expect-error Malformed types
19+
reactPlugin.configs.flat.recommended,
20+
// @ts-expect-error Malformed types
21+
reactPlugin.configs.flat["jsx-runtime"],
22+
{
23+
// TODO replace with https://github.com/facebook/react/pull/30774
24+
name: "react-hooks/recommended",
25+
plugins: { "react-hooks": reactHooksPlugin },
26+
rules: reactHooksPlugin.configs.recommended.rules,
27+
},
2828
{
2929
plugins: {
30-
react: fixupPluginRules(react),
31-
"@typescript-eslint": fixupPluginRules(typescriptEslint),
30+
"react-compiler": pluginReactCompiler,
3231
},
33-
34-
languageOptions: {
35-
parser: tsParser,
36-
ecmaVersion: 2022,
37-
sourceType: "module",
38-
39-
parserOptions: {
40-
ecmaFeatures: {
41-
jsx: true,
42-
},
43-
},
32+
rules: {
33+
"react-compiler/react-compiler": ["error", compilerOptions],
4434
},
45-
35+
},
36+
{
4637
settings: {
4738
react: {
4839
version: "detect",
4940
},
5041
},
51-
5242
rules: {
53-
"react/react-in-jsx-scope": "off",
54-
55-
"react/no-unknown-property": [
56-
"error",
43+
"no-empty-function": "warn",
44+
"no-nested-ternary": "warn",
45+
"no-unreachable": "warn",
46+
"object-shorthand": "warn",
47+
"linebreak-style": ["warn", "unix"],
48+
eqeqeq: ["warn", "smart"],
49+
"no-console": [
50+
"warn",
5751
{
58-
ignore: ["css"],
52+
allow: ["warn", "error", "info"],
53+
},
54+
],
55+
"no-restricted-syntax": [
56+
"warn",
57+
{
58+
selector: "TSEnumDeclaration",
59+
message: "Don't declare enums",
5960
},
6061
],
61-
62-
"no-constant-condition": "off",
63-
6462
"no-restricted-imports": [
6563
"warn",
6664
{
67-
paths: ["@emotion/styled/macro", "@emotion/react/macro", "lodash"],
65+
paths: [
66+
{
67+
name: "@ionic/react",
68+
importNames: ["IonHeader", "useIonToast"],
69+
message:
70+
"Has an App alternative. Replace 'Ion' with 'App' when importing.",
71+
},
72+
{
73+
name: "react",
74+
importNames: ["forwardRef"],
75+
message: "Please use ref prop directly.",
76+
},
77+
],
78+
patterns: [
79+
{
80+
regex: "\\.\\.\\/\\w+\\/",
81+
message: "Import via absolute path (e.g. #/helpers/myHelper)",
82+
},
83+
],
6884
},
6985
],
7086

71-
"@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "none" }],
87+
"@typescript-eslint/consistent-type-definitions": "error",
88+
"@typescript-eslint/no-empty-object-type": "off",
89+
"@typescript-eslint/no-unused-vars": [
90+
"warn",
91+
{
92+
destructuredArrayIgnorePattern: "^_",
93+
caughtErrorsIgnorePattern: "^_",
94+
},
95+
],
96+
97+
"react/prop-types": "off",
98+
"react/jsx-fragments": ["warn", "syntax"],
99+
"react/jsx-curly-brace-presence": ["warn", "never"],
100+
"react/no-unknown-property": [
101+
"error",
102+
{
103+
ignore: ["css"],
104+
},
105+
],
106+
"react/function-component-definition": [
107+
"error",
108+
{ namedComponents: "function-declaration", unnamedComponents: [] },
109+
],
110+
},
111+
},
112+
{
113+
files: ["**/*.test.ts", "**/*.test.tsx"],
114+
plugins: {
115+
vitest: vitestPlugin,
116+
},
117+
rules: {
118+
...vitestPlugin.configs.recommended.rules,
72119
},
73120
},
74-
];
121+
);

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
"@vitejs/plugin-react": "^4.3.4",
2424
"axios": "^1.7.9",
2525
"axios-retry": "^4.5.0",
26+
"babel-plugin-react-compiler": "19.0.0-beta-55955c9-20241229",
2627
"chroma-js": "^3.1.2",
2728
"date-fns": "^4.1.0",
2829
"date-fns-tz": "^3.2.0",
2930
"detect-browser": "^5.3.0",
3031
"emotion": "^11.0.0",
32+
"eslint-plugin-react-compiler": "19.0.0-beta-55955c9-20241229",
3133
"fast-xml-parser": "^4.5.1",
3234
"geolib": "^3.3.4",
3335
"gsl-parser": "^3.0.1",

pnpm-lock.yaml

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default defineConfig(() => {
1616
react({
1717
jsxImportSource: "@emotion/react",
1818
babel: {
19-
plugins: ["@emotion/babel-plugin"],
19+
plugins: ["babel-plugin-react-compiler", "@emotion/babel-plugin"],
2020
},
2121
}),
2222
svgr(),

0 commit comments

Comments
 (0)