-
-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy patheslint.config.mjs
More file actions
237 lines (225 loc) · 6.36 KB
/
eslint.config.mjs
File metadata and controls
237 lines (225 loc) · 6.36 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
// @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: {
project: true,
},
},
},
{
...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__/**/*', 'test/**/*'],
rules: {
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
},
},
{
files: ['companion/**/*.ts', 'companion/**/*.js'],
rules: {
'n/no-missing-import': [
'error',
{
allowModules: ['@companion-app/shared', '@companion-module/base', 'type-fest'],
},
],
'n/prefer-node-protocol': 'error',
},
},
{
files: ['launcher/**/*.ts', 'launcher/**/*.js', 'shared-lib/**/*.ts', 'shared-lib/**/*.js'],
rules: {
'n/prefer-node-protocol': 'error',
},
},
// 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/**/*',
'tools/**/*',
'module-local-dev/**/*',
'launcher/dev.cjs',
'webui/public/_deps/**/*',
'webui/post-install.ts',
'.yarnrc.yml',
'companion/generated/**/*',
'companion/lib/Service/Satellite/SatelliteSurfaceManifestSchema.ts',
// TMP
'companion/lib/Cloud/**/*',
'companion/test/**/*',
'webui/test/**/*',
'.cache/*',
],
},
{
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'],
})),
]