generated from mengxinssfd/lib-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.js
166 lines (157 loc) · 4.54 KB
/
eslint.config.js
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
const perfectionistRecommended = require('eslint-plugin-perfectionist/configs/recommended-line-length');
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
const perfectionist = require('eslint-plugin-perfectionist');
const prettier = require('eslint-plugin-prettier');
const tsEslint = require('typescript-eslint');
const jsdoc = require('eslint-plugin-jsdoc');
// const eslint = require('@eslint/js');
//const { FlatCompat } = require('@eslint/eslintrc');
//const compat = new FlatCompat({
// baseDirectory: __dirname
//});
const DOMGlobals = ['window', 'document'];
const NodeGlobals = ['module', 'require'];
const banConstEnum = {
message: 'Please use non-const enums. This project automatically inlines enums.',
selector: 'TSEnumDeclaration[const=true]',
};
module.exports = tsEslint.config(
{
rules: {
'perfectionist/sort-imports': [
'error',
{
'newlines-between': 'never',
type: 'line-length',
order: 'desc',
groups: [],
},
],
// Enforce the use of 'import type' for importing types
'@typescript-eslint/consistent-type-imports': [
'error',
{
fixStyle: 'inline-type-imports',
disallowTypeAnnotations: false,
},
],
// 优先使用 interface 而不是 type
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
// most of the codebase are expected to be env agnostic
'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
'@typescript-eslint/no-import-type-side-effects': 'error',
// code to indicate intentional type errors, improving code clarity and maintainability.
'@typescript-eslint/prefer-ts-expect-error': 'error',
// This rule enforces the preference for using '@ts-expect-error' comments in TypeScript
'no-restricted-syntax': ['error', banConstEnum],
'perfectionist/sort-exports': 'off',
'no-debugger': 'error',
'sort-imports': 'off',
// 禁止 == 判断
eqeqeq: 'error',
},
extends: [
// eslint.configs.recommended,
tsEslint.configs.base,
eslintPluginPrettierRecommended,
perfectionistRecommended,
jsdoc.configs['flat/recommended'],
],
plugins: {
// 'import-x': importX,
perfectionist,
prettier,
},
files: ['**/*.js', '**/*.ts', '**/*.tsx'],
},
// tests, no restrictions (runs in Node / Vitest with jsdom)
{
rules: {
'no-restricted-globals': 'off',
'no-restricted-syntax': 'off',
'no-console': 'off',
},
files: ['**/__tests__/**', 'packages/dts-test/**'],
languageOptions: {
globals: {},
},
plugins: {},
},
// JavaScript files
{
rules: {
// We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself.
'no-unused-vars': ['error', { args: 'none', vars: 'all' }],
},
files: ['*.js'],
},
{
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'jsdoc/require-jsdoc': 'off',
eqeqeq: 'off',
},
files: ['**/__tests__/**'],
},
{
rules: {
'@typescript-eslint/no-var-requires': 'off',
'jsdoc/require-jsdoc': 'off',
eqeqeq: 'off',
},
files: ['**/scripts/**.[jt]s', 'rollup.config.js'],
},
// Node scripts
{
rules: {
'no-restricted-syntax': ['error', banConstEnum],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'no-restricted-globals': 'off',
'jsdoc/require-jsdoc': 'off',
'no-console': 'off',
'no-undef': 'off',
},
files: [
'eslint.config.js',
'rollup*.config.js',
'scripts/**',
'./*.{js,ts}',
'packages/*/*.js',
'.prettierrc.js',
'jest.config.js',
'commitlint.config.js',
],
},
{
ignores: [
'*.sh',
'node_modules',
'*.md',
'*.woff',
'*.ttf',
'.vscode',
'.idea',
'dist',
'/public',
'/docs',
'.husky',
'.local',
'/bin',
'.eslintrc.js',
'prettier.config.js',
'/src/mock/*',
'coverage',
'.github',
'pnpm-lock.yaml',
'.output',
'*.d.ts',
'temp',
'docs-html',
],
},
);