-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy patheslint.config.js
More file actions
245 lines (244 loc) · 7.31 KB
/
eslint.config.js
File metadata and controls
245 lines (244 loc) · 7.31 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
import typescript from '@typescript-eslint/eslint-plugin'
import typescriptParser from '@typescript-eslint/parser'
import importPlugin from 'eslint-plugin-import'
import perfectionist from 'eslint-plugin-perfectionist'
import prettier from 'eslint-plugin-prettier'
import prettierConfig from 'eslint-config-prettier'
import noEnumRule from './scripts/eslint-rules/no-enum.js'
import noSdkTsBarrelRule from './scripts/eslint-rules/no-sdk-ts-barrel.js'
export default [
// Ignore patterns
{
ignores: [
'proto/**',
'protoV2/**',
'**/proto-ts/**',
'**/src/generated/**',
'**/*_pb.ts',
'**/*_pb.js',
'**/*_pb.mjs',
'**/*.d.ts',
'**/dist/**',
'deprecated/**',
'node_modules/**',
'**/tsdown.config.ts',
'**/src/utils/ofac.ts',
],
},
// Base configuration for TypeScript files
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
parser: typescriptParser,
parserOptions: {
// Enable type-aware linting with performance optimizations
project: true, // Auto-find nearest tsconfig
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
'@typescript-eslint': typescript,
import: importPlugin,
perfectionist: perfectionist,
prettier: prettier,
custom: {
rules: {
'no-enum': noEnumRule,
'no-sdk-ts-barrel': noSdkTsBarrelRule,
},
},
},
rules: {
// Essential type-aware rules (performance optimized)
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'separate-type-imports',
disallowTypeAnnotations: false,
},
],
'@typescript-eslint/consistent-type-exports': [
'error',
{
fixMixedExportsWithInlineTypeSpecifier: false,
},
],
'@typescript-eslint/no-import-type-side-effects': 'error',
// Disable the base import/no-duplicates rule as it conflicts with type imports
'import/no-duplicates': 'off',
// Enhanced import sorting with more granular groups
'perfectionist/sort-imports': [
'error',
{
type: 'line-length',
order: 'asc',
groups: [
['builtin', 'external'],
'internal',
['parent', 'sibling', 'index'],
'object',
'unknown',
'type',
'internal-type',
['parent-type', 'sibling-type', 'index-type'],
],
newlinesBetween: 'ignore',
internalPattern: ['^@/', '^~/', '^#'],
},
],
// Sort named imports alphabetically by line length
'perfectionist/sort-named-imports': [
'error',
{ type: 'line-length', order: 'asc' },
],
// Sort exports alphabetically by line length
'perfectionist/sort-exports': [
'error',
{ type: 'line-length', order: 'asc' },
],
// Allow .js extensions in TypeScript files (for ESM compatibility)
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
ts: 'never',
tsx: 'never',
},
],
// Allow unused vars that start with underscore
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
// Allow console in development
'no-console': 'warn',
// Allow any type (useful for complex types)
'@typescript-eslint/no-explicit-any': 'warn',
// Disable prefer-destructuring for object properties (too strict for this codebase)
'prefer-destructuring': 'off',
// Disable prefer-default-export (not suitable for library code)
'import/prefer-default-export': 'off',
// Disable no-use-before-define for TypeScript (TypeScript handles this better)
'no-console': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-use-before-define': 'off',
// Custom rule to discourage enums in favor of type + const pattern
'custom/no-enum': 'error',
// Custom rule to enforce subpath imports from @injectivelabs/sdk-ts
'custom/no-sdk-ts-barrel': 'error',
// Enforce spacing inside object/type brackets
'object-curly-spacing': ['error', 'always'],
// Prettier integration
'prettier/prettier': 'error',
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './tsconfig.json',
},
},
},
},
// Base configuration for JavaScript files
{
files: ['**/*.{js,jsx,cjs}'],
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
},
// Base configuration for CommonJS files
{
files: ['**/*.cjs'],
languageOptions: {
ecmaVersion: 2020,
sourceType: 'commonjs',
},
plugins: {
import: importPlugin,
perfectionist: perfectionist,
prettier: prettier,
},
rules: {
// Enhanced import sorting
'perfectionist/sort-imports': [
'error',
{
type: 'line-length',
order: 'asc',
groups: [
['builtin', 'external'],
'internal',
['parent', 'sibling', 'index'],
'object',
'unknown',
'type',
'internal-type',
['parent-type', 'sibling-type', 'index-type'],
],
newlinesBetween: 'ignore',
internalPattern: ['^@/', '^~/', '^#'],
},
],
'perfectionist/sort-named-imports': [
'error',
{ type: 'line-length', order: 'asc' },
],
'perfectionist/sort-exports': [
'error',
{ type: 'line-length', order: 'asc' },
],
// Allow console in development
'no-console': 'warn',
// Disable prefer-destructuring for object properties (too strict for this codebase)
'prefer-destructuring': 'off',
// Disable prefer-default-export (not suitable for library code)
'import/prefer-default-export': 'off',
// Disable no-use-before-define for JavaScript
'no-use-before-define': 'off',
// Enforce spacing inside object brackets
'object-curly-spacing': ['error', 'always'],
// Prettier integration
'prettier/prettier': 'error',
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './tsconfig.json',
},
},
},
},
// Test files configuration
{
files: ['**/*.test.ts', '**/*.spec.ts', '**/*.test.js', '**/*.spec.js'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
// Disable type-aware linting for test files since they're excluded from tsconfig
project: false,
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-console': 'off',
// Disable type-aware rules for test files
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/consistent-type-exports': 'off',
'@typescript-eslint/no-import-type-side-effects': 'off',
},
},
// Prettier config to disable conflicting rules
prettierConfig,
]