@houheaven/eslint-config-helper 1.4.0 → 2.1.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/LICENSE +21 -21
- package/README.md +149 -28
- package/lib/format-es5.js +23 -0
- package/lib/format-es6.js +25 -0
- package/lib/format-html.js +23 -0
- package/lib/format-import.js +23 -0
- package/lib/format-typescript.js +28 -0
- package/lib/format-vue2.js +23 -0
- package/lib/format-vue3.js +23 -0
- package/lib/html.js +16 -22
- package/lib/import.js +26 -0
- package/lib/javascript-es5.js +25 -0
- package/lib/javascript-es6.js +28 -0
- package/lib/support/es5-support.js +29 -0
- package/lib/support/es6-support.js +39 -0
- package/lib/support/html-support.js +38 -0
- package/lib/support/import-bugfix.js +65 -0
- package/lib/support/import-support.js +25 -0
- package/lib/support/typescript-support.js +27 -0
- package/lib/support/vue2-support.js +43 -0
- package/lib/support/vue3-support.js +43 -0
- package/lib/support/vue3-ts-support.js +51 -0
- package/lib/typescript.js +27 -32
- package/lib/utils/utils.js +2 -0
- package/lib/vue2.js +19 -22
- package/lib/vue3-ts.js +32 -0
- package/lib/vue3.js +16 -17
- package/node_modules/@houheaven/eslint-config-helper-core/package.json +7 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_deprecated.js +132 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_removed.js +25 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/es6.js +365 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/layout-formatting.js +441 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/possible-errors.js +199 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/suggestions.js +666 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/html/accessibility.js +68 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/html/best-practice.js +150 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/html/seo.js +29 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/html/style.js +70 -0
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/import/helpful-warnings.js +23 -18
- package/node_modules/@houheaven/eslint-config-helper-core/rules/import/module-systems.js +33 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/import/static-analysis.js +85 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/import/style-guide.js +125 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/_deprecated.js +57 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/conflict.js +16 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/deprecated.js +41 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/extension.js +207 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/fixable.js +215 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/other.js +125 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/stylistic.js +34 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/suggestion.js +53 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/type-checked.js +263 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/_deprecated.js +37 -0
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-base.js +1 -11
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-essential.js +25 -38
- package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/common-extension.js +321 -0
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-recommended.js +64 -31
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-strongly-recommended.js +37 -20
- package/{lib/rules/vue/common-extra.js → node_modules/@houheaven/eslint-config-helper-core/rules/vue/common-uncategorized.js} +141 -52
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue2-essential.js +16 -14
- package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/vue2-uncategorized.js +15 -0
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-essential.js +54 -24
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-strongly-recommended.js +8 -10
- package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/vue3-uncategorized.js +115 -0
- package/node_modules/@houheaven/eslint-config-helper-core/summary.js +57 -0
- package/node_modules/@houheaven/eslint-config-helper-core/utils/utils.js +160 -0
- package/package.json +59 -25
- package/lib/configs/eslint-es5.js +0 -24
- package/lib/configs/eslint.js +0 -23
- package/lib/configs/format-html.js +0 -22
- package/lib/configs/format-js.js +0 -134
- package/lib/configs/format-vue.js +0 -278
- package/lib/configs/html.js +0 -20
- package/lib/configs/import-bugfix.js +0 -36
- package/lib/configs/import.js +0 -44
- package/lib/configs/typescript.js +0 -10
- package/lib/configs/vue2.js +0 -28
- package/lib/configs/vue3.js +0 -28
- package/lib/eslint.js +0 -18
- package/lib/format.js +0 -40
- package/lib/rules/eslint/best-practices.js +0 -422
- package/lib/rules/eslint/es6.js +0 -196
- package/lib/rules/eslint/node.js +0 -48
- package/lib/rules/eslint/possible-errors.js +0 -190
- package/lib/rules/eslint/strict-mode.js +0 -12
- package/lib/rules/eslint/stylistic-issues.js +0 -578
- package/lib/rules/eslint/variables.js +0 -73
- package/lib/rules/html/accessibility.js +0 -44
- package/lib/rules/html/best-practice.js +0 -64
- package/lib/rules/html/seo.js +0 -24
- package/lib/rules/html/style.js +0 -32
- package/lib/rules/import/module-systems.js +0 -34
- package/lib/rules/import/static-analysis.js +0 -69
- package/lib/rules/import/style-guide.js +0 -97
- package/lib/rules/typescript/all.js +0 -193
- package/lib/rules/typescript/base.js +0 -10
- package/lib/rules/typescript/eslint-recommended.js +0 -36
- package/lib/rules/typescript/recommended-requiring-type-checking.js +0 -26
- package/lib/rules/typescript/recommended.js +0 -36
- package/lib/rules/typescript/strict.js +0 -47
- package/lib/rules/vue/common-eslint.js +0 -220
- package/lib/rules/vue/vue2-recommended.js +0 -17
- package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
- package/lib/rules/vue/vue3-recommended.js +0 -17
- /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vuejs-accessibility/index.js +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// html 支持
|
|
4
|
+
// ==========================================================
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
files: ["**/*.html", "**/*.htm", "**/*.php"],
|
|
10
|
+
parser: "@html-eslint/parser",
|
|
11
|
+
plugins: [
|
|
12
|
+
// 检查和修复 html 文件中的 html 代码
|
|
13
|
+
"@html-eslint/eslint-plugin",
|
|
14
|
+
// 检查和修复 html 文件中的 JS 代码,即 <script> 中的代码
|
|
15
|
+
// 仅仅提供技术支持,不包含任何规则,具体规则由 eslint.js 提供
|
|
16
|
+
"eslint-plugin-html",
|
|
17
|
+
],
|
|
18
|
+
// eslint-plugin-html 配置
|
|
19
|
+
// 注意:为了使 eslint-plugin-html 插件正常工作,parser 必须是 "@html-eslint/parser",不能是 require.resolve("@html-eslint/parser")
|
|
20
|
+
settings: {
|
|
21
|
+
"html/html-extensions": [".html", ".htm", ".php"],
|
|
22
|
+
"html/javascript-tag-names": ["script"],
|
|
23
|
+
// "html/javascript-mime-types": "/^(application|text)\\/(x-)?(javascript|babel|ecmascript-6|html)$/",
|
|
24
|
+
"html/javascript-mime-types": ["text/javascript", "module"],
|
|
25
|
+
"html/ignore-tags-without-type": false,
|
|
26
|
+
"html/report-bad-indent": "warn",
|
|
27
|
+
"html/indent": "+2",
|
|
28
|
+
},
|
|
29
|
+
// 规则
|
|
30
|
+
rules: {
|
|
31
|
+
// 此处不可删除,解决 html 中 <script> 换行问题
|
|
32
|
+
"eol-last": "off",
|
|
33
|
+
// 解决 HTML 注释(<!-- -->)引起 eslint 报错的问题
|
|
34
|
+
"spaced-comment": "off",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
// ===============================================================================
|
|
3
|
+
// eslint-plugin-import 插件的解析器("import/resolver")
|
|
4
|
+
// - 解决 Vue 中设置的别名(比如 @)无法被 import/no-unresolved 规则解析的问题
|
|
5
|
+
// - 解决 ts 文件无法被 import/extensions 规则解析的问题
|
|
6
|
+
// -------------------------------------------------------------------------------
|
|
7
|
+
// 依赖:eslint-import-resolver-node
|
|
8
|
+
// 作用:这是最基础、最标准的解析器。它遵循 Node.js 原生的模块解析机制
|
|
9
|
+
// - 查找 node_modules 中的依赖
|
|
10
|
+
// - 自动补全文件后缀(如 .js、.ts、.node)
|
|
11
|
+
// - 识别 index.js 作为目录入口
|
|
12
|
+
// -------------------------------------------------------------------------------
|
|
13
|
+
// 依赖:eslint-import-resolver-webpack
|
|
14
|
+
// 作用:让 ESLint 能够理解 Webpack 的配置
|
|
15
|
+
// - Webpack 允许配置 resolve.alias(别名,如 @ 指向 src )
|
|
16
|
+
// - Webpack 允许配置 resolve.modules(自定义模块目录)
|
|
17
|
+
// - Webpack 允许配置省略特定的后缀(如 .vue , .jsx )
|
|
18
|
+
// - 如果没有这个解析器,ESLint 会报错说找不到模块( import/no-unresolved ),即使 Webpack 编译能通过。
|
|
19
|
+
// 场景:主要用于 Vue 2 (Vue CLI) 或 React (Create React App) 等基于 Webpack 构建的项目。
|
|
20
|
+
// 在当前场景中,它被用来读取 @vue/cli-service 的 Webpack 配置。
|
|
21
|
+
// -------------------------------------------------------------------------------
|
|
22
|
+
// 依赖:eslint-import-resolver-alias
|
|
23
|
+
// 作用:一个轻量级的解析器,专门用来处理路径别名(Alias),而不依赖庞大的 Webpack 配置。
|
|
24
|
+
// - 简单直接地告诉 ESLint:“当看到 @ 时,去 src 目录下找”。
|
|
25
|
+
// - 它不需要读取复杂的 webpack.config.js ,配置更简单、速度通常更快。
|
|
26
|
+
// 场景 :
|
|
27
|
+
// - Vite 项目 :Vite 不使用 Webpack,所以无法使用 Webpack 解析器。通常配合此包来解决 Vite 中的别名问题。
|
|
28
|
+
// - 非 Webpack 项目 :任何使用了别名但没有 Webpack 的环境。
|
|
29
|
+
// - 在你的项目中,它主要用于 Vue 3 + Vite 的场景。
|
|
30
|
+
// ===============================================================================
|
|
31
|
+
|
|
32
|
+
const path = require("path");
|
|
33
|
+
|
|
34
|
+
const importResolver = {
|
|
35
|
+
// eslint-import-resolver-node 配置项
|
|
36
|
+
// 说明:
|
|
37
|
+
// 使用包的绝对路径作为键名来注册解析器,这是一种防御性写法。
|
|
38
|
+
// 在 Monorepo 或使用了 pnpm 等包管理器的项目中,依赖结构可能比较复杂,
|
|
39
|
+
// 直接写字符串 "node" 有时可能导致 ESLint 找不到对应的解析器包,
|
|
40
|
+
// 使用 require.resolve 可以确保准确找到该包。
|
|
41
|
+
[require.resolve("eslint-import-resolver-node")]: {
|
|
42
|
+
// 文件解析,Node 默认只会解析 js
|
|
43
|
+
extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts", ".vue"],
|
|
44
|
+
},
|
|
45
|
+
// eslint-import-resolver-alias 配置项(字符串简写)
|
|
46
|
+
// 别名解析
|
|
47
|
+
alias: {
|
|
48
|
+
map: [
|
|
49
|
+
["@", path.resolve(process.cwd(), "src")],
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// 针对 Vue CLI 项目
|
|
55
|
+
try {
|
|
56
|
+
const vueCliConfig = require.resolve("@vue/cli-service/webpack.config.js");
|
|
57
|
+
importResolver[require.resolve("eslint-import-resolver-webpack")] = {
|
|
58
|
+
config: vueCliConfig,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch(e) {
|
|
62
|
+
// ignore
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = importResolver;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// import 支持
|
|
4
|
+
// ==========================================================
|
|
5
|
+
|
|
6
|
+
const importResolver = require("./import-bugfix.js");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
plugins: ["eslint-plugin-import"],
|
|
10
|
+
parserOptions: {
|
|
11
|
+
sourceType: "module",
|
|
12
|
+
ecmaVersion: "latest",
|
|
13
|
+
},
|
|
14
|
+
settings: {
|
|
15
|
+
"import/resolver": {
|
|
16
|
+
...importResolver,
|
|
17
|
+
},
|
|
18
|
+
"import/extensions": [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
|
|
19
|
+
"import/parsers": {
|
|
20
|
+
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
|
|
21
|
+
},
|
|
22
|
+
"import/ignore": ["node_modules", "\\.(coffee|scss|css|less|hbs|svg|json)$"],
|
|
23
|
+
"import/docstyle": ["jsdoc", "tomdoc"],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// Typescript 支持
|
|
4
|
+
// ==========================================================
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
files: ["**/*.ts"],
|
|
10
|
+
plugins: [
|
|
11
|
+
"@typescript-eslint/eslint-plugin",
|
|
12
|
+
"@stylistic/eslint-plugin",
|
|
13
|
+
],
|
|
14
|
+
parser: require.resolve("@typescript-eslint/parser"),
|
|
15
|
+
parserOptions: {
|
|
16
|
+
sourceType: "module",
|
|
17
|
+
// 零配置方案
|
|
18
|
+
// - 自动适配项目中的 tsconfig.json 配置文件
|
|
19
|
+
// - 不需要指定具体路径,让 ESLint 自动查找
|
|
20
|
+
// 方案一:优先使用用户项目的 tsconfig.json
|
|
21
|
+
// project: true,
|
|
22
|
+
// 方案二:projectService 作为降级方案
|
|
23
|
+
projectService: true,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// vue2 支持
|
|
4
|
+
// ==========================================================
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
files: ["**/*.vue"],
|
|
10
|
+
plugins: ["eslint-plugin-vue"],
|
|
11
|
+
parser: require.resolve("vue-eslint-parser"),
|
|
12
|
+
parserOptions: {
|
|
13
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
14
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
15
|
+
ecmaFeatures: {
|
|
16
|
+
jsx: true, // 启用 JSX 全局变量和作用域规则
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
env: {
|
|
20
|
+
browser: true, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
|
|
21
|
+
node: true, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
|
|
22
|
+
commonjs: true, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
|
|
23
|
+
es6: true, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
|
|
24
|
+
},
|
|
25
|
+
rules: {
|
|
26
|
+
"indent": "off",
|
|
27
|
+
"max-len": "off",
|
|
28
|
+
"no-irregular-whitespace": "off",
|
|
29
|
+
// 禁止在 Vue 指定的版本上使用不支持的语法
|
|
30
|
+
// https://eslint.vuejs.org/rules/no-unsupported-features.html
|
|
31
|
+
"vue/no-unsupported-features": ["error", {
|
|
32
|
+
"version": "^2.6.0",
|
|
33
|
+
"ignores": [],
|
|
34
|
+
}],
|
|
35
|
+
// 禁止在 props 中使用保留关键字
|
|
36
|
+
// https://eslint.vuejs.org/rules/no-reserved-props.html
|
|
37
|
+
"vue/no-reserved-props": ["error", {
|
|
38
|
+
"vueVersion": 2,
|
|
39
|
+
}],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// vue3 支持
|
|
4
|
+
// ==========================================================
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
files: ["**/*.vue"],
|
|
10
|
+
plugins: ["eslint-plugin-vue"],
|
|
11
|
+
parser: require.resolve("vue-eslint-parser"),
|
|
12
|
+
parserOptions: {
|
|
13
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
14
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
15
|
+
ecmaFeatures: {
|
|
16
|
+
jsx: true, // 启用 JSX 全局变量和作用域规则
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
env: {
|
|
20
|
+
browser: true, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
|
|
21
|
+
node: true, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
|
|
22
|
+
commonjs: true, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
|
|
23
|
+
es6: true, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
|
|
24
|
+
},
|
|
25
|
+
rules: {
|
|
26
|
+
"indent": "off",
|
|
27
|
+
"max-len": "off",
|
|
28
|
+
"no-irregular-whitespace": "off",
|
|
29
|
+
// 禁止在 Vue 指定的版本上使用不支持的语法
|
|
30
|
+
// https://eslint.vuejs.org/rules/no-unsupported-features.html
|
|
31
|
+
"vue/no-unsupported-features": ["error", {
|
|
32
|
+
"version": "^3.4.0",
|
|
33
|
+
"ignores": [],
|
|
34
|
+
}],
|
|
35
|
+
// 禁止在 props 中使用保留关键字
|
|
36
|
+
// https://eslint.vuejs.org/rules/no-reserved-props.html
|
|
37
|
+
"vue/no-reserved-props": ["error", {
|
|
38
|
+
"vueVersion": 3,
|
|
39
|
+
}],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// vue3 支持(TypeScript)
|
|
4
|
+
// ==========================================================
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
files: ["**/*.vue"],
|
|
10
|
+
plugins: ["eslint-plugin-vue"],
|
|
11
|
+
parser: require.resolve("vue-eslint-parser"),
|
|
12
|
+
parserOptions: {
|
|
13
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
14
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
15
|
+
ecmaFeatures: {
|
|
16
|
+
jsx: true, // 启用 JSX 全局变量和作用域规则
|
|
17
|
+
},
|
|
18
|
+
// Vue 添加对 TypeScript 的支持
|
|
19
|
+
parser: require.resolve("@typescript-eslint/parser"),
|
|
20
|
+
extraFileExtensions: [".vue"],
|
|
21
|
+
// project: true, // 使用 projectService 会报错
|
|
22
|
+
project: [
|
|
23
|
+
"**/tsconfig.json",
|
|
24
|
+
"**/tsconfig.**.json",
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
env: {
|
|
28
|
+
browser: true, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
|
|
29
|
+
node: true, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
|
|
30
|
+
commonjs: true, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
|
|
31
|
+
es6: true, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
|
|
32
|
+
},
|
|
33
|
+
rules: {
|
|
34
|
+
"indent": "off",
|
|
35
|
+
"max-len": "off",
|
|
36
|
+
"no-irregular-whitespace": "off",
|
|
37
|
+
// 禁止在 Vue 指定的版本上使用不支持的语法
|
|
38
|
+
// https://eslint.vuejs.org/rules/no-unsupported-features.html
|
|
39
|
+
"vue/no-unsupported-features": ["error", {
|
|
40
|
+
"version": "^3.4.0",
|
|
41
|
+
"ignores": [],
|
|
42
|
+
}],
|
|
43
|
+
// 禁止在 props 中使用保留关键字
|
|
44
|
+
// https://eslint.vuejs.org/rules/no-reserved-props.html
|
|
45
|
+
"vue/no-reserved-props": ["error", {
|
|
46
|
+
"vueVersion": 3,
|
|
47
|
+
}],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
package/lib/typescript.js
CHANGED
|
@@ -1,45 +1,40 @@
|
|
|
1
1
|
|
|
2
|
-
//
|
|
2
|
+
// ==========================================================
|
|
3
3
|
// @houheaven/eslint-config-helper/typescript
|
|
4
|
-
//
|
|
5
|
-
// -
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
//
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// - @typescript-eslint/eslint-plugin 定制规则
|
|
6
|
+
// ==========================================================
|
|
7
|
+
|
|
8
|
+
// 这个插件为当前类库提供”开箱即用“的能力,使用者无需手动安装当前库的依赖项
|
|
9
|
+
require("@rushstack/eslint-patch/modern-module-resolution");
|
|
10
|
+
|
|
11
|
+
// 132 条规则
|
|
12
|
+
// 官方有很多种分类
|
|
13
|
+
// 配置分组:recommended、strict、stylistic
|
|
14
|
+
// 元数据分组:fixable、has-suggestions、type-checked、extension、deprecated
|
|
15
|
+
// 两类分组不能覆盖全部规则,部分规则还存在交叉,所以当前规则分类优先级如下:
|
|
16
|
+
// extension > fixable > type-checked > has-suggestions > other
|
|
17
|
+
|
|
18
|
+
const utils = require("@houheaven/eslint-config-helper-core");
|
|
9
19
|
|
|
10
20
|
module.exports = {
|
|
21
|
+
// Typescript 规则很多是类型感知规则,需要访问 TypeScript 类型系统(即需要配置 parserOptions)
|
|
22
|
+
// typescript-support.js 作用域是 TS 文件,如果没有 overrides 限制,utils.rules.typescript 规则会应用到所有文件
|
|
23
|
+
// 其他类型的文件没有经过 parserOptions 处理,就会导致报错,因此此处必须使用 overrides 嵌套
|
|
11
24
|
overrides: [
|
|
12
25
|
{
|
|
13
|
-
files: ["
|
|
26
|
+
files: ["**/*.ts"],
|
|
27
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
28
|
+
reportUnusedDisableDirectives: true,
|
|
29
|
+
// 继承配置文件
|
|
14
30
|
extends: [
|
|
15
|
-
|
|
16
|
-
"./
|
|
17
|
-
"./configs/typescript.js",
|
|
31
|
+
// Typescript 支持
|
|
32
|
+
"./support/typescript-support.js",
|
|
18
33
|
],
|
|
19
34
|
rules: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"import/no-unresolved": "off",
|
|
35
|
+
// @typescript-eslint/eslint-plugin 规则
|
|
36
|
+
...utils.rules.typescript,
|
|
23
37
|
},
|
|
24
38
|
},
|
|
25
|
-
// {
|
|
26
|
-
// files: ["*.ts", "**/*.ts"],
|
|
27
|
-
// parser: "@babel/eslint-parser",
|
|
28
|
-
// parserOptions: {
|
|
29
|
-
// sourceType: "module",
|
|
30
|
-
// babelOptions: {
|
|
31
|
-
// plugins: [
|
|
32
|
-
// [
|
|
33
|
-
// // 支持 ES7 新特性:装饰器
|
|
34
|
-
// "@babel/plugin-proposal-decorators",
|
|
35
|
-
// { version: "2023-01" }
|
|
36
|
-
// ],
|
|
37
|
-
// ],
|
|
38
|
-
// },
|
|
39
|
-
// },
|
|
40
|
-
// rules: {
|
|
41
|
-
// "class-methods-use-this": "off",
|
|
42
|
-
// },
|
|
43
|
-
// },
|
|
44
39
|
],
|
|
45
40
|
};
|
package/lib/vue2.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
|
|
2
|
-
//
|
|
2
|
+
// ==========================================================
|
|
3
3
|
// @houheaven/eslint-config-helper/vue2
|
|
4
|
-
//
|
|
5
|
-
// -
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// - eslint-plugin-vue 定制规则
|
|
6
|
+
// ==========================================================
|
|
7
|
+
|
|
8
|
+
// 这个插件为当前类库提供”开箱即用“的能力,使用者无需手动安装当前库的依赖项
|
|
9
|
+
require("@rushstack/eslint-patch/modern-module-resolution");
|
|
10
|
+
|
|
11
|
+
const utils = require("@houheaven/eslint-config-helper-core");
|
|
10
12
|
|
|
11
13
|
module.exports = {
|
|
14
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
15
|
+
reportUnusedDisableDirectives: true,
|
|
16
|
+
// 继承配置文件
|
|
12
17
|
extends: [
|
|
13
|
-
|
|
14
|
-
"./
|
|
18
|
+
// Vue2 支持
|
|
19
|
+
"./support/vue2-support.js",
|
|
15
20
|
],
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
// 规则
|
|
22
|
+
rules: {
|
|
23
|
+
// Vue2 规则
|
|
24
|
+
...utils.rules.vue,
|
|
25
|
+
...utils.rules.vue2,
|
|
19
26
|
},
|
|
20
|
-
rules: {},
|
|
21
|
-
overrides: [
|
|
22
|
-
{
|
|
23
|
-
files: ["*.vue", "**/*.vue"],
|
|
24
|
-
extends: [
|
|
25
|
-
"./configs/vue2.js",
|
|
26
|
-
"./rules/vuejs-accessibility",
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
27
|
};
|
package/lib/vue3-ts.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// @houheaven/eslint-config-helper/vue3-ts
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// - eslint-plugin-vue 定制规则
|
|
6
|
+
// ==========================================================
|
|
7
|
+
|
|
8
|
+
// 这个插件为当前类库提供”开箱即用“的能力,使用者无需手动安装当前库的依赖项
|
|
9
|
+
const utils = require("@houheaven/eslint-config-helper-core");
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
overrides: [
|
|
13
|
+
{
|
|
14
|
+
files: ["**/*.vue"],
|
|
15
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
16
|
+
reportUnusedDisableDirectives: true,
|
|
17
|
+
// 继承配置文件
|
|
18
|
+
extends: [
|
|
19
|
+
// Vue3 支持
|
|
20
|
+
"./support/vue3-ts-support.js",
|
|
21
|
+
],
|
|
22
|
+
// 规则
|
|
23
|
+
rules: {
|
|
24
|
+
// Vue3 规则
|
|
25
|
+
...utils.rules.vue,
|
|
26
|
+
...utils.rules.vue3,
|
|
27
|
+
// @typescript-eslint/eslint-plugin 规则
|
|
28
|
+
...utils.rules.typescript,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
};
|
package/lib/vue3.js
CHANGED
|
@@ -2,27 +2,26 @@
|
|
|
2
2
|
// ==========================================================
|
|
3
3
|
// @houheaven/eslint-config-helper/vue3
|
|
4
4
|
// ----------------------------------------------------------
|
|
5
|
-
// -
|
|
6
|
-
// - ./configs/import.js : eslint-plugin-import 定制规则
|
|
7
|
-
// - ./configs/vue3.js : eslint-plugin-vue 定制规则
|
|
5
|
+
// - eslint-plugin-vue 定制规则
|
|
8
6
|
// ==========================================================
|
|
9
7
|
|
|
8
|
+
// 这个插件为当前类库提供”开箱即用“的能力,使用者无需手动安装当前库的依赖项
|
|
9
|
+
require("@rushstack/eslint-patch/modern-module-resolution");
|
|
10
|
+
|
|
11
|
+
const utils = require("@houheaven/eslint-config-helper-core");
|
|
12
|
+
|
|
10
13
|
module.exports = {
|
|
14
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
15
|
+
reportUnusedDisableDirectives: true,
|
|
16
|
+
// 继承配置文件
|
|
11
17
|
extends: [
|
|
12
|
-
|
|
13
|
-
"./
|
|
18
|
+
// Vue3 支持
|
|
19
|
+
"./support/vue3-support.js",
|
|
14
20
|
],
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
// 规则
|
|
22
|
+
rules: {
|
|
23
|
+
// Vue3 规则
|
|
24
|
+
...utils.rules.vue,
|
|
25
|
+
...utils.rules.vue3,
|
|
18
26
|
},
|
|
19
|
-
rules: {},
|
|
20
|
-
overrides: [
|
|
21
|
-
{
|
|
22
|
-
files: ["*.vue", "**/*.vue"],
|
|
23
|
-
extends: [
|
|
24
|
-
"./configs/vue3.js",
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
27
|
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
|
|
2
|
+
// 这些规则已根据废弃政策被弃用,并被更新的规则所取代
|
|
3
|
+
|
|
4
|
+
// module.exports = {
|
|
5
|
+
// rules: {
|
|
6
|
+
// "callback-return": "", // [ ✅ 已使用 ]
|
|
7
|
+
// "global-require": "", // [ ✅ 已使用 ]
|
|
8
|
+
// "handle-callback-err": "", // [ ✅ 已使用 ]
|
|
9
|
+
// "id-blacklist": "", // [ ❌ 未使用 ] 替换为 id-denylist
|
|
10
|
+
// "indent-legacy": "", // [ ❌ 未使用 ] 替换为 indent
|
|
11
|
+
// "lines-around-directive": "", // [ ✅ 已使用 ] 替换为 padding-line-between-statements
|
|
12
|
+
// "newline-after-var": "", // [ ✅ 已使用 ] 替换为 padding-line-between-statements
|
|
13
|
+
// "newline-before-return": "", // [ ✅ 已使用 ] 替换为 padding-line-between-statements
|
|
14
|
+
// "no-buffer-constructor": "", // [ ✅ 已使用 ]
|
|
15
|
+
// "no-catch-shadow": "", // [ ✅ 已使用 ] 替换为 no-shadow
|
|
16
|
+
// "no-mixed-requires": "", // [ ✅ 已使用 ]
|
|
17
|
+
// "no-native-reassign": "", // [ ✅ 已使用 ] 替换为 no-global-assign
|
|
18
|
+
// "no-negated-in-lhs": "", // [ ✅ 已使用 ] 替换为 no-unsafe-negation
|
|
19
|
+
// "no-new-require": "", // [ ✅ 已使用 ]
|
|
20
|
+
// "no-path-concat": "", // [ ✅ 已使用 ]
|
|
21
|
+
// "no-process-env": "", // [ ✅ 已使用 ]
|
|
22
|
+
// "no-process-exit": "", // [ ✅ 已使用 ]
|
|
23
|
+
// "no-restricted-modules": "", // [ ✅ 已使用 ]
|
|
24
|
+
// "no-return-await": "", // [ ✅ 已使用 ]
|
|
25
|
+
// "no-spaced-func": "", // [ ❌ 未使用 ] 替换为 func-call-spacing
|
|
26
|
+
// "no-sync": "", // [ ✅ 已使用 ]
|
|
27
|
+
// "prefer-reflect": "", // [ ✅ 已使用 ]
|
|
28
|
+
// "require-jsdoc": "", // [ ✅ 已使用 ]
|
|
29
|
+
// "valid-jsdoc": "", // [ ✅ 已使用 ]
|
|
30
|
+
// },
|
|
31
|
+
// };
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
rules: {
|
|
35
|
+
// enforce return after a callback
|
|
36
|
+
// ❌ 已废弃
|
|
37
|
+
"callback-return": "off",
|
|
38
|
+
|
|
39
|
+
// 强制在模块顶部调用
|
|
40
|
+
// ❌ 已废弃
|
|
41
|
+
// https://zh-hans.eslint.org/docs/latest/rules/global-require
|
|
42
|
+
"global-require": "off",
|
|
43
|
+
|
|
44
|
+
// enforces error handling in callbacks (node environment)
|
|
45
|
+
// ❌ 已废弃
|
|
46
|
+
"handle-callback-err": "off",
|
|
47
|
+
|
|
48
|
+
// require or disallow newlines around directives
|
|
49
|
+
// ❌ 已废弃
|
|
50
|
+
// https://zh-hans.eslint.org/docs/latest/rules/lines-around-directive
|
|
51
|
+
"lines-around-directive": ["error", {
|
|
52
|
+
before: "always",
|
|
53
|
+
after: "always",
|
|
54
|
+
}],
|
|
55
|
+
|
|
56
|
+
// allow/disallow an empty newline after var statement
|
|
57
|
+
// ❌ 已废弃
|
|
58
|
+
"newline-after-var": "off",
|
|
59
|
+
|
|
60
|
+
// https://zh-hans.eslint.org/docs/latest/rules/newline-before-return
|
|
61
|
+
// ❌ 已废弃
|
|
62
|
+
"newline-before-return": "off",
|
|
63
|
+
|
|
64
|
+
// disallow use of the Buffer() constructor
|
|
65
|
+
// ❌ 已废弃
|
|
66
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-buffer-constructor
|
|
67
|
+
"no-buffer-constructor": "error",
|
|
68
|
+
|
|
69
|
+
// disallow the catch clause parameter name being the same as a variable in the outer scope
|
|
70
|
+
// ❌ 已废弃
|
|
71
|
+
"no-catch-shadow": "off",
|
|
72
|
+
|
|
73
|
+
// disallow mixing regular variable and require declarations
|
|
74
|
+
// ❌ 已废弃
|
|
75
|
+
"no-mixed-requires": ["off", false],
|
|
76
|
+
|
|
77
|
+
// deprecated in favor of no-global-assign
|
|
78
|
+
// ❌ 已废弃
|
|
79
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-native-reassign
|
|
80
|
+
"no-native-reassign": "off",
|
|
81
|
+
|
|
82
|
+
// disallow negation of the left operand of an in expression
|
|
83
|
+
// deprecated in favor of no-unsafe-negation
|
|
84
|
+
// ❌ 已废弃
|
|
85
|
+
"no-negated-in-lhs": "off",
|
|
86
|
+
|
|
87
|
+
// disallow use of new operator with the require function
|
|
88
|
+
// ❌ 已废弃
|
|
89
|
+
"no-new-require": "error",
|
|
90
|
+
|
|
91
|
+
// disallow string concatenation with __dirname and __filename
|
|
92
|
+
// ❌ 已废弃
|
|
93
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-path-concat
|
|
94
|
+
"no-path-concat": "error",
|
|
95
|
+
|
|
96
|
+
// disallow use of process.env
|
|
97
|
+
// ❌ 已废弃
|
|
98
|
+
"no-process-env": "off",
|
|
99
|
+
|
|
100
|
+
// disallow process.exit()
|
|
101
|
+
// ❌ 已废弃
|
|
102
|
+
"no-process-exit": "off",
|
|
103
|
+
|
|
104
|
+
// restrict usage of specified node modules
|
|
105
|
+
// ❌ 已废弃
|
|
106
|
+
"no-restricted-modules": "off",
|
|
107
|
+
|
|
108
|
+
// disallow redundant `return await`
|
|
109
|
+
// ❌ 已废弃
|
|
110
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-return-await
|
|
111
|
+
"no-return-await": "error",
|
|
112
|
+
|
|
113
|
+
// disallow use of synchronous methods (off by default)
|
|
114
|
+
// ❌ 已废弃
|
|
115
|
+
"no-sync": "off",
|
|
116
|
+
|
|
117
|
+
// suggest using Reflect methods where applicable
|
|
118
|
+
// ❌ 已废弃
|
|
119
|
+
// https://zh-hans.eslint.org/docs/latest/rules/prefer-reflect
|
|
120
|
+
"prefer-reflect": "off",
|
|
121
|
+
|
|
122
|
+
// do not require jsdoc
|
|
123
|
+
// ❌ 已废弃
|
|
124
|
+
// https://zh-hans.eslint.org/docs/latest/rules/require-jsdoc
|
|
125
|
+
"require-jsdoc": "off",
|
|
126
|
+
|
|
127
|
+
// ensure JSDoc comments are valid
|
|
128
|
+
// ❌ 已废弃
|
|
129
|
+
// https://zh-hans.eslint.org/docs/latest/rules/valid-jsdoc
|
|
130
|
+
"valid-jsdoc": "off",
|
|
131
|
+
},
|
|
132
|
+
};
|