Skip to content

Commit 79b0b61

Browse files
committed
chore(eslint): up to v9
1 parent 0d94225 commit 79b0b61

File tree

3 files changed

+160
-70
lines changed

3 files changed

+160
-70
lines changed

.eslintignore

Lines changed: 0 additions & 20 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

eslint.config.js

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
const perfectionistRecommended = require('eslint-plugin-perfectionist/configs/recommended-line-length');
2+
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
3+
const perfectionist = require('eslint-plugin-perfectionist');
4+
const prettier = require('eslint-plugin-prettier');
5+
const tsEslint = require('typescript-eslint');
6+
// const eslint = require('@eslint/js');
7+
//const { FlatCompat } = require('@eslint/eslintrc');
8+
9+
//const compat = new FlatCompat({
10+
// baseDirectory: __dirname
11+
//});
12+
13+
const DOMGlobals = ['window', 'document'];
14+
const NodeGlobals = ['module', 'require'];
15+
16+
const banConstEnum = {
17+
message: 'Please use non-const enums. This project automatically inlines enums.',
18+
selector: 'TSEnumDeclaration[const=true]',
19+
};
20+
21+
module.exports = tsEslint.config(
22+
{
23+
rules: {
24+
'perfectionist/sort-imports': [
25+
'error',
26+
{
27+
'newlines-between': 'never',
28+
type: 'line-length',
29+
order: 'desc',
30+
groups: [],
31+
},
32+
],
33+
// Enforce the use of 'import type' for importing types
34+
'@typescript-eslint/consistent-type-imports': [
35+
'error',
36+
{
37+
fixStyle: 'inline-type-imports',
38+
disallowTypeAnnotations: false,
39+
},
40+
],
41+
// 优先使用 interface 而不是 type
42+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
43+
// most of the codebase are expected to be env agnostic
44+
'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
45+
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
46+
47+
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
48+
'@typescript-eslint/no-import-type-side-effects': 'error',
49+
// code to indicate intentional type errors, improving code clarity and maintainability.
50+
'@typescript-eslint/prefer-ts-expect-error': 'error',
51+
// This rule enforces the preference for using '@ts-expect-error' comments in TypeScript
52+
'no-restricted-syntax': ['error', banConstEnum],
53+
'perfectionist/sort-exports': 'off',
54+
'no-debugger': 'error',
55+
'sort-imports': 'off',
56+
// 禁止 == 判断
57+
eqeqeq: 'error',
58+
},
59+
extends: [
60+
// eslint.configs.recommended,
61+
tsEslint.configs.base,
62+
eslintPluginPrettierRecommended,
63+
perfectionistRecommended,
64+
],
65+
plugins: {
66+
// 'import-x': importX,
67+
perfectionist,
68+
prettier,
69+
},
70+
files: ['**/*.js', '**/*.ts', '**/*.tsx'],
71+
},
72+
73+
// tests, no restrictions (runs in Node / Vitest with jsdom)
74+
{
75+
rules: {
76+
'no-restricted-globals': 'off',
77+
'no-restricted-syntax': 'off',
78+
'no-console': 'off',
79+
},
80+
files: ['**/__tests__/**', 'packages/dts-test/**'],
81+
languageOptions: {
82+
globals: {},
83+
},
84+
plugins: {},
85+
},
86+
87+
// JavaScript files
88+
{
89+
rules: {
90+
// We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself.
91+
'no-unused-vars': ['error', { args: 'none', vars: 'all' }],
92+
},
93+
files: ['*.js'],
94+
},
95+
{
96+
rules: {
97+
'@typescript-eslint/no-non-null-assertion': 'off',
98+
'@typescript-eslint/no-empty-function': 'off',
99+
'@typescript-eslint/ban-ts-comment': 'off',
100+
eqeqeq: 'off',
101+
},
102+
files: ['**/__tests__/**'],
103+
},
104+
{
105+
rules: {
106+
'@typescript-eslint/no-var-requires': 'off',
107+
eqeqeq: 'off',
108+
},
109+
files: ['**/scripts/**.[jt]s', 'rollup.config.js'],
110+
},
111+
112+
// Node scripts
113+
{
114+
rules: {
115+
'no-restricted-syntax': ['error', banConstEnum],
116+
'@typescript-eslint/no-var-requires': 'off',
117+
'@typescript-eslint/ban-ts-comment': 'off',
118+
'no-restricted-globals': 'off',
119+
'no-console': 'off',
120+
'no-undef': 'off',
121+
},
122+
files: [
123+
'eslint.config.js',
124+
'rollup*.config.js',
125+
'scripts/**',
126+
'./*.{js,ts}',
127+
'packages/*/*.js',
128+
'.prettierrc.js',
129+
'jest.config.js',
130+
'commitlint.config.js',
131+
],
132+
},
133+
134+
{
135+
ignores: [
136+
'*.sh',
137+
'node_modules',
138+
'*.md',
139+
'*.woff',
140+
'*.ttf',
141+
'.vscode',
142+
'.idea',
143+
'dist',
144+
'/public',
145+
'/docs',
146+
'.husky',
147+
'.local',
148+
'/bin',
149+
'.eslintrc.js',
150+
'prettier.config.js',
151+
'/src/mock/*',
152+
'coverage',
153+
'.github',
154+
'pnpm-lock.yaml',
155+
'.output',
156+
'*.d.ts',
157+
'temp',
158+
],
159+
},
160+
);

0 commit comments

Comments
 (0)