-
Notifications
You must be signed in to change notification settings - Fork 118
/
eslint.config.mjs
161 lines (153 loc) · 5.8 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
import eslint from '@eslint/js';
import eslintPluginImport from 'eslint-plugin-import';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import eslintPluginReact from 'eslint-plugin-react';
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
import eslintPluginPlaywright from 'eslint-plugin-playwright';
import eslintPluginTestingLibrary from 'eslint-plugin-testing-library';
import eslintPluginJestDom from 'eslint-plugin-jest-dom';
import eslintPluginJsxA11y from 'eslint-plugin-jsx-a11y';
import eslintPluginVitest from '@vitest/eslint-plugin';
// eslint-disable-next-line import/no-unresolved
import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
eslintPluginImport.flatConfigs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
// Uncomment once released - https://github.com/facebook/react/pull/30774
// eslintPluginReactHooks.configs.recommended,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
eslintPluginJsxA11y.flatConfigs.recommended,
eslintPluginReact.configs.flat.recommended,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
eslintPluginTestingLibrary.configs['flat/react'],
eslintPluginVitest.configs.recommended,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
eslintPluginJestDom.configs['flat/recommended'],
eslintPluginPlaywright.configs['flat/recommended'],
eslintPluginPrettierRecommended,
eslintConfigPrettier,
// https://eslint.org/docs/latest/use/configure/configuration-files#excluding-files-with-ignores
// When in their own config block without files, it tells ESLint to ignore those files.
// When in a config block with files, it stops that specific config block from affecting those ignored files.
{
ignores: [
'!.*',
'**/*.css',
'dist',
'node_modules',
'test-e2e-report',
'test-e2e-results',
'test-unit-report',
'eslint.config.mjs',
],
},
{
languageOptions: {
parserOptions: {
projectService: true,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
tsconfigRootDir: import.meta.name,
},
},
settings: {
'import/resolver': {
typescript: { project: './tsconfigs/tsconfig.dev.json' },
},
react: { version: 'detect' },
},
},
{
files: ['**/*.{js,ts,tsx}'],
plugins: {
// Remove once released - https://github.com/facebook/react/pull/30774
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'react-hooks': eslintPluginReactHooks,
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
rules: {
// Remove once released - https://github.com/facebook/react/pull/30774
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...eslintPluginReactHooks.configs.recommended.rules,
'prefer-template': 'error',
'no-nested-ternary': 'error',
'no-unneeded-ternary': 'error',
'spaced-comment': 'error',
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true }],
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'typeAlias',
format: ['PascalCase'],
},
{
// Generic type parameter must start with letter T, followed by any uppercase letter.
selector: 'typeParameter',
format: ['PascalCase'],
custom: { regex: '^T[A-Z]', match: true },
},
],
'import/no-default-export': 'error',
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'vitest/valid-title': [
'error',
{
mustMatch: {
it: [/should.*when/u.source, "Test title must include 'should' and 'when'"],
},
},
],
'playwright/valid-title': [
'error',
{
mustMatch: {
test: [/should.*when/u.source, "Test title must include 'should' and 'when'"],
},
},
],
},
},
{
files: ['stories/**/*.demozap.*', '**/*.stories.*'],
rules: {
'import/no-default-export': 'off',
},
},
{
files: ['**/*.spec.*', 'e2e/global.setup.ts'],
rules: {
// Turn off (ideally all the rules) from eslint-plugin-testing-library plugin, since it's not applicable for Playwright tests.
// 'testing-library/*': 'off',
'testing-library/prefer-screen-queries': 'off',
},
},
{
files: ['**/*.test.*'],
rules: {
// Turn off all the rules from eslint-plugin-playwright plugin, since it's not applicable for Vitest tests.
// 'playwright/*': 'off',
'playwright/missing-playwright-await': 'off',
'playwright/no-standalone-expect': 'off',
},
},
);