-
-
Notifications
You must be signed in to change notification settings - Fork 591
Expand file tree
/
Copy patheslint.config.mjs
More file actions
289 lines (277 loc) · 8.25 KB
/
Copy patheslint.config.mjs
File metadata and controls
289 lines (277 loc) · 8.25 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// @ts-check
import eslint from '@eslint/js'
import pluginQuery from '@tanstack/eslint-plugin-query'
import neslint from 'eslint-plugin-n'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import reacteslint from 'eslint-plugin-react'
import hookseslint from 'eslint-plugin-react-hooks'
import reactRefreshEslint from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
export default [
// setup the parser first
{
languageOptions: {
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
...neslint.configs['flat/recommended-script'],
ignores: [...(neslint.configs['flat/recommended-script'].ignores ?? []), 'webui/**/*', 'launcher-ui/**/*'],
},
{
// extends: commonExtends,
plugins: {
'@typescript-eslint': tseslint.plugin,
},
rules: {
// Default rules to be applied everywhere
'prettier/prettier': 'error',
...eslint.configs.recommended.rules,
'no-console': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' },
],
'no-extra-semi': 'off',
'no-useless-assignment': 'off',
'preserve-caught-error': 'off', // Future: Maybe this should be enabled?
// 'n/no-unsupported-features/es-syntax': ['error', { ignores: ['modules'] }],
'no-use-before-define': 'off',
'no-warning-comments': ['error', { terms: ['nocommit', '@nocommit', '@no-commit'] }],
// 'jest/no-mocks-import': 'off',
},
files: ['**/*.ts', '**/*.cts', '**/*.mts', '**/*.tsx'],
},
...tseslint.configs.recommendedTypeChecked,
{
// disable type-aware linting on JS files
files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
...tseslint.configs.disableTypeChecked,
rules: {
...tseslint.configs.disableTypeChecked.rules,
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' },
],
},
},
{
files: ['*.mjs'],
languageOptions: {
sourceType: 'module',
},
},
{
files: ['**/*.tsx', '**/*.ts', '**/*.cts', '**/*.mts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-await': 'off', // conflicts with 'promise-function-async'
'@typescript-eslint/consistent-type-imports': 'error',
'no-duplicate-imports': 'error',
/** Disable some annoyingly strict rules from the 'recommended-requiring-type-checking' pack */
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-argument': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/restrict-template-expressions': 0,
'@typescript-eslint/restrict-plus-operands': 0,
'@typescript-eslint/no-redundant-type-constituents': 0,
'@typescript-eslint/no-this-alias': 0, // Needed for some TRPC routers
/** End 'recommended-requiring-type-checking' overrides */
'@typescript-eslint/explicit-module-boundary-types': [
'error',
{
allowedNames: [
'createTrpcRouter', // The router wants to be inferred
'createTrpcRouterBase', // The router wants to be inferred
],
},
],
},
},
{
files: ['**/__tests__/**/*', 'companion/test/**/*', 'webui/test/**/*', 'config-tool/test/**/*'],
rules: {
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
{
files: ['companion/test/integration/modules/src/**/*'],
rules: {
// These sources are bundler inputs: the base library is resolved from a per-version
// scratch install by build-module-fixtures.mts, not from the repo's dependencies
'n/no-extraneous-import': 'off',
'n/no-extraneous-require': 'off',
// The v1 module contract is commonjs
'@typescript-eslint/no-require-imports': 'off',
},
},
{
files: ['e2e/**/*'],
rules: {
// @playwright/test is a root devDependency, which this rule doesn't recognise from here
'n/no-unpublished-import': 'off',
// playwright resolves fixture dependencies from the destructuring pattern, so an empty
// pattern is meaningful for fixtures with no dependencies
'no-empty-pattern': 'off',
// the app launcher is an entrypoint script, same as companion/lib/main.ts
'n/no-process-exit': 'off',
},
},
{
files: ['companion/**/*.ts', 'companion/**/*.js'],
rules: {
'n/no-missing-import': [
'error',
{
// stream-json's `exports` map only exposes `./*` -> `./src/*.js`; the resolver rewrites
// the `.js` subpath imports to `.ts` and fails to find a source, so allow the package.
allowModules: ['@companion-app/shared', '@companion-module/base', 'type-fest', 'stream-json'],
},
],
'n/prefer-node-protocol': 'error',
'n/no-unsupported-features/node-builtins': [
'error',
{
version: 'current',
ignores: ['sqlite'],
},
],
},
},
{
files: ['launcher/**/*.ts', 'launcher/**/*.js', 'shared-lib/**/*.ts', 'shared-lib/**/*.js'],
rules: {
'n/prefer-node-protocol': 'error',
'n/no-missing-import': [
'error',
{
// @companion-app/shared resolves to its TS sources during dev/test
allowModules: ['@companion-app/shared'],
},
],
},
},
{
files: ['config-tool/**/*.ts'],
rules: {
// Confusing import issues currently
'n/no-missing-import': [
'error',
{
allowModules: ['@companion-app/shared'],
},
],
},
},
// Add prettier at the end to give it final say on formatting
eslintPluginPrettierRecommended,
{
// But lastly, ensure that we ignore certain paths
ignores: [
'**/dist/*',
'**/build/*',
'/dist',
'**/pkg/*',
'**/docs/*',
'**/generated/*',
'**/node_modules/*',
'**/electron-output/*',
'*/vite.config.ts',
'webui/vitest.config.ts',
'vitest.config.ts',
'vitest.workspace.ts',
'html/**/*',
'bundled-modules/**/*',
// Generated module fixtures (bundles of @companion-module/base at pinned versions)
'companion/test/integration/modules/fixtures/**/*',
'companion/test/integration/modules/fixtures-invalid/**/*',
'tools/**/*',
'module-local-dev/**/*',
'launcher/dev.cjs',
'webui/public/_deps/**/*',
'webui/post-install.ts',
'.yarnrc.yml',
'.cache/*',
'companion/lib/Cloud/**/*', // Code is due to be removed soon, not worth fixing lint issues in it
],
},
{
files: ['eslint.config.*'],
rules: {
'n/no-unpublished-import': 'off',
},
},
// The above is mostly copied from https://github.com/bitfocus/companion-module-tools/blob/main/eslint/config.mjs with very little modifications. The below is extra rules that have been added
{
files: [
'webui/**/*.tsx',
'webui/**/*.jsx',
'webui/**/*.ts',
'webui/**/*.js',
'launcher-ui/**/*.tsx',
'launcher-ui/**/*.jsx',
'launcher-ui/**/*.ts',
'launcher-ui/**/*.js',
],
plugins: {
'react-hooks': hookseslint,
'react-refresh': reactRefreshEslint,
react: reacteslint,
},
rules: {
'import/no-unresolved': 'off',
...hookseslint.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{
extraHOCs: [
// tanstack router
'createFileRoute',
'createRootRoute',
// mobx
'observer',
],
},
],
'@typescript-eslint/only-throw-error': [
'error',
{
allow: [
{
from: 'package',
package: '@tanstack/router-core',
name: 'Redirect',
},
],
},
],
// HACK: temporary rules to suppress errors until we can fix them properly
'react-hooks/refs': 'off',
'react-hooks/set-state-in-effect': 'off',
'react-hooks/preserve-manual-memoization': 'off',
},
},
{
rules: {
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-duplicate-type-constituents': 'off',
},
},
...pluginQuery.configs['flat/recommended'].map((config) => ({
...config,
files: ['webui/**/*.tsx', 'webui/**/*.jsx', 'webui/**/*.ts', 'webui/**/*.js'],
})),
]