@zjutjh/eslint-config 2.0.0-beta.1 → 2.0.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
@@ -97,9 +97,6 @@ export default zjutjh({
97
97
  overrides: {
98
98
  vue: {
99
99
  "vue/multi-word-component-names": ["off"]
100
- },
101
- stylistic: {
102
- "stylistic/quotes": ["error", "single"]
103
100
  }
104
101
  },
105
102
  ignores: [
@@ -117,11 +114,6 @@ export default zjutjh({
117
114
  export default zjutjh(
118
115
  // 第一个参数是 zjutjh 专用的配置
119
116
  {
120
- overrides: {
121
- stylistic: {
122
- "stylistic/quotes": ["error", "single"]
123
- }
124
- },
125
117
  ignores: [
126
118
  "**/build"
127
119
  ]
@@ -151,16 +143,15 @@ export default zjutjh(
151
143
 
152
144
  ## 代码格式化
153
145
 
154
- 很多人在意代码的格式化,这里单独拿出一章讲。
146
+ 内置 [oxfmt](https://oxc.rs/docs/guide/usage/formatter) 作为格式化工具,**默认开启**,覆盖 js(x)/ts(x)、
147
+ vue、css/scss/less、html、json/jsonc/json5 等文件。
155
148
 
156
- 内置两种格式化工具。`@stylistic/eslint-plugin` (lint 工具对格式的检查) 和传统的 formatter 工具
157
- ([oxfmt](https://oxc.rs/docs/guide/usage/formatter))。stylistic 默认开启,如果要使用 oxfmt,需要手动开启。
149
+ 如果不希望由 ESLint 进行格式化(例如团队另有格式化方案),可以关闭:
158
150
 
159
151
  ```ts
160
- // 启用 oxfmt
161
152
  export default zjutjh({
162
- oxfmt: true
163
- }),
153
+ oxfmt: false
154
+ })
164
155
  ```
165
156
 
166
157
  支持自定义 oxfmt 格式化选项,以及关闭对部分文件的格式化(默认对支持的文件全部开启)
@@ -179,8 +170,7 @@ export default zjutjh({
179
170
  })
180
171
  ```
181
172
 
182
- stylistic 只对 js(x) 和 ts(x) 进行格式化,而 oxfmt 还对其他文件,如 vue,css,html,json 等的格式化。
183
- 如果你要**在编辑器中**自动格式化这些文件,需要配置编辑器来允许 eslint 校验这些类型的文件。
173
+ 如果你要**在编辑器中**自动格式化非 js/ts 的文件,需要配置编辑器来允许 eslint 校验这些类型的文件。
184
174
 
185
175
  ```jsonc
186
176
  // @filename .vscode/settings.json
package/dist/index.d.mts CHANGED
@@ -6,7 +6,6 @@ import { FormatOptions } from "oxfmt";
6
6
  interface OverridesConfigs {
7
7
  vue?: Linter.RulesRecord;
8
8
  ts?: Linter.RulesRecord;
9
- stylistic?: Linter.RulesRecord;
10
9
  react?: Linter.RulesRecord;
11
10
  }
12
11
  interface OptionsConfig extends OptionsComponentExts {
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import simpleImportSortPlugin from "eslint-plugin-simple-import-sort";
7
7
  import eslintJS from "@eslint/js";
8
8
  import globals from "globals";
9
9
  import uniconPlugin from "eslint-plugin-unicorn";
10
- import pluginStylistic from "@stylistic/eslint-plugin";
10
+ import pluginFormat from "eslint-plugin-format";
11
11
  //#region src/globs.ts
12
12
  const GLOB_VUE = "**/*.vue";
13
13
  const GLOB_JS = "**/*.?([cm])js";
@@ -119,7 +119,7 @@ function javascript() {
119
119
  name: "zjutjh/javascript/rules",
120
120
  rules: {
121
121
  ...eslintJS.configs.recommended.rules,
122
- "camelcase": "warn",
122
+ camelcase: "warn",
123
123
  "no-warning-comments": "warn",
124
124
  "no-console": ["warn", { allow: [
125
125
  "warn",
@@ -131,7 +131,7 @@ function javascript() {
131
131
  "prefer-const": "warn",
132
132
  "arrow-body-style": "error",
133
133
  "no-nested-ternary": "error",
134
- "curly": "error",
134
+ curly: "error",
135
135
  "no-else-return": "error",
136
136
  "no-implicit-coercion": "error",
137
137
  "no-useless-concat": "error",
@@ -156,31 +156,10 @@ function misc() {
156
156
  plugins: { unicorn: uniconPlugin }
157
157
  }, {
158
158
  name: "zjutjh/misc/rules",
159
- rules: { "unicorn/filename-case": ["error", { "case": "kebabCase" }] }
159
+ rules: { "unicorn/filename-case": ["error", { case: "kebabCase" }] }
160
160
  }];
161
161
  }
162
162
  //#endregion
163
- //#region src/utils.ts
164
- async function interopDefault(m) {
165
- const resolved = await m;
166
- return resolved.default || resolved;
167
- }
168
- async function ensurePackages(packages) {
169
- const nonExistingPackages = packages.filter((i) => i && !isPackageExists(i));
170
- if (nonExistingPackages.length === 0) return;
171
- if (await (await import("@clack/prompts")).confirm({ message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?` })) {
172
- const { installPackage } = await import("@antfu/install-pkg");
173
- await installPackage(nonExistingPackages, { dev: true });
174
- }
175
- }
176
- function resolveSubOptions(options, key) {
177
- if (typeof options[key] === "boolean") return {};
178
- return options[key] || {};
179
- }
180
- function getOverrides(options, key) {
181
- return { ...options.overrides?.[key] };
182
- }
183
- //#endregion
184
163
  //#region src/configs/oxfmt.ts
185
164
  /**
186
165
  * @see https://oxc.rs/docs/guide/usage/formatter
@@ -203,9 +182,7 @@ const oxfmtOptions = {
203
182
  embeddedLanguageFormatting: "auto",
204
183
  singleAttributePerLine: false
205
184
  };
206
- async function oxfmt(options) {
207
- await ensurePackages(["eslint-plugin-format", "oxfmt"]);
208
- const pluginFormat = await interopDefault(import("eslint-plugin-format"));
185
+ function oxfmt(options) {
209
186
  const { es: enableESFormat = true, html: enableHTMLFormat = true, css: enableCSSFormat = true, json: enableJSONFormat = true } = options?.lang ?? {};
210
187
  const mergedOptions = {
211
188
  ...oxfmtOptions,
@@ -256,6 +233,27 @@ async function oxfmt(options) {
256
233
  ];
257
234
  }
258
235
  //#endregion
236
+ //#region src/utils.ts
237
+ async function interopDefault(m) {
238
+ const resolved = await m;
239
+ return resolved.default || resolved;
240
+ }
241
+ async function ensurePackages(packages) {
242
+ const nonExistingPackages = packages.filter((i) => i && !isPackageExists(i));
243
+ if (nonExistingPackages.length === 0) return;
244
+ if (await (await import("@clack/prompts")).confirm({ message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?` })) {
245
+ const { installPackage } = await import("@antfu/install-pkg");
246
+ await installPackage(nonExistingPackages, { dev: true });
247
+ }
248
+ }
249
+ function resolveSubOptions(options, key) {
250
+ if (typeof options[key] === "boolean") return {};
251
+ return options[key] || {};
252
+ }
253
+ function getOverrides(options, key) {
254
+ return { ...options.overrides?.[key] };
255
+ }
256
+ //#endregion
259
257
  //#region src/configs/react.ts
260
258
  async function react(options) {
261
259
  await ensurePackages([
@@ -294,45 +292,6 @@ async function react(options) {
294
292
  }];
295
293
  }
296
294
  //#endregion
297
- //#region src/configs/stylistic.ts
298
- function stylistic(options) {
299
- return [{
300
- name: "zjutjh/stylistic/rules",
301
- plugins: { "@stylistic": pluginStylistic },
302
- rules: {
303
- "@stylistic/eol-last": ["error", "always"],
304
- "@stylistic/indent": ["error", 2],
305
- "@stylistic/keyword-spacing": "error",
306
- "@stylistic/key-spacing": "error",
307
- "@stylistic/no-trailing-spaces": "error",
308
- "@stylistic/linebreak-style": ["error", "unix"],
309
- "@stylistic/quotes": ["error", "double"],
310
- "@stylistic/function-call-spacing": "error",
311
- "@stylistic/semi": "error",
312
- "@stylistic/no-multiple-empty-lines": ["warn", { max: 1 }],
313
- "@stylistic/object-curly-spacing": ["error", "always"],
314
- "@stylistic/arrow-spacing": "error",
315
- "@stylistic/block-spacing": "error",
316
- "@stylistic/brace-style": "error",
317
- "@stylistic/comma-dangle": "error",
318
- "@stylistic/no-multi-spaces": "error",
319
- "@stylistic/comma-spacing": "error",
320
- "@stylistic/switch-colon-spacing": "error",
321
- "@stylistic/type-annotation-spacing": "error",
322
- "@stylistic/space-before-blocks": "error",
323
- "@stylistic/space-before-function-paren": ["error", {
324
- "anonymous": "never",
325
- "named": "never",
326
- "asyncArrow": "always"
327
- }],
328
- "@stylistic/space-in-parens": "error",
329
- "@stylistic/space-infix-ops": "error",
330
- "@stylistic/spaced-comment": "error",
331
- ...options.overrides
332
- }
333
- }];
334
- }
335
- //#endregion
336
295
  //#region src/configs/typescript.ts
337
296
  async function typescript(options) {
338
297
  const { componentExts = [], overrides, parserOptions } = options;
@@ -435,9 +394,9 @@ async function vue(options) {
435
394
  "vue/component-name-in-template-casing": [
436
395
  "error",
437
396
  "kebab-case",
438
- { "registeredComponentsOnly": true }
397
+ { registeredComponentsOnly: true }
439
398
  ],
440
- "vue/max-attributes-per-line": ["error", { "singleline": { "max": 3 } }],
399
+ "vue/max-attributes-per-line": ["error", { singleline: { max: 3 } }],
441
400
  "vue/prefer-true-attribute-shorthand": ["warn", options?.taro ? "never" : "always"],
442
401
  ...options?.overrides
443
402
  }
@@ -446,12 +405,12 @@ async function vue(options) {
446
405
  //#endregion
447
406
  //#region src/factory.ts
448
407
  async function zjutjh(options = {}, ...userConfigs) {
449
- const { componentExts = [], vue: enableVue = isPackageExists("vue"), ts: enableTs = isPackageExists("typescript"), taro: enableTaro = isPackageExists("@tarojs/taro"), jsx: enableJSX = isPackageExists("react"), react: enableReact = isPackageExists("react"), ignores: userIgnores, gitignore: enableGitignore = false, oxfmt: enableOxfmt = false } = options;
408
+ const { componentExts = [], vue: enableVue = isPackageExists("vue"), ts: enableTs = isPackageExists("typescript"), taro: enableTaro = isPackageExists("@tarojs/taro"), jsx: enableJSX = isPackageExists("react"), react: enableReact = isPackageExists("react"), ignores: userIgnores, gitignore: enableGitignore = false, oxfmt: enableOxfmt = true } = options;
450
409
  const configs = [];
451
410
  configs.push(ignores({
452
411
  userIgnores,
453
412
  gitignore: enableGitignore
454
- }), javascript(), imports(), stylistic({ overrides: getOverrides(options, "stylistic") }), misc());
413
+ }), javascript(), imports(), misc());
455
414
  if (enableVue) componentExts.push("vue");
456
415
  const typescriptOptions = resolveSubOptions(options, "ts");
457
416
  if (enableTs) configs.push(await typescript({
@@ -467,7 +426,7 @@ async function zjutjh(options = {}, ...userConfigs) {
467
426
  if (enableJSX) configs.push(jsx());
468
427
  if (enableReact) configs.push(await react({ overrides: getOverrides(options, "react") }));
469
428
  const oxfmtOptions = resolveSubOptions(options, "oxfmt");
470
- if (enableOxfmt) configs.push(await oxfmt(oxfmtOptions));
429
+ if (enableOxfmt) configs.push(oxfmt(oxfmtOptions));
471
430
  return configs.flat(1).concat(userConfigs);
472
431
  }
473
432
  //#endregion
package/package.json CHANGED
@@ -1,42 +1,66 @@
1
1
  {
2
2
  "name": "@zjutjh/eslint-config",
3
- "type": "module",
4
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.2",
4
+ "description": "ESLint config used by zjutjh",
5
5
  "license": "ISC",
6
6
  "author": "zjutjh",
7
- "description": "ESLint config used by zjutjh",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/zjutjh/eslint-config.git"
10
+ },
8
11
  "files": [
9
12
  "dist"
10
13
  ],
14
+ "type": "module",
11
15
  "exports": {
12
16
  ".": {
13
- "import": "./dist/index.mjs",
14
- "types": "./dist/index.d.mts"
17
+ "types": "./dist/index.d.mts",
18
+ "import": "./dist/index.mjs"
15
19
  }
16
20
  },
17
- "engines": {
18
- "node": ">=24"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/zjutjh/eslint-config.git"
23
- },
24
21
  "publishConfig": {
25
22
  "registry": "https://registry.npmjs.org/"
26
23
  },
27
- "simple-git-hooks": {
28
- "pre-commit": "pnpm lint-staged"
24
+ "dependencies": {
25
+ "@antfu/install-pkg": "^1.1.0",
26
+ "@clack/prompts": "^1.2.0",
27
+ "@eslint/compat": "^2.0.5",
28
+ "@eslint/js": "^10.0.1",
29
+ "eslint-plugin-format": "^2.0.1",
30
+ "eslint-plugin-import-x": "^4.16.2",
31
+ "eslint-plugin-simple-import-sort": "^13.0.0",
32
+ "eslint-plugin-unicorn": "^64.0.0",
33
+ "globals": "^17.5.0",
34
+ "local-pkg": "^1.1.2",
35
+ "oxfmt": "^0.35.0"
36
+ },
37
+ "devDependencies": {
38
+ "@eslint-react/eslint-plugin": "^4.2.3",
39
+ "@eslint/config-inspector": "^2.0.0",
40
+ "@eslint/core": "^1.2.1",
41
+ "@types/node": "^25.6.0",
42
+ "@typescript-eslint/eslint-plugin": "^8.58.2",
43
+ "@typescript-eslint/parser": "^8.58.2",
44
+ "bumpp": "^11.0.1",
45
+ "cspell": "^10.0.0",
46
+ "eslint": "^10.2.1",
47
+ "eslint-plugin-react-hooks": "^7.1.1",
48
+ "eslint-plugin-react-refresh": "^0.5.2",
49
+ "eslint-plugin-vue": "^10.8.0",
50
+ "lint-staged": "^16.4.0",
51
+ "simple-git-hooks": "^2.13.1",
52
+ "tsdown": "^0.21.9",
53
+ "typescript": "^6.0.3",
54
+ "vue-eslint-parser": "^10.4.0"
29
55
  },
30
56
  "peerDependencies": {
31
57
  "@eslint-react/eslint-plugin": "^4.2.3",
32
58
  "@typescript-eslint/eslint-plugin": "^8.58.2",
33
59
  "@typescript-eslint/parser": "^8.58.2",
34
60
  "eslint": "^10.2.1",
35
- "eslint-plugin-format": "^2.0.1",
36
61
  "eslint-plugin-react-hooks": "^7.1.1",
37
62
  "eslint-plugin-react-refresh": "^0.5.2",
38
63
  "eslint-plugin-vue": "^10.8.0",
39
- "oxfmt": "^0.35.0",
40
64
  "vue-eslint-parser": "^10.4.0"
41
65
  },
42
66
  "peerDependenciesMeta": {
@@ -49,9 +73,6 @@
49
73
  "@typescript-eslint/parser": {
50
74
  "optional": true
51
75
  },
52
- "eslint-plugin-format": {
53
- "optional": true
54
- },
55
76
  "eslint-plugin-react-hooks": {
56
77
  "optional": true
57
78
  },
@@ -61,45 +82,15 @@
61
82
  "eslint-plugin-vue": {
62
83
  "optional": true
63
84
  },
64
- "oxfmt": {
65
- "optional": true
66
- },
67
85
  "vue-eslint-parser": {
68
86
  "optional": true
69
87
  }
70
88
  },
71
- "dependencies": {
72
- "@antfu/install-pkg": "^1.1.0",
73
- "@clack/prompts": "^1.2.0",
74
- "@eslint/compat": "^2.0.5",
75
- "@eslint/js": "^10.0.1",
76
- "@stylistic/eslint-plugin": "^5.10.0",
77
- "eslint-plugin-import-x": "^4.16.2",
78
- "eslint-plugin-simple-import-sort": "^13.0.0",
79
- "eslint-plugin-unicorn": "^64.0.0",
80
- "globals": "^17.5.0",
81
- "local-pkg": "^1.1.2"
89
+ "simple-git-hooks": {
90
+ "pre-commit": "pnpm lint-staged"
82
91
  },
83
- "devDependencies": {
84
- "@eslint-react/eslint-plugin": "^4.2.3",
85
- "@eslint/config-inspector": "^2.0.0",
86
- "@eslint/core": "^1.2.1",
87
- "@types/node": "^25.6.0",
88
- "@typescript-eslint/eslint-plugin": "^8.58.2",
89
- "@typescript-eslint/parser": "^8.58.2",
90
- "bumpp": "^11.0.1",
91
- "cspell": "^10.0.0",
92
- "eslint": "^10.2.1",
93
- "eslint-plugin-format": "^2.0.1",
94
- "eslint-plugin-react-hooks": "^7.1.1",
95
- "eslint-plugin-react-refresh": "^0.5.2",
96
- "eslint-plugin-vue": "^10.8.0",
97
- "lint-staged": "^16.4.0",
98
- "oxfmt": "^0.35.0",
99
- "simple-git-hooks": "^2.13.1",
100
- "tsdown": "^0.21.9",
101
- "typescript": "^6.0.3",
102
- "vue-eslint-parser": "^10.4.0"
92
+ "engines": {
93
+ "node": ">=24"
103
94
  },
104
95
  "scripts": {
105
96
  "build": "tsdown",