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 PrimeNG's p-card in nested-cards (#290)

Pranav Arya525c68e67b4e
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index bc35604..aead54a 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -991,7 +991,8 @@ const rules = [
if (stack === "js" || stack === "web") {
// 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).
- for (const m of matches(/<(Card|IonCard|ion-card|VCard|v-card|mat-card|QCard|q-card|ElCard|el-card|NCard|n-card|ACard|a-card)(?=[\s/>])/, code)) {
+ // So does PrimeNG's p-card (#280).
+ for (const m of matches(/<(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)) {
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 0e76f3d..01cd216 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1423,6 +1423,30 @@ test("nested-cards flags Naive UI n-card and Ant Design Vue a-card nesting, not
assert.deepStrictEqual(cardLines(aCardPartsPascal), []);
});
+test("nested-cards flags PrimeNG p-card nesting, not other p- tags inside one card (issue #280)", () => {
+ 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 #280 repro:
+ const repro = [
+ '<p-card header="Plans">',
+ ' <p-card header="Pro">Pro plan</p-card>',
+ "</p-card>",
+ ].join("\n");
+ assert.deepStrictEqual(cardLines(repro), [[1, "noticeable"]]);
+
+ // Without attributes, and with the inner card a few levels down
+ assert.deepStrictEqual(cardLines("<p-card>\n <div>\n <p-card>Pro plan</p-card>\n </div>\n</p-card>\n"), [[1, "noticeable"]]);
+
+ // A single card, sibling cards and other PrimeNG tags inside one card stay quiet
+ assert.deepStrictEqual(cardLines('<p-card header="Pro">Pro plan</p-card>\n'), []);
+ assert.deepStrictEqual(cardLines('<p-card header="Pro">Pro</p-card>\n<p-card header="Team">Team</p-card>\n'), []);
+ assert.deepStrictEqual(cardLines('<p-card header="Pro">\n <p-tag value="New" />\n <p-button label="Buy" />\n</p-card>\n'), []);
+ // A longer tag that starts with p-card is not a card
+ assert.deepStrictEqual(cardLines("<p-card>\n <p-cardlist>Plans</p-cardlist>\n</p-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"), []);