@zjutjh/eslint-config 1.0.0 → 2.0.0-beta.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/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # `@zjutjh/eslint-config` [![npm-version](https://img.shields.io/npm/v/%40zjutjh%2Feslint-config)](https://www.npmjs.com/package/@zjutjh/eslint-config)
1
+ # `@zjutjh/eslint-config`
2
+
3
+ [![Open on npmx.dev](https://npmx.dev/api/registry/badge/license/@zjutjh/eslint-config?labelColor=000000&color=000000)](https://npmx.dev/package/@zjutjh/eslint-config)
4
+ [![Open on npmx.dev](https://npmx.dev/api/registry/badge/version/@zjutjh/eslint-config?labelColor=000000&color=000000)](https://npmx.dev/package/@zjutjh/eslint-config)
5
+ [![Open on npmx.dev](https://npmx.dev/api/registry/badge/size/@zjutjh/eslint-config?labelColor=000000&color=000000)](https://npmx.dev/package/@zjutjh/eslint-config)
2
6
 
3
7
  zjutjh 的 ESLint 配置,适用于 JS, TS, Vue3 等项目。
4
8
 
@@ -147,22 +151,23 @@ export default zjutjh(
147
151
  很多人在意代码的格式化,这里单独拿出一章讲。
148
152
 
149
153
  内置两种格式化工具。`@stylistic/eslint-plugin` (lint 工具对格式的检查) 和传统的 formatter 工具
150
- (Prettier) 。stylistic 默认开启,如果要使用 Prettier,需要手动开启。
154
+ ([oxfmt](https://oxc.rs/docs/guide/usage/formatter))。stylistic 默认开启,如果要使用 oxfmt,需要手动开启。
151
155
 
152
156
  ```ts
153
- // 启用 prettier
157
+ // 启用 oxfmt
154
158
  export default zjutjh({
155
- prettier: true
159
+ oxfmt: true
156
160
  }),
157
161
  ```
158
162
 
159
- 支持自定义 prettier 格式化选项,以及关闭对部分文件的格式化(默认对支持的文件全部开启)
163
+ 支持自定义 oxfmt 格式化选项,以及关闭对部分文件的格式化(默认对支持的文件全部开启)
160
164
 
161
165
  ```ts
162
166
  export default zjutjh({
163
- prettier: {
164
- prettierSelfOptions: {
165
- // 自定义 prettier 的格式化风格配置
167
+ oxfmt: {
168
+ oxfmtSelfOptions: {
169
+ // 自定义 oxfmt 的格式化风格配置
170
+ // 参考 https://oxc.rs/docs/guide/usage/formatter
166
171
  },
167
172
  lang: {
168
173
  html: false // 关闭对一些文件的格式化。默认对支持的文件全部开启
@@ -171,7 +176,7 @@ export default zjutjh({
171
176
  })
172
177
  ```
173
178
 
174
- stylistic 只对 js(x) 和 ts(x) 进行格式化,而 prettier 还对其他文件,如 css,html 等的格式化。
179
+ stylistic 只对 js(x) 和 ts(x) 进行格式化,而 oxfmt 还对其他文件,如 vue,css,html,json 等的格式化。
175
180
  如果你要**在编辑器中**自动格式化这些文件,需要配置编辑器来允许 eslint 校验这些类型的文件。
176
181
 
177
182
  ```jsonc
@@ -188,8 +193,8 @@ stylistic 只对 js(x) 和 ts(x) 进行格式化,而 prettier 还对其他文
188
193
  ```
189
194
 
190
195
  > [!WARNING]
191
- > 我们使用 eslint 调用 prettier 可执行文件来进行代码格式化,所以你的编辑器不需要安装 prettier 插件,有
192
- > eslint 插件就行。prettier 的格式化配置声明在配置源码内部,如果启用了 prettier 插件,他读取不到内部的配置,
196
+ > 我们通过 eslint 调用 oxfmt 来进行代码格式化,所以你的编辑器不需要安装额外的格式化插件,有
197
+ > eslint 插件就行。格式化配置声明在配置源码内部,如果启用了 prettier 插件,他读取不到内部的配置,
193
198
  > 会按照默认的配置来格式化,这会导致代码风格不一致。
194
199
 
195
200
  ## 开发指南
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Linter } from "eslint";
2
2
  import { ParserOptions } from "@typescript-eslint/parser";
3
- import { Options } from "prettier";
3
+ import { FormatOptions } from "oxfmt";
4
4
 
5
5
  //#region src/types.d.ts
6
6
  interface OverridesConfigs {
@@ -15,7 +15,7 @@ interface OptionsConfig extends OptionsComponentExts {
15
15
  taro?: boolean;
16
16
  jsx?: boolean;
17
17
  react?: boolean;
18
- prettier?: boolean | OptionsPrettier;
18
+ oxfmt?: boolean | OptionsOxfmt;
19
19
  ignores?: string[];
20
20
  overrides?: OverridesConfigs;
21
21
  }
@@ -25,9 +25,10 @@ interface OptionsComponentExts {
25
25
  interface OptionsTypeScriptParserOptions {
26
26
  parserOptions?: Partial<ParserOptions>;
27
27
  }
28
- interface OptionsPrettier {
29
- prettierSelfOptions?: Options;
30
- /** 对哪些文件启用 prettier,默认全部启用 */
28
+ interface OptionsOxfmt {
29
+ /** 传递给 oxfmt format() API 的选项,参考 https://oxc.rs/docs/guide/usage/formatter */
30
+ oxfmtSelfOptions?: FormatOptions;
31
+ /** 对哪些文件启用 oxfmt,默认全部启用 */
31
32
  lang?: {
32
33
  /** js, ts, vue 文件 */es: boolean; /** css, less, scss 文件 */
33
34
  css: boolean;
package/dist/index.mjs CHANGED
@@ -170,11 +170,11 @@ function getOverrides(options, key) {
170
170
  return { ...options.overrides?.[key] };
171
171
  }
172
172
  //#endregion
173
- //#region src/configs/prettier.ts
173
+ //#region src/configs/oxfmt.ts
174
174
  /**
175
- * @see https://prettier.io/docs/options
175
+ * @see https://oxc.rs/docs/guide/usage/formatter
176
176
  */
177
- const prettierOptions = {
177
+ const oxfmtOptions = {
178
178
  printWidth: 100,
179
179
  tabWidth: 2,
180
180
  useTabs: false,
@@ -186,42 +186,23 @@ const prettierOptions = {
186
186
  bracketSpacing: true,
187
187
  bracketSameLine: false,
188
188
  arrowParens: "always",
189
- requirePragma: false,
190
- insertPragma: false,
191
- proseWrap: "preserve",
192
189
  htmlWhitespaceSensitivity: "css",
193
190
  vueIndentScriptAndStyle: false,
194
191
  endOfLine: "lf",
195
192
  embeddedLanguageFormatting: "auto",
196
193
  singleAttributePerLine: false
197
194
  };
198
- async function prettier(options) {
199
- await ensurePackages([
200
- "eslint-plugin-format",
201
- "eslint-plugin-prettier",
202
- "eslint-config-prettier",
203
- "prettier"
204
- ]);
205
- const [configPrettier, pluginFormat] = await Promise.all([interopDefault(import("eslint-plugin-prettier/recommended")), interopDefault(import("eslint-plugin-format"))]);
195
+ async function oxfmt(options) {
196
+ await ensurePackages(["eslint-plugin-format", "oxfmt"]);
197
+ const pluginFormat = await interopDefault(import("eslint-plugin-format"));
206
198
  const { es: enableESFormat = true, html: enableHTMLFormat = true, css: enableCSSFormat = true, json: enableJSONFormat = true } = options?.lang ?? {};
207
- const mergedPrettierOptions = {
208
- ...prettierOptions,
209
- ...options?.prettierSelfOptions
199
+ const mergedOptions = {
200
+ ...oxfmtOptions,
201
+ ...options?.oxfmtSelfOptions
210
202
  };
211
203
  return [
212
204
  enableESFormat ? {
213
- name: "zjutjh/prettier/setup",
214
- files: [
215
- GLOB_VUE,
216
- GLOB_TS,
217
- GLOB_JS,
218
- GLOB_TSX,
219
- GLOB_JSX
220
- ],
221
- ...configPrettier
222
- } : {},
223
- enableESFormat ? {
224
- name: "zjutjh/prettier/es",
205
+ name: "zjutjh/oxfmt/es",
225
206
  files: [
226
207
  GLOB_VUE,
227
208
  GLOB_TS,
@@ -229,10 +210,11 @@ async function prettier(options) {
229
210
  GLOB_TSX,
230
211
  GLOB_JSX
231
212
  ],
232
- rules: { "prettier/prettier": ["error", mergedPrettierOptions] }
213
+ plugins: { format: pluginFormat },
214
+ rules: { "format/oxfmt": ["error", mergedOptions] }
233
215
  } : {},
234
216
  enableCSSFormat ? {
235
- name: "zjutjh/prettier/css",
217
+ name: "zjutjh/oxfmt/css",
236
218
  files: [
237
219
  GLOB_CSS,
238
220
  GLOB_LESS,
@@ -240,23 +222,17 @@ async function prettier(options) {
240
222
  ],
241
223
  languageOptions: { parser: pluginFormat.parserPlain },
242
224
  plugins: { format: pluginFormat },
243
- rules: { "format/prettier": ["error", {
244
- parser: "css",
245
- mergedPrettierOptions
246
- }] }
225
+ rules: { "format/oxfmt": ["error", mergedOptions] }
247
226
  } : {},
248
227
  enableHTMLFormat ? {
249
- name: "zjutjh/prettier/html",
228
+ name: "zjutjh/oxfmt/html",
250
229
  files: [GLOB_HTML],
251
230
  languageOptions: { parser: pluginFormat.parserPlain },
252
231
  plugins: { format: pluginFormat },
253
- rules: { "format/prettier": ["error", {
254
- parser: "html",
255
- mergedPrettierOptions
256
- }] }
232
+ rules: { "format/oxfmt": ["error", mergedOptions] }
257
233
  } : {},
258
234
  enableJSONFormat ? {
259
- name: "zjutjh/prettier/json",
235
+ name: "zjutjh/oxfmt/json",
260
236
  files: [
261
237
  GLOB_JSON,
262
238
  GLOB_JSON5,
@@ -264,10 +240,7 @@ async function prettier(options) {
264
240
  ],
265
241
  languageOptions: { parser: pluginFormat.parserPlain },
266
242
  plugins: { format: pluginFormat },
267
- rules: { "format/prettier": ["error", {
268
- parser: "json",
269
- mergedPrettierOptions
270
- }] }
243
+ rules: { "format/oxfmt": ["error", mergedOptions] }
271
244
  } : {}
272
245
  ];
273
246
  }
@@ -462,7 +435,7 @@ async function vue(options) {
462
435
  //#endregion
463
436
  //#region src/factory.ts
464
437
  async function zjutjh(options = {}, ...userConfigs) {
465
- 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, prettier: enablePrettier = false } = options;
438
+ 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, oxfmt: enableOxfmt = false } = options;
466
439
  const configs = [];
467
440
  configs.push(ignores({ userIgnores }), javascript(), imports(), stylistic({ overrides: getOverrides(options, "stylistic") }), misc());
468
441
  if (enableVue) componentExts.push("vue");
@@ -479,8 +452,8 @@ async function zjutjh(options = {}, ...userConfigs) {
479
452
  }));
480
453
  if (enableJSX) configs.push(jsx());
481
454
  if (enableReact) configs.push(await react({ overrides: getOverrides(options, "react") }));
482
- const codeStyleOptions = resolveSubOptions(options, "prettier");
483
- if (enablePrettier) configs.push(await prettier(codeStyleOptions));
455
+ const oxfmtOptions = resolveSubOptions(options, "oxfmt");
456
+ if (enableOxfmt) configs.push(await oxfmt(oxfmtOptions));
484
457
  return configs.flat(1).concat(userConfigs);
485
458
  }
486
459
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zjutjh/eslint-config",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "2.0.0-beta.0",
5
5
  "license": "ISC",
6
6
  "author": "zjutjh",
7
7
  "description": "ESLint config used by zjutjh",
@@ -32,13 +32,11 @@
32
32
  "@typescript-eslint/eslint-plugin": "^8.58.2",
33
33
  "@typescript-eslint/parser": "^8.58.2",
34
34
  "eslint": "^10.2.1",
35
- "eslint-config-prettier": "^10.1.8",
36
35
  "eslint-plugin-format": "^2.0.1",
37
- "eslint-plugin-prettier": "^5.5.5",
38
36
  "eslint-plugin-react-hooks": "^7.1.1",
39
37
  "eslint-plugin-react-refresh": "^0.5.2",
40
38
  "eslint-plugin-vue": "^10.8.0",
41
- "prettier": "^3.8.3",
39
+ "oxfmt": "^0.35.0",
42
40
  "vue-eslint-parser": "^10.4.0"
43
41
  },
44
42
  "peerDependenciesMeta": {
@@ -51,15 +49,9 @@
51
49
  "@typescript-eslint/parser": {
52
50
  "optional": true
53
51
  },
54
- "eslint-config-prettier": {
55
- "optional": true
56
- },
57
52
  "eslint-plugin-format": {
58
53
  "optional": true
59
54
  },
60
- "eslint-plugin-prettier": {
61
- "optional": true
62
- },
63
55
  "eslint-plugin-react-hooks": {
64
56
  "optional": true
65
57
  },
@@ -69,7 +61,7 @@
69
61
  "eslint-plugin-vue": {
70
62
  "optional": true
71
63
  },
72
- "prettier": {
64
+ "oxfmt": {
73
65
  "optional": true
74
66
  },
75
67
  "vue-eslint-parser": {
@@ -97,14 +89,12 @@
97
89
  "bumpp": "^11.0.1",
98
90
  "cspell": "^10.0.0",
99
91
  "eslint": "^10.2.1",
100
- "eslint-config-prettier": "^10.1.8",
101
92
  "eslint-plugin-format": "^2.0.1",
102
- "eslint-plugin-prettier": "^5.5.5",
103
93
  "eslint-plugin-react-hooks": "^7.1.1",
104
94
  "eslint-plugin-react-refresh": "^0.5.2",
105
95
  "eslint-plugin-vue": "^10.8.0",
106
96
  "lint-staged": "^16.4.0",
107
- "prettier": "^3.8.3",
97
+ "oxfmt": "^0.35.0",
108
98
  "simple-git-hooks": "^2.13.1",
109
99
  "tsdown": "^0.21.9",
110
100
  "typescript": "^6.0.3",