-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy patheslint.config.mjs
More file actions
250 lines (233 loc) · 7.82 KB
/
eslint.config.mjs
File metadata and controls
250 lines (233 loc) · 7.82 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
// @ts-check
import tseslint from 'typescript-eslint';
import stylistic from '@stylistic/eslint-plugin';
import airbnb from 'eslint-stylistic-airbnb';
import globals from 'globals';
import nofixPlugin from 'eslint-plugin-fix-disabled-rules';
import eslintPluginJsonc from 'eslint-plugin-jsonc';
import pluginESx from 'eslint-plugin-es-x';
import pluginN from 'eslint-plugin-n';
// fix renamed rule
if (airbnb.rules['@stylistic/func-call-spacing']) {
// @ts-ignore
airbnb.rules['@stylistic/function-call-spacing'] = airbnb.rules['@stylistic/func-call-spacing'];
// @ts-ignore
delete airbnb.rules['@stylistic/func-call-spacing'];
}
export default tseslint.config(
{
plugins: {
'@stylistic': stylistic,
'@nofix': nofixPlugin,
'es-x': pluginESx,
n: pluginN,
},
languageOptions: {
globals: {
...globals.node,
},
},
},
// @ts-ignore
airbnb,
...tseslint.configs.recommended,
{
ignores: [
'**/dist',
'**/dist-sea',
'**/node_modules',
'**/.turbo',
'packages/eslint-custom-rules',
'packages/env-spec-parser/src/grammar.js',
'packages/varlock-website/.astro',
'packages/varlock/src/env-graph/test/plugins',
'**/*.ignore',
'**/.vercel',
'**/.netlify',
'**/.astro',
'**/.next',
'**/out',
'**/next-env.d.ts',
'.magent',
'framework-tests/.test-projects',
'framework-tests/.packed',
'packages/intellij-plugin/build',
],
},
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
// NOTE - run `bunx @eslint/config-inspector@latest`
// to help audit these rules
rules: {
// some preset rules to relax -----------
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-explicit-any': 0,
'no-plusplus': 0,
radix: 0,
'no-return-await': 0,
'prefer-destructuring': 0,
'no-else-return': 0, // sometimes clearer even though unnecessary
'prefer-arrow-callback': 0,
'arrow-body-style': 0,
'@stylistic/lines-between-class-members': 0, // often nice to group related one-liners
'max-classes-per-file': 0, // can make sense to colocate small classes
'consistent-return': 0, // often can make sense to return (undefined) early
'no-useless-return': 0, // sometimes helps clarify you are bailing early
'no-continue': 0,
'no-underscore-dangle': 0,
'no-await-in-loop': 0,
'no-lonely-if': 0,
'@stylistic/no-multiple-empty-lines': 0,
'@typescript-eslint/no-empty-object-type': 0,
'class-methods-use-this': 0,
'no-empty-function': 0, // typescript version is enabled
'@typescript-eslint/no-unused-vars': [
'warn',
{
caughtErrors: 'none',
argsIgnorePattern: '^_|^(response|ctx)$',
varsIgnorePattern: '^_|^(props|emit)$',
},
],
'@typescript-eslint/return-await': 0,
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
'@stylistic/array-bracket-newline': ['error', { multiline: true }],
'@stylistic/array-element-newline': ['error', 'consistent'],
// other -----------------------------------------------------
curly: ['error', 'multi-line'],
'@stylistic/brace-style': 'error',
'@stylistic/max-len': [
'error',
120,
2,
{
// bumped to 120, otherwise same as airbnb's rule but ignoring comments
ignoreUrls: true,
ignoreComments: true,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
'@stylistic/max-statements-per-line': ['error', { max: 1 }],
// rules to disable for now, but will likely be turned back on --------
// TODO: review these rules, infractions case by case, probably turn back on?
'@typescript-eslint/no-use-before-define': 0,
'no-param-reassign': 0,
'no-restricted-syntax': 0,
'@typescript-eslint/naming-convention': 0,
'@typescript-eslint/no-shadow': 0,
'guard-for-in': 0,
// some rules to downgrade to warning which we'll allow while developing --------------------
'no-console': 'warn',
'@typescript-eslint/no-empty-function': 'warn',
'no-debugger': 'warn',
'no-alert': 'warn',
'no-empty': 'warn',
// rules that we want to warn, but disable agressive auto-fixing ----------------------------
// commenting out var modifications in later code means auto changing let to const, and then getting angry when uncommenting
'prefer-const': 0,
'@nofix/prefer-const': 'warn',
},
},
{
files: ['packages/varlock/src/**'],
rules: {
// top level await not allowed in CJS build needed for bundled SEA
'es-x/no-top-level-await': 'error',
},
},
{
files: ['packages/varlock/src/cli/**'],
rules: {
// use `gracefulExit` instead of process.exit in the CLI
'n/no-process-exit': 'error',
},
},
{
files: [
'scripts/**',
'examples/**',
'packages/*.ignore/**',
'packages/varlock/src/cli/**',
'packages/varlock/scripts/**',
'smoke-tests/**',
'framework-tests/**',
],
rules: {
'no-console': 0,
},
},
{
files: ['smoke-tests/smoke-test-plugin/plugins/**'],
rules: {
'@typescript-eslint/no-require-imports': 0,
},
},
{
// plugin files use triple-slash directives for the `plugin` global type
// which is injected at runtime by varlock via globalThis
files: [
'smoke-tests/**/plugins/**',
'packages/varlock/src/env-graph/test/plugins/**',
],
languageOptions: {
globals: {
plugin: 'readonly',
},
},
rules: {
'@typescript-eslint/triple-slash-reference': 0,
},
},
// set up lint rules for json files
// note - the simpler methods were not working properly, so we list the rules here instead
{
files: ['**/*.json'],
plugins: { jsonc: eslintPluginJsonc },
language: 'jsonc/json',
rules: {
// generic rules
'@stylistic/max-len': 0,
// json rules
'jsonc/no-bigint-literals': 'error',
'jsonc/no-binary-expression': 'error',
'jsonc/no-escape-sequence-in-identifier': 'error',
'jsonc/no-number-props': 'error',
'jsonc/no-parenthesized': 'error',
'jsonc/no-regexp-literals': 'error',
'jsonc/no-template-literals': 'error',
'jsonc/no-undefined-value': 'error',
'jsonc/no-unicode-codepoint-escapes': 'error',
'jsonc/valid-json-number': 'error', // enables/replaces many more specific rules
'jsonc/vue-custom-block/no-parsing-error': 'error',
'jsonc/array-bracket-newline': ['error', { multiline: true, minItems: null }],
'jsonc/array-bracket-spacing': ['error', 'never'],
'jsonc/comma-style': ['error', 'last'],
'jsonc/indent': ['error', 2, {}],
'jsonc/key-spacing': ['error', { beforeColon: false, afterColon: true, mode: 'strict' }],
'jsonc/no-dupe-keys': 'error',
'jsonc/no-irregular-whitespace': 'error',
'jsonc/no-multi-str': 'error',
'jsonc/no-octal-escape': 'error',
'jsonc/no-sparse-arrays': 'error',
'jsonc/no-useless-escape': 'error',
'jsonc/object-curly-newline': ['error', { consistent: true }],
'jsonc/object-curly-spacing': ['error', 'always'],
'jsonc/object-property-newline': 'error',
'jsonc/quote-props': ['error', 'always', {}],
'jsonc/quotes': ['error', 'double', { avoidEscape: false }],
// rules to enable below for jsonc
'jsonc/comma-dangle': ['error', 'never'],
'jsonc/no-comments': 'error',
},
},
{ // JSONC
files: ['**/tsconfig.json', '**/tsconfig.*.json', '**/.vscode/*.json', 'turbo.json'],
language: 'jsonc/jsonc',
rules: {
'jsonc/comma-dangle': ['error', 'only-multiline'],
'jsonc/no-comments': 0,
},
},
);