@polyv/eslint-config 0.7.0-beta.1 → 0.7.0

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/README.md CHANGED
@@ -1,41 +1,19 @@
1
1
  # 保利威前端工程 ESLint 通用配置
2
2
 
3
- ## 用法
3
+ ## 安装和使用
4
4
 
5
- ### 安装
5
+ 确保 Node.js 版本符合 **^20.10.0**(未测试其他版本的可用性),运行 npm 命令安装:
6
6
 
7
7
  ```bash
8
8
  npm install @polyv/eslint-config --save-dev
9
9
  ```
10
10
 
11
- 此外,根据工程使用的技术栈,还需要安装以下依赖:
12
-
13
- | 依赖 | 版本要求 | 纯 JS 工程 | 纯 TS 工程 | Vue.js 工程(JS) |
14
- | --- | --- | --- | --- | --- |
15
- | eslint | >=8.0.0 | √ | √ | √ |
16
- | eslint-config-standard | >=17.0.0 | √ | √ | √ |
17
- | eslint-plugin-n | >=15.7.0 | √ | √ | √ |
18
- | eslint-plugin-import | >= 2.0.0 | √ | √ | √ |
19
- | eslint-plugin-promise | >= 6.1.0 | √ | √ | √ |
20
- | eslint-plugin-sonarjs | >= 0.18.0 | √ | √ | √ |
21
- | @babel/core | >=7.19.0 | √ | | √ |
22
- | @babel/eslint-parser | >=7.19.0 | √ | | √ |
23
- | typescript | >=4.0.0 | | √ | |
24
- | @typescript-eslint/eslint-plugin | >=5.0.0 | | √ | |
25
- | @typescript-eslint/parser | >=5.0.0 | | √ |
26
- | eslint-import-resolver-typescript | >=3.5.0 | | √ | |
27
- | eslint-plugin-vue | >=9.0.0 | | | √ |
28
- | vue-eslint-parser | >=9.0.0 | | | √ |
29
- | @vue/eslint-config-standard | >=8.0.0 | | | √ |
30
-
31
- ### 调用
32
-
33
- 创建 `.eslintrc.js`(一般在工程根目录下创建),并配置 `extends` 字段:
11
+ 在项目中创建 `.eslintrc.js`(一般在根目录下创建),根据工程的开发语言和框架配置 `extends` 字段:
34
12
 
35
13
  ```javascript
36
14
  /* eslint-env node */
37
15
 
38
- // 纯 JS 工程的配置
16
+ // 纯 JavaScript 工程的配置
39
17
  module.exports = {
40
18
  root: true,
41
19
  extends: [
@@ -47,7 +25,7 @@ module.exports = {
47
25
  ```javascript
48
26
  /* eslint-env node */
49
27
 
