-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.js
211 lines (203 loc) · 6.17 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import path from "node:path";
import { fileURLToPath } from "node:url";
import { fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
import eslint from "@eslint/js";
import vitest from "@vitest/eslint-plugin";
import _import from "eslint-plugin-import";
import jsxA11Y from "eslint-plugin-jsx-a11y";
import playwright from "eslint-plugin-playwright";
import sortKeysFix from "eslint-plugin-sort-keys-fix";
import unicorn from "eslint-plugin-unicorn";
import unusedImports from "eslint-plugin-unused-imports";
import globals from "globals";
import tseslint from "typescript-eslint";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
...compat.extends(
"plugin:react/recommended",
"plugin:unicorn/recommended",
"prettier",
"plugin:jsx-a11y/recommended",
"plugin:react-hooks/recommended"
),
{
ignores: [
"cdk.out/*",
"server/build/*",
"coverage/*",
"lambdas/**/*.js",
"build/*",
"**/node_modules",
"public/build",
"build",
"**/.idea",
"**/__snapshots__/*",
"**/.cdk.staging",
"**/cdk.out",
"**/postman",
"**/package-lock.json",
"coverage",
"test-results/",
"playwright-report/",
"playwright/.cache/",
"e2e-tests/.auth/",
"eslint.config.js",
"postcss.config.js",
],
},
{
languageOptions: {
globals: {
...globals.jest,
},
},
},
{
plugins: {
"unused-imports": unusedImports,
import: fixupPluginRules(_import),
"jsx-a11y": jsxA11Y,
unicorn,
"sort-keys-fix": sortKeysFix,
// "testing-library": fixupPluginRules({
// rules: testingLibrary.rules,
// }),
// TODO add again package supports eslint 9
},
rules: {
"import/order": [
"warn",
{
"newlines-between": "always",
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
], // auto sort imports
"no-console": [
"error",
{
allow: ["dir", "info", "warn", "error"],
},
], // prevent debugging console.log statements
"max-params": ["warn", 5], // prevent functions with too many parameters
complexity: ["warn", 13], // prevent complex functions
"import/no-unresolved": "off", // IDE is recognizing it already
"unicorn/number-literal-case": "off", // prettier and unicorn collide here.
"react/jsx-uses-react": "error", // necessary to remove unused imports
"react/jsx-uses-vars": "error", // necessary to remove unused imports
"arrow-body-style": ["error", "always"], // always have a return in functions
"unused-imports/no-unused-imports": "error", // necessary to remove unused imports
"testing-library/render-result-naming-convention": "off", // conflicting with args variable from setup function on tests
"@typescript-eslint/require-await": "error", // avoid async functions without await
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_" },
],
"unused-imports/no-unused-vars": [
"warn",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
},
],
"unicorn/prevent-abbreviations": "off", // abbreviations like props or fn are wanted
"unicorn/prefer-ternary": "off", // ternary is not always better
"unicorn/no-useless-undefined": "off", // not working properly
"unicorn/no-null": "off", // not working properly
"unicorn/prefer-module": "off", // __dirname is not working with import.meta.url
"unicorn/consistent-function-scoping": "off", // makes code less readable
"unicorn/no-array-for-each": "off", // performance should only be improved until it causes problems
"unicorn/better-regex": "off", // more efficient regex may be less clear to read
"unicorn/prefer-query-selector": "off", // automatic fix breaks some queries
"unicorn/text-encoding-identifier-case": "off", // it is colliding with TypeScript types
"@typescript-eslint/restrict-template-expressions": "off", // not useful always
quotes: [
"error",
"double",
{
allowTemplateLiterals: false,
},
], // don't allow backticks if it's not a template literal
"react/react-in-jsx-scope": "off", // not necessary on React 18
"testing-library/no-await-sync-events": "off", // userEvents without async are not always working
"jest/no-export": "off", // export necessary for files with dynamic imports for mocks
"unicorn/prefer-node-protocol": "off", // not working with remix
"jest/no-mocks-import": "off", // necessary for prisma client
"playwright/missing-playwright-await": "off", // Rule collides with unit testing
"unicorn/expiring-todo-comments": "off", // Rule has a bug
"unicorn/filename-case": [
"error",
{
case: "kebabCase",
ignore: [
/\.\$[a-z]/, // ignore files with URL variables .$var - they need to be in camelCase for Remix
/_\./, // ignore files _. for remix routes
],
},
],
"@typescript-eslint/prefer-nullish-coalescing": [
"error",
{
ignoreConditionalTests: true,
ignoreMixedLogicalExpressions: true,
},
], // ?? is different from || when the value is 0 or false
},
},
{
files: ["e2e-tests/*"],
plugins: {
playwright,
},
rules: {
"testing-library/prefer-screen-queries": "off", // Playwright is fine with queries outside of screen
"playwright/missing-playwright-await": "warn", // Playwright needs await for some functions
"playwright/no-standalone-expect": "off", // false positives on Playwright setup functions
},
},
{
files: ["src/locales/*"],
rules: {
"sort-keys-fix/sort-keys-fix": "warn", // sort keys in locales
},
},
{
settings: {
react: {
version: "detect", // necessary for eslint-plugin-react
},
},
},
{
files: ["**/*.test.*"],
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
},
}
);