uilint 0.2.5 → 0.2.6
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/dist/index.js +71 -3
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1913,6 +1913,35 @@ function hasSpreadProperties(obj) {
|
|
|
1913
1913
|
(p2) => p2 && (p2.type === "SpreadElement" || p2.type === "SpreadProperty")
|
|
1914
1914
|
);
|
|
1915
1915
|
}
|
|
1916
|
+
var IGNORED_AST_KEYS = /* @__PURE__ */ new Set([
|
|
1917
|
+
"loc",
|
|
1918
|
+
"start",
|
|
1919
|
+
"end",
|
|
1920
|
+
"extra",
|
|
1921
|
+
"leadingComments",
|
|
1922
|
+
"trailingComments",
|
|
1923
|
+
"innerComments"
|
|
1924
|
+
]);
|
|
1925
|
+
function normalizeAstForCompare(node) {
|
|
1926
|
+
if (node === null) return null;
|
|
1927
|
+
if (node === void 0) return void 0;
|
|
1928
|
+
if (typeof node !== "object") return node;
|
|
1929
|
+
if (Array.isArray(node)) return node.map(normalizeAstForCompare);
|
|
1930
|
+
const out = {};
|
|
1931
|
+
const keys = Object.keys(node).filter((k) => !IGNORED_AST_KEYS.has(k)).sort();
|
|
1932
|
+
for (const k of keys) {
|
|
1933
|
+
if (k.startsWith("$")) continue;
|
|
1934
|
+
out[k] = normalizeAstForCompare(node[k]);
|
|
1935
|
+
}
|
|
1936
|
+
return out;
|
|
1937
|
+
}
|
|
1938
|
+
function astEquivalent(a, b) {
|
|
1939
|
+
try {
|
|
1940
|
+
return JSON.stringify(normalizeAstForCompare(a)) === JSON.stringify(normalizeAstForCompare(b));
|
|
1941
|
+
} catch {
|
|
1942
|
+
return false;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1916
1945
|
function collectUilintRuleIdsFromRulesObject(rulesObj) {
|
|
1917
1946
|
const ids = /* @__PURE__ */ new Set();
|
|
1918
1947
|
if (!rulesObj || rulesObj.type !== "ObjectExpression") return ids;
|
|
@@ -2209,8 +2238,46 @@ function extractConfiguredUilintRuleIds(source) {
|
|
|
2209
2238
|
function getMissingSelectedRules(selectedRules, configuredIds) {
|
|
2210
2239
|
return selectedRules.filter((r) => !configuredIds.has(r.id));
|
|
2211
2240
|
}
|
|
2212
|
-
function
|
|
2213
|
-
|
|
2241
|
+
function buildDesiredRuleValueExpression(rule) {
|
|
2242
|
+
if (rule.defaultOptions && rule.defaultOptions.length > 0) {
|
|
2243
|
+
return `["${rule.defaultSeverity}", ...${JSON.stringify(
|
|
2244
|
+
rule.defaultOptions,
|
|
2245
|
+
null,
|
|
2246
|
+
2
|
|
2247
|
+
)}]`;
|
|
2248
|
+
}
|
|
2249
|
+
return `"${rule.defaultSeverity}"`;
|
|
2250
|
+
}
|
|
2251
|
+
function collectUilintRuleValueNodesFromConfigArray(arrayExpr) {
|
|
2252
|
+
const out = /* @__PURE__ */ new Map();
|
|
2253
|
+
if (!arrayExpr || arrayExpr.type !== "ArrayExpression") return out;
|
|
2254
|
+
for (const el of arrayExpr.elements ?? []) {
|
|
2255
|
+
if (!el || el.type !== "ObjectExpression") continue;
|
|
2256
|
+
const rules = getObjectPropertyValue(el, "rules");
|
|
2257
|
+
if (!rules || rules.type !== "ObjectExpression") continue;
|
|
2258
|
+
for (const prop of rules.properties ?? []) {
|
|
2259
|
+
if (!prop) continue;
|
|
2260
|
+
if (prop.type !== "ObjectProperty" && prop.type !== "Property") continue;
|
|
2261
|
+
const key = prop.key;
|
|
2262
|
+
if (!isStringLiteral(key)) continue;
|
|
2263
|
+
const k = key.value;
|
|
2264
|
+
if (typeof k !== "string" || !k.startsWith("uilint/")) continue;
|
|
2265
|
+
const id = k.slice("uilint/".length);
|
|
2266
|
+
if (!out.has(id)) out.set(id, prop.value);
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
return out;
|
|
2270
|
+
}
|
|
2271
|
+
function getRulesNeedingUpdate(selectedRules, configuredIds, arrayExpr) {
|
|
2272
|
+
const existingVals = collectUilintRuleValueNodesFromConfigArray(arrayExpr);
|
|
2273
|
+
return selectedRules.filter((r) => {
|
|
2274
|
+
if (!configuredIds.has(r.id)) return false;
|
|
2275
|
+
const existing = existingVals.get(r.id);
|
|
2276
|
+
if (!existing) return true;
|
|
2277
|
+
const desiredExpr = buildDesiredRuleValueExpression(r);
|
|
2278
|
+
const desiredAst = parseExpression(desiredExpr).$ast;
|
|
2279
|
+
return !astEquivalent(existing, desiredAst);
|
|
2280
|
+
});
|
|
2214
2281
|
}
|
|
2215
2282
|
async function installEslintPlugin(opts) {
|
|
2216
2283
|
const configPath = findEslintConfigFile(opts.projectPath);
|
|
@@ -2243,7 +2310,8 @@ async function installEslintPlugin(opts) {
|
|
|
2243
2310
|
);
|
|
2244
2311
|
const rulesToUpdate = getRulesNeedingUpdate(
|
|
2245
2312
|
opts.selectedRules,
|
|
2246
|
-
configuredIds
|
|
2313
|
+
configuredIds,
|
|
2314
|
+
arrayExpr
|
|
2247
2315
|
);
|
|
2248
2316
|
let rulesToApply = [];
|
|
2249
2317
|
if (!info.configured) {
|