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 click handlers on table rows in clickable-div (#259)

tarekooooooo65b1f6b0ee78
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 8087977..9fcc404 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1383,7 +1383,7 @@ const rules = [
const hits = [];
// Each opening tag is read to its real end first, so an arrow function in an earlier
// attribute (`onKeyDown={(e) => ...}`) does not hide the click handler after it.
- for (const m of matches(/<(?:div|span|li|td|img|a|article|section)\b/, code)) {
+ for (const m of matches(/<(?:div|span|li|td|tr|img|a|article|section)\b/, code)) {
const end = tagEnd(code, m.index + m[0].length);
const tag = code.slice(m.index, end === -1 ? undefined : end);
// Only this element's own attributes: a nested element inside {...} is checked on its own.
diff --git a/test/detect.test.js b/test/detect.test.js
index b08262a..85c20d7 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1152,7 +1152,7 @@ test("clickable-div flags a href-less anchor with onClick", () => {
assert.deepStrictEqual(findingsFor('<a onClick={go} tabIndex={0}>Go</a>\n').map((f) => f.rule), ["clickable-div"]);
});
-test("clickable-div requires both an interactive role and tabIndex on div/span/li/td/img", () => {
+test("clickable-div requires both an interactive role and tabIndex on div/span/li/td/tr/img", () => {
const rulesFor = (src, file = "a.tsx") =>
scanSource(src, file)
.filter((f) => f.rule === "clickable-div")
@@ -1169,6 +1169,35 @@ test("clickable-div requires both an interactive role and tabIndex on div/span/l
assert.deepStrictEqual(rulesFor('<div role="button" tabindex="0" on:click={open}>Open</div>\n', "A.svelte"), []);
});
+test("clickable-div flags click handlers on table rows (issue #247)", () => {
+ const lines = (src, file = "Orders.tsx") => scanSource(src, file).filter((f) => f.rule === "clickable-div").map((f) => f.line);
+ const repro = [
+ "export function Orders({ orders, open }) {",
+ " return (",
+ " <table>",
+ " <tbody>",
+ " {orders.map((o) => (",
+ " <tr key={o.id} onClick={() => open(o.id)}>",
+ " <td>{o.number}</td>",
+ " </tr>",
+ " ))}",
+ " </tbody>",
+ " </table>",
+ " );",
+ "}",
+ ].join("\n");
+ assert.deepStrictEqual(lines(repro), [6]);
+ assert.deepStrictEqual(lines('<tr @click="open">\n <td>Open</td>\n</tr>\n', "Orders.vue"), [1]);
+ assert.deepStrictEqual(lines('<tr (click)="open()">\n <td>Open</td>\n</tr>\n', "orders.component.html"), [1]);
+ assert.deepStrictEqual(lines("<tr on:click={open}>\n <td>Open</td>\n</tr>\n", "Orders.svelte"), [1]);
+ assert.deepStrictEqual(lines('<tr role="button" onClick={open}>\n <td>Open</td>\n</tr>\n'), [1]);
+ // Quiet: no handler, a component row, an interactive role with tabIndex, and <track>.
+ assert.deepStrictEqual(lines("<tr>\n <td>Open</td>\n</tr>\n"), []);
+ assert.deepStrictEqual(lines("<TableRow onClick={open}>\n <TableCell>Open</TableCell>\n</TableRow>\n"), []);
+ assert.deepStrictEqual(lines('<tr role="button" tabIndex={0} onClick={open}>\n <td>Open</td>\n</tr>\n'), []);
+ assert.deepStrictEqual(lines('<track kind="captions" onClick={open} />\n'), []);
+});
+
test("tagEnd skips strings inside an attribute expression", () => {
const imgs = (code) => scanSource(code, "A.tsx").filter((f) => f.rule === "img-no-alt");
assert.deepStrictEqual(imgs('<img onLoad={() => loaded("}")} alt="Photo" src={src} />\n').length, 0);