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 TDesign t-image and TImage (#349)

MugunthPerumal78850fae5201
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 8c60fe0..9f93566 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1491,12 +1491,15 @@ 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).
- 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)) {
+ // 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)) {
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;
- const hasAlt = /[\s:\[.]alt\]?\s*=|\{\s*alt\s*\}|\{\s*\.\.\./.test(tag)
- || (stack === "web" && /\salt(?=[\s/>]|$)/.test(tag.replace(/=\s*(?:"[^"]*"|'[^']*')/g, '=""')));
+ const stripped = tag.replace(/=\s*(?:"[^"]*"|'[^']*')/g, '=""');
+ const hasAlt = /[\s:\[.]alt\]?\s*=|\{\s*alt\s*\}|\{\s*\.\.\./.test(stripped)
+ || (stack === "web" && /\bv-bind\s*=\s*(?:"[^"]*\{\s*[^"]*\balt\s*(?::|[,}])[^"]*"|'[^']*\{\s*[^']*\balt\s*(?::|[,}])[^']*')/.test(tag))
+ || (stack === "web" && /\s:?alt(?=[\s/>]|$)/.test(stripped));
if (!hasAlt) hits.push(m.index);
}
return hits;
diff --git a/test/detect.test.js b/test/detect.test.js
index fe47ffb..77da609 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1134,6 +1134,20 @@ test("img-no-alt flags Next.js <Image> without alt, and ignores <ImageGallery>",
assert.deepStrictEqual(rulesFor("<Image source={logo} accessibilityLabel=\"Logo\" />\n"), []);
});
+test("img-no-alt flags TDesign <t-image> and <TImage> without alt, and ignores <t-image-viewer>", () => {
+ const rulesFor = (src) => scanSource(src, "Cover.vue").map((f) => f.rule);
+ assert.deepStrictEqual(rulesFor('<template>\n <t-image src="/cover.png" fit="cover" />\n</template>\n'), ["img-no-alt"]);
+ assert.deepStrictEqual(rulesFor('<template>\n <TImage src="/cover.png" />\n</template>\n'), ["img-no-alt"]);
+ assert.deepStrictEqual(rulesFor('<template>\n <t-image src="/cover.png" alt="Cover" />\n</template>\n'), []);
+ assert.deepStrictEqual(rulesFor('<template>\n <t-image src="/cover.png" alt="" />\n</template>\n'), []);
+ assert.deepStrictEqual(rulesFor('<template>\n <t-image src="/cover.png" :alt="title" />\n</template>\n'), []);
+ assert.deepStrictEqual(rulesFor('<template>\n <t-image src="/cover.png" :alt />\n</template>\n'), []);
+ assert.deepStrictEqual(rulesFor('<template>\n <TImage src="/cover.png" :alt />\n</template>\n'), []);
+ assert.deepStrictEqual(rulesFor('<template>\n <t-image src="/cover.png" v-bind="{ alt: \'Cover\' }" />\n</template>\n'), []);
+ assert.deepStrictEqual(rulesFor('<template>\n <t-image src="/cover.png" title="Example alt=Cover" />\n</template>\n'), ["img-no-alt"]);
+ assert.deepStrictEqual(rulesFor('<template>\n <t-image-viewer :images="imgs" />\n <TImageViewer :images="imgs" />\n</template>\n'), []);
+});
+
test("clickable-div flags a href-less anchor with onClick", () => {
const findingsFor = (src) => scanSource(src, "a.tsx");
const src = [