50
- // 纯 TS 工程的配置
28
+ // 纯 TypeScript 工程的配置
51
29
  module.exports = {
52
30
  root: true,
53
31
  extends: [
@@ -60,24 +38,37 @@ module.exports = {
60
38
  ```javascript
61
39
  /* eslint-env node */
62
40
 
63
- // Vue.js 工程(JS)的配置
41
+ // Vue.js 2.x 工程(JavaScript)的配置
64
42
  module.exports = {
65
43
  root: true,
66
44
  extends: [
67
- './node_modules/@polyv/eslint-config/lib/for-vue'
45
+ './node_modules/@polyv/eslint-config/lib/for-vue2-js'
68
46
  ]
69
47
  };
70
48
  ```
71
49
 
72
50
  ## 注意点
73
51
 
52
+ ### 严格模式
53
+
54
+ 部分规则在严格模式下(环境变量 `STRICT_LINT` 不为 `false` 时),告警级别为错误,其他情况为警告。这些规则包括:
55
+
56
+ - sonarjs/no-nested-template-literals
57
+ - @typescript-eslint/naming-convention
58
+ - vue/custom-event-name-casing
59
+ - vue/no-mutating-props
60
+ - vue/multi-word-component-names
61
+ - vue/attribute-hyphenation
62
+ - vue/v-on-event-hyphenation
63
+
74
64
  ### 生产环境构建的差异
75
65
 
76
- 部分规则在 `NODE_ENV` 为 `production` 时,告警级别为错误,其他情况下为警告。这些规则包括:
66
+ 部分规则在环境变量 `NODE_ENV` 为 `production` 时,告警级别为错误,其他情况下为警告。这些规则包括:
77
67
 
78
68
  - no-debugger
79
69
  - no-unused-vars
80
70
  - no-constant-condition
81
71
  - no-empty
72
+ - sonarjs/no-duplicate-string
82
73
  - @typescript-eslint/no-unused-vars
83
74
  - @typescript-eslint/explicit-module-boundary-types
package/lib/for-js.js CHANGED
@@ -2,7 +2,10 @@
2
2
  * JavaScript 验证规则(基础规则)。
3
3
  */
4
4
 
5
- const { devWarnProdError } = require('./util');
5
+ const {
6
+ devWarnProdError,
7
+ strictErrorOtherwiseWarn
8
+ } = require('./util');
6
9
 
7
10
  module.exports = {
8
11
  parser: '@babel/eslint-parser',
@@ -73,9 +76,9 @@ module.exports = {
73
76
  'promise/prefer-await-to-then': 'warn',
74
77
 
75
78
  'sonarjs/cognitive-complexity': ['error', 20],
76
- 'sonarjs/no-duplicate-string': ['error', { threshold: 5 }],
79
+ 'sonarjs/no-duplicate-string': [devWarnProdError, { threshold: 5 }],
77
80
  'sonarjs/prefer-single-boolean-return': 'off',
78
81
  'sonarjs/no-collection-size-mischeck': 'off',
79
- 'sonarjs/no-nested-template-literals': 'warn'
82
+ 'sonarjs/no-nested-template-literals': strictErrorOtherwiseWarn
80
83
  }
81
84
  };
package/lib/for-ts.js CHANGED
@@ -2,7 +2,10 @@
2
2
  * TypeScript 工程的附加验证规则。
3
3
  */
4
4
 
5
- const { devWarnProdError } = require('./util');
5
+ const {
6
+ devWarnProdError,
7
+ strictErrorOtherwiseWarn
8
+ } = require('./util');
6
9
 
7
10
  module.exports = {
8
11
  overrides: [{
@@ -12,8 +15,6 @@ module.exports = {
12
15
  'plugin:import/typescript'
13
16
  ],
14
17
  rules: {
15
- '@typescript-eslint/no-explicit-any': 'warn',
16
-
17
18
  semi: 'off',
18
19
  '@typescript-eslint/semi': ['error', 'always'],
19
20
 
@@ -53,6 +54,7 @@ module.exports = {
53
54
  asyncArrow: 'always'
54
55
  }],
55
56
 
57
+ '@typescript-eslint/no-explicit-any': 'warn',
56
58
  '@typescript-eslint/no-empty-function': 'off',
57
59
  '@typescript-eslint/no-empty-interface': 'off',
58
60
  '@typescript-eslint/type-annotation-spacing': ['error', {
@@ -66,7 +68,7 @@ module.exports = {
66
68
  }
67
69
  }],
68
70
  '@typescript-eslint/explicit-module-boundary-types': devWarnProdError,
69
- '@typescript-eslint/naming-convention': ['warn', {
71
+ '@typescript-eslint/naming-convention': [strictErrorOtherwiseWarn, {
70
72
  selector: 'enumMember',
71
73
  format: ['UPPER_CASE']
72
74
  }, {
@@ -2,6 +2,7 @@
2
2
  * Vue.js 工程的验证规则。
3
3
  */
4
4
 
5
+ const { strictErrorOtherwiseWarn } = require('./util');
5
6
  const jsConfig = require('./for-js');
6
7
 
7
8
  module.exports = Object.assign({}, jsConfig, {
@@ -23,7 +24,9 @@ module.exports = Object.assign({}, jsConfig, {
23
24
  void: 'always',
24
25
  normal: 'never',
25
26
  component: 'always'
26
- }
27
+ },
28
+ svg: 'always',
29
+ math: 'always'
27
30
  }],
28
31
  'vue/no-v-html': 'off',
29
32
  'vue/max-attributes-per-line': ['error', {
@@ -31,14 +34,12 @@ module.exports = Object.assign({}, jsConfig, {
31
34
  multiline: 1
32
35
  }],
33
36
  'vue/singleline-html-element-content-newline': 'off',
34
-
35
- // 为兼容以前代码而设为 warn
36
- 'vue/custom-event-name-casing': ['warn', 'kebab-case'],
37
- 'vue/no-mutating-props': 'warn',
38
- 'vue/multi-word-component-names': ['warn', {
39
- ignores: ['index', 'Index']
37
+ 'vue/custom-event-name-casing': [strictErrorOtherwiseWarn, 'kebab-case'],
38
+ 'vue/no-mutating-props': strictErrorOtherwiseWarn,
39
+ 'vue/multi-word-component-names': [strictErrorOtherwiseWarn, {
40
+ ignores: ['index', 'Index', 'default', 'Default']
40
41
  }],
41
- 'vue/attribute-hyphenation': ['warn', 'always'],
42
- 'vue/v-on-event-hyphenation': ['warn', 'always']
42
+ 'vue/attribute-hyphenation': [strictErrorOtherwiseWarn, 'always'],
43
+ 'vue/v-on-event-hyphenation': [strictErrorOtherwiseWarn, 'always']
43
44
  }
44
45
  });
package/lib/util.js CHANGED
@@ -1 +1,7 @@
1
- exports.devWarnProdError = process.env.NODE_ENV === 'production' ? 'error' : 'warn';
1
+ exports.devWarnProdError = process.env.NODE_ENV === 'production'
2
+ ? 'error'
3
+ : 'warn';
4
+
5
+ exports.strictErrorOtherwiseWarn = process.env.STRICT_LINT !== 'false'
6
+ ? 'error'
7
+ : 'warn';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/eslint-config",
3
- "version": "0.7.0-beta.1",
3
+ "version": "0.7.0",
4
4
  "description": "Standard ESLint configuration for Polyv projects.",
5
5
  "keywords": [
6
6
  "polyv",
@@ -10,7 +10,7 @@
10
10
  "homepage": "https://www.polyv.net/",
11
11
  "license": "MIT",
12
12
  "engines": {
13
- "node": ">=20.0.0"
13
+ "node": "^20.10.0"
14
14
  },
15
15
  "dependencies": {
16
16
  "@babel/core": "^7.24.9",