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): recognise Angular [alt] bindings and Svelte {alt} shorthand in img-no-alt (#97)

Nguyễn Tuấn Anh41bfa3518cef
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 23cdd19..b1a3927 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -879,7 +879,7 @@ const rules = [
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*\.\.\./.test(tag)) hits.push(m.index);
+ if (!/[\s:\[.]alt\]?\s*=|\{\s*alt\s*\}|\{\s*\.\.\./.test(tag)) hits.push(m.index);
}
return hits;
},
diff --git a/test/detect.test.js b/test/detect.test.js
index e97a02b..14823a6 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -583,6 +583,18 @@ test("nested-cards ignores dotted subcomponents and ion-card parts, still flags
assert.deepStrictEqual(rulesFor("<ion-card><ion-card></ion-card></ion-card>", "a.html"), ["nested-cards"]);
});
+test("img-no-alt accepts Angular [alt] bindings and Svelte {alt} shorthand", () => {
+ const rulesFor = (src, file) => scanSource(src, file).map((f) => f.rule);
+ assert.deepStrictEqual(rulesFor('<img [src]="u.avatar" [alt]="u.name">\n', "a.component.html"), []);
+ assert.deepStrictEqual(rulesFor('<img [src]="u.avatar" [attr.alt]="u.name">\n', "a.component.html"), []);
+ assert.deepStrictEqual(rulesFor("<img {src} {alt} />\n", "A.svelte"), []);
+ // 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"), []);
+ 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"]);
+});
+
test("unverified-claim allows one adjective between the number and the noun", () => {
const rulesFor = (src) => scanSource(src, "a.tsx").map((f) => f.rule);
assert.deepStrictEqual(rulesFor("<p>Join 10,000+ customers</p>\n"), ["unverified-claim"]);