uilint 0.2.0 → 0.2.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/dist/index.js +67 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1732,14 +1732,69 @@ function collectUilintRuleIdsFromRulesObject(rulesObj) {
|
|
|
1732
1732
|
return ids;
|
|
1733
1733
|
}
|
|
1734
1734
|
function findExportedConfigArrayExpression(mod) {
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1735
|
+
function unwrapExpression(expr) {
|
|
1736
|
+
let e = expr;
|
|
1737
|
+
while (e) {
|
|
1738
|
+
if (e.type === "TSAsExpression" || e.type === "TSNonNullExpression") {
|
|
1739
|
+
e = e.expression;
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
if (e.type === "TSSatisfiesExpression") {
|
|
1743
|
+
e = e.expression;
|
|
1744
|
+
continue;
|
|
1745
|
+
}
|
|
1746
|
+
if (e.type === "ParenthesizedExpression") {
|
|
1747
|
+
e = e.expression;
|
|
1748
|
+
continue;
|
|
1749
|
+
}
|
|
1750
|
+
break;
|
|
1740
1751
|
}
|
|
1752
|
+
return e;
|
|
1753
|
+
}
|
|
1754
|
+
function resolveTopLevelIdentifierToArrayExpr(program3, name) {
|
|
1755
|
+
if (!program3 || program3.type !== "Program") return null;
|
|
1756
|
+
for (const stmt of program3.body ?? []) {
|
|
1757
|
+
if (stmt?.type !== "VariableDeclaration") continue;
|
|
1758
|
+
for (const decl of stmt.declarations ?? []) {
|
|
1759
|
+
const id = decl?.id;
|
|
1760
|
+
if (!isIdentifier(id, name)) continue;
|
|
1761
|
+
const init = unwrapExpression(decl?.init);
|
|
1762
|
+
if (!init) return null;
|
|
1763
|
+
if (init.type === "ArrayExpression") return init;
|
|
1764
|
+
if (init.type === "CallExpression" && isIdentifier(init.callee, "defineConfig") && unwrapExpression(init.arguments?.[0])?.type === "ArrayExpression") {
|
|
1765
|
+
return unwrapExpression(init.arguments?.[0]);
|
|
1766
|
+
}
|
|
1767
|
+
return null;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
return null;
|
|
1741
1771
|
}
|
|
1742
1772
|
const program2 = mod?.$ast;
|
|
1773
|
+
if (program2 && program2.type === "Program") {
|
|
1774
|
+
for (const stmt of program2.body ?? []) {
|
|
1775
|
+
if (!stmt || stmt.type !== "ExportDefaultDeclaration") continue;
|
|
1776
|
+
const decl = unwrapExpression(stmt.declaration);
|
|
1777
|
+
if (!decl) break;
|
|
1778
|
+
if (decl.type === "ArrayExpression") {
|
|
1779
|
+
return { kind: "esm", arrayExpr: decl, program: program2 };
|
|
1780
|
+
}
|
|
1781
|
+
if (decl.type === "CallExpression" && isIdentifier(decl.callee, "defineConfig") && unwrapExpression(decl.arguments?.[0])?.type === "ArrayExpression") {
|
|
1782
|
+
return {
|
|
1783
|
+
kind: "esm",
|
|
1784
|
+
arrayExpr: unwrapExpression(decl.arguments?.[0]),
|
|
1785
|
+
program: program2
|
|
1786
|
+
};
|
|
1787
|
+
}
|
|
1788
|
+
if (decl.type === "Identifier" && typeof decl.name === "string") {
|
|
1789
|
+
const resolved = resolveTopLevelIdentifierToArrayExpr(
|
|
1790
|
+
program2,
|
|
1791
|
+
decl.name
|
|
1792
|
+
);
|
|
1793
|
+
if (resolved) return { kind: "esm", arrayExpr: resolved, program: program2 };
|
|
1794
|
+
}
|
|
1795
|
+
break;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1743
1798
|
if (!program2 || program2.type !== "Program") return null;
|
|
1744
1799
|
for (const stmt of program2.body ?? []) {
|
|
1745
1800
|
if (!stmt || stmt.type !== "ExpressionStatement") continue;
|
|
@@ -1755,6 +1810,13 @@ function findExportedConfigArrayExpression(mod) {
|
|
|
1755
1810
|
if (right?.type === "CallExpression" && isIdentifier(right.callee, "defineConfig") && right.arguments?.[0]?.type === "ArrayExpression") {
|
|
1756
1811
|
return { kind: "cjs", arrayExpr: right.arguments[0], program: program2 };
|
|
1757
1812
|
}
|
|
1813
|
+
if (right?.type === "Identifier" && typeof right.name === "string") {
|
|
1814
|
+
const resolved = resolveTopLevelIdentifierToArrayExpr(
|
|
1815
|
+
program2,
|
|
1816
|
+
right.name
|
|
1817
|
+
);
|
|
1818
|
+
if (resolved) return { kind: "cjs", arrayExpr: resolved, program: program2 };
|
|
1819
|
+
}
|
|
1758
1820
|
}
|
|
1759
1821
|
return null;
|
|
1760
1822
|
}
|