forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
352 lines (336 loc) · 9.51 KB
/
Copy patheslint.config.js
File metadata and controls
352 lines (336 loc) · 9.51 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import {includeIgnoreFile} from '@eslint/compat';
import css from '@eslint/css';
import eslintConfigPrettier from 'eslint-config-prettier/flat';
import byoPlugin from 'eslint-plugin-byo';
import pluginPromise from 'eslint-plugin-promise';
import sveltePlugin from 'eslint-plugin-svelte';
import {defineConfig} from 'eslint/config';
import {fileURLToPath} from 'node:url';
import selectDom from 'select-dom/eslint-plugin';
import xo from 'xo';
import cssDocumentation from './eslint-rules/css-documentation.js';
import cssRequireFuchsiaFallback from './eslint-rules/css-require-fuchsia-fallback.js';
import noOptionalChaining from './eslint-rules/no-optional-chaining.js';
import restrictedSyntax from './eslint-rules/restricted-syntax.js';
const refinedGithubPlugin = {
rules: {
'no-optional-chaining': noOptionalChaining,
'css-documentation': cssDocumentation,
'css-require-fuchsia-fallback': cssRequireFuchsiaFallback,
},
};
const gitignorePath = fileURLToPath(new URL('.gitignore', import.meta.url));
export default defineConfig([
includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns'),
...xo.xoToEslintConfig([
{
semicolon: true,
prettier: false,
plugins: {
promise: pluginPromise,
'select-dom': selectDom,
},
languageOptions: {
globals: {
browser: 'readonly',
},
},
rules: {
'no-irregular-whitespace': 'off', // We do want to use non-breaking spaces
// Prefer unicorn's version
'no-warning-comments': 'off',
'unicorn/expiring-todo-comments': ['warn', {
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/expiring-todo-comments.md#disallow-warning-comments-no-warning-comments
allowWarningComments: false,
}],
// Disable some unicorn rules
'unicorn/no-nested-ternary': 'off',
'unicorn/better-regex': 'off',
'unicorn/prefer-top-level-await': 'off',
'unicorn/prefer-dom-node-dataset': 'off',
'unicorn/prefer-ternary': 'off', // Unreadable https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1633
'unicorn/prevent-abbreviations': [
'error',
{
replacements: {
utils: false,
props: false,
ref: false,
nav: false,
},
},
],
'require-unicode-regexp': 'off', // Too many violations to fix at once; enforce separately
// Restore errors
'no-await-in-loop': 'error',
'new-cap': [
'error',
{
newIsCap: true,
capIsNew: true,
},
],
'no-console': 'off',
'@stylistic/jsx-quotes': 'off', // Keep existing quote style in JSX
'@stylistic/function-paren-newline': 'off', // Allow JSX on separate lines from parens
'promise/prefer-await-to-then': ['error', {strict: false}], // Allows `await x.catch()`
// Allow unassigned imports for CSS and feature files
'import-x/no-unassigned-import': ['error', {
allow: [
'**/*.css',
'**/*.scss',
'**/*.sass',
'**/*.less',
'**/features/**',
'**/github-helpers/**',
'webext-bugs/*',
'vite/client',
'webext-dynamic-content-scripts',
],
}],
'no-alert': 'off',
'n/prefer-global/process': 'off',
'no-use-extend-native/no-use-extend-native': 'off', // False positives on ES2024 static methods (Map.groupBy, Object.groupBy, etc.)
// Import-x rules customization
'import-x/consistent-type-specifier-style': 'off',
'import-x/prefer-default-export': 'error',
'import-x/order': [
'error',
{
groups: [
[
'builtin',
'external',
],
],
'newlines-between': 'always-and-inside-groups',
},
],
},
},
// TypeScript-specific config
{
files: ['**/*.{ts,tsx,cts,mts}'],
rules: {
// TODO: Drop after moving to dprint
// Copied from here, except ImportDeclaration
// https://github.com/xojs/eslint-config-xo/blob/0e5bd83b1780f3a6a63ae270c3c8ee0ab947cc8f/source/javascript-rules.js#L458
'@stylistic/object-curly-newline': ['error', {
ObjectExpression: {
multiline: true,
minProperties: 4,
consistent: true,
},
ObjectPattern: {
multiline: true,
consistent: true,
},
ImportDeclaration: {
multiline: true,
minProperties: 10,
consistent: true,
},
ExportDeclaration: {
multiline: true,
minProperties: 4,
consistent: true,
},
}],
'@typescript-eslint/no-restricted-types': [
'error',
{
types: {
object: {
message:
'The `object` type is hard to use. Use `Record<string, unknown>` instead. See: https://github.com/typescript-eslint/typescript-eslint/pull/848',
fixWith: 'Record<string, unknown>',
},
null: {
message: 'Use `undefined` instead. See: https://github.com/sindresorhus/meta/issues/7',
fixWith: 'undefined',
},
Buffer: {
message: 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer',
suggest: [
'Uint8Array',
],
},
'[]': "Don't use the empty array type `[]`. It only allows empty arrays. Use `SomeType[]` instead.",
'[[]]':
"Don't use `[[]]`. It only allows an array with a single element which is an empty array. Use `SomeType[][]` instead.",
},
},
],
'@typescript-eslint/switch-exhaustiveness-check': ['error', {
considerDefaultExhaustiveForUnions: true,
}],
'@typescript-eslint/no-use-before-define': 'error',
'@typescript-eslint/parameter-properties': 'off', // Conflicts with erasable sintax
'@typescript-eslint/no-deprecated': 'off', // Too noisy for now
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-type-assertion': 'off',
'@typescript-eslint/strict-void-return': 'off', // Too many violations to fix at once
'@typescript-eslint/method-signature-style': 'off', // Disagree and it breaks types https://github.com/typescript-eslint/typescript-eslint/issues/1991
'@typescript-eslint/consistent-type-definitions': 'off', // Review later
'@typescript-eslint/consistent-type-imports': [
'error',
{
// Preferred style
fixStyle: 'inline-type-imports',
},
],
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
},
},
{
files: [
'build/*',
],
rules: {
'@typescript-eslint/triple-slash-reference': 'off',
'unicorn/prefer-module': 'off',
},
},
{
files: [
'source/features/*',
],
rules: {
'import-x/prefer-default-export': 'off',
},
},
{
files: [
'**/*.md',
],
rules: {
'unicorn/no-nested-ternary': 'off',
},
},
{
files: [
'.github/**',
],
rules: {
'unicorn/filename-case': 'off',
},
},
{
files: [
'**/*.svelte',
],
rules: {
'import-x/prefer-default-export': 'off',
},
},
// Config files can export objects directly
{
files: ['*.config.{js,ts}', 'rollup.config.js'],
rules: {
'import-x/no-anonymous-default-export': 'off',
},
},
// Test files need browser globals
{
files: ['test/**/*.js'],
languageOptions: {
globals: {
document: 'readonly',
location: 'readonly',
},
},
},
// https://eslint.org/docs/latest/use/configure/ignore#ignoring-files
{
ignores: ['safari'],
},
]),
{
// Disable on markdown files, which are somehow being read as JS files
// Other JSON files shouldn't be linted as JS (package.json is handled by xo with json/json language)
ignores: ['**/*.md', '**/*.json', '!**/package.json'],
},
{
files: ['**/*.css', '**/package.json'],
rules: {
'unicorn/expiring-todo-comments': 'off',
},
},
{
// Allow empty blocks like `catch {}` or `function noop() {}`
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx,cts,mts,vue,svelte,astro}'],
rules: {
'@stylistic/curly-newline': ['error', {minElements: 1}],
},
},
{
files: ['**/*.svelte'],
plugins: {svelte: sveltePlugin},
extends: [sveltePlugin.configs['flat/recommended']],
languageOptions: {
parserOptions: {
parser: '@typescript-eslint/parser',
},
globals: {
browser: 'readonly',
chrome: 'readonly',
location: 'readonly',
},
},
// TODO: Use global `/flat` config. Currently limited to svelte files because dprint is applied to their JS
rules: eslintConfigPrettier.rules,
},
{
plugins: {
byo: byoPlugin,
'refined-github': refinedGithubPlugin,
},
rules: {
...restrictedSyntax,
'select-dom/prefer': ['error', {
allowReadabilityExceptions: true,
}],
},
},
{
files: ['source/features/**'],
rules: {
'refined-github/no-optional-chaining': 'error',
},
},
{
files: ['source/features/github-bugs.css', 'source/refined-github.css'],
rules: {
'refined-github/css-documentation': 'error',
},
},
{
files: ['**/*.css'],
language: 'css/css',
plugins: {css},
extends: ['css/recommended'],
languageOptions: {
tolerant: true, // Required for @container
},
rules: {
'css/no-important': 'off', // Intentionally used to override GitHub styles
'css/use-baseline': 'off', // We support the latest browsers only
'css/no-invalid-properties': 'off', // https://github.com/eslint/css/issues/434
'refined-github/css-require-fuchsia-fallback': 'error',
},
},
{
files: ['**/*.js', '**/*.ts'],
// TODO: Use global `/flat` config
rules: eslintConfigPrettier.rules,
},
]);