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 missing alt on Ionic's ion-img and IonImg (#240)

Papito084c29513523c62
diff --git a/skills/unslop-anything/reference/web.md b/skills/unslop-anything/reference/web.md
index 7e38e94..7e435eb 100644
--- a/skills/unslop-anything/reference/web.md
+++ b/skills/unslop-anything/reference/web.md
@@ -20,7 +20,7 @@ These break the web for real people. They are Critical or Noticeable, whatever t
- **Real controls.** Actions are `<button>`, navigation is `<a href>`. A `div`, `span`, `article` or other non-interactive element with a click handler is unreachable by keyboard and silent to screen readers [`clickable-div`].
- **Visible focus.** Every interactive element shows a `:focus-visible` style, in the palette, instantly. `outline: none` with nothing in its place locks keyboard users out [`focus-removed`].
- **Zoom stays on.** No `maximum-scale=1` or `user-scalable=no` [`zoom-disabled`]. Inputs at 16px stop iOS from zooming on focus.
-- **Text alternatives.** Every content image has alt text, including framework image components such as `<Image>`, `<NuxtImg>` and Vuetify's `<v-img>` / `<VImg>`; decoration has `alt=""` [`img-no-alt`].
+- **Text alternatives.** Every content image has alt text, including framework image components such as `<Image>`, `<NuxtImg>`, Vuetify's `<v-img>` / `<VImg>` and Ionic's `<ion-img>` / `<IonImg>`; decoration has `alt=""` [`img-no-alt`].
- **URLs mean something.** The back button returns to the previous view. Filters, tabs, search, and pagination that someone would share live in the URL. Opening in a new tab works.
- **Contrast** 4.5:1 for body text and 3:1 for large text and meaningful icons, in light and dark.
- **Reduced motion.** Every animation has a `prefers-reduced-motion: reduce` fallback. Content is visible without it [`reduced-motion`].
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 9301e3b..d04738a 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1443,7 +1443,8 @@ const rules = [
const hits = [];
// Nuxt Image renders <NuxtImg> / <NuxtPicture>, also written kebab-case (#203).
// Vuetify renders <v-img> / <VImg> as an <img> too (#229).
- for (const m of matches(/<(?:img|Image|NuxtImg|NuxtPicture|nuxt-img|nuxt-picture|v-img|VImg)(?=[\s/>])/, code)) {
+ // Ionic renders <ion-img> / <IonImg> as an <img> too (#235).
+ for (const m of matches(/<(?:img|Image|NuxtImg|NuxtPicture|nuxt-img|nuxt-picture|v-img|VImg|ion-img|IonImg)(?=[\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;
diff --git a/test/detect.test.js b/test/detect.test.js
index 9f2d2d4..861054f 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1309,6 +1309,17 @@ test("img-no-alt flags Vuetify's v-img and VImg without alt", () => {
assert.deepStrictEqual(altLines('<v-img-gallery src="/hero.png" />\n'), []);
});
+test("img-no-alt flags Ionic's ion-img and IonImg without alt (issue #235)", () => {
+ const altLines = (src, file = "Hero.vue") => scanSource(src, file, { kind: "web" }).filter((f) => f.rule === "img-no-alt").map((f) => f.line);
+ // Issue #235: the repro.
+ assert.deepStrictEqual(altLines('<template>\n <ion-img src="/hero.png" />\n <IonImg src="/team.png" />\n</template>\n'), [2, 3]);
+ assert.deepStrictEqual(altLines('<ion-img src="/hero.png" alt="Team photo" />\n'), []);
+ assert.deepStrictEqual(altLines('<IonImg src="/divider.png" alt="" />\n'), []);
+ assert.deepStrictEqual(altLines('<ion-img :src="photo.url" :alt="photo.caption" />\n'), []);
+ assert.deepStrictEqual(altLines('<IonImg src="/hero.png" alt={caption} />\n', "Hero.tsx"), []);
+ assert.deepStrictEqual(altLines('<ion-img-viewer 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.