@ziloen/eslint-config 0.1.2 → 0.1.4

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/dist/index.cjs CHANGED
@@ -288,217 +288,256 @@ var javascript = [
288
288
  ];
289
289
 
290
290
  // src/configs/typescript.ts
291
- var typescript = [
292
- ...javascript,
293
- {
294
- files: [
295
- "**/*.?([cm])[tj]s?(x)"
296
- ],
297
- languageOptions: {
298
- parser: parserTs,
299
- sourceType: "module",
300
- parserOptions: {
301
- project: true
302
- // EXPERIMENTAL_useProjectService: true
291
+ var import_node_process = require("process");
292
+ function typescript({ tsconfigPath }) {
293
+ return [
294
+ ...javascript,
295
+ {
296
+ plugins: {
297
+ "@typescript-eslint": import_eslint_plugin.default
303
298
  }
304
299
  },
305
- plugins: {
306
- "@typescript-eslint": import_eslint_plugin.default
307
- },
308
- rules: {
309
- ...import_eslint_plugin.default.configs["strict-type-checked"].rules,
310
- /** ✅禁止不必要的 await */
311
- // '@typescript-eslint/await-thenable': 'warn',
312
- /** 🎨不限制只使用 interface 或者 type */
313
- "@typescript-eslint/consistent-type-definitions": "off",
314
- /** 可选参数必须放在最后 */
315
- "default-param-last": "off",
316
- "@typescript-eslint/default-param-last": "error",
317
- /** 🎨不强制使用 `.`(点) 来访问属性 */
318
- "dot-notation": "off",
319
- "@typescript-eslint/dot-notation": "off",
320
- /** 🔒禁止使用 void 函数的返回值 ("off" 因为 return voidExpression() 这种缩写 { voidExpress(); return } 也会报错) */
321
- "@typescript-eslint/no-confusing-void-expression": ["off", {
322
- ignoreArrowShorthand: true
323
- }],
324
- /** 不允许 class 有重复的成员 (TypeScript 已检查,禁用此规则) */
325
- "no-dupe-class-members": "off",
326
- "@typescript-eslint/no-dupe-class-members": "off",
327
- /** 🎨允许空函数 */
328
- "@typescript-eslint/no-empty-function": "off",
329
- /** ✅允许显式 any */
330
- "@typescript-eslint/no-explicit-any": "off",
331
- /** ✅允许未处理的 Promise */
332
- "@typescript-eslint/no-floating-promises": "off",
333
- /** 🔒不允许隐式 eval */
334
- // "no-implied-eval": "off",
335
- // "@typescript-eslint/no-implied-eval": "error",
336
- /** 禁止 for 循环内声明的函数引用函数外变量 */
337
- "no-loop-func": "off",
338
- "@typescript-eslint/no-loop-func": "error",
339
- /** 禁止 promise 错误用法 */
340
- "@typescript-eslint/no-misused-promises": ["error", {
341
- /** 允许快捷写法 */
342
- checksVoidReturn: false
343
- }],
344
- /** ✅禁止超出精度范围的数字 */
345
- // 'no-loss-of-precision': 'off',
346
- // '@typescript-eslint/no-loss-of-precision': 'error',
347
- /** 允许非空断言 */
348
- "@typescript-eslint/no-non-null-assertion": "off",
349
- /** 允许 TypeScript 重载声明 */
350
- "no-redeclare": "off",
351
- "@typescript-eslint/no-redeclare": ["error"],
352
- /** ✅禁止冗余类型定义 */
353
- "@typescript-eslint/no-redundant-type-constituents": "warn",
354
- /** 🔒Disallow throwing literals as exceptions. */
355
- "no-throw-literal": "off",
356
- "@typescript-eslint/no-throw-literal": ["error", {
357
- allowThrowingAny: false,
358
- allowThrowingUnknown: false
359
- }],
360
- /** 禁用默认`no-undef`,eslint 不会检查`*.d.ts`,导致误报全局变量与类型不存在 */
361
- "no-undef": "off",
362
- /**
363
- * 🔒不必要的条件判断
364
- *
365
- * 因为有时类型不正确,autofix 会导致运行时错误,故关闭
366
- */
367
- "@typescript-eslint/no-unnecessary-condition": "off",
368
- /**
369
- * ✅不必要的类型断言
370
- *
371
- * 因为有时类型不正确,autofix 会导致 TS 错误,故关闭
372
- */
373
- "@typescript-eslint/no-unnecessary-type-assertion": "off",
374
- /** 警告未使用的表达式 */
375
- "no-unused-expressions": "off",
376
- "@typescript-eslint/no-unused-expressions": ["warn", {
377
- allowShortCircuit: true,
378
- enforceForJSX: true
379
- }],
380
- /** 允许未使用变量 */
381
- "no-unused-vars": "off",
382
- "@typescript-eslint/no-unused-vars": "off",
383
- /**
384
- *
385
- */
386
- "@typescript-eslint/prefer-nullish-coalescing": ["warn", {
387
- ignorePrimitives: {
388
- bigint: true,
389
- boolean: true,
390
- number: true,
391
- string: true
300
+ {
301
+ files: ["**/*.?([cm])[tj]s?(x)", "**/*.vue"],
302
+ languageOptions: {
303
+ parser: parserTs,
304
+ sourceType: "module",
305
+ parserOptions: {
306
+ ecmaVersion: "latest",
307
+ project: tsconfigPath,
308
+ tsconfigRootDir: (0, import_node_process.cwd)()
309
+ // extraFileExtensions: ['.vue']
310
+ // project: true,
311
+ // EXPERIMENTAL_useProjectService: true,
392
312
  }
393
- }],
394
- /**
395
- * 使用可选链`a?.b`替代`a && a.b`
396
- *
397
- * FIXME:
398
- * ```ts
399
- * if (!a || !a.b)
400
- * // ^ 也会被要求改成 ?.,降低可读性,且无配置,故关闭
401
- * ```
402
- */
403
- "@typescript-eslint/prefer-optional-chain": "off",
404
- /**
405
- * 🔧返回 promise 的函数必须有 async 关键字
406
- *
407
- * 不写也行,不限制此偏好,故关闭
408
- */
409
- "@typescript-eslint/promise-function-async": ["off", {
410
- checkArrowFunctions: false
411
- }],
412
- /**
413
- * 数组排序需显式指明排序方法,默认行为可能并不是想要的结果
414
- * ```ts
415
- * [1, 2, 3, 10, 20, 30].sort(); //→ [1, 10, 2, 20, 3, 30]
416
- * ```
417
- */
418
- "@typescript-eslint/require-array-sort-compare": ["error"],
419
- /** ✅模板字符串只允许数字字符串 */
420
- "@typescript-eslint/restrict-template-expressions": ["error", {
421
- allowNumber: true
422
- }],
423
- /** 允许可合为一个联合类型的函数声明多个函数签名 */
424
- "@typescript-eslint/unified-signatures": "off"
313
+ },
314
+ rules: {
315
+ ...import_eslint_plugin.default.configs["strict-type-checked"].rules,
316
+ /** ✅禁止不必要的 await */
317
+ // '@typescript-eslint/await-thenable': 'warn',
318
+ /** 🎨不限制只使用 interface 或者 type */
319
+ "@typescript-eslint/consistent-type-definitions": "off",
320
+ /** 可选参数必须放在最后 */
321
+ "default-param-last": "off",
322
+ "@typescript-eslint/default-param-last": "error",
323
+ /** 🎨不强制使用 `.`(点) 来访问属性 */
324
+ "dot-notation": "off",
325
+ "@typescript-eslint/dot-notation": "off",
326
+ /** 🔒禁止使用 void 函数的返回值 ("off" 因为 return voidExpression() 这种缩写 { voidExpress(); return } 也会报错) */
327
+ "@typescript-eslint/no-confusing-void-expression": [
328
+ "off",
329
+ {
330
+ ignoreArrowShorthand: true
331
+ }
332
+ ],
333
+ /** 不允许 class 有重复的成员 (TypeScript 已检查,禁用此规则) */
334
+ "no-dupe-class-members": "off",
335
+ "@typescript-eslint/no-dupe-class-members": "off",
336
+ /** 🎨允许空函数 */
337
+ "@typescript-eslint/no-empty-function": "off",
338
+ /** ✅允许显式 any */
339
+ "@typescript-eslint/no-explicit-any": "off",
340
+ /** ✅允许未处理的 Promise */
341
+ "@typescript-eslint/no-floating-promises": "off",
342
+ /** 🔒不允许隐式 eval */
343
+ // "no-implied-eval": "off",
344
+ // "@typescript-eslint/no-implied-eval": "error",
345
+ /** 禁止 for 循环内声明的函数引用函数外变量 */
346
+ "no-loop-func": "off",
347
+ "@typescript-eslint/no-loop-func": "error",
348
+ /** 禁止 promise 错误用法 */
349
+ "@typescript-eslint/no-misused-promises": [
350
+ "error",
351
+ {
352
+ /** 允许快捷写法 */
353
+ checksVoidReturn: false
354
+ }
355
+ ],
356
+ /** ✅禁止超出精度范围的数字 */
357
+ // 'no-loss-of-precision': 'off',
358
+ // '@typescript-eslint/no-loss-of-precision': 'error',
359
+ /** 允许非空断言 */
360
+ "@typescript-eslint/no-non-null-assertion": "off",
361
+ /** 允许 TypeScript 重载声明 */
362
+ "no-redeclare": "off",
363
+ "@typescript-eslint/no-redeclare": ["error"],
364
+ /** ✅禁止冗余类型定义 */
365
+ "@typescript-eslint/no-redundant-type-constituents": "warn",
366
+ /** 🔒Disallow throwing literals as exceptions. */
367
+ "no-throw-literal": "off",
368
+ "@typescript-eslint/no-throw-literal": [
369
+ "error",
370
+ {
371
+ allowThrowingAny: false,
372
+ allowThrowingUnknown: false
373
+ }
374
+ ],
375
+ /** 禁用默认`no-undef`,eslint 不会检查`*.d.ts`,导致误报全局变量与类型不存在 */
376
+ "no-undef": "off",
377
+ /**
378
+ * 🔒不必要的条件判断
379
+ *
380
+ * 因为有时类型不正确,autofix 会导致运行时错误,故关闭
381
+ */
382
+ "@typescript-eslint/no-unnecessary-condition": "off",
383
+ /**
384
+ * ✅不必要的类型断言
385
+ *
386
+ * 因为有时类型不正确,autofix 会导致 TS 错误,故关闭
387
+ */
388
+ "@typescript-eslint/no-unnecessary-type-assertion": "off",
389
+ /** 警告未使用的表达式 */
390
+ "no-unused-expressions": "off",
391
+ "@typescript-eslint/no-unused-expressions": [
392
+ "warn",
393
+ {
394
+ allowShortCircuit: true,
395
+ enforceForJSX: true
396
+ }
397
+ ],
398
+ /** 允许未使用变量 */
399
+ "no-unused-vars": "off",
400
+ "@typescript-eslint/no-unused-vars": "off",
401
+ /**
402
+ *
403
+ */
404
+ "@typescript-eslint/prefer-nullish-coalescing": [
405
+ "warn",
406
+ {
407
+ ignorePrimitives: {
408
+ bigint: true,
409
+ boolean: true,
410
+ number: true,
411
+ string: true
412
+ }
413
+ }
414
+ ],
415
+ /**
416
+ * 使用可选链`a?.b`替代`a && a.b`
417
+ *
418
+ * FIXME:
419
+ * ```ts
420
+ * if (!a || !a.b)
421
+ * // ^ 也会被要求改成 ?.,降低可读性,且无配置,故关闭
422
+ * ```
423
+ */
424
+ "@typescript-eslint/prefer-optional-chain": "off",
425
+ /**
426
+ * 🔧返回 promise 的函数必须有 async 关键字
427
+ *
428
+ * 不写也行,不限制此偏好,故关闭
429
+ */
430
+ "@typescript-eslint/promise-function-async": [
431
+ "off",
432
+ {
433
+ checkArrowFunctions: false
434
+ }
435
+ ],
436
+ /**
437
+ * 数组排序需显式指明排序方法,默认行为可能并不是想要的结果
438
+ * ```ts
439
+ * [1, 2, 3, 10, 20, 30].sort(); //→ [1, 10, 2, 20, 3, 30]
440
+ * ```
441
+ */
442
+ "@typescript-eslint/require-array-sort-compare": ["error"],
443
+ /** ✅模板字符串只允许数字字符串 */
444
+ "@typescript-eslint/restrict-template-expressions": [
445
+ "error",
446
+ {
447
+ allowNumber: true
448
+ }
449
+ ],
450
+ /** 允许可合为一个联合类型的函数声明多个函数签名 */
451
+ "@typescript-eslint/unified-signatures": "off"
452
+ }
425
453
  }
426
- }
427
- ];
454
+ ];
455
+ }
428
456
 
429
457
  // src/configs/vue.ts
430
- var vue = [
431
- ...typescript,
432
- {
433
- files: ["**/*.vue"],
434
- languageOptions: {
435
- parser: import_vue_eslint_parser.default,
436
- parserOptions: {
437
- parser: parserTs,
438
- ecmaFeatures: {
439
- jsx: true
440
- },
441
- extraFileExtensions: [".vue"],
442
- sourceType: "module"
458
+ function vue({ tsconfigPath }) {
459
+ return [
460
+ ...typescript({ tsconfigPath }),
461
+ {
462
+ plugins: {
463
+ vue: import_eslint_plugin_vue.default
443
464
  }
444
465
  },
445
- plugins: {
446
- "@typescript-eslint": import_eslint_plugin.default,
447
- vue: import_eslint_plugin_vue.default
448
- },
449
- processor: import_eslint_plugin_vue.default.processors[".vue"],
450
- rules: {
451
- ...import_eslint_plugin_vue.default.configs["vue3-essential"].rules,
452
- /** allow ununed vars */
453
- "vue/no-unused-vars": "off",
454
- "vue/html-self-closing": "off",
455
- "vue/max-attributes-per-line": "off",
456
- "vue/multi-word-component-names": "off",
457
- // 'vue/no-v-html': 'off',
458
- "vue/require-default-prop": "off",
459
- "vue/require-prop-types": "off",
460
- "vue/singleline-html-element-content-newline": "off"
466
+ {
467
+ files: ["**/*.vue"],
468
+ // plugins: {
469
+ // vue: pluginVue,
470
+ // },
471
+ languageOptions: {
472
+ parser: import_vue_eslint_parser.default,
473
+ parserOptions: {
474
+ ecmaFeatures: {
475
+ jsx: true
476
+ },
477
+ ecmaVersion: "latest",
478
+ extraFileExtensions: [".vue"],
479
+ parser: parserTs,
480
+ sourceType: "module",
481
+ project: true
482
+ // EXPERIMENTAL_useProjectService: true,
483
+ }
484
+ },
485
+ processor: import_eslint_plugin_vue.default.processors[".vue"],
486
+ rules: {
487
+ ...import_eslint_plugin_vue.default.configs["vue3-essential"].rules,
488
+ /** allow ununed vars */
489
+ "vue/no-unused-vars": "off",
490
+ "vue/html-self-closing": "off",
491
+ "vue/max-attributes-per-line": "off",
492
+ "vue/multi-word-component-names": "off",
493
+ // 'vue/no-v-html': 'off',
494
+ "vue/require-default-prop": "off",
495
+ "vue/require-prop-types": "off",
496
+ "vue/singleline-html-element-content-newline": "off"
497
+ }
461
498
  }
462
- }
463
- ];
499
+ ];
500
+ }
464
501
 
465
502
  // src/configs/react.ts
466
- var react = [
467
- ...typescript,
468
- {
469
- files: ["**/*.jsx", "**/*.tsx"],
470
- plugins: {
471
- react: import_eslint_plugin_react.default,
472
- ziloen: import_eslint_plugin_ziloen.default
473
- },
474
- languageOptions: {
475
- parser: parserTs,
476
- parserOptions: {
477
- ecmaFeatures: {
478
- jsx: true
503
+ function react({ tsconfigPath }) {
504
+ return [
505
+ ...typescript({ tsconfigPath }),
506
+ {
507
+ files: ["**/*.jsx", "**/*.tsx"],
508
+ plugins: {
509
+ react: import_eslint_plugin_react.default,
510
+ ziloen: import_eslint_plugin_ziloen.default
511
+ },
512
+ languageOptions: {
513
+ parser: parserTs,
514
+ parserOptions: {
515
+ ecmaFeatures: {
516
+ jsx: true
517
+ }
479
518
  }
519
+ },
520
+ rules: {
521
+ /** 16+ 不需要此导入 React */
522
+ "react/react-in-jsx-scope": "off",
523
+ /** ✅需要 key */
524
+ "react/jsx-key": ["error", {
525
+ // checkFragmentShorthand: true
526
+ }],
527
+ /** 让 TS 检查 */
528
+ "react/jsx-no-undef": "off",
529
+ /** 简写 <React.Fragment></React.Fragment> => <></> */
530
+ "react/jsx-fragments": ["warn", "syntax"],
531
+ /** 避免错误用法 */
532
+ "react/no-invalid-html-attribute": "warn",
533
+ /** 不允许可能出错的的 render 类型(number | string | object),(即使是 bool 也会报错,太蠢了) */
534
+ // 'react/jsx-no-leaked-render': 'error',
535
+ /** 严格 jsx render 类型,支持 TS 检查,替代 react/jsx-no-leaked-render */
536
+ "ziloen/jsx-strict-logical-expressions": "error"
480
537
  }
481
- },
482
- rules: {
483
- /** 16+ 不需要此导入 React */
484
- "react/react-in-jsx-scope": "off",
485
- /** ✅需要 key */
486
- "react/jsx-key": ["error", {
487
- // checkFragmentShorthand: true
488
- }],
489
- /** 让 TS 检查 */
490
- "react/jsx-no-undef": "off",
491
- /** 简写 <React.Fragment></React.Fragment> => <></> */
492
- "react/jsx-fragments": ["warn", "syntax"],
493
- /** 避免错误用法 */
494
- "react/no-invalid-html-attribute": "warn",
495
- /** 不允许可能出错的的 render 类型(number | string | object),(即使是 bool 也会报错,太蠢了) */
496
- // 'react/jsx-no-leaked-render': 'error',
497
- /** 严格 jsx render 类型,支持 TS 检查,替代 react/jsx-no-leaked-render */
498
- "ziloen/jsx-strict-logical-expressions": "error"
499
538
  }
500
- }
501
- ];
539
+ ];
540
+ }
502
541
 
503
542
  // src/configs/format.ts
504
543
  var format = [
package/dist/index.d.cts CHANGED
@@ -3,12 +3,15 @@ export { FlatESLintConfig, FlatESLintConfigItem, defineFlatConfig } from 'eslint
3
3
 
4
4
  declare const javascript: FlatESLintConfigItem[];
5
5
 
6
- declare const typescript: FlatESLintConfigItem[];
6
+ type TSOptions = {
7
+ tsconfigPath: string;
8
+ };
9
+ declare function typescript({ tsconfigPath }: TSOptions): FlatESLintConfigItem[];
7
10
 
8
- declare const vue: FlatESLintConfigItem[];
11
+ declare function vue({ tsconfigPath }: TSOptions): FlatESLintConfigItem[];
9
12
 
10
- declare const react: FlatESLintConfigItem[];
13
+ declare function react({ tsconfigPath }: TSOptions): FlatESLintConfigItem[];
11
14
 
12
15
  declare const format: FlatESLintConfigItem[];
13
16
 
14
- export { format, javascript, react, typescript, vue };
17
+ export { TSOptions, format, javascript, react, typescript, vue };
package/dist/index.d.ts CHANGED
@@ -3,12 +3,15 @@ export { FlatESLintConfig, FlatESLintConfigItem, defineFlatConfig } from 'eslint
3
3
 
4
4
  declare const javascript: FlatESLintConfigItem[];
5
5
 
6
- declare const typescript: FlatESLintConfigItem[];
6
+ type TSOptions = {
7
+ tsconfigPath: string;
8
+ };
9
+ declare function typescript({ tsconfigPath }: TSOptions): FlatESLintConfigItem[];
7
10
 
8
- declare const vue: FlatESLintConfigItem[];
11
+ declare function vue({ tsconfigPath }: TSOptions): FlatESLintConfigItem[];
9
12
 
10
- declare const react: FlatESLintConfigItem[];
13
+ declare function react({ tsconfigPath }: TSOptions): FlatESLintConfigItem[];
11
14
 
12
15
  declare const format: FlatESLintConfigItem[];
13
16
 
14
- export { format, javascript, react, typescript, vue };
17
+ export { TSOptions, format, javascript, react, typescript, vue };
package/dist/index.js CHANGED
@@ -248,217 +248,256 @@ var javascript = [
248
248
  ];
249
249
 
250
250
  // src/configs/typescript.ts
251
- var typescript = [
252
- ...javascript,
253
- {
254
- files: [
255
- "**/*.?([cm])[tj]s?(x)"
256
- ],
257
- languageOptions: {
258
- parser: parserTs,
259
- sourceType: "module",
260
- parserOptions: {
261
- project: true
262
- // EXPERIMENTAL_useProjectService: true
251
+ import { cwd } from "node:process";
252
+ function typescript({ tsconfigPath }) {
253
+ return [
254
+ ...javascript,
255
+ {
256
+ plugins: {
257
+ "@typescript-eslint": default5
263
258
  }
264
259
  },
265
- plugins: {
266
- "@typescript-eslint": default5
267
- },
268
- rules: {
269
- ...default5.configs["strict-type-checked"].rules,
270
- /** ✅禁止不必要的 await */
271
- // '@typescript-eslint/await-thenable': 'warn',
272
- /** 🎨不限制只使用 interface 或者 type */
273
- "@typescript-eslint/consistent-type-definitions": "off",
274
- /** 可选参数必须放在最后 */
275
- "default-param-last": "off",
276
- "@typescript-eslint/default-param-last": "error",
277
- /** 🎨不强制使用 `.`(点) 来访问属性 */
278
- "dot-notation": "off",
279
- "@typescript-eslint/dot-notation": "off",
280
- /** 🔒禁止使用 void 函数的返回值 ("off" 因为 return voidExpression() 这种缩写 { voidExpress(); return } 也会报错) */
281
- "@typescript-eslint/no-confusing-void-expression": ["off", {
282
- ignoreArrowShorthand: true
283
- }],
284
- /** 不允许 class 有重复的成员 (TypeScript 已检查,禁用此规则) */
285
- "no-dupe-class-members": "off",
286
- "@typescript-eslint/no-dupe-class-members": "off",
287
- /** 🎨允许空函数 */
288
- "@typescript-eslint/no-empty-function": "off",
289
- /** ✅允许显式 any */
290
- "@typescript-eslint/no-explicit-any": "off",
291
- /** ✅允许未处理的 Promise */
292
- "@typescript-eslint/no-floating-promises": "off",
293
- /** 🔒不允许隐式 eval */
294
- // "no-implied-eval": "off",
295
- // "@typescript-eslint/no-implied-eval": "error",
296
- /** 禁止 for 循环内声明的函数引用函数外变量 */
297
- "no-loop-func": "off",
298
- "@typescript-eslint/no-loop-func": "error",
299
- /** 禁止 promise 错误用法 */
300
- "@typescript-eslint/no-misused-promises": ["error", {
301
- /** 允许快捷写法 */
302
- checksVoidReturn: false
303
- }],
304
- /** ✅禁止超出精度范围的数字 */
305
- // 'no-loss-of-precision': 'off',
306
- // '@typescript-eslint/no-loss-of-precision': 'error',
307
- /** 允许非空断言 */
308
- "@typescript-eslint/no-non-null-assertion": "off",
309
- /** 允许 TypeScript 重载声明 */
310
- "no-redeclare": "off",
311
- "@typescript-eslint/no-redeclare": ["error"],
312
- /** ✅禁止冗余类型定义 */
313
- "@typescript-eslint/no-redundant-type-constituents": "warn",
314
- /** 🔒Disallow throwing literals as exceptions. */
315
- "no-throw-literal": "off",
316
- "@typescript-eslint/no-throw-literal": ["error", {
317
- allowThrowingAny: false,
318
- allowThrowingUnknown: false
319
- }],
320
- /** 禁用默认`no-undef`,eslint 不会检查`*.d.ts`,导致误报全局变量与类型不存在 */
321
- "no-undef": "off",
322
- /**
323
- * 🔒不必要的条件判断
324
- *
325
- * 因为有时类型不正确,autofix 会导致运行时错误,故关闭
326
- */
327
- "@typescript-eslint/no-unnecessary-condition": "off",
328
- /**
329
- * ✅不必要的类型断言
330
- *
331
- * 因为有时类型不正确,autofix 会导致 TS 错误,故关闭
332
- */
333
- "@typescript-eslint/no-unnecessary-type-assertion": "off",
334
- /** 警告未使用的表达式 */
335
- "no-unused-expressions": "off",
336
- "@typescript-eslint/no-unused-expressions": ["warn", {
337
- allowShortCircuit: true,
338
- enforceForJSX: true
339
- }],
340
- /** 允许未使用变量 */
341
- "no-unused-vars": "off",
342
- "@typescript-eslint/no-unused-vars": "off",
343
- /**
344
- *
345
- */
346
- "@typescript-eslint/prefer-nullish-coalescing": ["warn", {
347
- ignorePrimitives: {
348
- bigint: true,
349
- boolean: true,
350
- number: true,
351
- string: true
260
+ {
261
+ files: ["**/*.?([cm])[tj]s?(x)", "**/*.vue"],
262
+ languageOptions: {
263
+ parser: parserTs,
264
+ sourceType: "module",
265
+ parserOptions: {
266
+ ecmaVersion: "latest",
267
+ project: tsconfigPath,
268
+ tsconfigRootDir: cwd()
269
+ // extraFileExtensions: ['.vue']
270
+ // project: true,
271
+ // EXPERIMENTAL_useProjectService: true,
352
272
  }
353
- }],
354
- /**
355
- * 使用可选链`a?.b`替代`a && a.b`
356
- *
357
- * FIXME:
358
- * ```ts
359
- * if (!a || !a.b)
360
- * // ^ 也会被要求改成 ?.,降低可读性,且无配置,故关闭
361
- * ```
362
- */
363
- "@typescript-eslint/prefer-optional-chain": "off",
364
- /**
365
- * 🔧返回 promise 的函数必须有 async 关键字
366
- *
367
- * 不写也行,不限制此偏好,故关闭
368
- */
369
- "@typescript-eslint/promise-function-async": ["off", {
370
- checkArrowFunctions: false
371
- }],
372
- /**
373
- * 数组排序需显式指明排序方法,默认行为可能并不是想要的结果
374
- * ```ts
375
- * [1, 2, 3, 10, 20, 30].sort(); //→ [1, 10, 2, 20, 3, 30]
376
- * ```
377
- */
378
- "@typescript-eslint/require-array-sort-compare": ["error"],
379
- /** ✅模板字符串只允许数字字符串 */
380
- "@typescript-eslint/restrict-template-expressions": ["error", {
381
- allowNumber: true
382
- }],
383
- /** 允许可合为一个联合类型的函数声明多个函数签名 */
384
- "@typescript-eslint/unified-signatures": "off"
273
+ },
274
+ rules: {
275
+ ...default5.configs["strict-type-checked"].rules,
276
+ /** ✅禁止不必要的 await */
277
+ // '@typescript-eslint/await-thenable': 'warn',
278
+ /** 🎨不限制只使用 interface 或者 type */
279
+ "@typescript-eslint/consistent-type-definitions": "off",
280
+ /** 可选参数必须放在最后 */
281
+ "default-param-last": "off",
282
+ "@typescript-eslint/default-param-last": "error",
283
+ /** 🎨不强制使用 `.`(点) 来访问属性 */
284
+ "dot-notation": "off",
285
+ "@typescript-eslint/dot-notation": "off",
286
+ /** 🔒禁止使用 void 函数的返回值 ("off" 因为 return voidExpression() 这种缩写 { voidExpress(); return } 也会报错) */
287
+ "@typescript-eslint/no-confusing-void-expression": [
288
+ "off",
289
+ {
290
+ ignoreArrowShorthand: true
291
+ }
292
+ ],
293
+ /** 不允许 class 有重复的成员 (TypeScript 已检查,禁用此规则) */
294
+ "no-dupe-class-members": "off",
295
+ "@typescript-eslint/no-dupe-class-members": "off",
296
+ /** 🎨允许空函数 */
297
+ "@typescript-eslint/no-empty-function": "off",
298
+ /** ✅允许显式 any */
299
+ "@typescript-eslint/no-explicit-any": "off",
300
+ /** ✅允许未处理的 Promise */
301
+ "@typescript-eslint/no-floating-promises": "off",
302
+ /** 🔒不允许隐式 eval */
303
+ // "no-implied-eval": "off",
304
+ // "@typescript-eslint/no-implied-eval": "error",
305
+ /** 禁止 for 循环内声明的函数引用函数外变量 */
306
+ "no-loop-func": "off",
307
+ "@typescript-eslint/no-loop-func": "error",
308
+ /** 禁止 promise 错误用法 */
309
+ "@typescript-eslint/no-misused-promises": [
310
+ "error",
311
+ {
312
+ /** 允许快捷写法 */
313
+ checksVoidReturn: false
314
+ }
315
+ ],
316
+ /** ✅禁止超出精度范围的数字 */
317
+ // 'no-loss-of-precision': 'off',
318
+ // '@typescript-eslint/no-loss-of-precision': 'error',
319
+ /** 允许非空断言 */
320
+ "@typescript-eslint/no-non-null-assertion": "off",
321
+ /** 允许 TypeScript 重载声明 */
322
+ "no-redeclare": "off",
323
+ "@typescript-eslint/no-redeclare": ["error"],
324
+ /** ✅禁止冗余类型定义 */
325
+ "@typescript-eslint/no-redundant-type-constituents": "warn",
326
+ /** 🔒Disallow throwing literals as exceptions. */
327
+ "no-throw-literal": "off",
328
+ "@typescript-eslint/no-throw-literal": [
329
+ "error",
330
+ {
331
+ allowThrowingAny: false,
332
+ allowThrowingUnknown: false
333
+ }
334
+ ],
335
+ /** 禁用默认`no-undef`,eslint 不会检查`*.d.ts`,导致误报全局变量与类型不存在 */
336
+ "no-undef": "off",
337
+ /**
338
+ * 🔒不必要的条件判断
339
+ *
340
+ * 因为有时类型不正确,autofix 会导致运行时错误,故关闭
341
+ */
342
+ "@typescript-eslint/no-unnecessary-condition": "off",
343
+ /**
344
+ * ✅不必要的类型断言
345
+ *
346
+ * 因为有时类型不正确,autofix 会导致 TS 错误,故关闭
347
+ */
348
+ "@typescript-eslint/no-unnecessary-type-assertion": "off",
349
+ /** 警告未使用的表达式 */
350
+ "no-unused-expressions": "off",
351
+ "@typescript-eslint/no-unused-expressions": [
352
+ "warn",
353
+ {
354
+ allowShortCircuit: true,
355
+ enforceForJSX: true
356
+ }
357
+ ],
358
+ /** 允许未使用变量 */
359
+ "no-unused-vars": "off",
360
+ "@typescript-eslint/no-unused-vars": "off",
361
+ /**
362
+ *
363
+ */
364
+ "@typescript-eslint/prefer-nullish-coalescing": [
365
+ "warn",
366
+ {
367
+ ignorePrimitives: {
368
+ bigint: true,
369
+ boolean: true,
370
+ number: true,
371
+ string: true
372
+ }
373
+ }
374
+ ],
375
+ /**
376
+ * 使用可选链`a?.b`替代`a && a.b`
377
+ *
378
+ * FIXME:
379
+ * ```ts
380
+ * if (!a || !a.b)
381
+ * // ^ 也会被要求改成 ?.,降低可读性,且无配置,故关闭
382
+ * ```
383
+ */
384
+ "@typescript-eslint/prefer-optional-chain": "off",
385
+ /**
386
+ * 🔧返回 promise 的函数必须有 async 关键字
387
+ *
388
+ * 不写也行,不限制此偏好,故关闭
389
+ */
390
+ "@typescript-eslint/promise-function-async": [
391
+ "off",
392
+ {
393
+ checkArrowFunctions: false
394
+ }
395
+ ],
396
+ /**
397
+ * 数组排序需显式指明排序方法,默认行为可能并不是想要的结果
398
+ * ```ts
399
+ * [1, 2, 3, 10, 20, 30].sort(); //→ [1, 10, 2, 20, 3, 30]
400
+ * ```
401
+ */
402
+ "@typescript-eslint/require-array-sort-compare": ["error"],
403
+ /** ✅模板字符串只允许数字字符串 */
404
+ "@typescript-eslint/restrict-template-expressions": [
405
+ "error",
406
+ {
407
+ allowNumber: true
408
+ }
409
+ ],
410
+ /** 允许可合为一个联合类型的函数声明多个函数签名 */
411
+ "@typescript-eslint/unified-signatures": "off"
412
+ }
385
413
  }
386
- }
387
- ];
414
+ ];
415
+ }
388
416
 
389
417
  // src/configs/vue.ts
390
- var vue = [
391
- ...typescript,
392
- {
393
- files: ["**/*.vue"],
394
- languageOptions: {
395
- parser: default8,
396
- parserOptions: {
397
- parser: parserTs,
398
- ecmaFeatures: {
399
- jsx: true
400
- },
401
- extraFileExtensions: [".vue"],
402
- sourceType: "module"
418
+ function vue({ tsconfigPath }) {
419
+ return [
420
+ ...typescript({ tsconfigPath }),
421
+ {
422
+ plugins: {
423
+ vue: default4
403
424
  }
404
425
  },
405
- plugins: {
406
- "@typescript-eslint": default5,
407
- vue: default4
408
- },
409
- processor: default4.processors[".vue"],
410
- rules: {
411
- ...default4.configs["vue3-essential"].rules,
412
- /** allow ununed vars */
413
- "vue/no-unused-vars": "off",
414
- "vue/html-self-closing": "off",
415
- "vue/max-attributes-per-line": "off",
416
- "vue/multi-word-component-names": "off",
417
- // 'vue/no-v-html': 'off',
418
- "vue/require-default-prop": "off",
419
- "vue/require-prop-types": "off",
420
- "vue/singleline-html-element-content-newline": "off"
426
+ {
427
+ files: ["**/*.vue"],
428
+ // plugins: {
429
+ // vue: pluginVue,
430
+ // },
431
+ languageOptions: {
432
+ parser: default8,
433
+ parserOptions: {
434
+ ecmaFeatures: {
435
+ jsx: true
436
+ },
437
+ ecmaVersion: "latest",
438
+ extraFileExtensions: [".vue"],
439
+ parser: parserTs,
440
+ sourceType: "module",
441
+ project: true
442
+ // EXPERIMENTAL_useProjectService: true,
443
+ }
444
+ },
445
+ processor: default4.processors[".vue"],
446
+ rules: {
447
+ ...default4.configs["vue3-essential"].rules,
448
+ /** allow ununed vars */
449
+ "vue/no-unused-vars": "off",
450
+ "vue/html-self-closing": "off",
451
+ "vue/max-attributes-per-line": "off",
452
+ "vue/multi-word-component-names": "off",
453
+ // 'vue/no-v-html': 'off',
454
+ "vue/require-default-prop": "off",
455
+ "vue/require-prop-types": "off",
456
+ "vue/singleline-html-element-content-newline": "off"
457
+ }
421
458
  }
422
- }
423
- ];
459
+ ];
460
+ }
424
461
 
425
462
  // src/configs/react.ts
426
- var react = [
427
- ...typescript,
428
- {
429
- files: ["**/*.jsx", "**/*.tsx"],
430
- plugins: {
431
- react: default6,
432
- ziloen: default7
433
- },
434
- languageOptions: {
435
- parser: parserTs,
436
- parserOptions: {
437
- ecmaFeatures: {
438
- jsx: true
463
+ function react({ tsconfigPath }) {
464
+ return [
465
+ ...typescript({ tsconfigPath }),
466
+ {
467
+ files: ["**/*.jsx", "**/*.tsx"],
468
+ plugins: {
469
+ react: default6,
470
+ ziloen: default7
471
+ },
472
+ languageOptions: {
473
+ parser: parserTs,
474
+ parserOptions: {
475
+ ecmaFeatures: {
476
+ jsx: true
477
+ }
439
478
  }
479
+ },
480
+ rules: {
481
+ /** 16+ 不需要此导入 React */
482
+ "react/react-in-jsx-scope": "off",
483
+ /** ✅需要 key */
484
+ "react/jsx-key": ["error", {
485
+ // checkFragmentShorthand: true
486
+ }],
487
+ /** 让 TS 检查 */
488
+ "react/jsx-no-undef": "off",
489
+ /** 简写 <React.Fragment></React.Fragment> => <></> */
490
+ "react/jsx-fragments": ["warn", "syntax"],
491
+ /** 避免错误用法 */
492
+ "react/no-invalid-html-attribute": "warn",
493
+ /** 不允许可能出错的的 render 类型(number | string | object),(即使是 bool 也会报错,太蠢了) */
494
+ // 'react/jsx-no-leaked-render': 'error',
495
+ /** 严格 jsx render 类型,支持 TS 检查,替代 react/jsx-no-leaked-render */
496
+ "ziloen/jsx-strict-logical-expressions": "error"
440
497
  }
441
- },
442
- rules: {
443
- /** 16+ 不需要此导入 React */
444
- "react/react-in-jsx-scope": "off",
445
- /** ✅需要 key */
446
- "react/jsx-key": ["error", {
447
- // checkFragmentShorthand: true
448
- }],
449
- /** 让 TS 检查 */
450
- "react/jsx-no-undef": "off",
451
- /** 简写 <React.Fragment></React.Fragment> => <></> */
452
- "react/jsx-fragments": ["warn", "syntax"],
453
- /** 避免错误用法 */
454
- "react/no-invalid-html-attribute": "warn",
455
- /** 不允许可能出错的的 render 类型(number | string | object),(即使是 bool 也会报错,太蠢了) */
456
- // 'react/jsx-no-leaked-render': 'error',
457
- /** 严格 jsx render 类型,支持 TS 检查,替代 react/jsx-no-leaked-render */
458
- "ziloen/jsx-strict-logical-expressions": "error"
459
498
  }
460
- }
461
- ];
499
+ ];
500
+ }
462
501
 
463
502
  // src/configs/format.ts
464
503
  var format = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziloen/eslint-config",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "author": "ziloen",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,28 +17,29 @@
17
17
  ],
18
18
  "dependencies": {
19
19
  "@eslint/js": "^8.52.0",
20
- "@typescript-eslint/eslint-plugin": "^6.8.0",
21
- "@typescript-eslint/parser": "^6.8.0",
20
+ "@types/node": "^20.8.9",
21
+ "@typescript-eslint/eslint-plugin": "^6.9.0",
22
+ "@typescript-eslint/parser": "^6.9.0",
22
23
  "bumpp": "^9.2.0",
23
24
  "eslint": "^8.52.0",
24
25
  "eslint-define-config": "^1.24.1",
25
26
  "eslint-plugin-promise": "^6.1.1",
26
27
  "eslint-plugin-react": "^7.33.2",
27
28
  "eslint-plugin-unicorn": "^48.0.1",
28
- "eslint-plugin-vue": "^9.17.0",
29
+ "eslint-plugin-vue": "^9.18.1",
29
30
  "eslint-plugin-ziloen": "^0.1.5",
30
31
  "react": "^18.2.0",
31
32
  "tsup": "^7.2.0",
32
33
  "typescript": "^5.2.2",
33
34
  "vue-eslint-parser": "^9.3.2",
34
- "@ziloen/eslint-config": "0.1.2"
35
+ "@ziloen/eslint-config": "0.1.4"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/eslint": "^8.44.6",
38
- "@types/react": "^18.2.31",
39
- "@typescript-eslint/rule-tester": "^6.8.0",
40
- "@typescript-eslint/utils": "^6.8.0",
41
- "vue": "^3.3.6"
39
+ "@types/react": "^18.2.33",
40
+ "@typescript-eslint/rule-tester": "^6.9.0",
41
+ "@typescript-eslint/utils": "^6.9.0",
42
+ "vue": "^3.3.7"
42
43
  },
43
44
  "scripts": {
44
45
  "build": "tsup src/index.ts --format esm,cjs --clean --dts",