@fast-china/eslint-config 1.0.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/Fast.png ADDED
Binary file
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ [中](https://gitee.com/China-xiaoFang/fast.eslint.config) | **En**
2
+
3
+ <h1 align="center">Fast.ESLint.Config</h1>
4
+
5
+ <p align="center">
6
+ <code>Fast</code> platform An rule library built based on <code>ESLint</code>.
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/@fast-china/eslint-config">
11
+ <img src="https://img.shields.io/npm/v/@fast-china/eslint-config?color=orange&label=" alt="version" />
12
+ </a>
13
+ <a href="https://gitee.com/China-xiaoFang/fast.eslint.config/blob/master/LICENSE">
14
+ <img src="https://img.shields.io/npm/l/@fast-china/eslint-config" alt="license" />
15
+ </a>
16
+ </p>
17
+
18
+ ## Install
19
+
20
+ #### Using a Package Manager
21
+
22
+ ```sh
23
+ # Choose a package manager of your choice
24
+
25
+ # NPM
26
+ npm install @fast-china/eslint-config --save-dev
27
+
28
+ # Yarn
29
+ yarn add @fast-china/eslint-config --dev
30
+
31
+ # pnpm (recommend)
32
+ pnpm install @fast-china/eslint-config --save-dev
33
+ ```
34
+
35
+ ## Use
36
+
37
+ ```typescript
38
+ // < v9.x version. The following is an example of '.eslintrc.cjs'.
39
+ const { defineConfig } = require("eslint-define-config");
40
+
41
+ module.exports = defineConfig({
42
+ root: true,
43
+ extends: ["@fast-china/eslint-config"],
44
+ });
45
+
46
+ // >= v9.x version. The following is an example of 'eslint.config.mjs'.
47
+ import tseslint from "typescript-eslint";
48
+ import fastChinaFlat from "@fast-china/eslint-config/flat";
49
+
50
+ export default tseslint.config({
51
+ extends: [...fastChinaFlat],
52
+ });
53
+ ```
54
+
55
+ ## Update log
56
+
57
+ Update log [Click to view](https://gitee.com/China-xiaoFang/fast.eslint.config/commits/master)
58
+
59
+ ## Protocol
60
+
61
+ [Fast.ESLint.Config](https://gitee.com/China-xiaoFang/fast.eslint.config) complies with the [Apache-2.0](https://gitee.com/China-xiaoFang/fast.eslint.config/blob/master/LICENSE) open source agreement. Welcome to submit `PR` or `Issue`.
62
+
63
+ ```
64
+ Apache Open Source License
65
+
66
+ Copyright © 2018-Now xiaoFang
67
+
68
+ The right to deal in the Software is hereby granted free of charge to any person obtaining a copy of this software and its related documentation (the "Software"),
69
+ Including but not limited to using, copying, modifying, merging, publishing, distributing, sublicensing, selling copies of the Software,
70
+ and permit individuals in possession of a copy of the software to do so, subject to the following conditions:
71
+
72
+ The above copyright notice and this license notice must be included on all copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS AND NON-INFRINGEMENT.
75
+ In no event shall the author or copyright holder be liable for any claim, damages or other liability,
76
+ WHETHER ARISING IN CONTRACT, TORT OR OTHERWISE, IN CONNECTION WITH THE SOFTWARE OR ITS USE OR OTHER DEALINGS.
77
+ ```
78
+
79
+ ## Disclaimer
80
+
81
+ ```
82
+ Please do not use it for projects that violate our country's laws
83
+ ```
84
+
85
+ ## Contributors
86
+
87
+ Thank you for all their contributions!
88
+
89
+ <a href="https://github.com/China-xiaoFang/Fast.ESLint.Config/graphs/contributors">
90
+ <img src="https://contrib.rocks/image?repo=China-xiaoFang/Fast.ESLint.Config" />
91
+ </a>
92
+
93
+ ## Supplementary instructions
94
+
95
+ ```
96
+ If it is helpful to you, you can click ⭐Star in the upper right corner to collect it and get the latest updates. Thank you!
97
+ ```
package/README.zh.md ADDED
@@ -0,0 +1,97 @@
1
+ **中** | [En](https://github.com/China-xiaoFang/fast.eslint.config)
2
+
3
+ <h1 align="center">Fast.ESLint.Config</h1>
4
+
5
+ <p align="center">
6
+ <code>Fast</code> 平台下基于 <code>ESLint</code> 构建的规则库。
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/@fast-china/eslint-config">
11
+ <img src="https://img.shields.io/npm/v/@fast-china/eslint-config?color=orange&label=" alt="version" />
12
+ </a>
13
+ <a href="https://gitee.com/China-xiaoFang/fast.eslint.config/blob/master/LICENSE">
14
+ <img src="https://img.shields.io/npm/l/@fast-china/eslint-config" alt="license" />
15
+ </a>
16
+ </p>
17
+
18
+ ## 安装
19
+
20
+ #### 使用包管理器
21
+
22
+ ```sh
23
+ # 选择一个你喜欢的包管理器
24
+
25
+ # NPM
26
+ npm install @fast-china/eslint-config --save-dev
27
+
28
+ # Yarn
29
+ yarn add @fast-china/eslint-config --dev
30
+
31
+ # pnpm(推荐)
32
+ pnpm install @fast-china/eslint-config --save-dev
33
+ ```
34
+
35
+ ## 使用
36
+
37
+ ```typescript
38
+ // < v9.x 版本。以下已 ‘.eslintrc.cjs’ 为示例。
39
+ const { defineConfig } = require("eslint-define-config");
40
+
41
+ module.exports = defineConfig({
42
+ root: true,
43
+ extends: ["@fast-china/eslint-config"],
44
+ });
45
+
46
+ // >= v9.x 版本。以下已 ‘eslint.config.mjs’ 未实例。
47
+ import tseslint from "typescript-eslint";
48
+ import fastChinaFlat from "@fast-china/eslint-config/flat";
49
+
50
+ export default tseslint.config({
51
+ extends: [...fastChinaFlat],
52
+ });
53
+ ```
54
+
55
+ ## 更新日志
56
+
57
+ 更新日志 [点击查看](https://gitee.com/China-xiaoFang/fast.eslint.config/commits/master)
58
+
59
+ ## 协议
60
+
61
+ [Fast.ESLint.Config](https://gitee.com/China-xiaoFang/fast.eslint.config) 遵循 [Apache-2.0](https://gitee.com/China-xiaoFang/fast.eslint.config/blob/master/LICENSE) 开源协议,欢迎大家提交 `PR` 或 `Issue`。
62
+
63
+ ```
64
+ Apache开源许可证
65
+
66
+ 版权所有 © 2018-Now 小方
67
+
68
+ 特此免费授予获得本软件及其相关文档文件(以下简称“软件”)副本的任何人以处理本软件的权利,
69
+ 包括但不限于使用、复制、修改、合并、发布、分发、再许可、销售软件的副本,
70
+ 以及允许拥有软件副本的个人进行上述行为,但须遵守以下条件:
71
+
72
+ 在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
73
+
74
+ 软件按“原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于对适销性、适用性和非侵权的保证。
75
+ 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,
76
+ 无论是因合同、侵权或其他方式引起的,与软件或其使用或其他交易有关。
77
+ ```
78
+
79
+ ## 免责申明
80
+
81
+ ```
82
+ 请勿用于违反我国法律的项目上
83
+ ```
84
+
85
+ ## 贡献者
86
+
87
+ 感谢他们的所做的一切贡献!
88
+
89
+ <a href="https://github.com/China-xiaoFang/Fast.ESLint.Config/graphs/contributors">
90
+ <img src="https://contrib.rocks/image?repo=China-xiaoFang/Fast.ESLint.Config" />
91
+ </a>
92
+
93
+ ## 补充说明
94
+
95
+ ```
96
+ 如果对您有帮助,您可以点右上角 ⭐Star 收藏一下 ,获取第一时间更新,谢谢!
97
+ ```
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@fast-china/eslint-config",
3
+ "author": "小方",
4
+ "version": "1.0.1",
5
+ "description": "Fast ESLint 规则库.",
6
+ "keywords": [
7
+ "fast",
8
+ "ESLint"
9
+ ],
10
+ "license": "Apache-2.0",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "homepage": "https://fastdotnet.com",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://gitee.com/China-xiaoFang/fast.eslint.config"
18
+ },
19
+ "bugs": {
20
+ "url": "https://gitee.com/China-xiaoFang/fast.eslint.config/issues"
21
+ },
22
+ "main": "src/index-v8.x.js",
23
+ "exports": {
24
+ "./flat": {
25
+ "import": "./src/index-v9.x.js",
26
+ "require": "./src/index-v9.x.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "./Fast.png",
31
+ "./LICENSE",
32
+ "./README.md",
33
+ "./README.zh.md"
34
+ ],
35
+ "peerDependencies": {
36
+ "eslint": "^8 || ^9"
37
+ },
38
+ "dependencies": {
39
+ "@typescript-eslint/eslint-plugin": "^8.26.1",
40
+ "@typescript-eslint/parser": "^8.26.1",
41
+ "eslint-config-prettier": "^10.1.1",
42
+ "eslint-define-config": "^2.1.0",
43
+ "eslint-plugin-import": "^2.30.0",
44
+ "eslint-plugin-jsonc": "^2.19.1",
45
+ "eslint-plugin-markdown": "^5.1.0",
46
+ "eslint-plugin-prettier": "^5.2.3",
47
+ "eslint-plugin-vue": "^10.0.0",
48
+ "jsonc-eslint-parser": "^2.4.0",
49
+ "prettier": "^3.5.3",
50
+ "typescript": "^5.8.2",
51
+ "vue-eslint-parser": "^10.1.1"
52
+ },
53
+ "devDependencies": {
54
+ "eslint": "^8 || ^9"
55
+ },
56
+ "engines": {
57
+ "node": ">=20.0.0"
58
+ }
59
+ }
@@ -0,0 +1,471 @@
1
+ const { defineConfig } = require("eslint-define-config");
2
+
3
+ // @see: http://eslint.cn
4
+ module.exports = defineConfig({
5
+ env: {
6
+ es6: true,
7
+ browser: true,
8
+ node: true,
9
+ },
10
+ plugins: ["@typescript-eslint", "prettier"],
11
+ // 继承某些已有的规则
12
+ extends: [
13
+ "eslint:recommended",
14
+ "plugin:import/recommended",
15
+ "plugin:jsonc/recommended-with-jsonc",
16
+ "plugin:markdown/recommended-legacy",
17
+ "plugin:vue/recommended",
18
+ "plugin:@typescript-eslint/recommended",
19
+ "prettier",
20
+ ],
21
+ settings: {
22
+ // 确保 ESLint 和 eslint-plugin-import 能够正确解析项目中的所有相关文件类型
23
+ "import/resolver": {
24
+ node: { extensions: [".js", ".mjs", ".ts", ".d.ts", ".tsx"] },
25
+ },
26
+ },
27
+ overrides: [
28
+ {
29
+ files: ["*.ts", "*.vue", "*.tsx"],
30
+ rules: {
31
+ // 关闭 - 禁止使用未声明的变量,除非/*global *\/注释中提到
32
+ "no-undef": "off",
33
+ },
34
+ },
35
+ {
36
+ files: ["*.d.ts"],
37
+ rules: {
38
+ // 关闭 - 禁止在文件中重复导入相同的模块
39
+ "import/no-duplicates": "off",
40
+ // 关闭 - 一致地使用 TypeScript 类型导入
41
+ "@typescript-eslint/consistent-type-imports": "off",
42
+ },
43
+ },
44
+ {
45
+ files: ["*.js"],
46
+ rules: {
47
+ // 关闭 - 不允许使用 require 语句
48
+ "@typescript-eslint/no-var-requires": "off",
49
+ },
50
+ },
51
+ {
52
+ files: ["*.cjs"],
53
+ rules: {
54
+ // 关闭 - 不允许使用 require 语句
55
+ "@typescript-eslint/no-var-requires": "off",
56
+ "@typescript-eslint/no-require-imports": "off",
57
+ },
58
+ },
59
+ {
60
+ files: ["*.tsx"],
61
+ rules: {
62
+ // 关闭 - 要求在 TypeScript 函数和方法中显式地指定返回类型
63
+ // "@typescript-eslint/explicit-function-return-type": "off",
64
+ },
65
+ },
66
+ {
67
+ files: ["**/*.md/*.js", "**/*.md/*.ts"],
68
+ rules: {
69
+ // 使用使用控制台
70
+ "no-console": "off",
71
+ // 关闭 - 禁用对无法解析的模块导入的检查
72
+ "import/no-unresolved": "off",
73
+ // 允许定义未使用的变量
74
+ "@typescript-eslint/no-unused-vars": "off",
75
+ },
76
+ },
77
+ {
78
+ files: ["*.json", "*.json5", "*.jsonc"],
79
+ // 允许 ESLint 处理 JSON 文件中的模板和脚本
80
+ parser: "jsonc-eslint-parser",
81
+ },
82
+ {
83
+ files: ["*.vue"],
84
+ // 允许 ESLint 处理 Vue 文件中的模板和脚本
85
+ parser: "vue-eslint-parser",
86
+ parserOptions: {
87
+ // 允许在 Vue 文件中的脚本部分使用 TypeScript 语法
88
+ parser: "@typescript-eslint/parser",
89
+ // 指定额外的文件扩展名,告诉解析器 .vue 文件也需要处理
90
+ extraFileExtensions: [".vue"],
91
+ // 允许使用最新的 ECMAScript 语法特性
92
+ ecmaVersion: "latest",
93
+ // 允许使用 JSX/TSX 语法,适用于 Vue 组件中的 JSX/TSX 代码。
94
+ ecmaFeatures: {
95
+ jsx: true,
96
+ tsx: true,
97
+ },
98
+ },
99
+ rules: {
100
+ // 关闭 - 禁止使用未声明的变量,以避免在 .vue 文件中出现关于未定义变量的警告,这在 Vue 单文件组件中可能不适用或会导致不必要的警告
101
+ "no-undef": "off",
102
+ },
103
+ },
104
+ ],
105
+ /**
106
+ * "off" 或 0 ==> 关闭规则
107
+ * "warn" 或 1 ==> 打开的规则作为警告(不影响代码执行)
108
+ * "error" 或 2 ==> 规则作为一个错误(代码不能执行,界面报错)
109
+ */
110
+ rules: {
111
+ // JS/TS (http://eslint.cn/docs/rules)
112
+
113
+ // 强制使用 camelCase 命名风格
114
+ camelcase: [
115
+ "error",
116
+ {
117
+ // 允许对象属性使用非 camelCase 风格
118
+ properties: "never",
119
+ },
120
+ ],
121
+ // 禁止使用控制台
122
+ "no-console": [
123
+ "warn",
124
+ {
125
+ // 允许除 warn/error 之外的其他 console.xx 方法
126
+ allow: ["warn", "error"],
127
+ },
128
+ ],
129
+ // 禁止使用 debugger
130
+ "no-debugger": "warn",
131
+ // 禁止在条件语句中使用常量条件
132
+ "no-constant-condition": [
133
+ "error",
134
+ {
135
+ // 允许在循环语句中使用常量条件
136
+ checkLoops: false,
137
+ },
138
+ ],
139
+ // 禁止使用某些特定的语法
140
+ "no-restricted-syntax": [
141
+ "error",
142
+ // 禁止使用标记语句(labeled statements)
143
+ "LabeledStatement",
144
+ // 禁止使用 with 语句
145
+ "WithStatement",
146
+ ],
147
+ // 禁止在 return 语句中使用 await
148
+ "no-return-await": "error",
149
+ // 禁止使用 var 关键字,强制使用 let 或 const
150
+ "no-var": "error",
151
+ // 禁止使用空的块语句
152
+ "no-empty": [
153
+ "error",
154
+ {
155
+ // 允许空的 catch 块
156
+ allowEmptyCatch: true,
157
+ },
158
+ ],
159
+ // 该规则禁止使用不规则或不标准的空白字符
160
+ "no-irregular-whitespace": "error",
161
+ // 禁止在函数或变量定义之前使用它们
162
+ "no-use-before-define": "warn",
163
+ // 强制使用 const 声明不被修改的变量
164
+ "prefer-const": [
165
+ "warn",
166
+ {
167
+ // 在解构赋值时也推荐使用 const
168
+ destructuring: "all",
169
+ // 允许在变量首次赋值前读取变量的值
170
+ ignoreReadBeforeAssign: true,
171
+ },
172
+ ],
173
+ // 强制使用箭头函数而非普通函数
174
+ "prefer-arrow-callback": [
175
+ "error",
176
+ {
177
+ // 不允许使用命名函数作为回调函数
178
+ allowNamedFunctions: false,
179
+ // 允许在箭头函数中使用 this 绑定的上下文
180
+ allowUnboundThis: true,
181
+ },
182
+ ],
183
+ // 强制使用对象字面量的方法和属性简写语法
184
+ "object-shorthand": [
185
+ "error",
186
+ "always",
187
+ {
188
+ // 不忽略构造函数中的属性简写
189
+ ignoreConstructors: false,
190
+ // 强制避免在属性名中使用引号
191
+ avoidQuotes: true,
192
+ },
193
+ ],
194
+ // 强制使用 rest 参数代替 arguments 对象
195
+ "prefer-rest-params": "error",
196
+ // 强制使用展开运算符(...)代替 Function.prototype.apply
197
+ "prefer-spread": "error",
198
+ // 强制使用模板字面量代替字符串连接
199
+ "prefer-template": "error",
200
+ // 禁止在同一作用域中重新声明变量
201
+ "no-redeclare": "error",
202
+
203
+ // 最佳实践
204
+ // 确保数组的回调函数(如 Array.prototype.map、Array.prototype.filter、Array.prototype.reduce 等)总是有一个返回值
205
+ "array-callback-return": "error",
206
+ // 强制使用块级作用域变量(let 或 const),避免使用函数作用域变量(var)
207
+ "block-scoped-var": "error",
208
+ // 禁止使用 alert、confirm 和 prompt 等浏览器弹出对话框
209
+ "no-alert": "warn",
210
+ // 禁止在 switch 语句的 case 或 default 子句中声明变量
211
+ "no-case-declarations": "error",
212
+ // 禁止使用多行字符串,即不允许使用反斜杠 \ 来连接多行字符串
213
+ "no-multi-str": "error",
214
+ // 禁止使用 with 语句
215
+ "no-with": "error",
216
+ // 禁止使用 void 操作符
217
+ "no-void": "error",
218
+ // 禁止多个空行
219
+ "no-multiple-empty-lines": [
220
+ "error",
221
+ {
222
+ // 最多允许1行
223
+ max: 1,
224
+ },
225
+ ],
226
+
227
+ // import 排序
228
+ "sort-imports": [
229
+ "warn",
230
+ {
231
+ // 不忽略导入语句中模块名的大小写
232
+ ignoreCase: false,
233
+ // 忽略导入声明的排序
234
+ ignoreDeclarationSort: true,
235
+ // 不忽略导入成员的排序
236
+ ignoreMemberSort: false,
237
+ // 成员语法排序顺序
238
+ memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
239
+ // 不允许分组导入
240
+ allowSeparatedGroups: false,
241
+ },
242
+ ],
243
+
244
+ // 强制在数学运算中使用 ** 运算符代替 Math.pow()
245
+ "prefer-exponentiation-operator": "error",
246
+
247
+ // TS (https://typescript-eslint.io/rules)
248
+
249
+ // 要求在导出函数和类的公共方法上显式声明返回类型
250
+ "@typescript-eslint/explicit-module-boundary-types": "off",
251
+ // 要求在 TypeScript 函数和方法中显式地指定返回类型
252
+ "@typescript-eslint/explicit-function-return-type": "error",
253
+ // 禁止在同一作用域中重新声明 TypeScript 变量
254
+ "@typescript-eslint/no-redeclare": "error",
255
+ // 允许定义未使用的变量
256
+ "@typescript-eslint/no-unused-vars": "off",
257
+ // 允许使用自定义TypeScript模块和命名空间
258
+ "@typescript-eslint/no-namespace": "off",
259
+ // 允许使用 any 类型
260
+ "@typescript-eslint/no-explicit-any": "off",
261
+ // 禁止在 TypeScript 文件中使用 require 函数进行模块导入
262
+ "@typescript-eslint/no-var-requires": "error",
263
+ // 禁止定义空函数
264
+ "@typescript-eslint/no-empty-function": "error",
265
+ // 禁止无用的表达式
266
+ "@typescript-eslint/no-unused-expressions": [
267
+ "error",
268
+ {
269
+ // 允许短路操作符(&& 和 ||)中的无副作用表达式
270
+ allowShortCircuit: true,
271
+ // 允许三元操作符中的无副作用表达式
272
+ allowTernary: true,
273
+ },
274
+ ],
275
+ // 禁止在 TypeScript 代码中对类型已经可以被推断的变量或参数进行显式的类型注解
276
+ "@typescript-eslint/no-inferrable-types": "error",
277
+ // 禁止使用后缀运算符的非空断言(!)
278
+ "@typescript-eslint/no-non-null-assertion": "error",
279
+ // 禁止在可选链(?)后使用非空断言(!)
280
+ "@typescript-eslint/no-non-null-asserted-optional-chain": "error",
281
+ // 禁止在代码中使用 @ts-ignore 注释
282
+ "@typescript-eslint/ban-ts-comment": ["error", { "ts-ignore": false }],
283
+ // 一致地使用 TypeScript 类型导入
284
+ "@typescript-eslint/consistent-type-imports": [
285
+ "error",
286
+ {
287
+ // 允许使用类型注解
288
+ disallowTypeAnnotations: false,
289
+ },
290
+ ],
291
+
292
+ // vue (https://eslint.vuejs.org/rules)
293
+
294
+ // 允许使用 v-html
295
+ "vue/no-v-html": "off",
296
+ // 禁用所有 props 必填时,必须提供默认值
297
+ "vue/require-default-prop": "off",
298
+ // 强制组件中必须使用 emits 选项声明事件
299
+ "vue/require-explicit-emits": "error",
300
+ // 禁用组件名称必须是多单词
301
+ "vue/multi-word-component-names": "off",
302
+ // 关闭 - 强制从 vue 中导入 Vue相关 API
303
+ "vue/prefer-import-from-vue": "off",
304
+ // 强制 HTML 属性使用 camelCase 风格
305
+ "vue/attribute-hyphenation": [
306
+ "error",
307
+ "always",
308
+ {
309
+ ignore: [
310
+ // 忽略 Element-Plus 加载文案"element-loading-text"
311
+ ],
312
+ },
313
+ ],
314
+
315
+ // 禁止重复的字段名
316
+ "vue/no-dupe-keys": "error",
317
+ // 禁止直接修改 props 的值
318
+ "vue/no-mutating-props": "error",
319
+ // 禁止使用 Vue.js 内置的保留组件名称(如 transition、keep-alive 等)作为自定义组件名称
320
+ "vue/no-reserved-component-names": "error",
321
+ // 禁止在自定义组件上使用 v-text 或 v-html 指令
322
+ "vue/no-v-text-v-html-on-component": "off",
323
+ // 防止<script setup>使用的变量<template>被标记为未使用,此规则仅在启用该no-unused-vars规则时有效。
324
+ "vue/script-setup-uses-vars": "error",
325
+ // 强制自定义事件名称使用 camelCase 风格命名
326
+ "vue/custom-event-name-casing": ["error", "camelCase"],
327
+ // 强制每个 Vue 文件中只包含一个 Vue 组件
328
+ "vue/one-component-per-file": "off",
329
+ // 闭合标签换行风格
330
+ "vue/html-closing-bracket-newline": [
331
+ "error",
332
+ {
333
+ // 强制要求当 HTML 元素跨多行时,闭合标签必须出现在新的一行上
334
+ multiline: "always",
335
+ // 强制要求当 HTML 元素只有一行时,闭合标签应与开始标签在同一行上
336
+ singleline: "never",
337
+ },
338
+ ],
339
+ // 强制 Vue 模板中 HTML 元素的属性按照指定的顺序排列
340
+ "vue/attributes-order": [
341
+ "error",
342
+ {
343
+ order: [
344
+ "DEFINITION",
345
+ "LIST_RENDERING",
346
+ "CONDITIONALS",
347
+ "RENDER_MODIFIERS",
348
+ "GLOBAL",
349
+ "UNIQUE",
350
+ "OTHER_ATTR",
351
+ "EVENTS",
352
+ "CONTENT",
353
+ ],
354
+ },
355
+ ],
356
+
357
+ // 确保 Prettier 错误被 ESLint 捕获
358
+ "prettier/prettier": "error",
359
+
360
+ // import
361
+
362
+ // 确保所有的 import 语句位于文件的顶部,紧接在文件的开头部分,且在任何其他代码之前
363
+ "import/first": "error",
364
+ // 禁止在同一文件中出现重复的 import 语句
365
+ "import/no-duplicates": "error",
366
+ // 导入模块排序风格
367
+ "import/order": [
368
+ "error",
369
+ {
370
+ // 导入模块分组
371
+ groups: [
372
+ // Node.js 内置模块
373
+ "builtin",
374
+ // 第三方模块
375
+ "external",
376
+ // 项目内部模块
377
+ "internal",
378
+ // 父级目录中的模块
379
+ "parent",
380
+ // 具有相同父级的模块
381
+ "sibling",
382
+ // 当前目录的 index.js 或 index.ts 文件
383
+ "index",
384
+ "object",
385
+ "type",
386
+ "unknown",
387
+ ],
388
+ pathGroups: [
389
+ {
390
+ pattern: "vue",
391
+ group: "external",
392
+ position: "before",
393
+ },
394
+ {
395
+ pattern: "@vue/**",
396
+ group: "external",
397
+ position: "before",
398
+ },
399
+ {
400
+ pattern: "element-plus",
401
+ group: "external",
402
+ position: "before",
403
+ },
404
+ {
405
+ pattern: "@element-plus/**",
406
+ group: "external",
407
+ position: "before",
408
+ },
409
+ {
410
+ pattern: "fast-element-plus",
411
+ group: "external",
412
+ position: "before",
413
+ },
414
+ {
415
+ pattern: "@fast-china/**",
416
+ group: "external",
417
+ position: "before",
418
+ },
419
+ ],
420
+ pathGroupsExcludedImportTypes: ["type"],
421
+ // 禁止不同组之间进行换行
422
+ "newlines-between": "never",
423
+ //根据字母顺序对每个组内的顺序进行排序
424
+ alphabetize: {
425
+ order: "asc",
426
+ caseInsensitive: true,
427
+ },
428
+ },
429
+ ],
430
+ // 关闭 - 禁用对无法解析的模块导入的检查
431
+ "import/no-unresolved": "off",
432
+ // 关闭 - 禁用对命名空间导入(例如,import * as)的检查
433
+ "import/namespace": "off",
434
+ // 关闭 - 禁用对默认导入的检查
435
+ "import/default": "off",
436
+ // 关闭 - 禁用对以默认导出方式作为命名导入的检查
437
+ "import/no-named-as-default": "off",
438
+ // 关闭 - 禁用对将默认导出成员当作命名导入的检查
439
+ "import/no-named-as-default-member": "off",
440
+ // 关闭 - 禁用对命名导入(即从模块中导入特定命名的内容)的检查
441
+ "import/named": "off",
442
+ // 限制某些模块导入
443
+ "no-restricted-imports": [
444
+ "error",
445
+ {
446
+ paths: [
447
+ { name: "lodash", message: "Use lodash-unified instead." },
448
+ { name: "lodash-es", message: "Use lodash-unified instead." },
449
+ ],
450
+ patterns: [
451
+ {
452
+ group: ["lodash/*", "lodash-es/*"],
453
+ message: "Use lodash-unified instead.",
454
+ },
455
+ ],
456
+ },
457
+ // {
458
+ // paths: [
459
+ // { name: "lodash-es", message: "Use lodash instead." },
460
+ // { name: "lodash-unified", message: "Use lodash instead." },
461
+ // ],
462
+ // patterns: [
463
+ // {
464
+ // group: ["lodash-es/*", "lodash-unified/*"],
465
+ // message: "Use lodash instead.",
466
+ // },
467
+ // ],
468
+ // },
469
+ ],
470
+ },
471
+ });