@lincy/eslint-config 5.3.2 → 5.4.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
@@ -101,16 +101,6 @@ export default lincy()
101
101
  }
102
102
  ```
103
103
 
104
- ### 使用.ts文件作为配置文件
105
-
106
- 1. 将`eslint`更新至最新版本
107
- 2. 在`package.json`中的`eslint .`后面添加参数`--flag unstable_ts_config`, 包括`scripts`、`lint-staged`中
108
- 3. 在`.vscode/settings.json`文件添加`"eslint.options": {
109
- "flags": [
110
- "unstable_ts_config"
111
- ]
112
- }`
113
-
114
104
  ## 定制化
115
105
 
116
106
  通常你只需要导入 `lincy` 预设:
package/dist/index.cjs CHANGED
@@ -101,7 +101,7 @@ __export(src_exports, {
101
101
  });
102
102
  module.exports = __toCommonJS(src_exports);
103
103
 
104
- // node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js
104
+ // node_modules/.pnpm/tsup@8.3.5_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.3_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js
105
105
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
106
106
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
107
107
 
@@ -260,7 +260,7 @@ async function disables() {
260
260
  },
261
261
  {
262
262
  files: [`**/*.config.${GLOB_SRC_EXT}`, `**/*.config.*.${GLOB_SRC_EXT}`],
263
- name: "antfu/disables/config-files",
263
+ name: "eslint/disables/config-files",
264
264
  rules: {
265
265
  "antfu/no-top-level-await": "off",
266
266
  "no-console": "off",
@@ -350,7 +350,7 @@ async function ensurePackages(packages) {
350
350
  const p = await import("@clack/prompts");
351
351
  const result = await p.confirm({
352
352
  // message: `${nonExistingPackages.length === 1 ? 'Package is' : 'Packages are'} required for this config: ${nonExistingPackages.join(', ')}. Do you want to install them?`,
353
- message: `\u6B64\u914D\u7F6E\u9700\u8981\u8F6F\u4EF6\u5305: ${nonExistingPackages.join(", ")}. \u4F60\u60F3\u5B89\u88C5\u5B83\u4EEC\u5417?`
353
+ message: `此配置需要软件包: ${nonExistingPackages.join(", ")}. 你想安装它们吗?`
354
354
  });
355
355
  if (result)
356
356
  await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
@@ -839,7 +839,7 @@ async function javascript(options = {}) {
839
839
  allowTaggedTemplates: true,
840
840
  allowTernary: true
841
841
  }],
842
- "no-unused-vars": ["error", {
842
+ "no-unused-vars": ["warn", {
843
843
  args: "none",
844
844
  caughtErrors: "none",
845
845
  ignoreRestSiblings: true,
@@ -872,7 +872,7 @@ async function javascript(options = {}) {
872
872
  }
873
873
  ],
874
874
  "prefer-const": [
875
- "error",
875
+ isInEditor ? "warn" : "error",
876
876
  {
877
877
  destructuring: "all",
878
878
  ignoreReadBeforeAssign: true
@@ -886,7 +886,7 @@ async function javascript(options = {}) {
886
886
  "prefer-template": "error",
887
887
  "symbol-description": "error",
888
888
  "unicode-bom": ["error", "never"],
889
- "unused-imports/no-unused-imports": isInEditor ? "off" : "error",
889
+ "unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
890
890
  "unused-imports/no-unused-vars": [
891
891
  "error",
892
892
  {
@@ -1200,6 +1200,21 @@ var import_local_pkg2 = require("local-pkg");
1200
1200
  var ReactRefreshAllowConstantExportPackages = [
1201
1201
  "vite"
1202
1202
  ];
1203
+ var RemixPackages = [
1204
+ "@remix-run/node",
1205
+ "@remix-run/react",
1206
+ "@remix-run/serve",
1207
+ "@remix-run/dev"
1208
+ ];
1209
+ var ReactRouterPackages = [
1210
+ "@react-router/node",
1211
+ "@react-router/react",
1212
+ "@react-router/serve",
1213
+ "@react-router/dev"
1214
+ ];
1215
+ var NextJsPackages = [
1216
+ "next"
1217
+ ];
1203
1218
  async function react(options = {}) {
1204
1219
  const {
1205
1220
  files = [GLOB_SRC],
@@ -1210,15 +1225,15 @@ async function react(options = {}) {
1210
1225
  overrides = {},
1211
1226
  tsconfigPath
1212
1227
  } = options;
1213
- const isTypeAware = !!tsconfigPath;
1214
- const typeAwareRules = {
1215
- "react/no-leaked-conditional-rendering": "warn"
1216
- };
1217
1228
  await ensurePackages([
1218
1229
  "@eslint-react/eslint-plugin",
1219
1230
  "eslint-plugin-react-hooks",
1220
1231
  "eslint-plugin-react-refresh"
1221
1232
  ]);
1233
+ const isTypeAware = !!tsconfigPath;
1234
+ const typeAwareRules = {
1235
+ "react/no-leaked-conditional-rendering": "warn"
1236
+ };
1222
1237
  const [
1223
1238
  pluginReact,
1224
1239
  pluginReactHooks,
@@ -1229,9 +1244,12 @@ async function react(options = {}) {
1229
1244
  interopDefault(import("eslint-plugin-react-hooks")),
1230
1245
  interopDefault(import("eslint-plugin-react-refresh"))
1231
1246
  ]);
1232
- const _isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
1247
+ const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
1233
1248
  (i) => (0, import_local_pkg2.isPackageExists)(i)
1234
1249
  );
1250
+ const isUsingRemix = RemixPackages.some((i) => (0, import_local_pkg2.isPackageExists)(i));
1251
+ const isUsingReactRouter = ReactRouterPackages.some((i) => (0, import_local_pkg2.isPackageExists)(i));
1252
+ const isUsingNext = NextJsPackages.some((i) => (0, import_local_pkg2.isPackageExists)(i));
1235
1253
  const plugins = pluginReact.configs.all.plugins;
1236
1254
  return [
1237
1255
  {
@@ -1242,7 +1260,8 @@ async function react(options = {}) {
1242
1260
  "react-hooks": pluginReactHooks,
1243
1261
  "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
1244
1262
  "react-naming-convention": plugins["@eslint-react/naming-convention"],
1245
- "react-refresh": pluginReactRefresh
1263
+ "react-refresh": pluginReactRefresh,
1264
+ "react-web-api": plugins["@eslint-react/web-api"]
1246
1265
  }
1247
1266
  },
1248
1267
  {
@@ -1273,10 +1292,41 @@ async function react(options = {}) {
1273
1292
  "react-hooks/exhaustive-deps": "warn",
1274
1293
  "react-hooks/rules-of-hooks": "error",
1275
1294
  // react refresh
1276
- // 'react-refresh/only-export-components': [
1277
- // 'warn',
1278
- // { allowConstantExport: isAllowConstantExport },
1279
- // ],
1295
+ "react-refresh/only-export-components": [
1296
+ "warn",
1297
+ {
1298
+ allowConstantExport: isAllowConstantExport,
1299
+ allowExportNames: [
1300
+ ...isUsingNext ? [
1301
+ "dynamic",
1302
+ "dynamicParams",
1303
+ "revalidate",
1304
+ "fetchCache",
1305
+ "runtime",
1306
+ "preferredRegion",
1307
+ "maxDuration",
1308
+ "config",
1309
+ "generateStaticParams",
1310
+ "metadata",
1311
+ "generateMetadata",
1312
+ "viewport",
1313
+ "generateViewport"
1314
+ ] : [],
1315
+ ...isUsingRemix || isUsingReactRouter ? [
1316
+ "meta",
1317
+ "links",
1318
+ "headers",
1319
+ "loader",
1320
+ "action"
1321
+ ] : []
1322
+ ]
1323
+ }
1324
+ ],
1325
+ // recommended rules from @eslint-react/web-api
1326
+ "react-web-api/no-leaked-event-listener": "warn",
1327
+ "react-web-api/no-leaked-interval": "warn",
1328
+ "react-web-api/no-leaked-resize-observer": "warn",
1329
+ "react-web-api/no-leaked-timeout": "warn",
1280
1330
  // recommended rules from @eslint-react
1281
1331
  "react/ensure-forward-ref-using-ref": "warn",
1282
1332
  "react/no-access-state-in-setstate": "error",
@@ -1619,7 +1669,7 @@ async function test(options = {}) {
1619
1669
  "test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
1620
1670
  "test/no-identical-title": "error",
1621
1671
  "test/no-import-node-test": "error",
1622
- "test/no-only-tests": isInEditor ? "off" : "error",
1672
+ "test/no-only-tests": isInEditor ? "warn" : "error",
1623
1673
  "test/prefer-hooks-in-order": "error",
1624
1674
  "test/prefer-lowercase-title": "error",
1625
1675
  // Disables
@@ -1824,7 +1874,7 @@ async function typescript(options = {}) {
1824
1874
  allowTernary: true
1825
1875
  }],
1826
1876
  "ts/no-unused-vars": [
1827
- "error",
1877
+ "warn",
1828
1878
  {
1829
1879
  args: "all",
1830
1880
  argsIgnorePattern: "^_",
@@ -2077,7 +2127,7 @@ async function vue(options = {}) {
2077
2127
  "vue/no-restricted-v-bind": ["error", "/^v-/"],
2078
2128
  "vue/no-setup-props-reactivity-loss": "off",
2079
2129
  "vue/no-sparse-arrays": "error",
2080
- "vue/no-unused-refs": "error",
2130
+ "vue/no-unused-refs": "warn",
2081
2131
  "vue/no-useless-v-bind": "error",
2082
2132
  "vue/no-v-html": "off",
2083
2133
  "vue/no-v-text-v-html-on-component": "off",
@@ -2392,7 +2442,7 @@ function lincy(options = {}, ...userConfigs) {
2392
2442
  disables()
2393
2443
  );
2394
2444
  if ("files" in options) {
2395
- throw new Error("[@lincy/eslint-config] \u7B2C\u4E00\u4E2A\u53C2\u6570\u4E0D\u5E94\u5305\u542B\u201Cfiles\u201D\u5C5E\u6027\uFF0C\u56E0\u4E3A\u9009\u9879\u5E94\u8BE5\u662F\u5168\u5C40\u7684\u3002\u8BF7\u5C06\u5176\u653E\u5728\u7B2C\u4E8C\u4E2A\u6216\u66F4\u540E\u9762\u7684\u914D\u7F6E\u4E2D\u3002");
2445
+ throw new Error("[@lincy/eslint-config] 第一个参数不应包含“files”属性,因为选项应该是全局的。请将其放在第二个或更后面的配置中。");
2396
2446
  }
2397
2447
  const fusedConfig = flatConfigProps.reduce((acc, key) => {
2398
2448
  if (key in options)
@@ -2409,6 +2459,15 @@ function lincy(options = {}, ...userConfigs) {
2409
2459
  if (autoRenamePlugins) {
2410
2460
  composer = composer.renamePlugins(defaultPluginRenaming);
2411
2461
  }
2462
+ if (isInEditor) {
2463
+ composer = composer.disableRulesFix([
2464
+ "unused-imports/no-unused-imports",
2465
+ "test/no-only-tests",
2466
+ "prefer-const"
2467
+ ], {
2468
+ builtinRules: () => import(["eslint", "use-at-your-own-risk"].join("/")).then((r) => r.builtinRules)
2469
+ });
2470
+ }
2412
2471
  return composer;
2413
2472
  }
2414
2473
  function resolveSubOptions(options, key) {