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: recognize bare alt attributes in web templates (#130)

Nandani Naulab86e7029260f
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index f6fc77e..ba9e440 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1046,13 +1046,15 @@ const rules = [
stacks: ["js", "web"],
message: "Image without alt text.",
fix: "Describe what the image shows, or use alt=\"\" for pure decoration.",
- find({ code }) {
+ find({ code, stack }) {
const hits = [];
for (const m of matches(/<(?:img|Image)(?=[\s/>])/, code)) {
const end = tagEnd(code, m.index);
const tag = code.slice(m.index, end === -1 ? undefined : end);
if (tag.startsWith("<Image") && !/\ssrc\s*=/.test(tag)) continue;
- if (!/[\s:\[.]alt\]?\s*=|\{\s*alt\s*\}|\{\s*\.\.\./.test(tag)) hits.push(m.index);
+ const hasAlt = /[\s:\[.]alt\]?\s*=|\{\s*alt\s*\}|\{\s*\.\.\./.test(tag)
+ || (stack === "web" && /\salt(?=[\s/>]|$)/.test(tag));
+ if (!hasAlt) hits.push(m.index);
}
return hits;
},
diff --git a/test/detect.test.js b/test/detect.test.js
index 25db29f..0e293f7 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -814,6 +814,16 @@ test("img-no-alt accepts Angular [alt] bindings and Svelte {alt} shorthand", ()
// Plain alt and Vue :alt keep working, and a missing alt is still reported.
assert.deepStrictEqual(rulesFor('<img src="x.png" alt="hi">\n', "a.html"), []);
assert.deepStrictEqual(rulesFor('<img :src="u" :alt="n">\n', "a.vue"), []);
+ // HTML-style bare alt attributes count as an empty alt value across web templates.
+ assert.deepStrictEqual(rulesFor('<img src="divider.png" alt>\n', "a.html"), []);
+ assert.deepStrictEqual(rulesFor('<img src="divider.png" alt />\n', "a.vue"), []);
+ assert.deepStrictEqual(rulesFor('<img src="divider.png" alt/>\n', "A.svelte"), []);
+ assert.deepStrictEqual(rulesFor('<img src="divider.png" alt>\n', "a.astro"), []);
+ assert.deepStrictEqual(rulesFor('<img alt src="divider.png">\n', "index.html"), []);
+ assert.deepStrictEqual(rulesFor('<img src="divider.png" alt />\n', "index.html"), []);
+ assert.deepStrictEqual(rulesFor('<img src="photo.png">\n', "index.html"), ["img-no-alt"]);
+ // JSX treats a bare alt as true rather than useful alternative text.
+ assert.deepStrictEqual(rulesFor('<img src="divider.png" alt />\n', "a.jsx"), ["img-no-alt"]);
assert.deepStrictEqual(rulesFor('<img [src]="u.avatar">\n', "a.component.html"), ["img-no-alt"]);
assert.deepStrictEqual(rulesFor("<img {src} />\n", "A.svelte"), ["img-no-alt"]);
});