@polyv/eslint-config 0.5.0-beta.1 → 0.6.0-beta.2

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
@@ -2,25 +2,41 @@
2
2
 
3
3
  ## 用法
4
4
 
5
- ### 安装配置
5
+ ### 安装
6
6
 
7
7
  ```bash
8
8
  npm install @polyv/eslint-config --save-dev
9
9
  ```
10
10
 
11
- ### 调用配置
11
+ 此外,根据工程使用的技术栈,还需要安装以下依赖:
12
+
13
+ | 依赖 | 版本要求 | 纯 JS 工程 | 纯 TS 工程 | Vue.js 工程(JS) |
14
+ | --- | --- | --- | --- | --- |
15
+ | eslint | >=8.0.0 | √ | √ | √ |
16
+ | eslint-plugin-import | >= 2.0.0 | √ | √ | √ |
17
+ | eslint-plugin-promise | >= 6.1.0 | √ | √ | √ |
18
+ | eslint-plugin-sonarjs | >= 0.18.0 | √ | √ | √ |
19
+ | @babel/core | >=7.19.0 | √ | | √ |
20
+ | @babel/eslint-parser | >=7.19.0 | √ | | √ |
21
+ | typescript | >=4.0.0 | | √ | |
22
+ | @typescript-eslint/eslint-plugin | >=5.0.0 | | √ | |
23
+ | @typescript-eslint/parser | >=5.0.0 | | √ |
24
+ | eslint-plugin-vue | >=9.0.0 | | | √ |
25
+ | vue-eslint-parser | >=9.0.0 | | | √ |
26
+ | @vue/eslint-config-standard | >=7.0.0 | | | √ |
27
+
28
+ ### 调用
12
29
 
13
30
  创建 `.eslintrc.js`(一般在工程根目录下创建),并配置 `extends` 字段:
14
31
 
15
32
  ```javascript
16
33
  /* eslint-env node */
17
34
 
18
- // TypeScript 工程的配置
35
+ // JS 工程的配置
19
36
  module.exports = {
20
37
  root: true,
21
38
  extends: [
22
- './node_modules/@polyv/eslint-config/lib/for-js',
23
- './node_modules/@polyv/eslint-config/lib/for-ts'
39
+ './node_modules/@polyv/eslint-config/lib/for-js'
24
40
  ]
25
41
  };
26
42
  ```
