-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy patheslint.config.ts
More file actions
221 lines (215 loc) · 6.59 KB
/
eslint.config.ts
File metadata and controls
221 lines (215 loc) · 6.59 KB
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
212
213
214
215
216
217
218
219
220
221
/*
* Wire
* Flat ESLint configuration (ESLint 9+)
*/
import path from 'path';
import {FlatCompat} from '@eslint/eslintrc';
// @ts-ignore - No types available for @emotion/eslint-plugin with ESLint 9
import emotionPlugin from '@emotion/eslint-plugin';
import stylisticPlugin from '@stylistic/eslint-plugin';
import importPlugin from 'eslint-plugin-import';
import tsParser from '@typescript-eslint/parser';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import headerPlugin, { HeaderOptions, HeaderRuleConfig } from '@tony.ganchev/eslint-plugin-header';
import globals from 'globals';
import type {Linter} from 'eslint';
const year = new Date().getFullYear();
const runtimeGlobals = {
...globals.es2020,
...globals.browser,
...globals.node,
};
const compat = new FlatCompat({
baseDirectory: __dirname,
resolvePluginsRelativeTo: __dirname,
});
const ignores = [
'.git/',
'docs/',
'bin/',
'**/node_modules/',
'apps/webapp/assets/',
'resource/',
'apps/webapp/resource/',
'apps/webapp/test/',
'**/__mocks__/**',
'**/setupTests.*',
'**/*.config.*',
'apps/webapp/*.config.*',
'apps/webapp/src/sw.js',
'apps/server/bin/',
'apps/server/dist/',
'apps/server/node_modules/',
'apps/webapp/src/ext/',
'apps/webapp/src/script/localization/**/webapp*.js',
'apps/webapp/src/worker/',
'apps/webapp/src/script/components/Icon.tsx',
'**/*.test.*',
'**/*.spec.*',
'*.js',
'apps/webapp/src/types/i18n.d.ts',
'apps/webapp/playwright-report/',
'libraries/core/lib/',
'libraries/api-client/lib/',
'libraries/core/.tmp/',
'libraries/core/src/test/',
'libraries/config/lib/',
'**/jest.setup.ts',
];
const base = compat.extends('@wireapp/eslint-config');
// Remove 'project' from parserOptions in all base configs to avoid conflict with projectService
const cleanedBase = base.map(cfg => {
if (cfg.languageOptions?.parserOptions) {
const parserOptions = cfg.languageOptions.parserOptions as Record<string, unknown>;
const {project, ...rest} = parserOptions;
return {
...cfg,
languageOptions: {
...cfg.languageOptions,
parserOptions: rest,
},
};
}
return cfg;
});
const config: Linter.Config[] = [
{ignores},
...cleanedBase,
{
// Adjust legacy bits from extended config
rules: {
'no-unsanitized/DOM': 'off', // deprecated config variant; rely on recommended defaults instead
'valid-jsdoc': 'off', // rule removed in ESLint 9
'header/header': 'off', // disable existing header rule to use our own
},
},
{
files: ['**/*.{ts,tsx,js,jsx,cjs,mjs}'],
plugins: {
'@stylistic': stylisticPlugin,
},
rules: {
'@stylistic/eol-last': ['error', 'always'],
},
},
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: tsParser,
parserOptions: {
// Enable type-aware linting for TypeScript sources with project references support
projectService: true,
tsconfigRootDir: __dirname,
},
globals: {
...runtimeGlobals,
React: 'readonly',
JSX: 'readonly',
amplify: 'readonly',
NodeJS: 'readonly',
},
},
// @ts-ignore - Plugin type compatibility issues with ESLint 9 flat config
plugins: {
'@emotion': emotionPlugin,
import: importPlugin,
'react-hooks': reactHooksPlugin,
'header-tony': headerPlugin,
},
rules: {
'@emotion/pkg-renaming': 'error',
'@emotion/no-vanilla': 'error',
'@emotion/import-from-emotion': 'error',
'@emotion/styled-import': 'error',
'header-tony/header': [
'error',
{
header: {
commentType: 'block',
lines: [
'',
' * Wire',
{
pattern: ' \\* Copyright \\(C\\) \\d{4} Wire Swiss GmbH',
template: ` * Copyright (C) ${year} Wire Swiss GmbH`,
},
' *',
' * This program is free software: you can redistribute it and/or modify',
' * it under the terms of the GNU General Public License as published by',
' * the Free Software Foundation, either version 3 of the License, or',
' * (at your option) any later version.',
' *',
' * This program is distributed in the hope that it will be useful,',
' * but WITHOUT ANY WARRANTY; without even the implied warranty of',
' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the',
' * GNU General Public License for more details.',
' *',
' * You should have received a copy of the GNU General Public License',
' * along with this program. If not, see http://www.gnu.org/licenses/.',
' *',
' ',
],
},
trailingEmptyLines: {
minimum: 2,
},
} as HeaderOptions,
] as HeaderRuleConfig,
'id-length': 'warn',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^(_?err(or)?|error)$',
varsIgnorePattern: '^(_?err(or)?|error)$',
},
],
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'error',
'@typescript-eslint/typedef': 'off',
'no-dupe-class-members': 'off',
'no-unsanitized/property': 'off',
'prefer-promise-reject-errors': 'off',
'jest/no-jasmine-globals': 'off',
'jsx-a11y/media-has-caption': 'off',
'no-empty': 'error',
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
},
{
files: ['**/*.js', '**/*.jsx', '**/*.cjs', '**/*.mjs'],
languageOptions: {
parser: require('espree'),
parserOptions: {
project: null,
tsconfigRootDir: __dirname,
},
globals: runtimeGlobals,
},
rules: {
// Disable TS-only rules on JS mocks/shims
'@typescript-eslint/require-array-sort-compare': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['**/*.test.tsx', '**/*.test.ts', '**/*.spec.tsx', '**/*.spec.ts', '**/test/**/*', '**/mocks/**/*'],
rules: {
'no-magic-numbers': 'off',
'id-length': 'off',
},
},
];
export default config;