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): check NG-ZORRO's nz-card in nested-cards (#336)

Pranav Arya1873bb79cdf1
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 039a00f..3e550e9 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -992,8 +992,9 @@ const rules = [
// Vuetify's v-card, Angular Material's mat-card, Quasar's q-card and Element Plus's el-card nest like ion-card (#202, #228).
// Naive UI's n-card and Ant Design Vue's a-card nest like ion-card too (#266).
// So does PrimeNG's p-card (#280).
+ // NG-ZORRO's nz-card nests the same way (#326).
// Chakra UI v3's Card.Root is the card itself; its Card.Header/Body/Footer parts are not (#305).
- for (const m of matches(/<(Card\.Root|Card|IonCard|ion-card|VCard|v-card|mat-card|QCard|q-card|ElCard|el-card|NCard|n-card|ACard|a-card|p-card)(?=[\s/>])/, code)) {
+ for (const m of matches(/<(Card\.Root|Card|IonCard|ion-card|VCard|v-card|mat-card|QCard|q-card|ElCard|el-card|NCard|n-card|ACard|a-card|p-card|nz-card)(?=[\s/>])/, code)) {
const end = tagEnd(code, m.index + m[0].length);
if (end === -1) continue;
if (/\/\s*$/.test(code.slice(m.index + m[0].length, end))) continue;
diff --git a/test/detect.test.js b/test/detect.test.js
index ac5eba7..524dda2 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1502,6 +1502,31 @@ test("nested-cards flags PrimeNG p-card nesting, not other p- tags inside one ca
assert.deepStrictEqual(cardLines("<mat-card>\n <mat-card>Pro plan</mat-card>\n</mat-card>\n"), [[1, "noticeable"]]);
});
+test("nested-cards flags NG-ZORRO nz-card nesting, not its card parts (issue #326)", () => {
+ const cardLines = (src, file = "plans.component.html") => scanSource(src, file, { kind: "web" }).filter((f) => f.rule === "nested-cards").map((f) => [f.line, f.severity]);
+ // Issue #326 repro:
+ const repro = [
+ '<nz-card nzTitle="Plans">',
+ ' <nz-card nzTitle="Pro">$9</nz-card>',
+ "</nz-card>",
+ ].join("\n");
+ assert.deepStrictEqual(cardLines(repro), [[1, "noticeable"]]);
+
+ // Without attributes, and with the inner card a few levels down
+ assert.deepStrictEqual(cardLines("<nz-card>\n <div>\n <nz-card>Pro plan</nz-card>\n </div>\n</nz-card>\n"), [[1, "noticeable"]]);
+
+ // A single card with its parts stays quiet: card parts are not cards
+ assert.deepStrictEqual(cardLines('<nz-card nzTitle="Pro">$9</nz-card>\n'), []);
+ assert.deepStrictEqual(cardLines('<nz-card>\n <nz-card-meta nzTitle="Pro" nzDescription="$9"></nz-card-meta>\n</nz-card>\n'), []);
+ assert.deepStrictEqual(cardLines('<nz-card>\n <nz-card-tab>\n <nz-tabset></nz-tabset>\n </nz-card-tab>\n</nz-card>\n'), []);
+ // Sibling cards and other NG-ZORRO tags inside one card stay quiet
+ assert.deepStrictEqual(cardLines('<nz-card nzTitle="Pro">$9</nz-card>\n<nz-card nzTitle="Team">$29</nz-card>\n'), []);
+ assert.deepStrictEqual(cardLines('<nz-card nzTitle="Pro">\n <nz-tag>New</nz-tag>\n <button nz-button>Buy</button>\n</nz-card>\n'), []);
+
+ // The existing cards keep working
+ assert.deepStrictEqual(cardLines("<mat-card>\n <mat-card>Pro plan</mat-card>\n</mat-card>\n"), [[1, "noticeable"]]);
+});
+
test("nested-cards reads opening tags with tagEnd so arrows or > in props do not misread sibling cards", () => {
const rulesFor = (src, file = "a.tsx") => scanSource(src, file).filter((f) => f.rule === "nested-cards").map((f) => f.rule);
assert.deepStrictEqual(rulesFor("<Card onClick={() => open()} />\n<Card><p>Second</p></Card>\n"), []);