-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
207 lines (198 loc) · 5.95 KB
/
Copy patheslint.config.mjs
File metadata and controls
207 lines (198 loc) · 5.95 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
import universeNodeConfig from 'eslint-config-universe/flat/node.js';
import universeTypescriptAnalysisConfig from 'eslint-config-universe/flat/shared/typescript-analysis.js';
import universeWebConfig from 'eslint-config-universe/flat/web.js';
import lodash from 'eslint-plugin-lodash';
import * as mdx from 'eslint-plugin-mdx';
import oxlint from 'eslint-plugin-oxlint';
import unicorn from 'eslint-plugin-unicorn';
import { defineConfig, globalIgnores } from 'eslint/config';
// Rules that are still active in ESLint (not migrated to oxlint or oxfmt)
const ACTIVE_RULES = {
'no-return-await': 'off',
'lodash/import-scope': [2, 'method'],
'unicorn/better-regex': 'error',
'unicorn/prevent-abbreviations': [
'error',
{
extendDefaultReplacements: false,
replacements: {
e: {
error: true,
event: true,
},
},
},
],
};
// Rules not auto-detected by eslint-plugin-oxlint:
// - oxfmt handles these (not in .oxlintrc.json)
// - type-aware TS rules (eslint-plugin-oxlint doesn't read type-aware overrides)
// - @next/next/no-img-element (set to 'off' in oxlint, so the plugin skips it)
const MIGRATED_RULES_MANUAL = {
'prettier/prettier': 'off',
'import/order': 'off',
'prefer-promise-reject-errors': 'off',
'@typescript-eslint/await-thenable': 'off',
'@typescript-eslint/no-confusing-void-expression': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-for-in-array': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/only-throw-error': 'off',
'@typescript-eslint/prefer-includes': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/return-await': 'off',
'@next/next/no-img-element': 'off',
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
};
export default defineConfig([
globalIgnores([
'**/.cache',
'**/.next/',
'**/.swc/',
'**/.wrangler/',
'**/.worker-test/',
'**/.vale',
'**/node_modules',
'**/out',
'**/public',
'pages/versions/latest',
'scripts/generate-llms/talks.js',
'types/global.d.ts',
'README.md',
'next-env.d.ts',
]),
universeWebConfig,
universeNodeConfig,
universeTypescriptAnalysisConfig,
// Auto-disable ESLint rules that oxlint handles (reads .oxlintrc.json)
// Filter out MDX ignore since ESLint still needs to lint MDX via eslint-plugin-mdx
...oxlint
.buildFromOxlintConfigFile('./.oxlintrc.json')
.map(c => (c.ignores ? { ...c, ignores: c.ignores.filter(p => p !== '**/*.{md,mdx}') } : c)),
// Manual overrides for rules the auto plugin misses
{
rules: MIGRATED_RULES_MANUAL,
},
// Overrides needed to make flat config rules work
{
settings: {
'import/resolver': {
typescript: { project: './tsconfig.json' },
},
},
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
// TypeScript files configuration
{
files: ['**/*.ts', '**/*.tsx', '**/*.d.ts'],
plugins: {
lodash,
unicorn,
},
rules: {
...ACTIVE_RULES,
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'typeLike', format: ['PascalCase'] },
{ selector: 'enumMember', format: ['UPPER_CASE'] },
{
selector: ['variable', 'parameter'],
modifiers: ['destructured'],
format: null,
},
{
selector: ['objectLiteralProperty', 'objectLiteralMethod'],
format: null,
},
{
selector: 'typeProperty',
format: ['camelCase', 'snake_case', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allowSingleOrDouble',
},
{
selector: 'default',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: ['function', 'variable', 'method'],
format: ['camelCase'],
modifiers: ['async'],
leadingUnderscore: 'allow',
suffix: ['Async'],
filter: {
regex: 'getServerSideProps',
match: false,
},
},
],
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'react/no-this-in-sfc': 'off',
'react/no-unescaped-entities': 'off',
'no-restricted-properties': [
'error',
{
object: 'it',
property: 'only',
message: 'it.only should not be committed to main.',
},
{
object: 'test',
property: 'only',
message: 'test.only should not be committed to main.',
},
{
object: 'describe',
property: 'only',
message: 'describe.only should not be committed to main.',
},
],
},
},
// JavaScript/Node files configuration
{
files: ['**/*.js', '**/*.cjs'],
plugins: {
lodash,
unicorn,
},
extends: [universeNodeConfig],
rules: {
...ACTIVE_RULES,
...MIGRATED_RULES_MANUAL,
...Object.fromEntries(
oxlint
.buildFromOxlintConfigFile('./.oxlintrc.json')
.flatMap(c => Object.entries(c.rules ?? {}))
),
},
},
// MDX configuration
{
...mdx.flat,
files: ['**/*.mdx'],
languageOptions: {
...mdx.flat.languageOptions,
parserOptions: { extensions: ['.js', '.md', '.mdx'] },
},
rules: {
...mdx.flat.rules,
'import/no-unresolved': 'error',
'no-unused-vars': ['error', { vars: 'all', args: 'none', ignoreRestSiblings: true }],
'no-unused-expressions': 'off',
'no-useless-escape': 'off',
'no-irregular-whitespace': 'off',
'react/self-closing-comp': 'off',
},
},
]);