@lincy/eslint-config 5.7.1 → 5.8.1

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
@@ -283,50 +283,29 @@ export default lincy({
283
283
  * 覆盖规则
284
284
  */
285
285
  overrides: {
286
+ comments: {
287
+ // comments 规则
288
+ },
286
289
  ignores: [
287
290
  // 忽略的路径/文件
288
291
  ],
292
+ imports: {
293
+ // imports 规则
294
+ },
289
295
  javascript: {
290
296
  // javascript 规则
291
297
  },
292
- typescript: {
293
- // typescript 规则
294
- },
295
- stylistic: {
296
- // stylistic 规则
297
- },
298
- test: {
299
- // test 规则
300
- },
301
- vue: {
302
- // vue 规则
303
- },
304
- react: {
305
- // react 规则
298
+ jsdoc: {
299
+ // jsdoc 规则
306
300
  },
307
301
  jsonc: {
308
302
  // jsonc 规则
309
303
  },
310
- yaml: {
311
- // yaml 规则
312
- },
313
- toml: {
314
- // toml 规则
315
- },
316
304
  markdown: {
317
305
  // markdown 规则
318
306
  },
319
- unocss: {
320
- // unocss 规则
321
- },
322
- comments: {
323
- // comments 规则
324
- },
325
- imports: {
326
- // imports 规则
327
- },
328
- jsdoc: {
329
- // jsdoc 规则
307
+ nextjs: {
308
+ // nextjs 规则
330
309
  },
331
310
  node: {
332
311
  // node 规则
@@ -334,15 +313,36 @@ export default lincy({
334
313
  perfectionist: {
335
314
  // perfectionist 规则
336
315
  },
337
- sort: {
338
- // sort 规则
316
+ react: {
317
+ // react 规则
318
+ },
319
+ regexp: {
320
+ // regexp 规则
321
+ },
322
+ stylistic: {
323
+ // stylistic 规则
324
+ },
325
+ test: {
326
+ // test 规则
327
+ },
328
+ toml: {
329
+ // toml 规则
330
+ },
331
+ typescript: {
332
+ // typescript 规则
339
333
  },
340
334
  unicorn: {
341
335
  // unicorn 规则
342
336
  },
343
- regexp: {
344
- // regexp 规则
345
- }
337
+ unocss: {
338
+ // unocss 规则
339
+ },
340
+ vue: {
341
+ // vue 规则
342
+ },
343
+ yaml: {
344
+ // yaml 规则
345
+ },
346
346
  },
347
347
 
348
348
  // 工厂函数第一个参数默认为各规则的开关, 但是也可以作为追加规则使用, 当包含以下键名将会自动整合到一个规则里
@@ -463,13 +463,14 @@ export default combine(
463
463
 
464
464
  由于扁平化配置支持显式提供了插件名称,因此我们重命名了一些插件以使它们更加一致并隐藏实现细节。
465
465
 
466
- | New Prefix | Original Prefix | Source Plugin |
467
- | ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
468
- | `import/*` | `import-lite/*` | [eslint-plugin-import-lite](https://github.com/9romise/eslint-plugin-import-lite) |
469
- | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
470
- | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
471
- | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
472
- | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
466
+ | New Prefix | Original Prefix | Source Plugin |
467
+ | ---------- | ---------------------- | ----------------------------------------------------------------------------------------------------- |
468
+ | `import/*` | `import-lite/*` | [eslint-plugin-import-lite](https://github.com/9romise/eslint-plugin-import-lite) |
469
+ | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
470
+ | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
471
+ | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
472
+ | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
473
+ | `next/*` | `@next/next` | [@next/eslint-plugin-next](https://github.com/vercel/next.js/tree/canary/packages/eslint-plugin-next) |
473
474
 
474
475
  当您想要覆盖规则或内联禁用它们时,您需要更新到新的前缀:
475
476
 
@@ -573,7 +574,7 @@ export default lincy({
573
574
 
574
575
  使用外部格式化程序来格式化 ESLint 无法处理的文件(.css、.html 等)。 由 [eslint-plugin-format](https://github.com/antfu/eslint-plugin-format) 提供支持
575
576
 
576
- ```js
577
+ ```ts
577
578
  // eslint.config.js
578
579
  import lincy from '@lincy/eslint-config'
579
580
 
@@ -626,12 +627,40 @@ pnpm add eslint-plugin-format -D
626
627
 
627
628
  当检测到依赖安装了`react`, 则默认开启
628
629
 
630
+ ```ts
631
+ // eslint.config.js
632
+ import lincy from '@lincy/eslint-config'
633
+
634
+ export default lincy({
635
+ react: true
636
+ })
637
+ ```
638
+
629
639
  运行“npx eslint”会提示您安装所需的依赖项,当然,也可以手动安装它们:
630
640
 
631
641
  ```bash
632
642
  pnpm i -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh
633
643
  ```
634
644
 
645
+ #### Next.js
646
+
647
+ 要启用 nextjs 支持,需要显式打开它
648
+
649
+ ```ts
650
+ // eslint.config.js
651
+ import lincy from '@lincy/eslint-config'
652
+
653
+ export default lincy({
654
+ nextjs: true
655
+ })
656
+ ```
657
+
658
+ 运行“npx eslint”会提示您安装所需的依赖项,当然,也可以手动安装它们:
659
+
660
+ ```bash
661
+ pnpm i -D @next/eslint-plugin-next
662
+ ```
663
+
635
664
  #### UnoCSS
636
665
 
637
666
  要启用 UnoCSS 支持,需要显式打开它
package/dist/index.cjs CHANGED
@@ -882,6 +882,34 @@ async function markdown(options = {}) {
882
882
  ];
883
883
  }
884
884
 
885
+ //#endregion
886
+ //#region src/configs/nextjs.ts
887
+ function normalizeRules(rules) {
888
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => [key, typeof value === "string" ? [value] : value]));
889
+ }
890
+ async function nextjs(options = {}) {
891
+ const { files = [GLOB_SRC], overrides = {} } = options;
892
+ await ensurePackages(["@next/eslint-plugin-next"]);
893
+ const pluginNextJS = await interopDefault(import("@next/eslint-plugin-next"));
894
+ return [{
895
+ name: "eslint/nextjs/setup",
896
+ plugins: { next: pluginNextJS }
897
+ }, {
898
+ files,
899
+ languageOptions: {
900
+ parserOptions: { ecmaFeatures: { jsx: true } },
901
+ sourceType: "module"
902
+ },
903
+ name: "eslint/nextjs/rules",
904
+ rules: {
905
+ ...normalizeRules(pluginNextJS.configs.recommended.rules),
906
+ ...normalizeRules(pluginNextJS.configs["core-web-vitals"].rules),
907
+ ...overrides
908
+ },
909
+ settings: { react: { version: "detect" } }
910
+ }];
911
+ }
912
+
885
913
  //#endregion
886
914
  //#region src/configs/node.ts
887
915
  async function node(options = {}) {
@@ -1613,11 +1641,12 @@ async function typescript(options = {}) {
1613
1641
  //#endregion
1614
1642
  //#region src/configs/unicorn.ts
1615
1643
  async function unicorn(options = {}) {
1644
+ const { allRecommended = false, overrides = {} } = options;
1616
1645
  return [{
1617
1646
  name: "eslint/unicorn/rules",
1618
1647
  plugins: { unicorn: eslint_plugin_unicorn.default },
1619
1648
  rules: {
1620
- ...options.allRecommended ? eslint_plugin_unicorn.default.configs["flat/recommended"].rules : {
1649
+ ...allRecommended ? eslint_plugin_unicorn.default.configs.recommended.rules : {
1621
1650
  "unicorn/consistent-empty-array-spread": "error",
1622
1651
  "unicorn/error-message": "error",
1623
1652
  "unicorn/escape-case": "error",
@@ -1634,7 +1663,7 @@ async function unicorn(options = {}) {
1634
1663
  "unicorn/prefer-type-error": "error",
1635
1664
  "unicorn/throw-new-error": "error"
1636
1665
  },
1637
- ...options.overrides
1666
+ ...overrides
1638
1667
  }
1639
1668
  }];
1640
1669
  }
@@ -1969,6 +1998,7 @@ const defaultPluginRenaming = {
1969
1998
  "@eslint-react/dom": "react-dom",
1970
1999
  "@eslint-react/hooks-extra": "react-hooks-extra",
1971
2000
  "@eslint-react/naming-convention": "react-naming-convention",
2001
+ "@next/next": "next",
1972
2002
  "@stylistic": "style",
1973
2003
  "@typescript-eslint": "ts",
1974
2004
  "import-lite": "import",
@@ -1987,7 +2017,7 @@ const defaultPluginRenaming = {
1987
2017
  * 合并的 ESLint 配置
1988
2018
  */
1989
2019
  function lincy(options = {}, ...userConfigs) {
1990
- const { autoRenamePlugins = true, componentExts = [], gitignore: enableGitignore = true, ignores: ignoresList = [], imports: enableImports = true, jsx: enableJsx = true, overrides = {}, pnpm: enableCatalogs = false, react: enableReact = false, regexp: enableRegexp = true, typescript: enableTypeScript = (0, local_pkg.isPackageExists)("typescript"), unicorn: enableUnicorn = true, unocss: enableUnoCSS = false, vue: enableVue = VuePackages.some((i) => (0, local_pkg.isPackageExists)(i)) } = options;
2020
+ const { autoRenamePlugins = true, componentExts = [], gitignore: enableGitignore = true, ignores: ignoresList = [], imports: enableImports = true, jsx: enableJsx = true, nextjs: enableNextjs = false, overrides = {}, pnpm: enableCatalogs = false, react: enableReact = false, regexp: enableRegexp = true, typescript: enableTypeScript = (0, local_pkg.isPackageExists)("typescript"), unicorn: enableUnicorn = true, unocss: enableUnoCSS = false, vue: enableVue = VuePackages.some((i) => (0, local_pkg.isPackageExists)(i)) } = options;
1991
2021
  let isInEditor = options.isInEditor;
1992
2022
  if (isInEditor == null) {
1993
2023
  isInEditor = isInEditorEnv();
@@ -2009,19 +2039,16 @@ function lincy(options = {}, ...userConfigs) {
2009
2039
  configs$1.push(ignores({ ignores: [...overrides.ignores || [], ...ignoresList] }), javascript({
2010
2040
  isInEditor,
2011
2041
  overrides: getOverrides(options, "javascript")
2012
- }), comments({ overrides: overrides.comments }), node({ overrides: overrides.node }), jsdoc({
2013
- overrides: overrides.jsdoc,
2014
- stylistic: stylisticOptions
2015
- }), imports({
2016
- overrides: overrides.imports,
2042
+ }), comments({ overrides: getOverrides(options, "comments") }), node({ overrides: getOverrides(options, "node") }), jsdoc({
2043
+ overrides: getOverrides(options, "jsdoc"),
2017
2044
  stylistic: stylisticOptions
2018
- }), perfectionist({ overrides: overrides.perfectionist }));
2045
+ }), perfectionist({ overrides: getOverrides(options, "perfectionist") }));
2019
2046
  if (enableUnicorn) configs$1.push(unicorn({
2020
2047
  ...enableUnicorn === true ? {} : enableUnicorn,
2021
- overrides: overrides.unicorn
2048
+ overrides: getOverrides(options, "unicorn")
2022
2049
  }));
2023
2050
  if (enableImports) configs$1.push(imports({
2024
- overrides: overrides.imports,
2051
+ overrides: getOverrides(options, "imports"),
2025
2052
  stylistic: stylisticOptions
2026
2053
  }));
2027
2054
  if (enableVue) componentExts.push("vue");
@@ -2058,6 +2085,7 @@ function lincy(options = {}, ...userConfigs) {
2058
2085
  overrides: getOverrides(options, "react"),
2059
2086
  tsconfigPath
2060
2087
  }));
2088
+ if (enableNextjs) configs$1.push(nextjs({ overrides: getOverrides(options, "nextjs") }));
2061
2089
  if (enableUnoCSS) configs$1.push(unocss({
2062
2090
  ...resolveSubOptions(options, "unocss"),
2063
2091
  overrides: getOverrides(options, "unocss")
@@ -2165,6 +2193,7 @@ exports.jsonc = jsonc;
2165
2193
  exports.jsx = jsx;
2166
2194
  exports.lincy = lincy;
2167
2195
  exports.markdown = markdown;
2196
+ exports.nextjs = nextjs;
2168
2197
  exports.node = node;
2169
2198
  exports.parserPlain = parserPlain;
2170
2199
  exports.perfectionist = perfectionist;