-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy patheslint.config.mjs
More file actions
222 lines (210 loc) · 6.71 KB
/
Copy patheslint.config.mjs
File metadata and controls
222 lines (210 loc) · 6.71 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
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import tseslint from 'typescript-eslint';
import eslint from '@eslint/js';
import globals from 'globals';
import importPlugin from 'eslint-plugin-import-x';
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript';
import jest from 'eslint-plugin-jest';
const __dirname = dirname(fileURLToPath(import.meta.url));
export default tseslint.config(
// Global ignores (replaces .eslintignore + ignorePatterns)
{
ignores: [
'**/.yarn/**',
'**/dist/**',
'**/.next/**',
'**/.vite/**',
// NOTE: we are ignoring these examples because they were being ignored
// before, we will need to isolate specific rules for examples and
// remove these in the future.
'**/vercel/examples/**',
'**/react-native/example/**',
'**/react-native/example-fdv2/**',
'**/react/contract-tests/**',
'**/react/examples/**',
'**/jest/example/**',
'**/electron/example/**',
'**/svelte/.svelte-kit/**',
'**/svelte/example/**',
'**/fastly/example/build/**',
'**/server-ai/examples/chat-judge/**',
'**/server-ai/examples/direct-judge/**',
'**/fromExternal/**',
],
},
// Base config for all TypeScript files
{
files: ['**/*.ts', '**/*.tsx'],
extends: [
eslint.configs.recommended,
importPlugin.flatConfigs.recommended,
tseslint.configs.recommended
],
plugins: {
// Alias as 'import' so existing eslint-disable comments with import/ prefix keep working
import: importPlugin,
jest,
},
languageOptions: {
parserOptions: {
project: './tsconfig.eslint.json',
tsconfigRootDir: __dirname,
},
globals: {
...globals.node,
BigInt: 'readonly',
},
},
settings: {
'import-x/resolver-next': [
createTypeScriptImportResolver({
project: 'tsconfig.eslint.json',
}),
],
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
varsIgnorePattern: '^__',
caughtErrors: 'none',
},
],
// naming conventions
'@typescript-eslint/naming-convention': [
'error',
{
selector: ['method'],
format: ['camelCase'],
leadingUnderscore: 'forbid',
},
{
selector: ['method'],
format: ['camelCase'],
modifiers: ['private'],
leadingUnderscore: 'require',
},
{
selector: ['classProperty', 'parameterProperty'],
format: ['camelCase'],
leadingUnderscore: 'forbid',
},
{
selector: ['classProperty', 'parameterProperty'],
modifiers: ['static'],
format: ['PascalCase'],
leadingUnderscore: 'forbid',
},
{
selector: ['classProperty', 'parameterProperty'],
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'require',
},
],
'@typescript-eslint/no-empty-object-type': [
'error',
{ allowInterfaces: 'with-single-extends' },
],
'no-restricted-syntax': [
'error',
{ selector: 'ForInStatement', message: 'Use Object.{keys,values,entries} instead.' },
{ selector: 'LabeledStatement', message: 'Labels are a form of GOTO.' },
{ selector: 'WithStatement', message: '`with` is disallowed in strict mode.' },
],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
// NOTE: we should uncomment this in the future as config files typically
// only read from devdependencies
'**/jest*.ts',
// '**/*.config.ts',
'**/*.d.ts',
'**/*{.,_}test.{ts,tsx}',
// '**/*{.,_}spec.{ts,tsx}',
],
},
],
// enable url-scheme imports
'import-x/no-unresolved': ['error', { ignore: ['^[a-z]+:'] }],
'no-underscore-dangle': ['error', { allowAfterThis: true }],
'no-await-in-loop': 'error',
'no-new': 'error',
'no-console': 'error',
// Catches whitespace-only lines left behind when auto-fix removes
// eslint-disable directives. Auto-fixable, so a second --fix pass cleans up.
'no-trailing-spaces': 'error',
'prefer-const': ['error', { ignoreReadBeforeAssign: true }],
// NOTE: this will allow object fields to be reassigned.
'no-param-reassign': [ 'error' ],
// TODO: we may want to re-enable this in the future.
'@typescript-eslint/ban-ts-comment': 'off',
// extension rules (https://typescript-eslint.io/rules#extension-rules)
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error",
'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
// Keeping this as a reference, but I don't think we really need to enforce this rule.
// "class-methods-use-this": "off",
// "@typescript-eslint/class-methods-use-this": "error"
},
},
// Test files: add jest globals and jest rules; relax test-specific rules
{
files: [
'**/*.test.ts',
'**/*.test.tsx',
'**/__tests__/**/*.ts',
'**/__tests__/**/*.tsx'
],
languageOptions: {
globals: {
...globals.jest,
},
},
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/valid-expect': 'error',
// 'no-console': 'off',
'@typescript-eslint/no-require-imports': 'off',
'import-x/no-unresolved': 'off',
},
},
// Examples, contract-tests, and tooling packages: allow console
{
files: [
'**/example/**',
'**/examples/**',
'**/example-*/**',
'**/contract-tests/**',
'packages/tooling/**',
],
rules: {
'no-console': 'off',
// TODO: a lot of our examples fail this one, will need to check
'import-x/no-unresolved': 'off',
},
},
// Svelte SDK: the package's tsconfig extends .svelte-kit/tsconfig.json which
// is gitignored and only generated by `svelte-kit sync`. The import-x
// resolver crashes if it tries to walk that chain.
{
files: ['packages/sdk/svelte/**/*.ts', 'packages/sdk/svelte/**/*.tsx'],
rules: {
'import-x/no-unresolved': 'off',
},
},
// Override: contract-test-utils needs 'always' extensions (with ts exception)
{
files: ['packages/tooling/contract-test-utils/**/*.ts'],
rules: {
'import/extensions': ['error', 'always', { ts: 'never' }],
},
},
);