Skip to content

Your app looks AI-generated. Vincent Van Gogh noticed. An agent skill that finds and fixes AI-looking UI and UX in mobile apps, web apps, and websites.

fix(detect): stop nested-cards flagging Card subcomponents (#92)

Nguyễn Tuấn Anh85509f8a5105
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 0b285f9..56131d8 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -462,13 +462,13 @@ const rules = [
find({ code, stack }) {
const hits = [];
if (stack === "js" || stack === "web") {
- for (const m of matches(/<(Card|ion-card)\b[^>]*?(\/?)>/, code)) {
+ for (const m of matches(/<(Card|ion-card)(?=[\s/>])[^>]*?(\/?)>/, code)) {
if (m[2] === "/") continue;
const tag = m[1];
const close = code.indexOf(`</${tag}>`, m.index);
if (close === -1) continue;
const inner = code.slice(m.index + m[0].length, close);
- if (new RegExp(`<${tag}\\b`).test(inner)) hits.push(m.index);
+ if (new RegExp(`<${tag}(?=[\\s/>])`).test(inner)) hits.push(m.index);
}
} else {
const card = /\b(?:Elevated|Outlined|Filled)?Card\s*[({]/;
diff --git a/test/detect.test.js b/test/detect.test.js
index a600d59..3ad258a 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -521,6 +521,20 @@ test("focus-removed flags a bare focus:outline-none, not one with a ring replace
assert.deepStrictEqual(rulesFor('<input className="focus:outline-none focus-visible:ring-2" />\n'), []);
});
+test("nested-cards ignores dotted subcomponents and ion-card parts, still flags a real nested card", () => {
+ const rulesFor = (src, file = "a.tsx") => scanSource(src, file).map((f) => f.rule);
+ // Issue #65: dotted subcomponents of a single card are not nested cards.
+ assert.deepStrictEqual(rulesFor("<Card>\n <Card.Title title=\"Hi\" />\n <Card.Content><Text>x</Text></Card.Content>\n</Card>\n"), []);
+ // Same for Ionic: hyphenated subcomponents are parts of one card.
+ assert.deepStrictEqual(rulesFor("<ion-card><ion-card-header><ion-card-title>x</ion-card-title></ion-card-header></ion-card>", "a.html"), []);
+ // A compound tag name starting with Card is not a nested card either.
+ assert.deepStrictEqual(rulesFor("<Card><CardHeader>x</CardHeader></Card>"), []);
+ // A genuine nested card is still flagged.
+ assert.deepStrictEqual(rulesFor("<Card><Card><Text>x</Text></Card></Card>"), ["nested-cards"]);
+ assert.deepStrictEqual(rulesFor("<Card className=\"x\"><Card className=\"y\">z</Card></Card>"), ["nested-cards"]);
+ assert.deepStrictEqual(rulesFor("<ion-card><ion-card></ion-card></ion-card>", "a.html"), ["nested-cards"]);
+});
+
test("unverified-claim allows one adjective between the number and the noun", () => {
const rulesFor = (src) => scanSource(src, "a.tsx").map((f) => f.rule);
assert.deepStrictEqual(rulesFor("<p>Join 10,000+ customers</p>\n"), ["unverified-claim"]);