-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.mjs
182 lines (170 loc) · 5.99 KB
/
eslint.config.mjs
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import importConfig from "eslint-plugin-import";
import importAlias from "eslint-plugin-import-alias";
import prettier from "eslint-plugin-prettier/recommended";
import react from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import next from "@next/eslint-plugin-next";
import ts from "typescript-eslint";
import testingLibrary from "eslint-plugin-testing-library";
import jestDom from "eslint-plugin-jest-dom";
import globals from "globals";
const flatCompat = new FlatCompat();
const addNameToEachConfig = (name, configs) =>
configs.map((conf) => ({
...conf,
name: [conf.name, name].filter(Boolean).join("-"),
}));
const reactFix = addNameToEachConfig("react", fixupConfigRules(flatCompat.config(react.configs.recommended)));
const reactHooksFix = addNameToEachConfig(
"react-hook",
fixupConfigRules(flatCompat.config(reactHooks.configs.recommended)),
);
const importFix = addNameToEachConfig("imports", fixupConfigRules(flatCompat.config(importConfig.configs.recommended)));
const nextCoreWebVitalsFix = addNameToEachConfig(
"next-core-web-vitals",
fixupConfigRules(flatCompat.config(next.configs[("core-web-vitals", "recommended")])),
);
const tsConfig = addNameToEachConfig(
"typescript-custom",
ts.config(ts.configs.eslintRecommended, ...ts.configs.recommendedTypeChecked, {
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parser: ts.parser,
parserOptions: {
project: "./tsconfig.json",
ecmaVersion: "latest",
sourceType: "module",
},
},
rules: {
"@typescript-eslint/no-shadow": ["error"],
"no-shadow": "off",
"@typescript-eslint/array-type": "warn",
},
}),
);
const testingLibraryConfig = addNameToEachConfig(
"testing-library",
fixupConfigRules(flatCompat.config(testingLibrary.configs.react)),
);
const jestDomConfig = addNameToEachConfig("jest-dom", fixupConfigRules(flatCompat.config(jestDom.configs.recommended)));
export default [
{
name: "files-ignore",
ignores: [
"lib/**",
"scripts/**",
".yarn/**",
".next/**",
"coverage/**",
"__tests__/**",
"**/*pnp*",
"**/*.d.ts",
"**/*.test.ts(x)?",
"**/*.config.js",
"*.config.mjs",
".prettierrc.cjs",
],
},
...reactFix,
...reactHooksFix,
...importFix,
...tsConfig,
...nextCoreWebVitalsFix,
...testingLibraryConfig,
...jestDomConfig,
{ ...prettier, name: "prettier" },
{
name: "global-custom",
languageOptions: {
parser: ts.parser,
parserOptions: {
ecmaFeatures: { jsx: true },
project: "./tsconfig.json",
tsconfigRootDir: "./",
},
ecmaVersion: "latest",
sourceType: "module",
globals: {
// Add browser and node globals
...Object.fromEntries(Object.entries(globals.browser).map(([key, value]) => [key, "readonly"])),
...Object.fromEntries(Object.entries(globals.node).map(([key, value]) => [key, "readonly"])),
},
},
plugins: {
"import-alias": fixupPluginRules(importAlias),
import: fixupPluginRules(importConfig),
},
rules: {
"array-callback-return": "warn",
"capitalized-comments": ["error", "always", { line: { ignoreConsecutiveComments: true } }],
"default-param-last": "error",
"max-lines": ["error", { max: 250, skipBlankLines: true, skipComments: true }],
"no-console": ["error", { allow: ["warn", "error"] }],
"no-multi-assign": "error",
"no-multi-spaces": "error",
"no-negated-condition": "off",
"no-nested-ternary": "off",
"no-prototype-builtins": "warn",
"no-restricted-imports": "warn",
"object-shorthand": "warn",
"one-var": ["error", "never"],
"prefer-destructuring": "error",
"prefer-object-spread": "warn",
// React - rules from `eslint-plugin-react`
"react/jsx-filename-extension": ["error", { extensions: [".tsx", ".jsx"] }],
"react/react-in-jsx-scope": "off",
"react/jsx-boolean-value": "warn",
"react/jsx-closing-tag-location": "error",
"react/jsx-curly-spacing": "error",
"react/jsx-pascal-case": "error",
"react/jsx-tag-spacing": "error",
"react/jsx-wrap-multilines": "warn",
"react/no-array-index-key": "warn",
"react/no-multi-comp": ["error", { ignoreStateless: true }],
"react/no-unescaped-entities": "off",
"react/prop-types": "off",
"react/style-prop-object": "off",
// Import
"import/prefer-default-export": "off",
"import/extensions": ["error", "never", { svg: "always", json: "always" }],
"import/order": ["error", { "newlines-between": "always" }],
"import/no-extraneous-dependencies": "off",
// Import alias
"import-alias/import-alias": [
"error",
{
relativeDepth: 2,
aliases: [
{ alias: "ZC", matcher: "./components/" },
{ alias: "ZL", matcher: "./lib/" },
{ alias: "ZP", matcher: "./public/" },
{ alias: "ZT", matcher: "./types/" },
{ alias: "ZU", matcher: "./utils/" },
],
},
],
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": ["error", { allow: ["functions", "arrowFunctions", "methods"] }],
"@typescript-eslint/no-unsafe-return": "warn",
},
settings: {
"import/resolver": {
node: { extensions: [".js", ".jsx", ".ts", ".tsx"] },
typescript: {},
},
"import/extensions": [".js", ".jsx", ".ts", ".tsx"],
"import/parsers": {
// TODO: Handle this once eslint-plugin-import properly supports v9 & flat config
// Using espree as a fix as per: https://github.com/import-js/eslint-plugin-import/issues/2556#issuecomment-2272395246
espree: [".js", ".cjs", ".mjs", ".jsx"],
"@typescript-eslint/parser": [".ts", ".tsx"],
},
react: {
version: "detect",
},
},
},
];