Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
178 lines (163 loc) · 4.71 KB
/
Copy patheslint.config.js
File metadata and controls
178 lines (163 loc) · 4.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
// eslint.config.js
import js from '@eslint/js';
import eslintComments from '@eslint-community/eslint-plugin-eslint-comments';
import eslintConfigPrettier from 'eslint-config-prettier';
import importPlugin from 'eslint-plugin-import';
import promise from 'eslint-plugin-promise';
import regexp from 'eslint-plugin-regexp';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import unicorn from 'eslint-plugin-unicorn';
import unusedImports from 'eslint-plugin-unused-imports';
import globals from 'globals';
import tseslint from 'typescript-eslint';
const commonFiles = '**/*.{js,jsx,cjs,mjs,ts,tsx}';
const testFiles = '**/*.{test,spec}.{js,jsx,ts,tsx}';
const commonPlugins = {
promise,
unicorn,
import: importPlugin,
'eslint-comments': eslintComments,
regexp,
'unused-imports': unusedImports,
'simple-import-sort': simpleImportSort,
};
const coreRules = {
'no-restricted-syntax': ['error', 'WithStatement', 'LabeledStatement'],
'no-console': 'off',
};
const promiseRules = {
'promise/no-return-wrap': 'error',
'promise/param-names': 'error',
'promise/catch-or-return': 'error',
'promise/no-nesting': 'warn',
'promise/no-promise-in-callback': 'warn',
'promise/no-callback-in-promise': 'warn',
'promise/no-new-statics': 'error',
'promise/no-return-in-finally': 'warn',
'promise/valid-params': 'warn',
};
const unicornRules = {
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-null': 'off',
'unicorn/prefer-switch': 'warn',
'unicorn/prefer-logical-operator-over-ternary': 'warn',
'unicorn/no-await-expression-member': 'error',
};
const importRules = {
'import/no-extraneous-dependencies': 'off',
'import/order': 'off',
'import/first': 'error',
'import/no-duplicates': 'error',
'import/no-cycle': 'error',
'unused-imports/no-unused-imports': 'error',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
};
const eslintCommentsRules = {
'eslint-comments/disable-enable-pair': 'error',
'eslint-comments/no-unlimited-disable': 'error',
'eslint-comments/no-unused-disable': 'error',
};
const regexpRules = {
'regexp/no-empty-capturing-group': 'error',
'regexp/no-lazy-ends': 'error',
};
export default [
// Ignore patterns
{
ignores: [
'**/{dist,build,coverage,.bun}/**',
'**/node_modules/**',
'**/*.lock',
'**/README.md',
'**/package.json',
],
},
// Base configuration
js.configs.recommended,
// Common JavaScript/TypeScript rules
{
files: [commonFiles],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
importAttributes: true,
},
},
globals: {
Bun: 'readonly',
...globals.node,
...globals.browser,
},
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
plugins: commonPlugins,
settings: {
'import/resolver': {
typescript: { project: ['./tsconfig.json'], alwaysTryTypes: true },
},
},
rules: {
...coreRules,
...promiseRules,
...unicornRules,
...importRules,
...eslintCommentsRules,
...regexpRules,
// Reduce noise and duplication with TS
'import/no-cycle': 'warn',
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_', ignoreRestSiblings: true },
],
},
},
// TypeScript: fast defaults (no type info)
...tseslint.configs.recommended,
// TypeScript: type-aware linting only in src for performance
...tseslint.configs.recommendedTypeChecked.map((config) => ({
...config,
files: ['src/**/*.{ts,tsx}'],
languageOptions: {
...(config.languageOptions ?? {}),
parserOptions: { projectService: true },
},
rules: {
...(config.rules ?? {}),
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_', ignoreRestSiblings: true },
],
},
})),
// Test file overrides
{
files: [testFiles],
languageOptions: {
globals: {
describe: 'readonly',
it: 'readonly',
test: 'readonly',
expect: 'readonly',
beforeAll: 'readonly',
afterAll: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'off',
},
},
// Put Prettier last to switch off conflicting stylistic rules
eslintConfigPrettier,
];