@lincy/eslint-config 5.3.2 → 5.4.0

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
 
@@ -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 }));
@@ -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",
@@ -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)