@huangjunsen/eslint-config 1.0.5 → 1.0.7

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.
Files changed (2) hide show
  1. package/README.md +128 -0
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -0,0 +1,128 @@
1
+ # @huangjunsen/eslint-config
2
+
3
+ 提供给前端工程开箱即用的 ESLint 共享配置集。内置 **ES5 / ES6+ / React / Vue / Node.js / TypeScript** 完整预设,同时支持 **Flat Config** 与传统的 `.eslintrc`。
4
+
5
+ 排版与格式规则已全部交由 Prettier 负责,本配置集不含格式化规则,不会与之冲突。
6
+
7
+ > 支持 `eslint` `^8.57.0 || ^9.0.0 || ^10.0.0`。
8
+
9
+ ---
10
+
11
+ ## 安装
12
+
13
+ ```bash
14
+ npm install @huangjunsen/eslint-config eslint --save-dev
15
+
16
+ # TypeScript 项目额外安装
17
+ npm install typescript --save-dev
18
+
19
+ # React 项目额外安装
20
+ npm install eslint-plugin-react eslint-plugin-react-hooks --save-dev
21
+
22
+ # Vue 项目额外安装
23
+ npm install eslint-plugin-vue vue-eslint-parser --save-dev
24
+ ```
25
+
26
+ ---
27
+
28
+ ## 1. Flat Config(推荐,ESLint 9+)
29
+
30
+ 在项目根目录创建 `eslint.config.mjs`:
31
+
32
+ | 项目类型 | 入口 |
33
+ | --- | --- |
34
+ | JavaScript | `@huangjunsen/eslint-config/flat` |
35
+ | TypeScript | `@huangjunsen/eslint-config/flat/typescript` |
36
+ | React(含 TSX) | `@huangjunsen/eslint-config/flat/react` |
37
+ | Vue(含 `lang="ts"` / `lang="tsx"` 的 SFC) | `@huangjunsen/eslint-config/flat/vue` |
38
+ | Node.js | `@huangjunsen/eslint-config/flat/node` |
39
+
40
+ Vue / React 项目若使用 TypeScript,把 `flat/typescript` 一并引入,并放在**最后**:
41
+
42
+ ```javascript
43
+ import vueConfig from '@huangjunsen/eslint-config/flat/vue';
44
+ import tsConfig from '@huangjunsen/eslint-config/flat/typescript';
45
+
46
+ export default [
47
+ ...vueConfig,
48
+ // 放在最后,保证 TypeScript 的规则能覆盖前置预设
49
+ ...tsConfig,
50
+ ];
51
+ ```
52
+
53
+ 纯 JavaScript 项目:
54
+
55
+ ```javascript
56
+ import config from '@huangjunsen/eslint-config/flat';
57
+
58
+ export default [...config];
59
+ ```
60
+
61
+ > 所有 Flat Config 预设都已内置 `eslint-config-prettier`,不会与 Prettier 产生规则冲突。
62
+ > ESLint 8.57 使用 Flat Config 时需要 `FlatESLint`(`encode-fe-lint` 已自动处理)。
63
+
64
+ ### Vue 预设的规则档位
65
+
66
+ Vue 预设基于 `eslint-plugin-vue` 的 `flat/essential`,而非 `recommended`。
67
+
68
+ `recommended` 中包含 `vue/attributes-order`、`vue/attribute-hyphenation` 等**格式类**规则,Prettier 无法修复,会在存量项目产生数千条长期告警。因此本预设降到 `essential` 并显式关闭以下噪音规则:
69
+
70
+ ```text
71
+ vue/attributes-order
72
+ vue/attribute-hyphenation
73
+ vue/require-default-prop
74
+ vue/multi-word-component-names
75
+ ```
76
+
77
+ 同时保留 `vue/no-v-html`(warn)、`vue/require-explicit-emits`(warn)、`vue/no-mutating-props`(error)。
78
+
79
+ ---
80
+
81
+ ## 2. 传统 `.eslintrc`(ESLint 8 / 9)
82
+
83
+ ```javascript
84
+ // .eslintrc.js
85
+ module.exports = {
86
+ extends: ['@huangjunsen/eslint-config'],
87
+ };
88
+ ```
89
+
90
+ | 项目类型 | 入口 |
91
+ | --- | --- |
92
+ | JavaScript | `@huangjunsen/eslint-config` |
93
+ | ES5 | `@huangjunsen/eslint-config/es5` |
94
+ | React | `@huangjunsen/eslint-config/react` |
95
+ | Vue | `@huangjunsen/eslint-config/vue` |
96
+ | Node.js | `@huangjunsen/eslint-config/node` |
97
+ | TypeScript | `@huangjunsen/eslint-config/typescript` |
98
+ | TypeScript + React | `@huangjunsen/eslint-config/typescript/react` |
99
+ | TypeScript + Vue | `@huangjunsen/eslint-config/typescript/vue` |
100
+ | TypeScript + Node.js | `@huangjunsen/eslint-config/typescript/node` |
101
+
102
+ > ESLint 10 已彻底移除 `.eslintrc` 支持,新项目请直接使用 Flat Config。
103
+
104
+ ---
105
+
106
+ ## 配置文件格式:新旧对照
107
+
108
+ | 工具 | ✅ 新(推荐) | ⚠️ 旧(仍支持但不建议新增) |
109
+ | --- | --- | --- |
110
+ | **ESLint** | `eslint.config.{js,mjs,cjs,ts,mts,cts}` | `.eslintrc.*`、`package.json` 的 `eslintConfig` |
111
+ | **Stylelint** | `stylelint.config.{js,cjs,mjs,ts}` | `.stylelintrc*`(旧格式**优先级更高**,会遮蔽新格式) |
112
+ | **Prettier** | `.prettierrc.*` 与 `prettier.config.*` 同等 | —(无「旧格式」概念) |
113
+ | **markdownlint** | `.markdownlint.{jsonc,json,yaml,yml,cjs,mjs}` | — |
114
+ | **commitlint** | `commitlint.config.{js,cjs,mjs,ts,cts,mts}` | `.commitlintrc*` |
115
+
116
+ ---
117
+
118
+ ## 相关包
119
+
120
+ - [`@huangjunsen/encode-fe-lint`](https://www.npmjs.com/package/@huangjunsen/encode-fe-lint) —— 一键接入与扫描的 CLI
121
+ - [`@huangjunsen/stylelint-config`](https://www.npmjs.com/package/@huangjunsen/stylelint-config)
122
+ - [`@huangjunsen/prettier-config`](https://www.npmjs.com/package/@huangjunsen/prettier-config)
123
+ - [`@huangjunsen/markdownlint-config`](https://www.npmjs.com/package/@huangjunsen/markdownlint-config)
124
+ - [`@huangjunsen/commitlint-config`](https://www.npmjs.com/package/@huangjunsen/commitlint-config)
125
+
126
+ ## 文档
127
+
128
+ 完整说明见 [项目文档](https://huangjunsen0406.github.io/js-encode-fe-spec/packages/eslint-config.html)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huangjunsen/eslint-config",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "index.js",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -36,14 +36,14 @@
36
36
  }
37
37
  },
38
38
  "author": "Huangjunsen <951434130@qq.com>",
39
- "homepage": "https://github.com/Huang-junsen/js-encode-fe-spec#readme",
39
+ "homepage": "https://huangjunsen0406.github.io/js-encode-fe-spec/packages/eslint-config.html",
40
40
  "license": "ISC",
41
41
  "repository": {
42
42
  "type": "git",
43
- "url": "git+https://github.com/Huang-junsen/js-encode-fe-spec.git"
43
+ "url": "git+https://github.com/huangjunsen0406/js-encode-fe-spec.git"
44
44
  },
45
45
  "bugs": {
46
- "url": "https://github.com/Huang-junsen/js-encode-fe-spec/issues"
46
+ "url": "https://github.com/huangjunsen0406/js-encode-fe-spec/issues"
47
47
  },
48
48
  "dependencies": {
49
49
  "@babel/core": "^7.24.4",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "scripts": {
73
73
  "lint": "eslint ./",
74
- "test": "mocha ./__tests__/*.test.js --timeout 5000",
74
+ "test": "mocha ./__tests__/*.test.js --timeout 30000",
75
75
  "print-config": "eslint --print-config ./index.js > ./print-config.json"
76
76
  }
77
77
  }