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 article and section in clickable-div (#237)

Papito084b8e582f37026
diff --git a/skills/unslop-anything/reference/web.md b/skills/unslop-anything/reference/web.md
index 70f1e90..7e38e94 100644
--- a/skills/unslop-anything/reference/web.md
+++ b/skills/unslop-anything/reference/web.md
@@ -17,7 +17,7 @@ A product's marketing site and its app are two scopes. Review one at a time.
These break the web for real people. They are Critical or Noticeable, whatever the look.
-- **Real controls.** Actions are `<button>`, navigation is `<a href>`. A `div` or `span` with a click handler is unreachable by keyboard and silent to screen readers [`clickable-div`].
+- **Real controls.** Actions are `<button>`, navigation is `<a href>`. A `div`, `span`, `article` or other non-interactive element with a click handler is unreachable by keyboard and silent to screen readers [`clickable-div`].
- **Visible focus.** Every interactive element shows a `:focus-visible` style, in the palette, instantly. `outline: none` with nothing in its place locks keyboard users out [`focus-removed`].
- **Zoom stays on.** No `maximum-scale=1` or `user-scalable=no` [`zoom-disabled`]. Inputs at 16px stop iOS from zooming on focus.
- **Text alternatives.** Every content image has alt text, including framework image components such as `<Image>`, `<NuxtImg>` and Vuetify's `<v-img>` / `<VImg>`; decoration has `alt=""` [`img-no-alt`].
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index c6c8394..8c9a654 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1377,13 +1377,13 @@ const rules = [
family: "accessibility",
severity: "noticeable",
stacks: ["js", "web"],
- message: "Click handler on a div or span. Keyboard and screen reader users cannot reach it.",
+ message: "Click handler on a non-interactive element such as a div, span or article. Keyboard and screen reader users cannot reach it.",
fix: "Use a <button> for actions and an <a href> for navigation. They come with focus, Enter and Space, and the right role.",
find({ code }) {
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)\b/, code)) {
+ for (const m of matches(/<(?:div|span|li|td|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 834eff2..580f22d 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1910,6 +1910,46 @@ test("clickable-div flags Qwik onClick$ handlers (issue #178)", () => {
assert.deepStrictEqual(lines('<button onClick$={() => open()}>Open</button>\n'), []);
});
+test("clickable-div flags click handlers on article and section (issue #231)", () => {
+ const rulesFor = (src, file = "Plan.tsx") =>
+ scanSource(src, file)
+ .filter((f) => f.rule === "clickable-div")
+ .map((f) => f.rule);
+ const linesFor = (src, file = "Plan.tsx") =>
+ scanSource(src, file)
+ .filter((f) => f.rule === "clickable-div")
+ .map((f) => f.line);
+
+ // Issue #231 repro:
+ const repro = [
+ "export function Plan() {",
+ " return (",
+ ' <article className="card" onClick={() => choose("pro")}>',
+ " Pro plan",
+ " </article>",
+ " );",
+ "}",
+ ].join("\n");
+ assert.deepStrictEqual(linesFor(repro, "Plan.tsx"), [3]);
+
+ // Flagged forms across article and section with various click handlers
+ assert.deepStrictEqual(rulesFor('<article onClick={() => choose("pro")}>Pro</article>\n'), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<section onClick={() => choose("pro")}>Pro</section>\n'), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<article @click="choose">Pro</article>\n', "Plan.vue"), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<section (click)="choose()">Pro</section>\n', "Plan.html"), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<article on:click={choose}>Pro</article>\n', "Plan.svelte"), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<section onclick="choose()">Pro</section>\n', "Plan.html"), ["clickable-div"]);
+ assert.deepStrictEqual(rulesFor('<article onClick$={() => choose("pro")}>Pro</article>\n'), ["clickable-div"]);
+
+ // Quiet cases: no handler, components with Article/Section prefixes, interactive role + tabIndex
+ assert.deepStrictEqual(rulesFor('<article className="card">Pro plan</article>\n'), []);
+ assert.deepStrictEqual(rulesFor('<section className="card">Pro plan</section>\n'), []);
+ assert.deepStrictEqual(rulesFor('<ArticleCard onClick={() => choose("pro")}>Pro</ArticleCard>\n'), []);
+ assert.deepStrictEqual(rulesFor('<SectionCard onClick={() => choose("pro")}>Pro</SectionCard>\n'), []);
+ assert.deepStrictEqual(rulesFor('<article onClick={() => choose("pro")} role="button" tabIndex={0}>Pro</article>\n'), []);
+ assert.deepStrictEqual(rulesFor('<section onClick={() => choose("pro")} role="button" tabIndex={0}>Pro</section>\n'), []);
+});
+
test("template-theme flags create-vite's #646cff and #535bf2", () => {
const rulesFor = (src) => scanSource(src, "index.css").map((f) => f.rule).filter((r) => r === "template-theme");
assert.deepStrictEqual(rulesFor("a {\n font-weight: 500;\n color: #646cff;\n}\na:hover {\n color: #535bf2;\n}\n"), ["template-theme"]);