@houheaven/eslint-config-helper 3.1.0 → 3.2.1

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
@@ -38,6 +38,7 @@ pnpm add -D @houheaven/eslint-config-helper@next
38
38
  | configs.es6 | 校验 JS(Es6+)+ import 代码 | `.js` `.mjs` `.cjs` |
39
39
  | configs.typescript | 校验 TS + JS(Es6+)+ import 代码 | `.ts` |
40
40
  | configs.vue2 | 校验 Vue2 + JS(Es6+)+ import 代码 | `.vue` |
41
+ | configs.vue2Ts | 校验 Vue2 + TS + JS(Es6+)+ import 代码 | `.vue` |
41
42
  | configs.vue3 | 校验 Vue3 + JS(Es6+)+ import 代码 | `.vue` |
42
43
  | configs.vue3Ts | 校验 Vue3 + TS + JS(Es6+)+ import 代码 | `.vue` |
43
44
  | configs.reactJsx | 校验 React + JS(Es6+)+ import 代码 | `.jsx` |
@@ -52,6 +53,7 @@ pnpm add -D @houheaven/eslint-config-helper@next
52
53
  | supports.es6 | 校验 JS(Es6+)+ import 代码 | `.js` `.mjs` `.cjs` |
53
54
  | supports.typescript | 校验 TS + JS(Es6+)+ import 代码 | `.ts` |
54
55
  | supports.vue2 | 校验 Vue2 + JS(Es6+)+ import 代码 | `.vue` |
56
+ | supports.vue2Ts | 校验 Vue2 + TS + JS(Es6+)+ import 代码 | `.vue` |
55
57
  | supports.vue3 | 校验 Vue3 + JS(Es6+)+ import 代码 | `.vue` |
56
58
  | supports.vue3Ts | 校验 Vue3 + TS + JS(Es6+)+ import 代码 | `.vue` |
57
59
  | supports.reactJsx | 校验 React + JS(Es6+)+ import 代码 | `.jsx` |
@@ -120,6 +122,20 @@ export default [
120
122
  ];