@@ -28,24 +44,37 @@ module.exports = {
28
44
  ```javascript
29
45
  /* eslint-env node */
30
46
 
31
- // Vue.js 工程(不含 TypeScript)的配置
47
+ // TS 工程的配置
32
48
  module.exports = {
33
49
  root: true,
34
50
  extends: [
35
- './node_modules/@polyv/eslint-config/lib/for-vue'
51
+ './node_modules/@polyv/eslint-config/lib/for-js',
52
+ './node_modules/@polyv/eslint-config/lib/for-ts'
36
53
  ]
37
54
  };
38
55
  ```
39
56
 
40
-
41
57
  ```javascript
42
58
  /* eslint-env node */
43
59
 
44
- // JavaScript 工程的配置
60
+ // Vue.js 工程(JS)的配置
45
61
  module.exports = {
46
62
  root: true,
47
63
  extends: [
48
- './node_modules/@polyv/eslint-config/lib/for-js'
64
+ './node_modules/@polyv/eslint-config/lib/for-vue'
49
65
  ]
50
66
  };
51
- ```
67
+ ```
68
+
69
+ ## 注意点
70
+
71
+ ### 生产环境构建的差异
72
+
73
+ 部分规则在 `NODE_ENV` 为 `production` 时,告警级别为错误,其他情况下为警告。这些规则包括:
74
+
75
+ - no-debugger
76
+ - no-unused-vars
77
+ - no-constant-condition
78
+ - no-empty
79
+ - @typescript-eslint/no-unused-vars
80
+ - @typescript-eslint/explicit-module-boundary-types
package/lib/for-js.js CHANGED
@@ -21,7 +21,8 @@ module.exports = {
21
21
  ],
22
22
  extends: [
23
23
  'eslint:recommended',
24
- 'plugin:sonarjs/recommended',
24
+ 'plugin:import/recommended',
25
+ 'plugin:sonarjs/recommended'
25
26
  ],
26
27
  rules: {
27
28
  'no-debugger': devWarnProdError,
@@ -109,6 +110,7 @@ module.exports = {
109
110
  'no-lonely-if': 'off',
110
111
  'curly': ['error', 'multi-line'],
111
112
  'wrap-iife': ['error', 'inside'],
113
+ 'import/no-unresolved': 'off',
112
114
 
113
115
  // ES6
114
116
  'no-var': 'error',
@@ -119,17 +121,13 @@ module.exports = {
119
121
  'no-template-curly-in-string': 'off',
120
122
  'arrow-spacing': 'error',
121
123
  'no-confusing-arrow': 'error',
122
- 'import/order': 'off',
123
- 'unicorn/prefer-includes': 'off',
124
124
  'promise/prefer-await-to-then': 'error',
125
125
 
126
- // Node
127
- 'node/no-callback-literal': 'off',
128
-
129
126
  // SonarJS
130
127
  'sonarjs/cognitive-complexity': ['error', 18],
131
128
  'sonarjs/no-duplicate-string': ['error', 5],
132
129
  'sonarjs/prefer-single-boolean-return': 'off',
133
- 'sonarjs/no-collection-size-mischeck': 'off'
130
+ 'sonarjs/no-collection-size-mischeck': 'off',
131
+ 'sonarjs/no-nested-template-literals': 'warn'
134
132
  }
135
133
  };
package/lib/for-ts.js CHANGED
@@ -26,6 +26,8 @@ module.exports = {
26
26
  }],
27
27
  '@typescript-eslint/comma-spacing': ['error'],
28
28
  '@typescript-eslint/no-duplicate-imports': ['error'],
29
+ '@typescript-eslint/no-empty-function': 'off',
30
+ '@typescript-eslint/no-empty-interface': 'off',
29
31
  '@typescript-eslint/type-annotation-spacing': ['error', {
30
32
  after: true,
31
33
  before: false,
@@ -46,7 +48,7 @@ module.exports = {
46
48
  'classes': false,
47
49
  'variables': true
48
50
  }],
49
- '@typescript-eslint/explicit-module-boundary-types': ['error']
51
+ '@typescript-eslint/explicit-module-boundary-types': devWarnProdError
50
52
  }
51
53
  }]
52
54
  };
package/lib/for-vue.js CHANGED
@@ -35,7 +35,9 @@ module.exports = Object.assign({}, jsConfig, {
35
35
  // 为兼容以前代码而设为 warn
36
36
  'vue/custom-event-name-casing': ['warn', 'kebab-case'],
37
37
  'vue/no-mutating-props': 'warn',
38
- 'vue/multi-word-component-names': 'warn',
38
+ 'vue/multi-word-component-names': ['warn', {
39
+ ignores: ['index', 'Index']
40
+ }],
39
41
  'vue/attribute-hyphenation': ['warn', 'always'],
40
42
  'vue/v-on-event-hyphenation': ['warn', 'always']
41
43
  }
package/package.json CHANGED
@@ -1,30 +1,41 @@
1
1
  {
2
2
  "name": "@polyv/eslint-config",
3
- "version": "0.5.0-beta.1",
3
+ "version": "0.6.0-beta.2",
4
4
  "description": "Standard ESLint configuration for Polyv projects.",
5
- "keywords": ["polyv", "eslint", "config"],
5
+ "keywords": [
6
+ "polyv",
7
+ "eslint",
8
+ "config"
9
+ ],
6
10
  "homepage": "https://www.polyv.net/",
7
11
  "license": "MIT",
8
- "dependencies": {
9
- "@babel/eslint-parser": "^7.19.1",
10
- "@typescript-eslint/eslint-plugin": "^5.51.0",
11
- "@typescript-eslint/parser": "^5.51.0",
12
- "@vue/eslint-config-standard": "^6.1.0",
13
- "eslint-plugin-import": "^2.27.5",
14
- "eslint-plugin-node": "^11.1.0",
15
- "eslint-plugin-promise": "^6.1.1",
16
- "eslint-plugin-sonarjs": "^0.18.0",
17
- "eslint-plugin-vue": "^9.9.0",
18
- "vue-eslint-parser": "^9.1.0"
19
- },
20
12
  "peerDependencies": {
21
13
  "@babel/core": ">=7.19.0",
14
+ "@babel/eslint-parser": ">=7.19.0",
15
+ "@typescript-eslint/eslint-plugin": ">=5.0.0",
16
+ "@typescript-eslint/parser": ">=5.0.0",
17
+ "@vue/eslint-config-standard": ">=7.0.0",
22
18
  "eslint": ">=8.0.0",
23
- "typescript": ">=4.0.0"
19
+ "eslint-plugin-import": ">=2.0.0",
20
+ "eslint-plugin-node": ">=11.1.0",
21
+ "eslint-plugin-promise": ">=6.1.0",
22
+ "eslint-plugin-sonarjs": ">=0.18.0",
23
+ "eslint-plugin-vue": ">=9.0.0",
24
+ "typescript": ">=4.0.0",
25
+ "vue-eslint-parser": ">=9.0.0"
24
26
  },
25
27
  "devDependencies": {
26
- "@babel/core": "^7.19.6",
27
- "eslint": "^8.33.0",
28
- "typescript": "^4.9.5"
28
+ "@babel/core": "^7.21.4",
29
+ "@babel/eslint-parser": "^7.21.3",
30
+ "@typescript-eslint/eslint-plugin": "^5.59.1",
31
+ "@typescript-eslint/parser": "^5.59.1",
32
+ "@vue/eslint-config-standard": "^8.0.1",
33
+ "eslint": "^8.39.0",
34
+ "eslint-plugin-import": "^2.27.5",
35
+ "eslint-plugin-promise": "^6.1.1",
36
+ "eslint-plugin-sonarjs": "^0.19.0",
37
+ "eslint-plugin-vue": "^9.11.0",
38
+ "typescript": "^5.0.4",
39
+ "vue-eslint-parser": "^9.1.1"
29
40
  }
30
41
  }