@utoo/lint 0.4.8 → 0.4.9

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.
Files changed (2) hide show
  1. package/bin/migrate.js +35 -12
  2. package/package.json +6 -6
package/bin/migrate.js CHANGED
@@ -7,6 +7,7 @@ import { Legacy } from "@eslint/eslintrc";
7
7
  import eslintJs from "@eslint/js";
8
8
 
9
9
  import { Linter } from "../index.js";
10
+ import { nativeRuleConfig } from "../lib/native-rule-options.cjs";
10
11
 
11
12
  const ESLINT_CONFIG_FILENAMES = [
12
13
  "eslint.config.js",
@@ -37,11 +38,23 @@ const MIGRATION_SOURCE = Symbol("migrationSource");
37
38
  const JAVASCRIPT_CONFIG_LOADER_SCRIPT = `
38
39
  import { writeFileSync } from "node:fs";
39
40
  import { pathToFileURL } from "node:url";
41
+ import { nativeRuleConfig } from ${JSON.stringify(new URL("../lib/native-rule-options.cjs", import.meta.url).href)};
40
42
 
41
43
  const loaded = await import(pathToFileURL(process.argv[1]).href);
44
+ const nativeRuleIds = new Map(JSON.parse(process.argv[2]));
42
45
  const seen = new Set();
43
46
 
44
- function strip(value) {
47
+ function nativeOptions(rules) {
48
+ if (!rules || typeof rules !== "object" || Array.isArray(rules)) {
49
+ return rules;
50
+ }
51
+ return Object.fromEntries(Object.entries(rules).map(([ruleId, ruleConfig]) => [
52
+ ruleId,
53
+ nativeRuleIds.has(ruleId) ? nativeRuleConfig(nativeRuleIds.get(ruleId), ruleConfig) : ruleConfig
54
+ ]));
55
+ }
56
+
57
+ function strip(value, configEntry = false) {
45
58
  if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
46
59
  return value;
47
60
  }
@@ -56,13 +69,19 @@ function strip(value) {
56
69
  }
57
70
  seen.add(value);
58
71
  if (Array.isArray(value)) {
59
- const items = value.map(strip).filter((item) => item !== undefined);
72
+ const items = value.map((item) => strip(item, configEntry)).filter((item) => item !== undefined);
60
73
  seen.delete(value);
61
74
  return items;
62
75
  }
63
76
  const object = {};
64
77
  for (const [key, item] of Object.entries(value)) {
65
- const stripped = strip(item);
78
+ // Preserve native unlimited spellings before this subprocess serializes
79
+ // the config. Only rules that will be migrated need native JSON options;
80
+ // ignored and unsupported plugin rules retain the usual report behavior.
81
+ const stripped = strip(
82
+ configEntry && key === "rules" ? nativeOptions(item) : item,
83
+ configEntry && key === "overrides"
84
+ );
66
85
  if (stripped !== undefined) {
67
86
  object[key] = stripped;
68
87
  }
@@ -71,7 +90,7 @@ function strip(value) {
71
90
  return object;
72
91
  }
73
92
 
74
- const json = JSON.stringify(strip(loaded.default ?? loaded));
93
+ const json = JSON.stringify(strip(loaded.default ?? loaded, true));
75
94
  if (json === undefined) {
76
95
  throw new TypeError("config did not export a migratable value");
77
96
  }
@@ -192,8 +211,8 @@ function migrateEslintConfig(options) {
192
211
  throw new Error("utoo-lint migrate eslint: no ESLint config found; pass --from PATH");
193
212
  }
194
213
 
195
- const eslintConfig = loadEslintConfig(sourcePath, options.cwd);
196
214
  const supportedRuleIds = new Set(new Linter().getRules().keys());
215
+ const eslintConfig = loadEslintConfig(sourcePath, options.cwd, supportedRuleIds);
197
216
  const migrationInput = migrationInputFromConfig(
198
217
  eslintConfig,
199
218
  sourcePath,
@@ -224,7 +243,7 @@ function migrateEslintConfig(options) {
224
243
  unsupportedRules.push({ ruleId, scope: migrationRuleScope(entry), source });
225
244
  continue;
226
245
  }
227
- rules[migratedRuleId] = migratableRuleConfig(ruleConfig);
246
+ rules[migratedRuleId] = nativeRuleConfig(migratedRuleId, ruleConfig);
228
247
  supportedRules.push(migratedRuleId);
229
248
  if (migratedRuleId !== ruleId) {
230
249
  translatedRules.push({ sourceRuleId: ruleId, targetRuleId: migratedRuleId });
@@ -665,9 +684,17 @@ function findEslintConfig(cwd) {
665
684
  }
666
685
  }
667
686
 
668
- function loadEslintConfig(path, cwd) {
687
+ function loadEslintConfig(path, cwd, supportedRuleIds) {
669
688
  if (JAVASCRIPT_CONFIG_EXTENSIONS.has(extname(path))) {
670
- const result = spawnSync(process.execPath, ["--input-type=module", "--eval", JAVASCRIPT_CONFIG_LOADER_SCRIPT, path], {
689
+ const nativeRuleIds = new Map([...supportedRuleIds]
690
+ .filter((ruleId) => !IGNORED_RULES.has(ruleId))
691
+ .map((ruleId) => [ruleId, ruleId]));
692
+ for (const [sourceRuleId, targetRuleId] of REVIEWED_RULE_ALIASES) {
693
+ if (supportedRuleIds.has(targetRuleId)) {
694
+ nativeRuleIds.set(sourceRuleId, targetRuleId);
695
+ }
696
+ }
697
+ const result = spawnSync(process.execPath, ["--input-type=module", "--eval", JAVASCRIPT_CONFIG_LOADER_SCRIPT, path, JSON.stringify([...nativeRuleIds])], {
671
698
  cwd,
672
699
  encoding: "utf8",
673
700
  stdio: ["ignore", "pipe", "pipe", "pipe"]
@@ -761,10 +788,6 @@ function isGlobalIgnoreEntry(entry) {
761
788
  return Boolean(entry.ignores) && Object.keys(entry).every((key) => key === "name" || key === "ignores");
762
789
  }
763
790
 
764
- function migratableRuleConfig(ruleConfig) {
765
- return Array.isArray(ruleConfig) ? [...ruleConfig] : ruleConfig;
766
- }
767
-
768
791
  function isRuleDisabled(ruleConfig) {
769
792
  const severity = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
770
793
  return severity === "off" || severity === 0 || severity === false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/lint",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "High-performance JavaScript and TypeScript linter powered by Yuku",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -74,11 +74,11 @@
74
74
  "use-at-your-own-risk.js"
75
75
  ],
76
76
  "optionalDependencies": {
77
- "@utoo/lint-darwin-arm64": "0.4.8",
78
- "@utoo/lint-darwin-x64": "0.4.8",
79
- "@utoo/lint-linux-arm64": "0.4.8",
80
- "@utoo/lint-linux-x64": "0.4.8",
81
- "@utoo/lint-win32-x64": "0.4.8"
77
+ "@utoo/lint-darwin-arm64": "0.4.9",
78
+ "@utoo/lint-darwin-x64": "0.4.9",
79
+ "@utoo/lint-linux-arm64": "0.4.9",
80
+ "@utoo/lint-linux-x64": "0.4.9",
81
+ "@utoo/lint-win32-x64": "0.4.9"
82
82
  },
83
83
  "dependencies": {
84
84
  "@eslint/eslintrc": "2.1.4",