@utoo/lint 0.4.7 → 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.
- package/bin/migrate.js +35 -12
- package/lib/estree-parser.cjs +0 -29
- package/package.json +7 -7
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
|
|
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
|
-
|
|
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] =
|
|
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
|
|
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/lib/estree-parser.cjs
CHANGED
|
@@ -178,32 +178,6 @@ function forEachChild(node, callback) {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
const JSX_ENTITIES = {
|
|
182
|
-
amp: "&", lt: "<", gt: ">", quot: "\"", apos: "'", nbsp: "\u00a0", copy: "\u00a9", reg: "\u00ae",
|
|
183
|
-
trade: "\u2122", hellip: "\u2026", mdash: "\u2014", ndash: "\u2013", laquo: "\u00ab", raquo: "\u00bb",
|
|
184
|
-
lsquo: "\u2018", rsquo: "\u2019", ldquo: "\u201c", rdquo: "\u201d", times: "\u00d7", divide: "\u00f7",
|
|
185
|
-
euro: "\u20ac", pound: "\u00a3", yen: "\u00a5", cent: "\u00a2", deg: "\u00b0", plusmn: "\u00b1",
|
|
186
|
-
middot: "\u00b7", bull: "\u2022", larr: "\u2190", rarr: "\u2192", uarr: "\u2191", darr: "\u2193",
|
|
187
|
-
hearts: "\u2665", sect: "\u00a7", para: "\u00b6", iexcl: "\u00a1", iquest: "\u00bf", frac12: "\u00bd",
|
|
188
|
-
frac14: "\u00bc", frac34: "\u00be", micro: "\u00b5", ensp: "\u2002", emsp: "\u2003", thinsp: "\u2009",
|
|
189
|
-
zwnj: "\u200c", zwj: "\u200d", shy: "\u00ad", infin: "\u221e", ne: "\u2260", le: "\u2264", ge: "\u2265"
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// ESLint's parsers expose entity-decoded JSX text and attribute values while
|
|
193
|
-
// keeping `raw` intact; mirror that for the common entities.
|
|
194
|
-
function decodeJsxEntities(value) {
|
|
195
|
-
if (typeof value !== "string" || !value.includes("&")) {
|
|
196
|
-
return value;
|
|
197
|
-
}
|
|
198
|
-
return value.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z][a-zA-Z0-9]*);/gu, (match, entity) => {
|
|
199
|
-
if (entity[0] === "#") {
|
|
200
|
-
const codePoint = entity[1] === "x" || entity[1] === "X" ? Number.parseInt(entity.slice(2), 16) : Number.parseInt(entity.slice(1), 10);
|
|
201
|
-
return Number.isFinite(codePoint) && codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : match;
|
|
202
|
-
}
|
|
203
|
-
return Object.hasOwn(JSX_ENTITIES, entity) ? JSX_ENTITIES[entity] : match;
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
181
|
function setParent(node, parent) {
|
|
208
182
|
Object.defineProperty(node, "parent", {
|
|
209
183
|
value: parent,
|
|
@@ -230,9 +204,6 @@ function normalizeTree(program, text, locate) {
|
|
|
230
204
|
}
|
|
231
205
|
decorateNode(node, locate);
|
|
232
206
|
setParent(node, parent);
|
|
233
|
-
if (node.type === "JSXText" || (node.type === "Literal" && parent?.type === "JSXAttribute")) {
|
|
234
|
-
node.value = decodeJsxEntities(node.value);
|
|
235
|
-
}
|
|
236
207
|
forEachChild(node, (child) => stack.push([child, node]));
|
|
237
208
|
}
|
|
238
209
|
program.start = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/lint",
|
|
3
|
-
"version": "0.4.
|
|
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.
|
|
78
|
-
"@utoo/lint-darwin-x64": "0.4.
|
|
79
|
-
"@utoo/lint-linux-arm64": "0.4.
|
|
80
|
-
"@utoo/lint-linux-x64": "0.4.
|
|
81
|
-
"@utoo/lint-win32-x64": "0.4.
|
|
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",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"eslint-scope": "9.1.2",
|
|
89
89
|
"esquery": "1.7.0",
|
|
90
90
|
"jiti": "2.7.0",
|
|
91
|
-
"yuku-parser": "0.
|
|
91
|
+
"yuku-parser": "0.18.0"
|
|
92
92
|
},
|
|
93
93
|
"publishConfig": {
|
|
94
94
|
"access": "public",
|