-
Notifications
You must be signed in to change notification settings - Fork 31
/
eslint.config.mjs
194 lines (180 loc) · 5.98 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
183
184
185
186
187
188
189
190
191
192
193
194
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import pluginCypress from 'eslint-plugin-cypress/flat';
import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths';
import preferredImportPath from 'eslint-plugin-preferred-import-path';
import reactPlugin from 'eslint-plugin-react';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import sonarjs from 'eslint-plugin-sonarjs';
import testingLibrary from 'eslint-plugin-testing-library';
import unusedImports from 'eslint-plugin-unused-imports';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
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,
});
// eslint-disable-next-line import/no-default-export
export default tseslint.config(
js.configs.recommended,
...tseslint.configs.recommended,
...fixupConfigRules(
compat.extends(
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:jsx-a11y/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:prettier/recommended',
),
),
{
ignores: [
'**/node_modules',
'**/coverage',
'**/dist',
'**/*.snap',
'src/features/expressions/shared-tests/**/*.json',
'schemas/**/*.json',
'webpack*.js', // FIXME: should this be included?
'.yarn/*',
],
},
{
plugins: {
sonarjs: fixupPluginRules(sonarjs),
'no-relative-import-paths': noRelativeImportPaths,
'preferred-import-path': preferredImportPath,
'simple-import-sort': simpleImportSort,
'unused-imports': unusedImports,
react: fixupPluginRules(reactPlugin),
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.es2020,
window: true,
},
ecmaVersion: 2020,
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
settings: {
'import/extensions': ['.js', '.jsx', '.ts', '.tsx'],
'import/parsers': {
'@typescript-eslint/parser': ['.js', '.cjs', '.mjs', '.jsx', '.ts', '.tsx'],
},
react: {
version: 'detect',
},
},
rules: {
curly: ['error', 'all'],
'object-shorthand': ['error', 'always'],
'arrow-body-style': ['error', 'as-needed'],
'no-dupe-class-members': ['off'],
'no-console': ['warn', { allow: ['warn', 'error'] }],
'no-unused-vars': ['off'],
'prefer-template': ['warn'],
'no-restricted-syntax': [
'error',
{ selector: 'ExportAllDeclaration', message: 'Do not re-exports already exported symbols' },
{
selector: "ExportNamedDeclaration[source.type='Literal']",
message: 'Do not re-exports already exported symbols',
},
],
'jsx-a11y/no-autofocus': ['off'],
'import/no-unresolved': ['off'],
'import/no-default-export': ['error'],
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },
],
'@typescript-eslint/consistent-type-imports': ['warn'],
'unused-imports/no-unused-imports': ['error'],
'react-hooks/exhaustive-deps': ['error', { additionalHooks: '^(useMemoDeepEqual)$' }],
'react/jsx-filename-extension': ['error', { extensions: ['.jsx', '.tsx'] }],
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }],
'react/jsx-fragments': ['error'],
'react/jsx-no-useless-fragment': ['error'],
'react/self-closing-comp': ['error'],
'react/prop-types': ['off'],
'sonarjs/no-duplicate-string': ['off'],
'sonarjs/cognitive-complexity': ['off'],
'sonarjs/no-collapsible-if': ['warn'],
'sonarjs/prefer-single-boolean-return': ['warn'],
'sonarjs/no-identical-functions': ['warn'],
'sonarjs/no-small-switch': ['warn'],
'sonarjs/no-nested-template-literals': ['warn'],
'no-relative-import-paths/no-relative-import-paths': ['warn', { allowSameFolder: false }],
'preferred-import-path/preferred-import-path': ['warn', { '^/src': 'src', '^/test/': 'test/' }],
'simple-import-sort/imports': [
'error',
{
groups: [
['^\\u0000core.js$'],
['^react[^\\u0000]*$', '^react.*\\u0000$'],
['^\\u0000'],
['^@?(?!src/|test/)\\w+[^\\u0000]*$', '^@?(?!src/|test/)\\w+.*\\u0000$'],
['^\\./?[^\\u0000]*$', '^\\./?.*\\u0000$'],
['^test/[^\\u0000]+$', '^test/.*\\u0000$'],
['^src/[^\\u0000]+$', '^src/.*\\u0000$'],
['^.+\\.(s?css|less)$'],
],
},
],
},
},
{
files: ['test/e2e/**/*.ts'],
...pluginCypress.configs.recommended,
},
{
files: ['src/**/*.test.ts', 'src/**/*.test.tsx', 'src/**/test/**/*.ts', 'src/**/test/**/*.tsx'],
plugins: {
'testing-library': fixupPluginRules(testingLibrary),
},
languageOptions: {
globals: {
...globals.jest,
},
},
rules: {
'testing-library/await-async-queries': ['warn'],
'jsx-a11y/label-has-associated-control': ['off'],
},
},
{
files: ['src/layout/*/index.tsx', 'src/layout/LayoutComponent.tsx'],
rules: {
'react-hooks/rules-of-hooks': 'off', // FIXME: Refactor to follow rules and remove this rule
},
},
{
files: ['src/codegen/**/*.ts'],
rules: {
'no-console': 'off',
},
},
{
files: ['src/**/*.generated.{ts,tsx}'],
rules: {
'no-explicit-any': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
);