-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheslint.config.js
117 lines (111 loc) · 3.44 KB
/
eslint.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// @ts-check
import { fixupPluginRules } from "@eslint/compat";
// @ts-expect-error Has no valid TS export
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
// @ts-expect-error TS type not correctly exposed
import importPlugin from "eslint-plugin-import";
import prettier from "eslint-plugin-prettier";
import react from "eslint-plugin-react";
// @ts-expect-error Has no valid TS export
import reactCompiler from "eslint-plugin-react-compiler";
import simpleImpSort from "eslint-plugin-simple-import-sort";
import path from "node:path";
import { fileURLToPath } from "node:url";
// eslint-disable-next-line import/no-unresolved
import ts from "typescript-eslint";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({ baseDirectory: __dirname });
/**
* source: https://github.com/import-js/eslint-plugin-import/issues/2948#issuecomment-2148832701
* @param {string} name the pugin name
* @param {string} alias the plugin alias
* @returns {import("eslint").ESLint.Plugin}
*/
function legacyPlugin(name, alias = name) {
const plugin = compat.plugins(name)[0]?.plugins?.[alias];
if (!plugin) {
throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`);
}
return fixupPluginRules(plugin);
}
export default ts.config(
{ ignores: ["node_modules", "dist"] },
{
files: ["**/*.{j,t}s?(x)"],
extends: [
js.configs.recommended,
...ts.configs.recommended,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
react.configs.flat["jsx-runtime"],
],
plugins: {
prettier,
reactCompiler,
"simple-import-sort": simpleImpSort,
// will be eventually replaced by the new eslint-plugin-react-compiler when React 19 gets released
"react-hooks": legacyPlugin("eslint-plugin-react-hooks", "react-hooks"),
},
rules: {
"reactCompiler/react-compiler": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"prettier/prettier": "warn",
"arrow-body-style": ["warn", "as-needed"],
"no-console": "warn",
eqeqeq: ["error", "always"],
"simple-import-sort/imports": [
"warn",
{
groups: [
[
"vitest",
// scss and css file imports
"\\.s?css$",
// side effect (e.g. `import "./foo"`)
"^\\u0000",
// every import starting with "react"
"^react",
// things that start with a letter (or digit or underscore), or `@` followed by a letter
"^@?\\w",
// internal relative paths
"^\\.",
],
],
},
],
"simple-import-sort/exports": "warn",
"no-restricted-imports": [
"error",
{
patterns: ["**/build/*", "**/dist/*"],
},
],
"import/no-duplicates": "warn",
"import/no-commonjs": "warn",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
},
},
{
files: ["**/*.d.ts"],
rules: {
"no-var": "off",
},
},
{
files: ["**/*.test.ts?(x)"],
rules: {
"@typescript-eslint/no-non-null-assertion": "off",
},
},
);