121
123
  ```
122
124
 
125
+ ### Vue2 + TypeScript
126
+
127
+ 校验文件范围:`.vue` `.ts` `.js`
128
+
129
+ ```js
130
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
131
+
132
+ export default [
133
+ ...hhEslintConfigHelper.configs.es6,
134
+ ...hhEslintConfigHelper.configs.typescript,
135
+ ...hhEslintConfigHelper.configs.vue2Ts,
136
+ ];
137
+ ```
138
+
123
139
  ### Vue3
124
140
 
125
141
  校验文件范围:`.vue` `.js`
@@ -0,0 +1,65 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper/support-vue2-ts
4
+ // ----------------------------------------------------------
5
+ // - 解析 Vue 文件(Vue2 + TypeScript 语法)
6
+ // ==========================================================
7
+
8
+ import globals from "globals";
9
+ import pluginStylistic from "@stylistic/eslint-plugin";
10
+ import pluginTs from "@typescript-eslint/eslint-plugin";
11
+ import pluginVue from "eslint-plugin-vue";
12
+ import parserVue from "vue-eslint-parser";
13
+ import parserTs from "@typescript-eslint/parser";
14
+
15
+ const supportVue2Ts = {
16
+ plugins: {
17
+ "vue": pluginVue,
18
+ "@typescript-eslint": pluginTs,
19
+ "@stylistic": pluginStylistic,
20
+ },
21
+ languageOptions: {
22
+ parser: parserVue,
23
+ sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
24
+ ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
25
+ parserOptions: {
26
+ sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
27
+ ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
28
+ ecmaFeatures: {
29
+ jsx: true, // 启用 JSX 全局变量和作用域规则
30
+ },
31
+ // Vue 添加对 TypeScript 的支持
32
+ parser: parserTs,
33
+ extraFileExtensions: [".vue"],
34
+ project: [
35
+ "**/tsconfig.json",
36
+ "**/tsconfig.**.json",
37
+ ],
38
+ },
39
+ globals: {
40
+ ...globals.browser, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
41
+ ...globals.node, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
42
+ ...globals.commonjs, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
43
+ ...globals.es6, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
44
+ },
45
+ },
46
+ processor: "vue/vue",
47
+ rules: {
48
+ "indent": "off",
49
+ "max-len": "off",
50
+ "no-irregular-whitespace": "off",
51
+ // 禁止在 Vue 指定的版本上使用不支持的语法
52
+ // https://eslint.vuejs.org/rules/no-unsupported-features.html
53
+ "vue/no-unsupported-features": ["error", {
54
+ "version": "^2.6.0",
55
+ "ignores": [],
56
+ }],
57
+ // 禁止在 props 中使用保留关键字
58
+ // https://eslint.vuejs.org/rules/no-reserved-props.html
59
+ "vue/no-reserved-props": ["error", {
60
+ "vueVersion": 2,
61
+ }],
62
+ },
63
+ };
64
+
65
+ export default supportVue2Ts;
package/lib/vue2.js CHANGED
@@ -8,6 +8,7 @@ import utils from "@houheaven/eslint-config-helper-core";
8
8
  import supportEs6 from "./supports/support-es6.js";
9
9
  import supportImport from "./supports/support-import.js";
10
10
  import supportVue2 from "./supports/support-vue2.js";
11
+ import supportVue2Ts from "./supports/support-vue2-ts.js";
11
12
 
12
13
  // 基础配置
13
14
  const vueCommonConfig = {
@@ -46,6 +47,36 @@ const supportVue2Config = {
46
47
  },
47
48
  };
48
49
 
50
+ // 基础支持:校验 ES5、ES6、import、vue2-ts 规则
51
+ const supportVue2TsConfig = {
52
+ plugins: {
53
+ ...supportEs6.plugins,
54
+ ...supportImport.plugins,
55
+ ...supportVue2Ts.plugins,
56
+ },
57
+ languageOptions: {
58
+ ...supportEs6.languageOptions,
59
+ ...supportVue2Ts.languageOptions,
60
+ },
61
+ settings: {
62
+ ...supportImport.settings,
63
+ },
64
+ processor: supportVue2Ts.processor,
65
+ rules: {
66
+ // Eslint 基础规则
67
+ ...utils.rules.es5,
68
+ ...utils.rules.es6,
69
+ // eslint-plugin-import 规则
70
+ ...utils.rules.import,
71
+ // Vue2 规则
72
+ ...supportVue2Ts.rules,
73
+ ...utils.rules.vue,
74
+ ...utils.rules.vue2,
75
+ // @typescript-eslint/eslint-plugin 规则
76
+ ...utils.rules.typescript,
77
+ },
78
+ };
79
+
49
80
  // 预设配置:校验 vue2 文件的 ES5、ES6、import、vue2 规则
50
81
  const vue2Config = {
51
82
  name: "@houheaven/eslint-config-helper/vue2",
@@ -53,13 +84,24 @@ const vue2Config = {
53
84
  ...supportVue2Config,
54
85
  };
55
86
 
87
+ // 预设配置:校验 Vue2 + TypeScript 文件的 ES5、ES6、import、vue2-ts 规则
88
+ const vue2TsConfig = {
89
+ name: "@houheaven/eslint-config-helper/vue2-ts",
90
+ ...vueCommonConfig,
91
+ ...supportVue2TsConfig,
92
+ };
93
+
56
94
  export default {
57
95
  supports: {
58
96
  vue2: supportVue2Config,
97
+ vue2Ts: supportVue2TsConfig,
59
98
  },
60
99
  configs: {
61
100
  vue2: [
62
101
  vue2Config,
63
102
  ],
103
+ vue2Ts: [
104
+ vue2TsConfig,
105
+ ],
64
106
  },
65
107
  };
@@ -128,5 +128,21 @@ module.exports = {
128
128
  // ❌ 已废弃
129
129
  // https://zh-hans.eslint.org/docs/latest/rules/valid-jsdoc
130
130
  "valid-jsdoc": "off",
131
+
132
+ // 禁止冗余的括号
133
+ // https://zh-hans.eslint.org/docs/latest/rules/no-extra-parens
134
+ "no-extra-parens": ["warn", "all", {
135
+ conditionalAssign: false, // 允许在条件测试表达式中的赋值周围加上括号
136
+ returnAssign: false, // 允许在 return 语句中使用额外的小括号
137
+ nestedBinaryExpressions: false, // 允许在嵌套二进制表达式中使用额外的小括号
138
+ ternaryOperandBinaryExpressions: false, // 允许在三元运算符 ?: 的操作数周围添加额外的括号
139
+ ignoreJSX: "all", // 允许在没有/所有/多行/单行 JSX 组件周围使用额外的小括号,delegate to eslint-plugin-react
140
+ // enforceForArrowConditionals: false, // 废弃 - 允许在作为箭头函数主体的三元表达式周围添加小括号
141
+ enforceForSequenceExpressions: false, // 允许在序列表达式周围加上小括号
142
+ // enforceForNewInMemberExpressions: false, // 废弃 - 允许在成员表达式中的 new 表达式周围使用额外的小括号
143
+ enforceForFunctionPrototypeMethods: false, // 允许在函数表达式的即时 .call 和 .apply 方法调用周围以及同一上下文中的函数表达式周围添加括号
144
+ allowParensAfterCommentPattern: "", // 允许在匹配正则表达式的注释前面加上额外的括号
145
+ // nestedConditionalExpressions: false, // 允许在嵌套的条件表达式周围添加额外的小括号
146
+ }],
131
147
  },
132
148
  };
@@ -237,23 +237,6 @@ module.exports = {
237
237
  ignoreChainWithDepth: 4,
238
238
  }],
239
239
 
240
- // TODO
241
- // 禁止冗余的括号
242
- // https://zh-hans.eslint.org/docs/latest/rules/no-extra-parens
243
- "no-extra-parens": ["warn", "all", {
244
- conditionalAssign: false, // 允许在条件测试表达式中的赋值周围加上括号
245
- returnAssign: false, // 允许在 return 语句中使用额外的小括号
246
- nestedBinaryExpressions: false, // 允许在嵌套二进制表达式中使用额外的小括号
247
- ternaryOperandBinaryExpressions: false, // 允许在三元运算符 ?: 的操作数周围添加额外的括号
248
- ignoreJSX: "all", // 允许在没有/所有/多行/单行 JSX 组件周围使用额外的小括号,delegate to eslint-plugin-react
249
- enforceForArrowConditionals: false, // 废弃 - 允许在作为箭头函数主体的三元表达式周围添加小括号
250
- enforceForSequenceExpressions: false, // 允许在序列表达式周围加上小括号
251
- enforceForNewInMemberExpressions: false, // 废弃 - 允许在成员表达式中的 new 表达式周围使用额外的小括号
252
- enforceForFunctionPrototypeMethods: false, // 允许在函数表达式的即时 .call 和 .apply 方法调用周围以及同一上下文中的函数表达式周围添加括号
253
- allowParensAfterCommentPattern: "", // 允许在匹配正则表达式的注释前面加上额外的括号
254
- // nestedConditionalExpressions: false, // 允许在嵌套的条件表达式周围添加额外的小括号
255
- }],
256
-
257
240
  // 禁止空格和 tab 的混合缩进
258
241
  "no-mixed-spaces-and-tabs": "error",
259
242
 
@@ -20,5 +20,19 @@ module.exports = {
20
20
  maxBOF: 1,
21
21
  maxEOF: 1,
22
22
  }],
23
+
24
+ // 禁止冗余的括号
25
+ // https://eslint.style/rules/no-extra-parens
26
+ "@stylistic/no-extra-parens": ["warn", "all", {
27
+ conditionalAssign: false, // 允许在条件测试表达式中的赋值周围加上括号
28
+ returnAssign: false, // 允许在 return 语句中使用额外的小括号
29
+ nestedBinaryExpressions: false, // 允许在嵌套二进制表达式中使用额外的小括号
30
+ ternaryOperandBinaryExpressions: false, // 允许在三元运算符 ?: 的操作数周围添加额外的括号
31
+ ignoreJSX: "all", // 允许在没有/所有/多行/单行 JSX 组件周围使用额外的小括号,delegate to eslint-plugin-react
32
+ enforceForSequenceExpressions: false, // 允许在序列表达式周围加上小括号
33
+ enforceForFunctionPrototypeMethods: false, // 允许在函数表达式的即时 .call 和 .apply 方法调用周围以及同一上下文中的函数表达式周围添加括号
34
+ allowParensAfterCommentPattern: "", // 允许在匹配正则表达式的注释前面加上额外的括号
35
+ nestedConditionalExpressions: false, // 允许在嵌套的条件表达式周围添加额外的小括号
36
+ }],
23
37
  },
24
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@houheaven/eslint-config-helper",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
4
4
  "description": "Eslint 规则助手 (Flat Config)",
5
5
  "author": "立树",
6
6
  "license": "MIT",
@@ -17,12 +17,12 @@
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "https://gitee.com/houheaven/eslint-config-helper.git"
20
+ "url": "https://github.com/houheaven/eslint-config-helper.git"
21
21
  },
22
22
  "bugs": {
23
- "url": "https://gitee.com/houheaven/eslint-config-helper/issues"
23
+ "url": "https://github.com/houheaven/eslint-config-helper/issues"
24
24
  },
25
- "homepage": "https://gitee.com/houheaven/eslint-config-helper",
25
+ "homepage": "https://github.com/houheaven/eslint-config-helper",
26
26
  "scripts": {
27
27
  "lint": "eslint ."
28
28
  },