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): flag Angular (click) and Alpine x-on:click in clickable-div (#164)

susheelg1197cc57b88dbede
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 78cf9dc..02a179f 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1108,7 +1108,9 @@ const rules = [
// Only this element's own attributes: a nested element inside {...} is checked on its own.
let top = m[0];
walkTag(code, m.index + m[0].length, (i) => { top += code[i]; });
- if (!/\s(?:on[cC]lick|@click|v-on:click|on:click)(?:\.[\w-]+|\|\w+)*\s*=/.test(top)) continue;
+ // onClick/onclick (React, HTML), @click/v-on:click (Vue, Alpine), x-on:click (Alpine),
+ // on:click (Svelte) and (click) (Angular).
+ if (!/\s(?:(?:on[cC]lick|@click|v-on:click|x-on:click|on:click)(?:\.[\w-]+|\|\w+)*|\(click\))\s*=/.test(top)) continue;
if (/^<a\b/.test(tag) && /(?:^|[\s{:[])href\]?\s*=/.test(tag)) continue;
// A non-semantic clickable element (or href-less anchor) is only
// keyboard- and screen-reader-accessible when it has both an
diff --git a/test/detect.test.js b/test/detect.test.js
index 0af3283..358447a 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1536,3 +1536,16 @@ test("drawer-nav catches every style of the hamburger icon (issue #146)", () =>
assert.deepStrictEqual(lines("Icon(Icons.menu_book)\n", "header.dart"), []);
assert.deepStrictEqual(lines('<Ionicons name="menu-sharp-outline" />\n', "Header.tsx"), []);
});
+
+test("clickable-div flags Angular (click) and Alpine x-on:click handlers", () => {
+ const rulesFor = (src) => scanSource(src, "a.html").map((f) => f.rule);
+ assert.deepStrictEqual(rulesFor('<div class="card" (click)="open()">Details</div>\n'), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<span (click) = "open()">x</span>\n'), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<div class="card" x-on:click="open = true">Details</div>\n'), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<div x-on:click.prevent="open = true">x</div>\n'), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<div role="button" tabindex="0" (click)="open()">Details</div>\n'), []);
+ assert.deepStrictEqual(rulesFor('<div role="button" tabindex="0" x-on:click="open = true">x</div>\n'), []);
+ assert.deepStrictEqual(rulesFor('<a href="/x" (click)="track()">x</a>\n'), []);
+ assert.deepStrictEqual(rulesFor('<button (click)="open()">x</button>\n'), []);
+ assert.deepStrictEqual(rulesFor('<button x-on:click="open = true">x</button>\n'), []);
+});