Repository navigation
Expand file tree
/
Copy patheslint.config.mjs
More file actions
236 lines (226 loc) · 9.41 KB
/
Copy patheslint.config.mjs
File metadata and controls
236 lines (226 loc) · 9.41 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
import { fileURLToPath } from 'node:url';
import { includeIgnoreFile } from '@eslint/compat';
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';
import preferLet from 'eslint-plugin-prefer-let';
import storybook from 'eslint-plugin-storybook';
import svelte from 'eslint-plugin-svelte';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
import { defineConfig } from 'eslint/config';
import globals from 'globals';
import ts from 'typescript-eslint';
import svelteConfig from './svelte/svelte.config.js';
const gitignorePath = fileURLToPath(new URL('.gitignore', import.meta.url));
export default defineConfig(
{
languageOptions: {
globals: globals.builtin,
},
plugins: {
unicorn: eslintPluginUnicorn,
},
rules: unicornRules(),
},
includeIgnoreFile(gitignorePath),
// `crates/` (Rust workspace crates) is not in `.gitignore` but should not be
// linted. `svelte/static/` contains vendored files like `mockServiceWorker.js`
// (auto-generated by MSW) that should not be linted either.
{ ignores: ['crates/', 'svelte/static/'] },
js.configs.recommended,
...ts.configs.recommended,
...svelte.configs.recommended,
...svelte.configs.prettier,
...storybook.configs['flat/recommended'],
prettier,
{
plugins: {
'prefer-let': preferLet,
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
// Defined at build time by Vite (see `vite.config.ts`) and declared
// ambiently in `src/app.d.ts`. ESLint's `no-undef` rule does not see
// ambient `.d.ts` declarations, so we have to spell it out here.
__TEST__: 'readonly',
},
parserOptions: {
tsconfigRootDir: fileURLToPath(new URL('.', import.meta.url)),
},
},
rules: {
// it's fine to use `return` without a value and rely on the implicit `undefined` return value
'getter-return': 'off',
'prefer-const': 'off',
'prefer-let/prefer-let': 'error',
},
},
{
files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
languageOptions: {
parserOptions: {
projectService: true,
extraFileExtensions: ['.svelte'],
parser: ts.parser,
svelteConfig,
tsconfigRootDir: fileURLToPath(new URL('svelte', import.meta.url)),
},
},
},
);
/**
* Returns the Unicorn rules that are appropriate for crates.io.
*
* Even Unicorn's `unopinionated` preset enables many rules that encode style
* preferences or otherwise do not fit this project. Defining the rules here
* lets us enable only checks that we consider relevant, and prevents dependency
* upgrades from silently changing the project's lint policy. New Unicorn rules
* should therefore be reviewed and added deliberately instead of inherited
* through a built-in preset.
*/
function unicornRules() {
return {
'unicorn/better-dom-traversing': 'error',
'unicorn/consistent-compound-words': 'error',
'unicorn/consistent-date-clone': 'error',
'unicorn/consistent-existence-index-check': 'error',
'unicorn/dom-node-dataset': 'error',
'unicorn/error-message': 'error',
'unicorn/escape-case': 'error',
'unicorn/expiring-todo-comments': 'error',
'unicorn/explicit-length-check': ['error', { 'non-zero': 'not-equal' }],
'unicorn/import-style': 'error',
'unicorn/new-for-builtins': 'error',
'unicorn/no-abusive-eslint-disable': 'error',
'unicorn/no-accessor-recursion': 'error',
'unicorn/no-anonymous-default-export': 'error',
'unicorn/no-array-fill-with-reference-type': 'error',
'unicorn/no-for-each': 'error',
'unicorn/no-array-from-fill': 'error',
'unicorn/no-array-method-this-argument': 'error',
'unicorn/no-array-reverse': 'error',
'unicorn/no-array-sort': 'error',
'unicorn/no-await-in-promise-methods': 'error',
'unicorn/no-blob-to-file': 'error',
'unicorn/no-canvas-to-image': 'error',
'unicorn/no-console-spaces': 'error',
'unicorn/no-document-cookie': 'error',
'unicorn/no-empty-file': 'error',
'unicorn/no-exports-in-scripts': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/no-instanceof-builtins': 'error',
'unicorn/no-invalid-fetch-options': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-lonely-if': 'error',
'unicorn/no-magic-array-flat-depth': 'error',
'unicorn/no-named-default': 'error',
'unicorn/no-negated-condition': 'error',
'unicorn/no-negation-in-equality-check': 'error',
'unicorn/no-new-array': 'error',
'unicorn/no-new-buffer': 'error',
'unicorn/no-object-as-default-parameter': 'error',
'unicorn/no-process-exit': 'error',
'unicorn/no-single-promise-in-promise-methods': 'error',
'unicorn/no-static-only-class': 'error',
'unicorn/no-thenable': 'error',
'unicorn/no-this-assignment': 'error',
'unicorn/no-typeof-undefined': 'error',
'unicorn/no-unnecessary-array-flat-depth': 'error',
'unicorn/no-unnecessary-array-splice-count': 'error',
'unicorn/no-unnecessary-await': 'error',
'unicorn/no-unnecessary-nested-ternary': 'error',
'unicorn/no-unnecessary-polyfills': 'error',
'unicorn/no-unnecessary-slice-end': 'error',
'unicorn/no-unreadable-array-destructuring': 'error',
'unicorn/no-unreadable-iife': 'error',
'unicorn/no-unused-array-method-return': 'error',
'unicorn/no-useless-collection-argument': 'error',
'unicorn/no-useless-error-capture-stack-trace': 'error',
'unicorn/no-useless-fallback-in-spread': 'error',
'unicorn/no-useless-iterator-to-array': 'error',
'unicorn/no-useless-length-check': 'error',
'unicorn/no-useless-promise-resolve-reject': 'error',
'unicorn/no-useless-spread': 'error',
'unicorn/no-useless-switch-case': 'error',
'unicorn/no-useless-undefined': 'error',
'unicorn/no-zero-fractions': 'error',
'unicorn/number-literal-case': 'error',
'unicorn/numeric-separators-style': 'error',
'unicorn/prefer-add-event-listener': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-last-methods': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-at': 'error',
'unicorn/prefer-bigint-literals': 'error',
'unicorn/prefer-blob-reading-methods': 'error',
'unicorn/prefer-class-fields': 'error',
'unicorn/prefer-classlist-toggle': 'error',
'unicorn/prefer-code-point': 'error',
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-dom-node-append': 'error',
'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-dom-node-text-content': 'error',
'unicorn/prefer-event-target': 'error',
'unicorn/prefer-global-this': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-iterator-to-array-at-end': 'error',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/prefer-logical-operator-over-ternary': 'error',
'unicorn/prefer-math-abs': 'error',
'unicorn/prefer-math-min-max': 'error',
'unicorn/prefer-math-trunc': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-modern-math-apis': 'error',
// We don't want to go all-in on ES6 modules for Node.js code yet.
'unicorn/prefer-module': 'off',
'unicorn/prefer-native-coercion-functions': 'error',
'unicorn/prefer-negative-index': 'error',
'unicorn/prefer-node-protocol': 'error',
// This rule seems unnecessary.
'unicorn/prefer-number-properties': 'off',
'unicorn/prefer-object-from-entries': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-prototype-methods': 'error',
'unicorn/prefer-queue-microtask': 'error',
'unicorn/prefer-reflect-apply': 'error',
'unicorn/prefer-regexp-test': 'error',
'unicorn/prefer-response-static-json': 'error',
'unicorn/prefer-set-has': 'error',
'unicorn/prefer-set-size': 'error',
'unicorn/prefer-simple-condition-first': 'error',
// This rule has false positives on non-array `push()` methods.
'unicorn/prefer-single-call': 'off',
'unicorn/prefer-split-limit': 'error',
'unicorn/prefer-string-match-all': 'error',
'unicorn/prefer-string-pad-start-end': 'error',
'unicorn/prefer-string-raw': 'error',
'unicorn/prefer-string-repeat': 'error',
'unicorn/prefer-string-replace-all': 'error',
'unicorn/prefer-string-slice': 'error',
'unicorn/prefer-string-starts-ends-with': 'error',
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-structured-clone': 'error',
// Switch statements in JavaScript are quite error-prone.
'unicorn/prefer-switch': 'off',
// Guard clauses and multi-line returns are clearer than ternaries.
'unicorn/prefer-ternary': 'off',
// Svelte component `<script>` blocks instantiate synchronously, so top-level
// await is not appropriate there.
'unicorn/prefer-top-level-await': 'off',
'unicorn/prefer-type-error': 'error',
'unicorn/relative-url-style': 'error',
'unicorn/require-array-join-separator': 'error',
'unicorn/require-css-escape': 'error',
'unicorn/require-module-attributes': 'error',
'unicorn/require-module-specifiers': 'error',
'unicorn/require-number-to-fixed-digits-argument': 'error',
'unicorn/require-passive-events': 'error',
'unicorn/text-encoding-identifier-case': 'error',
'unicorn/throw-new-error': 'error',
};
}