-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy patheslint.config.mjs
223 lines (212 loc) · 7.03 KB
/
eslint.config.mjs
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
import base, { createConfig } from '@metamask/eslint-config';
import jest from '@metamask/eslint-config-jest';
import nodejs from '@metamask/eslint-config-nodejs';
import typescript from '@metamask/eslint-config-typescript';
const NODE_LTS_VERSION = 22;
const config = createConfig([
...base,
{
ignores: [
'**/dist/**',
'**/docs/**',
'**/coverage/**',
'merged-packages/**',
'.yarn/**',
'scripts/create-package/package-template/**',
],
},
{
rules: {
// Left disabled because various properties throughough this repo are snake_case because the
// names come from external sources or must comply with standards
// e.g. `txreceipt_status`, `signTypedData_v4`, `token_id`
camelcase: 'off',
'id-length': 'off',
// TODO: re-enble most of these rules
'function-paren-newline': 'off',
'id-denylist': 'off',
'implicit-arrow-linebreak': 'off',
'import-x/no-anonymous-default-export': 'off',
'import-x/no-unassigned-import': 'off',
'lines-around-comment': 'off',
'no-async-promise-executor': 'off',
'no-case-declarations': 'off',
'no-invalid-this': 'off',
'no-negated-condition': 'off',
'no-new': 'off',
'no-param-reassign': 'off',
'no-restricted-syntax': 'off',
radix: 'off',
'require-atomic-updates': 'off',
'jsdoc/match-description': [
'off',
{ matchDescription: '^[A-Z`\\d_][\\s\\S]*[.?!`>)}]$' },
],
// TODO: These rules created more errors after the upgrade to ESLint 9.
// Re-enable these rules and address any lint violations.
'import-x/no-named-as-default-member': 'warn',
'prettier/prettier': 'warn',
'no-empty-function': 'warn',
},
settings: {
jsdoc: {
mode: 'typescript',
},
},
},
{
files: [
'**/*.{js,cjs,mjs}',
'**/*.test.{js,ts}',
'**/tests/**/*.{js,ts}',
'scripts/*.ts',
'scripts/create-package/**/*.ts',
],
extends: [nodejs],
rules: {
// TODO: Re-enable this
'n/no-sync': 'off',
// TODO: These rules created more errors after the upgrade to ESLint 9.
// Re-enable these rules and address any lint violations.
'n/no-unsupported-features/node-builtins': 'warn',
},
},
{
files: ['**/*.test.{js,ts}', '**/tests/**/*.{js,ts}'],
extends: [jest],
rules: {
// TODO: These rules created more errors after the upgrade to ESLint 9.
// Re-enable these rules and address any lint violations.
'jest/no-conditional-in-test': 'warn',
'jest/prefer-lowercase-title': 'warn',
'jest/prefer-strict-equal': 'warn',
},
settings: {
node: {
version: `^${NODE_LTS_VERSION}`,
},
},
},
{
// These files are test helpers, not tests. We still use the Jest ESLint
// config here to ensure that ESLint expects a test-like environment, but
// various rules meant just to apply to tests have been disabled.
files: ['**/tests/**/*.{js,ts}'],
ignores: ['**/*.test.{js,ts}'],
rules: {
'jest/no-export': 'off',
'jest/require-top-level-describe': 'off',
'jest/no-if': 'off',
},
},
{
files: ['**/*.{js,cjs}'],
languageOptions: {
sourceType: 'script',
ecmaVersion: 2020,
},
},
{
files: ['**/*.ts'],
extends: [typescript],
languageOptions: {
parserOptions: {
tsconfigRootDir: import.meta.dirname,
project: './tsconfig.packages.json',
// Disable `projectService` because we run into out-of-memory issues.
// See this ticket for inspiration out how to solve this:
// <https://github.com/typescript-eslint/typescript-eslint/issues/1192>
projectService: false,
},
},
rules: {
// These rules have been customized from their defaults.
'@typescript-eslint/switch-exhaustiveness-check': [
'error',
{
considerDefaultExhaustiveForUnions: true,
},
],
// This rule does not detect multiple imports of the same file where types
// are being imported in one case and runtime values are being imported in
// another
'import-x/no-duplicates': 'off',
// Enable rules that are disabled in `@metamask/eslint-config-typescript`
'@typescript-eslint/no-explicit-any': 'error',
// TODO: auto-fix breaks stuff
'@typescript-eslint/promise-function-async': 'off',
// TODO: re-enable most of these rules
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/prefer-enum-initializers': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/prefer-reduce-type-parameter': 'off',
'no-restricted-syntax': 'off',
'no-restricted-globals': 'off',
// TODO: These rules created more errors after the upgrade to ESLint 9.
// Re-enable these rules and address any lint violations.
'@typescript-eslint/consistent-type-exports': 'warn',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-duplicate-enum-values': 'warn',
'@typescript-eslint/no-misused-promises': 'warn',
'@typescript-eslint/no-unsafe-enum-comparison': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/only-throw-error': 'warn',
'@typescript-eslint/prefer-promise-reject-errors': 'warn',
'@typescript-eslint/prefer-readonly': 'warn',
'import-x/namespace': 'warn',
'import-x/no-named-as-default': 'warn',
'import-x/order': 'warn',
'jsdoc/check-tag-names': 'warn',
'jsdoc/require-returns': 'warn',
'jsdoc/tag-lines': 'warn',
'no-unused-private-class-members': 'warn',
'promise/always-return': 'warn',
'promise/catch-or-return': 'warn',
'promise/param-names': 'warn',
},
},
{
files: ['tests/setupAfterEnv/matchers.ts'],
languageOptions: {
sourceType: 'script',
},
},
// This should really be in `@metamask/eslint-config-typescript`
{
files: ['**/*.d.ts'],
rules: {
'@typescript-eslint/naming-convention': 'warn',
'import-x/unambiguous': 'off',
},
},
{
files: ['scripts/*.ts'],
rules: {
// Scripts may be self-executable and thus have hashbangs.
'n/hashbang': 'off',
},
},
{
files: ['**/jest.environment.js'],
rules: {
// These files run under Node, and thus `require(...)` is expected.
'n/global-require': 'off',
// TODO: These rules created more errors after the upgrade to ESLint 9.
// Re-enable these rules and address any lint violations.
'n/prefer-global/text-encoder': 'warn',
'n/prefer-global/text-decoder': 'warn',
'no-shadow': 'warn',
},
},
{
files: ['**/*.mjs'],
languageOptions: {
sourceType: 'module',
},
},
]);
export default config;