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 header cells (#315)

daocuong118a2642e490c5
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index a024493..1afa6a4 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1408,7 +1408,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|tr|img|a|article|section|h[1-6]|p|header|footer|figure)(?=[\s/>])/, code)) {
+ for (const m of matches(/<(?:div|span|li|td|th|tr|img|a|article|section|h[1-6]|p|header|footer|figure)(?=[\s/>])/, 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 c1c2957..167e999 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1198,6 +1198,31 @@ test("clickable-div flags click handlers on table rows (issue #247)", () => {
assert.deepStrictEqual(lines('<track kind="captions" onClick={open} />\n'), []);
});
+test("clickable-div flags click handlers on table header cells (issue #299)", () => {
+ const lines = (src, file = "Table.tsx") => scanSource(src, file).filter((f) => f.rule === "clickable-div").map((f) => f.line);
+ // The repro from issue #299.
+ const repro = [
+ 'export const Table = ({ sort }) => (',
+ " <table>",
+ " <thead>",
+ " <tr>",
+ ' <th onClick={() => sort("name")}>Name</th>',
+ " </tr>",
+ " </thead>",
+ " </table>",
+ ");",
+ ].join("\n");
+ assert.deepStrictEqual(lines(repro), [5]);
+ assert.deepStrictEqual(lines('<th @click="sort">Name</th>\n', "Table.vue"), [1]);
+ assert.deepStrictEqual(lines('<th (click)="sort()">Name</th>\n', "table.component.html"), [1]);
+ assert.deepStrictEqual(lines("<th on:click={sort}>Name</th>\n", "Table.svelte"), [1]);
+ // Quiet: a button inside the header cell, an interactive role with tabIndex,
+ // and a longer custom tag that only starts the same way.
+ assert.deepStrictEqual(lines('<th><button onClick={sort}>Name</button></th>\n'), []);
+ assert.deepStrictEqual(lines('<th role="button" tabIndex={0} onClick={sort}>Name</th>\n'), []);
+ assert.deepStrictEqual(lines('<th-sort (click)="sort()">Name</th-sort>\n', "table.component.html"), []);
+});
+
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);