Skip to content

gate-31 img-alt flattens the whole .vue file, so an <img> written inside a JSDoc comment counts as an image #235

Closed

Description

@rubenvdlinde

Summary

gate-31 (img-alt) reads a .vue file as one flat string and greps it for <img …>:

hydra-gates/scripts/run-hydra-gates.sh (at 756fe89), gate-31 block:

_flat=$(tr '\n' ' ' < "${vue}")
echo "${_flat}" | grep -oE '<img\b[^>]*>' | while IFS= read -r tag; do
    if ! echo "${tag}" | grep -qE '(^|[[:space:]])(:?alt|v-bind:alt|alt-text)='; then
        echo "${vue}: ${tag}" >> "${_ia_log}"
    fi
done

The flattening covers <template>, <script> and comments. A JSDoc line like

 * @param {Event} e - The `<img>` `error` event fired when the light-icon

contains the literal <img>, matches <img\b[^>]*>, carries no alt, and is reported as an image without alternative text.

Measured on ConductionNL/openbuild @ c70f7b8d9

[gate-31] img-alt: FAIL — 3 <img> tag(s) without alt attribute

src/dialogs/IconUploadSection.vue: <img>
src/dialogs/IconUploadSection.vue: <img>
src/components/ApplicationCard.vue: <img>

3 of 3 are JSDoc mentions. The finding text itself is the tell — a real tag would print with its attributes; these print as the bare four characters <img>.

Running the gate's own matcher over the two files:

=== src/dialogs/IconUploadSection.vue ===
ok:      [<img  v-if="iconLightUrl"  :src="iconLightUrl"  :alt=...]
ok:      [<img  v-if="iconDarkUrl"   :src="iconDarkUrl"   :alt=...]
FLAGGED: [<img>]      <- line 193, ` * @param {Event} e - The \`<img>\` \`error\` event ...`
FLAGGED: [<img>]      <- line 206, same shape

=== src/components/ApplicationCard.vue ===
ok:      [<img  class="ob-app-card__icon"  :src="`/index.php/a...]
FLAGGED: [<img>]      <- line 236, same shape

Every real <img> in this repository already carries :alt, which the gate's regex explicitly accepts. There is nothing to fix in the app.

Why it cannot be fixed in the leaf

The only ways to make the gate green from openbuild's side are to reword or delete the docblocks that explain the error handlers. That is satisfying a checker by editing a comment — the same dodge #184 fixed for gate-64, where a commented-out prelude counted as a real one. Same root cause, opposite sign: gate-64 read a comment as compliance, gate-31 reads a comment as a violation.

Same shape elsewhere

gate-32 (semantic-controls) and gate-34 (window-confirm) also tr '\n' ' ' the whole file. gate-32 happened not to fire on a comment here, but the exposure is identical: a <div @click> written inside a docblock explaining a click handler would be reported.

Suggested fix

Strip <script> blocks and HTML/JS comments before matching, in the gates that scan .vue templates for markup (31, 32, 34 at minimum). check_semantic_auth.py already has a _strip_comments that blanks comments while preserving offsets, and its docblock gives exactly this reason ("a comment reading … would otherwise buy the exemption"). The template gates need the same treatment.

A cheap partial guard, if full stripping is too invasive: ignore a match that is exactly <img> / <img/> with no attributes at all. A real image tag always has at least a src.

Activity

  1. rubenvdlinde commented on Aug 8, 2026

    @rubenvdlinde
    ContributorAuthor

    Fixed and merged to main in #269 (cdfbd7a). Live fleet-wide now.

    Your diagnosis was exact, including the tell — "a real tag would print with its attributes; these print as the bare four characters <img>". That observation is now an assertion in the suite: a finding must name the tag with its attributes, and <img> alone is rejected.

    Measured post-merge on openbuild, attribution-isolated (main@32fa23e → main@cdfbd7a), from the runner's stdout:

    A (before): [gate-31] img-alt: FAIL — 3 <img> tag(s) without alt attribute
                  src/dialogs/IconUploadSection.vue: <img>
                  src/dialogs/IconUploadSection.vue: <img>
                  src/components/ApplicationCard.vue: <img>
    B (after):  [gate-31] img-alt: PASS
    

    Nothing changed in openbuild. All three were JSDoc mentions, as you reported.

    On the cheap partial guard you offered (ignore a match that is exactly <img> with no attributes) — deliberately not taken. It would have hidden this instance while leaving <img src=x> written in a docblock still scored, and it treats the symptom rather than the scope. Full stripping was affordable: source_scope.markup_mask keeps the <template> region only and blanks HTML comments, and gates 12, 31 and 32 now share it, as you suggested in "Same shape elsewhere". gate-32 is fixed in the same PR via #236.

    Both directions are asserted per gate, each relaxation paired with the true positive it must not swallow — including your exact file with one :alt deleted, which must report exactly 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions