|
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 |
9 | 2 |
|
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"; |
17 | 5 |
|
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 | + }, |
28 | 28 | { |
29 | 29 | plugins: { |
30 | | - react: fixupPluginRules(react), |
31 | | - "@typescript-eslint": fixupPluginRules(typescriptEslint), |
| 30 | + "react-compiler": pluginReactCompiler, |
32 | 31 | }, |
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], |
44 | 34 | }, |
45 | | - |
| 35 | + }, |
| 36 | + { |
46 | 37 | settings: { |
47 | 38 | react: { |
48 | 39 | version: "detect", |
49 | 40 | }, |
50 | 41 | }, |
51 | | - |
52 | 42 | 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", |
57 | 51 | { |
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", |
59 | 60 | }, |
60 | 61 | ], |
61 | | - |
62 | | - "no-constant-condition": "off", |
63 | | - |
64 | 62 | "no-restricted-imports": [ |
65 | 63 | "warn", |
66 | 64 | { |
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 | + ], |
68 | 84 | }, |
69 | 85 | ], |
70 | 86 |
|
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, |
72 | 119 | }, |
73 | 120 | }, |
74 | | -]; |
| 121 | +); |
0 commit comments