@zjutjh/eslint-config 0.5.2 → 0.5.3

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 (3) hide show
  1. package/dist/index.d.ts +15 -16
  2. package/dist/index.js +152 -149
  3. package/package.json +30 -15
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Linter } from 'eslint';
2
2
  import { ParserOptions } from '@typescript-eslint/parser';
3
+ import { Options } from 'prettier';
3
4
 
4
5
  type OverridesConfigs = {
5
6
  vue?: Linter.RulesRecord;
@@ -10,7 +11,7 @@ type OptionsConfig = {
10
11
  vue?: boolean;
11
12
  ts?: boolean | (OptionsOverrides & OptionsTypeScriptParserOptions);
12
13
  taro?: boolean;
13
- codeStyle?: boolean | OptionsCodeStyle<string>;
14
+ prettier?: boolean | OptionsPrettier;
14
15
  overrides?: OverridesConfigs;
15
16
  };
16
17
  type OptionsOverrides = {
@@ -19,21 +20,19 @@ type OptionsOverrides = {
19
20
  interface OptionsTypeScriptParserOptions {
20
21
  parserOptions?: Partial<ParserOptions>;
21
22
  }
22
- type OptionsStylistic = {
23
- tool: "stylistic";
24
- };
25
- type OptionsFormatter = {
26
- tool: "formatter";
27
- /**
28
- * 自定义 prettier 配置
29
- * @see https://prettier.io/docs/options
30
- */
31
- prettier?: Record<string, any>;
32
- };
33
- /**
34
- * 默认使用 `@stylistic/eslint-plugin` 作为 formatter
35
- */
36
- type OptionsCodeStyle<T extends string> = T extends OptionsStylistic["tool"] ? OptionsStylistic : OptionsFormatter;
23
+ interface OptionsPrettier {
24
+ prettierSelfOption?: Options;
25
+ /** 对哪些文件启用 prettier,默认全部启用 */
26
+ lang?: {
27
+ /** js, ts, vue 文件 */
28
+ es: boolean;
29
+ /** css, less, scss 文件 */
30
+ css: boolean;
31
+ html: boolean;
32
+ /** json, json5, jsonc 文件 */
33
+ json: boolean;
34
+ };
35
+ }
37
36
 
38
37
  declare function zjutjh(options?: OptionsConfig): Promise<Linter.Config<Linter.RulesRecord>[]>;
39
38
 
package/dist/index.js CHANGED
@@ -1,6 +1,105 @@
1
1
  // src/factory.ts
2
2
  import { isPackageExists as isPackageExists2 } from "local-pkg";
3
3
 
4
+ // src/configs/imports.ts
5
+ import simpleImportSortPlugin from "eslint-plugin-simple-import-sort";
6
+ function imports() {
7
+ return [
8
+ {
9
+ name: "zjutjh/imports/setup",
10
+ plugins: {
11
+ "simple-import-sort": simpleImportSortPlugin
12
+ }
13
+ },
14
+ {
15
+ name: "zjutjh/imports/rules",
16
+ rules: {
17
+ "simple-import-sort/imports": "error",
18
+ "simple-import-sort/exports": "error"
19
+ }
20
+ }
21
+ ];
22
+ }
23
+
24
+ // src/configs/javascript.ts
25
+ import eslintJS from "@eslint/js";
26
+ import globals from "globals";
27
+ function javascript() {
28
+ return [
29
+ {
30
+ name: "zjutjh/javascript/setup",
31
+ languageOptions: {
32
+ ecmaVersion: 2022,
33
+ globals: {
34
+ ...globals.browser,
35
+ ...globals.es2021,
36
+ ...globals.node,
37
+ document: "readonly",
38
+ navigator: "readonly",
39
+ window: "readonly"
40
+ },
41
+ parserOptions: {
42
+ ecmaFeatures: {
43
+ jsx: true
44
+ },
45
+ ecmaVersion: 2022,
46
+ sourceType: "module"
47
+ },
48
+ sourceType: "module"
49
+ },
50
+ linterOptions: {
51
+ reportUnusedDisableDirectives: true
52
+ }
53
+ },
54
+ {
55
+ name: "zjutjh/javascript/rules",
56
+ rules: {
57
+ ...eslintJS.configs.recommended.rules,
58
+ "camelcase": "warn",
59
+ "no-warning-comments": "warn",
60
+ "no-console": ["warn", { allow: ["warn", "error", "info"] }],
61
+ "no-var": "error",
62
+ "no-undef": "off",
63
+ "prefer-const": "warn",
64
+ "arrow-body-style": "error",
65
+ "no-nested-ternary": "error",
66
+ "curly": "error",
67
+ "no-else-return": "error",
68
+ "no-implicit-coercion": "error"
69
+ }
70
+ }
71
+ ];
72
+ }
73
+
74
+ // src/globs.ts
75
+ var VUE_GLOBS = [
76
+ "**/*.vue"
77
+ ];
78
+ var TS_GLOBS = [
79
+ "**/*.?([cm])ts"
80
+ ];
81
+ var JS_GLOBS = [
82
+ "**/*.?([cm])js"
83
+ ];
84
+ var CSS_GLOBS = [
85
+ "**/*.css"
86
+ ];
87
+ var SASS_GLOBS = [
88
+ "**/*.scss",
89
+ "**/*.sass"
90
+ ];
91
+ var LESS_GLOBS = [
92
+ "**/*.less"
93
+ ];
94
+ var HTML_GLOBS = [
95
+ "**/*.html"
96
+ ];
97
+ var JSON_GLOBS = [
98
+ "**/*.json",
99
+ "**/*.json5",
100
+ "**/*.jsonc"
101
+ ];
102
+
4
103
  // src/utils.ts
5
104
  import { isPackageExists } from "local-pkg";
6
105
  async function interopDefault(m) {
@@ -26,7 +125,7 @@ function getOverrides(options, key) {
26
125
  };
27
126
  }
28
127
 
29
- // src/configs/formatter.ts
128
+ // src/configs/prettier.ts
30
129
  var prettierOptions = {
31
130
  printWidth: 100,
32
131
  tabWidth: 2,
@@ -48,167 +147,74 @@ var prettierOptions = {
48
147
  embeddedLanguageFormatting: "auto",
49
148
  singleAttributePerLine: false
50
149
  };
51
- async function formatter(options) {
52
- await ensurePackages([
53
- "eslint-plugin-format"
54
- ]);
55
- const [
56
- pluginFormat
57
- ] = await Promise.all([
150
+ async function prettier(options) {
151
+ await ensurePackages(["eslint-plugin-prettier", "eslint-config-prettier", "prettier"]);
152
+ const [configPrettier, pluginFormat] = await Promise.all([
153
+ interopDefault(import("eslint-plugin-prettier/recommended")),
58
154
  interopDefault(import("eslint-plugin-format"))
59
155
  ]);
156
+ const {
157
+ es: enableESFormat = true,
158
+ html: enableHTMLFormat = true,
159
+ css: enableCSSFormat = true,
160
+ json: enableJSONFormat = true
161
+ } = options?.lang ?? {};
60
162
  const mergedPrettierOptions = {
61
163
  ...prettierOptions,
62
- ...options?.prettier
164
+ ...options?.prettierSelfOption
63
165
  };
64
166
  return [
65
- {
66
- name: "zjutjh/formatter/setup",
67
- plugins: {
68
- format: pluginFormat
69
- }
70
- },
71
- {
72
- name: "zjutjh/formatter/css/rules",
73
- languageOptions: {
74
- parser: pluginFormat.parserPlain
75
- },
76
- files: [
77
- "**/*.less",
78
- "**/*.css",
79
- "**/*.scss",
80
- "**/*.sass"
81
- ],
167
+ enableESFormat ? {
168
+ name: "zjutjh/prettier/setup",
169
+ files: [...VUE_GLOBS, ...TS_GLOBS, ...JS_GLOBS],
170
+ ...configPrettier
171
+ } : {},
172
+ enableESFormat ? {
173
+ name: "zjutjh/prettier/es",
174
+ files: [...VUE_GLOBS, ...TS_GLOBS, ...JS_GLOBS],
82
175
  rules: {
83
- "format/prettier": ["error", { parser: "css", ...mergedPrettierOptions }]
176
+ "prettier/prettier": ["error", mergedPrettierOptions]
84
177
  }
85
- },
86
- {
87
- name: "zjutjh/formatter/vue/rules",
178
+ } : {},
179
+ enableCSSFormat ? {
180
+ name: "zjutjh/prettier/css",
181
+ files: [...CSS_GLOBS, LESS_GLOBS, SASS_GLOBS],
88
182
  languageOptions: {
89
183
  parser: pluginFormat.parserPlain
90
184
  },
91
- files: [
92
- "**/*.vue"
93
- ],
94
- rules: {
95
- "format/prettier": ["error", { parser: "vue", ...mergedPrettierOptions }]
96
- }
97
- },
98
- {
99
- name: "zjutjh/formatter/json/rules",
100
- languageOptions: {
101
- parser: pluginFormat.parserPlain
185
+ plugins: {
186
+ format: pluginFormat
102
187
  },
103
- files: [
104
- "**/*.json"
105
- ],
106
188
  rules: {
107
- "format/prettier": ["error", { parser: "json", ...mergedPrettierOptions }]
189
+ "format/prettier": ["error", { parser: "css", mergedPrettierOptions }]
108
190
  }
109
- },
110
- {
111
- name: "zjutjh/formatter/html/rules",
191
+ } : {},
192
+ enableHTMLFormat ? {
193
+ name: "zjutjh/prettier/html",
194
+ files: [...HTML_GLOBS],
112
195
  languageOptions: {
113
196
  parser: pluginFormat.parserPlain
114
197
  },
115
- files: [
116
- "**/*.html"
117
- ],
118
- rules: {
119
- "format/prettier": ["error", { parser: "html", ...mergedPrettierOptions }]
120
- }
121
- },
122
- {
123
- name: "zjutjh/formatter/js/rules",
124
- languageOptions: {
125
- parser: pluginFormat.parserPlain
198
+ plugins: {
199
+ format: pluginFormat
126
200
  },
127
- files: ["**/*.js", "**/*.jsx"],
128
201
  rules: {
129
- "format/prettier": ["error", { parser: "babel", ...mergedPrettierOptions }]
202
+ "format/prettier": ["error", { parser: "html", mergedPrettierOptions }]
130
203
  }
131
- },
132
- {
133
- name: "zjutjh/formatter/ts/rules",
204
+ } : {},
205
+ enableJSONFormat ? {
206
+ name: "zjutjh/prettier/json",
207
+ files: [...JSON_GLOBS],
134
208
  languageOptions: {
135
209
  parser: pluginFormat.parserPlain
136
210
  },
137
- files: ["**/*.ts", "**/*.tsx"],
138
- rules: {
139
- "format/prettier": ["error", { parser: "typescript", ...mergedPrettierOptions }]
140
- }
141
- }
142
- ];
143
- }
144
-
145
- // src/configs/imports.ts
146
- import simpleImportSortPlugin from "eslint-plugin-simple-import-sort";
147
- function imports() {
148
- return [
149
- {
150
- name: "zjutjh/imports/setup",
151
211
  plugins: {
152
- "simple-import-sort": simpleImportSortPlugin
153
- }
154
- },
155
- {
156
- name: "zjutjh/imports/rules",
157
- rules: {
158
- "simple-import-sort/imports": "error",
159
- "simple-import-sort/exports": "error"
160
- }
161
- }
162
- ];
163
- }
164
-
165
- // src/configs/javascript.ts
166
- import eslintJS from "@eslint/js";
167
- import globals from "globals";
168
- function javascript() {
169
- return [
170
- {
171
- name: "zjutjh/javascript/setup",
172
- languageOptions: {
173
- ecmaVersion: 2022,
174
- globals: {
175
- ...globals.browser,
176
- ...globals.es2021,
177
- ...globals.node,
178
- document: "readonly",
179
- navigator: "readonly",
180
- window: "readonly"
181
- },
182
- parserOptions: {
183
- ecmaFeatures: {
184
- jsx: true
185
- },
186
- ecmaVersion: 2022,
187
- sourceType: "module"
188
- },
189
- sourceType: "module"
212
+ format: pluginFormat
190
213
  },
191
- linterOptions: {
192
- reportUnusedDisableDirectives: true
193
- }
194
- },
195
- {
196
- name: "zjutjh/javascript/rules",
197
214
  rules: {
198
- ...eslintJS.configs.recommended.rules,
199
- "camelcase": "warn",
200
- "no-warning-comments": "warn",
201
- "no-console": ["warn", { allow: ["warn", "error", "info"] }],
202
- "no-var": "error",
203
- "no-undef": "off",
204
- "prefer-const": "warn",
205
- "arrow-body-style": "error",
206
- "no-nested-ternary": "error",
207
- "curly": "error",
208
- "no-else-return": "error",
209
- "no-implicit-coercion": "error"
215
+ "format/prettier": ["error", { parser: "json", mergedPrettierOptions }]
210
216
  }
211
- }
217
+ } : {}
212
218
  ];
213
219
  }
214
220
 
@@ -282,7 +288,7 @@ async function typescript(options) {
282
288
  },
283
289
  {
284
290
  name: "zjutjh/typescript/parser",
285
- files: ["**/*.?([cm])ts"],
291
+ files: TS_GLOBS,
286
292
  languageOptions: {
287
293
  parser: parserTs,
288
294
  parserOptions: {
@@ -339,7 +345,7 @@ async function vue(options) {
339
345
  },
340
346
  {
341
347
  name: "zjutjh/vue/rules",
342
- files: ["**/*.vue"],
348
+ files: VUE_GLOBS,
343
349
  languageOptions: {
344
350
  parser: parserVue,
345
351
  parserOptions: {
@@ -372,11 +378,16 @@ async function zjutjh(options = {}) {
372
378
  vue: enableVue = isPackageExists2("vue"),
373
379
  ts: enableTs = isPackageExists2("typescript"),
374
380
  taro: enableTaro = isPackageExists2("@tarojs/taro"),
375
- codeStyle: enableCodeStyle = true
381
+ prettier: enablePrettier = false
376
382
  } = options;
377
383
  const configs = [];
378
384
  configs.push(javascript());
379
385
  configs.push(imports());
386
+ configs.push(
387
+ stylistic({
388
+ overrides: getOverrides(options, "stylistic")
389
+ })
390
+ );
380
391
  const typescriptOptions = resolveSubOptions(options, "ts");
381
392
  if (enableTs) {
382
393
  configs.push(
@@ -395,17 +406,9 @@ async function zjutjh(options = {}) {
395
406
  })
396
407
  );
397
408
  }
398
- const codeStyleOptions = resolveSubOptions(options, "codeStyle");
399
- if (enableCodeStyle) {
400
- if (codeStyleOptions.tool === "formatter") {
401
- configs.push(await formatter(codeStyleOptions));
402
- } else {
403
- configs.push(
404
- stylistic({
405
- overrides: getOverrides(options, "stylistic")
406
- })
407
- );
408
- }
409
+ const codeStyleOptions = resolveSubOptions(options, "prettier");
410
+ if (enablePrettier) {
411
+ configs.push(await prettier(codeStyleOptions));
409
412
  }
410
413
  return configs.flat(1);
411
414
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zjutjh/eslint-config",
3
3
  "type": "module",
4
- "version": "0.5.2",
4
+ "version": "0.5.3",
5
5
  "license": "ISC",
6
6
  "author": "zjutjh",
7
7
  "description": "Eslint config used by zjutjh",
@@ -21,12 +21,15 @@
21
21
  "registry": "https://registry.npmjs.org/"
22
22
  },
23
23
  "peerDependencies": {
24
- "@typescript-eslint/eslint-plugin": "^8.26.1",
25
- "@typescript-eslint/parser": "^8.26.1",
26
- "eslint-plugin-vue": "^10.0.0",
27
- "vue-eslint-parser": "^10.1.1",
24
+ "@typescript-eslint/eslint-plugin": "^8.29.0",
25
+ "@typescript-eslint/parser": "^8.29.0",
28
26
  "eslint": "^9.9.0",
29
- "eslint-plugin-format": "^1.0.1"
27
+ "eslint-config-prettier": "^10.1.1",
28
+ "eslint-plugin-format": "^1.0.1",
29
+ "eslint-plugin-vue": "^10.0.0",
30
+ "eslint-plugin-prettier": "^5.2.6",
31
+ "prettier": "^3.5.3",
32
+ "vue-eslint-parser": "^10.1.1"
30
33
  },
31
34
  "peerDependenciesMeta": {
32
35
  "@typescript-eslint/eslint-plugin": {
@@ -35,18 +38,27 @@
35
38
  "@typescript-eslint/parser": {
36
39
  "optional": true
37
40
  },
41
+ "eslint-config-prettier": {
42
+ "optional": true
43
+ },
44
+ "eslint-plugin-format": {
45
+ "optional": true
46
+ },
47
+ "eslint-plugin-prettier": {
48
+ "optional": true
49
+ },
38
50
  "eslint-plugin-vue": {
39
51
  "optional": true
40
52
  },
41
- "vue-eslint-parser": {
53
+ "prettier": {
42
54
  "optional": true
43
55
  },
44
- "eslint-plugin-format": {
56
+ "vue-eslint-parser": {
45
57
  "optional": true
46
58
  }
47
59
  },
48
60
  "dependencies": {
49
- "@eslint/js": "^9.22.0",
61
+ "@eslint/js": "^9.24.0",
50
62
  "@stylistic/eslint-plugin": "^4.2.0",
51
63
  "eslint-plugin-simple-import-sort": "^12.1.1",
52
64
  "globals": "^16.0.0",
@@ -54,17 +66,20 @@
54
66
  },
55
67
  "devDependencies": {
56
68
  "@eslint/config-inspector": "^1.0.2",
57
- "@types/node": "^22.13.10",
58
- "@typescript-eslint/eslint-plugin": "^8.26.1",
59
- "@typescript-eslint/parser": "^8.26.1",
69
+ "@types/node": "^22.14.0",
70
+ "@typescript-eslint/eslint-plugin": "^8.29.0",
71
+ "@typescript-eslint/parser": "^8.29.0",
60
72
  "bumpp": "^10.1.0",
61
- "eslint": "^9.9.0",
73
+ "eslint": "^9.24.0",
74
+ "eslint-config-prettier": "^10.1.1",
62
75
  "eslint-plugin-format": "^1.0.1",
76
+ "eslint-plugin-prettier": "^5.2.6",
63
77
  "eslint-plugin-vue": "^10.0.0",
64
78
  "jiti": "^2.4.2",
79
+ "prettier": "^3.5.3",
65
80
  "tsup": "^8.4.0",
66
- "typescript": "^5.8.2",
67
- "vue-eslint-parser": "^10.1.1"
81
+ "typescript": "^5.8.3",
82
+ "vue-eslint-parser": "^10.1.3"
68
83
  },
69
84
  "scripts": {
70
85
  "build": "tsup --format esm --clean --dts",