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 SvelteKit enhanced:img in img-no-alt (#307)

Rishav Raj0ebab79cf007
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 1f738a1..8273642 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1466,7 +1466,8 @@ const rules = [
// Quasar renders <q-img> / <QImg> and Element Plus <el-image> / <ElImage> as <img> too (#249).
// Astro renders <Picture> as an <img> too (#268).
// So do Gatsby's <StaticImage> and <GatsbyImage> from gatsby-plugin-image (#285).
- for (const m of matches(/<(?:img|Image|Picture|NuxtImg|NuxtPicture|nuxt-img|nuxt-picture|v-img|VImg|ion-img|IonImg|q-img|QImg|el-image|ElImage|StaticImage|GatsbyImage)(?=[\s/>])/, code)) {
+ // 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)(?=[\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 f1b1cc1..fd858da 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1619,6 +1619,31 @@ test("img-no-alt flags Gatsby's StaticImage and GatsbyImage without alt (issue #
assert.deepStrictEqual(altLines('<GatsbyImageList items={items} />\n'), []);
});
+test("img-no-alt flags SvelteKit's enhanced:img without alt (issue #304)", () => {
+ const altLines = (src, file = "Hero.svelte") => scanSource(src, file, { kind: "web" }).filter((f) => f.rule === "img-no-alt").map((f) => f.line);
+ // Issue #304 repro:
+ const repro = [
+ "<script>",
+ ' let title = "Hero";',
+ "</script>",
+ "",
+ '<enhanced:img src="./hero.png" />',
+ ].join("\n");
+ assert.deepStrictEqual(altLines(repro), [5]);
+
+ // Alt forms (including Svelte {alt} shorthand) stay quiet
+ assert.deepStrictEqual(altLines('<enhanced:img src="./hero.png" alt="Hero" />\n'), []);
+ assert.deepStrictEqual(altLines('<enhanced:img src="./hero.png" alt="" />\n'), []);
+ assert.deepStrictEqual(altLines('<enhanced:img src="./hero.png" alt={title} />\n'), []);
+ assert.deepStrictEqual(altLines('<enhanced:img src="./hero.png" {alt} />\n'), []);
+ assert.deepStrictEqual(altLines('<enhanced:img src="./hero.png" {...props} />\n'), []);
+
+ // Plain <img> still works and unrelated enhanced:* tags stay quiet
+ assert.deepStrictEqual(altLines('<img src="./hero.png" />\n'), [1]);
+ assert.deepStrictEqual(altLines('<img src="./hero.png" alt="Hero" />\n'), []);
+ assert.deepStrictEqual(altLines('<enhanced:img-wrapper src="./hero.png" />\n'), []);
+});
+
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.