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