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): flag Next.js <Image> without alt in img-no-alt (#81)

Nguyễn Tuấn Anhb8e4c37f1313
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 5c7c13f..7bc108c 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -735,9 +735,10 @@ const rules = [
fix: "Describe what the image shows, or use alt=\"\" for pure decoration.",
find({ code }) {
const hits = [];
- for (const m of matches(/<img(?=[\s/>])/, code)) {
+ for (const m of matches(/<(?:img|Image)(?=[\s/>])/, code)) {
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);
}
return hits;
diff --git a/test/detect.test.js b/test/detect.test.js
index 7fa423c..4bf4340 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -420,6 +420,18 @@ test("an arrow function in an attribute does not end the tag for clickable-div a
assert.deepStrictEqual(rulesFor("<img src={src} onError={() => setBroken(true)} />\n"), ["img-no-alt"]);
});
+test("img-no-alt flags Next.js <Image> without alt, and ignores <ImageGallery>", () => {
+ const rulesFor = (src) => scanSource(src, "a.tsx").map((f) => f.rule);
+ // Flagged: the exact line from the issue.
+ assert.deepStrictEqual(rulesFor('<Image src="/a.png" width={10} height={10} />\n'), ["img-no-alt"]);
+ // Unflagged: alt present, and the existing spread exception carries over.
+ assert.deepStrictEqual(rulesFor('<Image src="/a.png" alt="Team photo" />\n'), []);
+ assert.deepStrictEqual(rulesFor('<Image src="/a.png" {...props} />\n'), []);
+ // A component that merely starts with the letters must not match.
+ assert.deepStrictEqual(rulesFor("<ImageGallery items={items} />\n"), []);
+ assert.deepStrictEqual(rulesFor("<Image source={logo} accessibilityLabel=\"Logo\" />\n"), []);
+});
+
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"]);