{"record":{"id":"8a5667930b80233e","repo":"oxc-project/oxc","slug":"missing-value-for-aria-label-attribute","errorCode":null,"errorMessage":"Missing value for `aria-label` attribute.","messagePattern":"Missing value for `aria-label` attribute\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs","lineNumber":36,"sourceCode":"    },\n};\n\nfn missing_alt_prop(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing `alt` attribute.\")\n        .with_help(\"Must have `alt` prop, either with meaningful text, or an empty string for decorative images.\")\n        .with_label(span)\n}\n\nfn missing_alt_value(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Invalid `alt` value.\")\n        .with_help(\n            \"Must have meaningful value for `alt` prop. Use alt=\\\"\\\" for presentational images.\",\n        )\n        .with_label(span)\n}\n\nfn aria_label_value(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing value for `aria-label` attribute.\")\n        .with_help(\"Give `aria-label` a meaningful value. Prever the `alt` attribute over `aria-label` for images.\")\n        .with_label(span)\n}\n\nfn aria_labelled_by_value(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing value for `aria-labelledby` attribute.\")\n        .with_help(\"Give `aria-labelledby` an ID to a label element. Prefer the `alt` attribute over `aria-labelledby` for images.\")\n        .with_label(span)\n}\n\nfn prefer_alt(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"ARIA used where native HTML could suffice.\")\n        .with_help(\"Prefer alt=\\\"\\\" over presentational role. Native HTML attributes should be preferred for accessibility before resorting to ARIA attributes.\")\n        .with_label(span)\n}\n\nfn object(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing alternative text.\")","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs#L18-L54","documentation":"This is the oxlint `jsx-a11y/alt-text` diagnostic for an `img` that has no `alt` but does have `aria-label`, and the `aria-label` carries no value. The rule accepts `aria-label` as an alternative to `alt` only when it is non-empty; an empty or undefined `aria-label` names the image for no one.","triggerScenarios":"`img_rule` finds no `alt`, no presentation role, and an `aria-label` prop for which `aria_label_has_value` is false: empty string literal (`aria-label=\"\"`) or an expression container that is not a real expression / is `undefined`.","commonSituations":"Teams switching from `alt` to `aria-label` per design-system guidance but leaving the value blank; dynamic labels that default to `undefined`.","solutions":["Provide a non-empty label or switch back to `alt`: `<img src={src} alt={name} />` (the help text itself says prefer `alt`).","Fix dynamic label logic so `aria-label` is always a non-empty string when rendered.","Use `aria-labelledby` pointing at a visible caption instead."],"exampleFix":"// before\n<img src={src} aria-label=\"\" />\n<img src={src} aria-label={undefined} />\n\n// after\n<img src={src} alt=\"Company headquarters\" />","handlingStrategy":"validation","validationCode":"// Ensure aria-label is a non-empty string before rendering it on an img\nconst label = typeof maybeLabel === 'string' && maybeLabel.trim() !== '' ? maybeLabel : undefined;\nreturn label ? <img src={src} aria-label={label} /> : <img src={src} alt=\"\" />;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer `alt` over `aria-label` for images (the rule's own help says so).","Compute label values so they never resolve to `undefined` at render time.","Add a tiny component-level invariant: throw or default when an accessible name is missing."],"tags":["jsx-a11y","accessibility","aria","alt-text","react","lint","oxlint"],"backgroundTag":"jsx-a11y-alt-text","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}