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): check Naive UI's n-image and Ant Design Vue's a-image in img-no-alt (#335)

Pranav Arya671970bdfc1c
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 73f5509..039a00f 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1488,7 +1488,8 @@ const rules = [
// Astro renders <Picture> as an <img> too (#268).
// So do Gatsby's <StaticImage> and <GatsbyImage> from gatsby-plugin-image (#285).
// SvelteKit's <enhanced:img> from @sveltejs/enhanced-img renders an <img> too (#304).
- for (const m of matches(/<(?:img|enhanced:img|Image|Picture|NuxtImg|NuxtPicture|nuxt-img|nuxt-picture|v-img|VImg|ion-img|IonImg|q-img|QImg|el-image|ElImage|StaticImage|GatsbyImage|p-image)(?=[\s/>])/, code)) {
+ // Naive UI's <n-image> / <NImage> and Ant Design Vue's <a-image> / <AImage> render an <img> too (#325).
+ for (const m of matches(/<(?:img|enhanced:img|Image|Picture|NuxtImg|NuxtPicture|nuxt-img|nuxt-picture|v-img|VImg|ion-img|IonImg|q-img|QImg|el-image|ElImage|StaticImage|GatsbyImage|p-image|n-image|NImage|a-image|AImage)(?=[\s/>])/, code)) {
const end = tagEnd(code, m.index);
const tag = code.slice(m.index, end === -1 ? undefined : end);
if ((tag.startsWith("<Image") || tag.startsWith("<Picture")) && !/\ssrc\s*=/.test(tag)) continue;
diff --git a/test/detect.test.js b/test/detect.test.js
index 15fda3e..ac5eba7 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1693,6 +1693,38 @@ test("img-no-alt flags SvelteKit's enhanced:img without alt (issue #304)", () =>
assert.deepStrictEqual(altLines('<enhanced:img-wrapper src="./hero.png" />\n'), []);
});
+test("img-no-alt flags Naive UI's n-image and Ant Design Vue's a-image without alt (issue #325)", () => {
+ const altLines = (src, file = "Gallery.vue") => scanSource(src, file, { kind: "web" }).filter((f) => f.rule === "img-no-alt").map((f) => f.line);
+ // Issue #325 repro:
+ const repro = [
+ "<template>",
+ ' <n-image src="/hero.png" width="200" />',
+ ' <a-image src="/team.png" :width="200" />',
+ "</template>",
+ ].join("\n");
+ assert.deepStrictEqual(altLines(repro), [2, 3]);
+
+ for (const tag of ["n-image", "NImage", "a-image", "AImage"]) {
+ assert.deepStrictEqual(altLines(`<${tag} src="/hero.png" />\n`), [1], tag);
+ assert.deepStrictEqual(altLines(`<${tag} src="/hero.png" width="200"></${tag}>\n`), [1], tag);
+ // Alt forms stay quiet
+ assert.deepStrictEqual(altLines(`<${tag} src="/hero.png" alt="Hero" />\n`), [], tag);
+ assert.deepStrictEqual(altLines(`<${tag} src="/hero.png" alt="" />\n`), [], tag);
+ assert.deepStrictEqual(altLines(`<${tag} :src="photo.url" :alt="title" />\n`), [], tag);
+ }
+
+ // Longer tags that start the same way are not images
+ assert.deepStrictEqual(altLines('<n-image-group>\n <n-image src="/a.png" alt="A" />\n</n-image-group>\n'), []);
+ assert.deepStrictEqual(altLines('<a-image-preview-group>\n <a-image src="/a.png" alt="A" />\n</a-image-preview-group>\n'), []);
+ assert.deepStrictEqual(altLines("<NImageGroup>\n <NImage src=\"/a.png\" alt=\"A\" />\n</NImageGroup>\n"), []);
+ assert.deepStrictEqual(altLines("<AImagePreviewGroup>\n <AImage src=\"/a.png\" alt=\"A\" />\n</AImagePreviewGroup>\n"), []);
+ // The group does not stand in for its images
+ assert.deepStrictEqual(altLines('<n-image-group>\n <n-image src="/a.png" />\n</n-image-group>\n'), [2]);
+
+ // The existing kit images keep working
+ assert.deepStrictEqual(altLines('<el-image src="/hero.png" />\n'), [1]);
+});
+
test("placeholder-label flags inputs that use a placeholder as their only label", () => {
const rulesFor = (src) => scanSource(src, "a.tsx").map((f) => f.rule);
// The issue's repro.