@blueking/eslint-config-bk 3.0.0-beta.3 → 3.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tencent/base.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Tencent is pleased to support the open source community by making
3
3
  * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
4
4
  *
5
- * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
5
+ * Copyright (C) 2021 Tencent. All rights reserved.
6
6
  *
7
7
  * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
8
8
  *
@@ -23,27 +23,241 @@
23
23
  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
24
  * IN THE SOFTWARE.
25
25
  */
26
- const js = require('@eslint/js');
27
- const globals = require('globals');
28
- const importPlugin = require('eslint-plugin-import');
26
+ import importPlugin from 'eslint-plugin-import';
27
+ import oxlint from 'eslint-plugin-oxlint';
28
+ import simpleImportSort from 'eslint-plugin-simple-import-sort';
29
+ import globals from 'globals';
29
30
 
30
- // base
31
- module.exports = [
31
+ import js from '@eslint/js';
32
+ import stylistic from '@stylistic/eslint-plugin';
33
+
34
+ const stylisticRules = {
35
+ '@stylistic/array-bracket-spacing': ['error', 'never'], // 数组括号内是否有空格
36
+ '@stylistic/function-call-spacing': ['error', 'never'], // 函数调用括号前空格
37
+ '@stylistic/arrow-parens': [
38
+ 'warn',
39
+ 'as-needed',
40
+ { requireForBlockBody: true },
41
+ ], // 箭头函数参数括号
42
+ '@stylistic/arrow-spacing': 'warn', // 箭头函数箭头前后空格
43
+ '@stylistic/block-spacing': 'error', // 代码块大括号内空格
44
+ '@stylistic/brace-style': 'error', // 大括号风格
45
+ '@stylistic/comma-dangle': ['warn', 'always-multiline'], // 末尾逗号
46
+ '@stylistic/comma-spacing': ['error', { before: false, after: true }], // 逗号前后空格
47
+ '@stylistic/comma-style': ['error', 'last'], // 逗号位置
48
+ '@stylistic/computed-property-spacing': ['warn', 'never'], // 计算属性括号内空格
49
+ '@stylistic/eol-last': ['error', 'always'], // 文件末尾换行
50
+ '@stylistic/function-paren-newline': ['warn', 'multiline'], // 函数参数括号换行
51
+ '@stylistic/generator-star-spacing': ['warn', { before: false, after: true }], // generator 星号空格
52
+ '@stylistic/implicit-arrow-linebreak': ['warn', 'beside'], // 箭头函数箭头换行
53
+ '@stylistic/indent': [
54
+ 'warn',
55
+ 2,
56
+ {
57
+ SwitchCase: 1,
58
+ VariableDeclarator: 1,
59
+ outerIIFEBody: 1,
60
+ FunctionDeclaration: { parameters: 1, body: 1 },
61
+ FunctionExpression: { parameters: 1, body: 1 },
62
+ CallExpression: { arguments: 1 },
63
+ ArrayExpression: 1,
64
+ ObjectExpression: 1,
65
+ ImportDeclaration: 1,
66
+ flatTernaryExpressions: false,
67
+ ignoredNodes: [
68
+ 'JSXElement',
69
+ 'JSXElement > *',
70
+ 'JSXAttribute',
71
+ 'JSXIdentifier',
72
+ 'JSXNamespacedName',
73
+ 'JSXMemberExpression',
74
+ 'JSXSpreadAttribute',
75
+ 'JSXExpressionContainer',
76
+ 'JSXOpeningElement',
77
+ 'JSXClosingElement',
78
+ 'JSXFragment',
79
+ 'JSXOpeningFragment',
80
+ 'JSXClosingFragment',
81
+ 'JSXText',
82
+ 'JSXEmptyExpression',
83
+ 'JSXSpreadChild',
84
+ ],
85
+ ignoreComments: false,
86
+ },
87
+ ], // 缩进风格
88
+ '@stylistic/key-spacing': 'error', // 对象键值冒号空格
89
+ '@stylistic/keyword-spacing': [
90
+ 'error',
91
+ {
92
+ overrides: {
93
+ if: { after: true },
94
+ for: { after: true },
95
+ while: { after: true },
96
+ else: { after: true },
97
+ },
98
+ },
99
+ ], // 关键字前后空格
100
+ '@stylistic/linebreak-style': ['warn', 'unix'], // 换行符风格
101
+ '@stylistic/max-len': [
102
+ 'error',
103
+ {
104
+ code: 120,
105
+ ignoreStrings: true,
106
+ ignoreUrls: true,
107
+ ignoreRegExpLiterals: true,
108
+ ignoreTemplateLiterals: true,
109
+ },
110
+ ], // 最大行长度
111
+ '@stylistic/newline-per-chained-call': ['warn', { ignoreChainWithDepth: 2 }], // 链式调用换行
112
+ '@stylistic/no-mixed-operators': [
113
+ 'error',
114
+ {
115
+ groups: [
116
+ ['%', '**'],
117
+ ['%', '+'],
118
+ ['%', '-'],
119
+ ['%', '*'],
120
+ ['%', '/'],
121
+ ['&', '|', '<<', '>>', '>>>'],
122
+ ['==', '!=', '===', '!=='],
123
+ ['&&', '||'],
124
+ ],
125
+ allowSamePrecedence: false,
126
+ },
127
+ ], // 禁止混用不同优先级操作符
128
+ '@stylistic/no-multiple-empty-lines': 'error', // 禁止多行空行
129
+ '@stylistic/no-trailing-spaces': 'error', // 禁止行尾空格
130
+ '@stylistic/object-curly-spacing': ['warn', 'always'], // 对象大括号内空格
131
+ '@stylistic/operator-linebreak': [
132
+ 'error',
133
+ 'before',
134
+ { overrides: { '=': 'none' } },
135
+ ], // 操作符换行
136
+ '@stylistic/padded-blocks': ['error', 'never'], // 代码块内空行
137
+ '@stylistic/quote-props': ['error', 'as-needed', { keywords: false }], // 属性名加引号
138
+ '@stylistic/quotes': ['warn', 'single', { allowTemplateLiterals: false }], // 字符串引号
139
+ '@stylistic/semi': ['error', 'always'], // 语句分号
140
+ '@stylistic/space-before-blocks': 'error', // 代码块前空格
141
+ '@stylistic/space-before-function-paren': [
142
+ 'error',
143
+ { anonymous: 'always', named: 'never', asyncArrow: 'always' },
144
+ ], // 函数括号前空格
145
+ '@stylistic/space-in-parens': ['error', 'never'], // 括号内空格
146
+ '@stylistic/space-infix-ops': 'error', // 操作符两边空格
147
+ '@stylistic/spaced-comment': ['error', 'always'], // 注释前空格
148
+ '@stylistic/template-curly-spacing': ['error', 'never'], // 模板字符串花括号内空格
149
+ '@stylistic/wrap-iife': ['error', 'outside'], // IIFE 括号风格
150
+ };
151
+
152
+ const baseRules = {
153
+ ...js.configs.recommended.rules, // https://github.com/eslint/eslint/blob/main/packages/js/src/configs/eslint-recommended.js
154
+ 'array-callback-return': 'warn', // 数组回调必须有返回值
155
+ camelcase: ['error', { ignoreDestructuring: true, properties: 'never' }], // 驼峰命名
156
+ 'dot-notation': 'warn', // 点号访问对象属性
157
+ eqeqeq: ['warn', 'always'], // 强制全等
158
+ 'func-style': ['off', 'expression'], // 函数风格
159
+ 'new-cap': [
160
+ 'error',
161
+ {
162
+ newIsCap: true,
163
+ newIsCapExceptions: [],
164
+ capIsNew: false,
165
+ capIsNewExceptions: ['Immutable.Map', 'Immutable.Set', 'Immutable.List'],
166
+ properties: false,
167
+ },
168
+ ], // 构造函数大写
169
+ 'no-array-constructor': ['error'], // 禁止 Array 构造函数
170
+ 'no-else-return': ['warn', { allowElseIf: false }], // return 后禁止 else
171
+ 'no-eval': 'error', // 禁止 eval
172
+ 'no-iterator': 'warn', // 禁止 __iterator__
173
+ 'no-loop-func': 'error', // 禁止循环内定义函数
174
+ 'no-multi-assign': 'error', // 禁止链式赋值
175
+ 'no-nested-ternary': 'warn', // 禁止嵌套三元
176
+ 'no-new-func': 'error', // 禁止 Function 构造函数
177
+ 'no-new-object': 'error', // 禁止 Object 构造函数
178
+ 'no-new-wrappers': 'warn', // 禁止包装类
179
+ 'no-param-reassign': [
180
+ 'warn',
181
+ {
182
+ props: true,
183
+ ignorePropertyModificationsFor: [
184
+ 'acc',
185
+ 'accumulator',
186
+ 'e',
187
+ 'ctx',
188
+ 'req',
189
+ 'request',
190
+ 'res',
191
+ 'response',
192
+ '$scope',
193
+ 'staticContext',
194
+ 'state',
195
+ ],
196
+ },
197
+ ], // 禁止参数重新赋值
198
+ 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], // 禁止 ++/--
199
+ 'no-restricted-properties': [
200
+ 'warn',
201
+ { object: 'Math', property: 'pow', message: 'Please use ** instand' },
202
+ ], // 限制属性
203
+ 'no-restricted-syntax': [
204
+ 'warn',
205
+ {
206
+ selector: 'ForInStatement',
207
+ message:
208
+ 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
209
+ },
210
+ {
211
+ selector: 'LabeledStatement',
212
+ message:
213
+ 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
214
+ },
215
+ {
216
+ selector: 'WithStatement',
217
+ message:
218
+ '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
219
+ },
220
+ ], // 限制语法
221
+ 'no-underscore-dangle': 'warn', // 禁止下划线变量
222
+ 'no-unused-vars': [
223
+ 'error',
224
+ {
225
+ argsIgnorePattern: '^_.*', // 忽略以下划线开头的参数
226
+ varsIgnorePattern: '^_.*', // 忽略以下划线开头的变量
227
+ },
228
+ ], // 禁止未使用变量
229
+ 'no-unneeded-ternary': 'warn', // 禁止不必要三元
230
+ 'no-useless-constructor': 'warn', // 禁止无用构造函数
231
+ 'no-var': 'error', // 禁止 var
232
+ 'object-shorthand': 'warn', // 对象简写
233
+ 'one-var': ['warn', 'never'], // 单行声明多个变量
234
+ 'prefer-arrow-callback': 'warn', // 优先箭头回调
235
+ 'prefer-const': [
236
+ 'error',
237
+ { destructuring: 'any', ignoreReadBeforeAssign: false },
238
+ ], // 优先 const
239
+ 'prefer-destructuring': [
240
+ 'warn',
241
+ {
242
+ VariableDeclarator: { array: false, object: true },
243
+ AssignmentExpression: { array: true, object: false },
244
+ },
245
+ { enforceForRenamedProperties: false },
246
+ ], // 优先解构
247
+ 'prefer-rest-params': 'warn', // 优先剩余参数
248
+ 'prefer-spread': 'warn', // 优先扩展运算符
249
+ 'prefer-template': 'error', // 优先模板字符串
250
+ radix: 'warn', // parseInt 必须指定基数
251
+ };
252
+
253
+ export default [
32
254
  {
33
- ignores: [
34
- 'dist',
35
- 'public',
36
- 'postcss.config.js',
37
- 'bk.config.js',
38
- 'paas-server',
39
- 'mock-server',
40
- 'node_modules',
41
- ],
255
+ ignores: ['**/node_modules/**'], // 排除 node_modules 下所有文件
42
256
  },
43
- importPlugin.flatConfigs.recommended,
44
257
  {
45
258
  languageOptions: {
46
259
  ecmaVersion: 'latest',
260
+ sourceType: 'module',
47
261
  globals: {
48
262
  document: 'readonly',
49
263
  window: 'readonly',
@@ -51,111 +265,52 @@ module.exports = [
51
265
  ...globals.browser,
52
266
  },
53
267
  },
268
+ plugins: {
269
+ '@stylistic': stylistic,
270
+ import: importPlugin,
271
+ 'simple-import-sort': simpleImportSort,
272
+ },
54
273
  rules: {
55
- ...js.configs.recommended.rules, // https://github.com/eslint/eslint/blob/main/packages/js/src/configs/eslint-recommended.js
56
- 'array-callback-return': 'warn', // 在数组方法的回调中强制执行 return 语句
57
- camelcase: ['error', { ignoreDestructuring: true, properties: 'never' }], // 强制实施驼峰命名约定
58
- 'dot-notation': 'warn', // 尽可能强制使用点表示法
59
- eqeqeq: ['warn', 'always'], // 需要使用 === 和 !==
60
- 'func-style': ['off', 'expression'], // 强制一致地使用分配给变量的函数声明或表达式
61
- 'new-cap': [
62
- 'error',
63
- {
64
- newIsCap: true,
65
- newIsCapExceptions: [],
66
- capIsNew: false,
67
- capIsNewExceptions: [
68
- 'Immutable.Map',
69
- 'Immutable.Set',
70
- 'Immutable.List',
71
- ],
72
- properties: false,
274
+ ...baseRules,
275
+ ...stylisticRules,
276
+ ...importPlugin.configs.recommended.rules,
277
+ 'simple-import-sort/exports': 'error',
278
+ 'import/first': 'error',
279
+ 'import/newline-after-import': 'error',
280
+ 'import/no-duplicates': 'error',
281
+ 'simple-import-sort/imports': ['error', {
282
+ groups: [
283
+ ['^[a-zA-Z]'],
284
+ ['^@'],
285
+ ['^@lib'],
286
+ ['^@service'],
287
+ ['^@model'],
288
+ ['^@hooks'],
289
+ ['^@components'],
290
+ ['^@views'],
291
+ ['^@\\w'],
292
+ ['^@router'],
293
+ ['^@utils'],
294
+ ['^@css'],
295
+ ['^@language'],
296
+ ['^\\.\\.'],
297
+ ['^\\.'],
298
+ ],
299
+ }],
300
+ },
301
+ settings: {
302
+ 'import/resolver': {
303
+ node: {
304
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.json'],
73
305
  },
74
- ], // 要求构造函数名称以大写字母开头
75
- 'no-array-constructor': ['error'], // 禁止数组构造函数
76
- 'no-else-return': ['warn', { allowElseIf: false }], // 不允许在 if 语句中的 return 语句后使用 else 块
77
- 'no-eval': 'error', // 不允许使用 eval()
78
- 'no-iterator': 'warn', // 禁止使用 __iterator__ 属性
79
- 'no-loop-func': 'error', // 禁止在循环语句中包含不安全引用的函数声明
80
- 'no-multi-assign': 'error', // 禁止使用链式赋值表达式
81
- 'no-nested-ternary': 'warn', // 不允许嵌套的三元表达式
82
- 'no-new-func': 'error', // 禁止使用 Function 对象使用新运算符
83
- 'no-new-object': 'error', // 不允许 Object 构造函数 // 替换 no-object-constructor。
84
- 'no-new-wrappers': 'warn', // 不允许使用 String、Number 和 Boolean 对象使用新运算符
85
- 'no-param-reassign': [
86
- 'warn',
87
- {
88
- props: true,
89
- ignorePropertyModificationsFor: [
90
- 'acc',
91
- 'accumulator',
92
- 'e',
93
- 'ctx',
94
- 'req',
95
- 'request',
96
- 'res',
97
- 'response',
98
- '$scope',
99
- 'staticContext',
100
- 'state',
306
+ alias: {
307
+ map: [
308
+ ['@', './src'],
101
309
  ],
310
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.json'],
102
311
  },
103
- ], // 不允许重新分配函数参数
104
- 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], // 不允许使用一元运算符 ++ 和 --
105
- 'no-restricted-properties': [
106
- 'warn',
107
- { object: 'Math', property: 'pow', message: 'Please use ** instand' },
108
- ], // 禁止对某些对象使用某些属性
109
- 'no-restricted-syntax': [
110
- 'warn',
111
- {
112
- selector: 'ForInStatement',
113
- message:
114
- 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
115
- },
116
- {
117
- selector: 'LabeledStatement',
118
- message:
119
- 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
120
- },
121
- {
122
- selector: 'WithStatement',
123
- message:
124
- '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
125
- },
126
- ], // 禁止指定语法
127
- 'no-underscore-dangle': 'warn', // 不允许标识符中出现悬空下划线
128
- 'no-unused-vars': [
129
- 'error',
130
- {
131
- argsIgnorePattern: '^_.*', // 忽略以下划线开头的参数
132
- varsIgnorePattern: '^_.*', // 忽略以下划线开头的变量
133
- },
134
- ], // 禁止未使用的变量
135
- 'no-unneeded-ternary': 'warn', // 当存在更简单的替代项时,不允许使用三元运算符
136
- 'no-useless-constructor': 'warn', // 不允许不必要的构造函数
137
- 'no-var': 'error', // 需要 let 或 const 而不是 var
138
- 'object-shorthand': 'warn', // 需要或禁止对象文本的方法和属性速记语法
139
- 'one-var': ['warn', 'never'], // 强制在函数中一起或单独声明变量
140
- 'prefer-arrow-callback': 'warn', // 要求使用箭头函数进行回调
141
- 'prefer-const': [
142
- 'error',
143
- { destructuring: 'any', ignoreReadBeforeAssign: false },
144
- ], // 要求对在声明后从不重新分配的变量进行 const 声明
145
- 'prefer-destructuring': [
146
- 'warn',
147
- {
148
- VariableDeclarator: { array: false, object: true },
149
- AssignmentExpression: { array: true, object: false },
150
- },
151
- { enforceForRenamedProperties: false },
152
- ], // 需要从数组和/或对象中解构
153
- 'prefer-rest-params': 'warn', // 需要 rest 参数而不是参数
154
- 'prefer-spread': 'warn', // 需要扩展运算符而不是 .apply()
155
- 'prefer-template': 'error', // 需要模板文本而不是字符串连接
156
- quotes: ['warn', 'single', { allowTemplateLiterals: false }], // 强制一致使用反引号、双引号或单引号
157
- radix: 'warn', // 在使用 parseInt() 时强制一致地使用 radix 参数
158
- semi: ['error', 'always'], // 需要或不允许使用分号代替 ASI
312
+ },
159
313
  },
160
314
  },
315
+ ...oxlint.buildFromOxlintConfigFile('./oxlint.config.js'),
161
316
  ];