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(img-no-alt): detect missing alt on Vant van-image and VanImage (#352)

Shreeyasshf98a96ce33f6
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 1983ba7..e1233a6 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1491,8 +1491,9 @@ const rules = [
// 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).
// Naive UI's <n-image> / <NImage> and Ant Design Vue's <a-image> / <AImage> render an <img> too (#325).
- // TDesign's <t-image> / <TImage> renders an <img> too (#341).
- 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|t-image|TImage)(?=[\s/>])/, code)) {
+ // TDesign's <t-image> / <TImage> (#341) and Vant's <van-image> / <VanImage> (#340) render an
+ // <img> too.
+ 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|t-image|TImage|van-image|VanImage)(?=[\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 83d6de4..bf39c32 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -3494,6 +3494,24 @@ test("drawer-nav catches Compose DismissibleNavigationDrawer and ModalNavigation
assert.deepStrictEqual(drawerLines(unusedImport), []);
});
+test("img-no-alt catches Vant van-image and VanImage without alt (issue #340)", () => {
+ const imgLines = (src, file = "Avatar.vue") =>
+ scanSource(src, file, { kind: "web" }).filter((f) => f.rule === "img-no-alt").map((f) => f.line);
+
+ assert.deepStrictEqual(imgLines('<template>\n <van-image src="/avatar.png" width="80" height="80" />\n</template>\n'), [2]);
+ assert.deepStrictEqual(imgLines('<template>\n <VanImage src="/avatar.png" />\n</template>\n'), [2]);
+
+ for (const tag of [
+ '<van-image src="/avatar.png" alt="Avatar" />',
+ '<van-image src="/avatar.png" alt="" />',
+ '<van-image src="/avatar.png" :alt="name" />',
+ '<VanImage src="/avatar.png" alt="Avatar" />',
+ '<van-image-preview show />',
+ ]) {
+ assert.deepStrictEqual(imgLines(`<template>\n ${tag}\n</template>\n`), [], tag);
+ }
+});
+
test("drawer-nav catches @expo/vector-icons bars icon name (issue #337)", () => {
const drawerLines = (src, file = "Header.tsx") =>
scanSource(src, file, { kind: "mobile" }).filter((f) => f.rule === "drawer-nav").map((f) => f.line);