Skip to content

Commit 338cebe

Browse files
committed
chore(eslint): up to v9
1 parent de6e01c commit 338cebe

File tree

3 files changed

+166
-68
lines changed

3 files changed

+166
-68
lines changed

.eslintignore

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

.eslintrc.js

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

eslint.config.js

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

0 commit comments

Comments
 (0)