{"record":{"id":"fd239fa8e0b3c9bb","repo":"oxc-project/oxc","slug":"invalid-alt-value","errorCode":null,"errorMessage":"Invalid `alt` value.","messagePattern":"Invalid `alt` value\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs","lineNumber":28,"sourceCode":"\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::Rule,\n    utils::{\n        get_element_type, get_prop_value, get_string_literal_prop_value, has_jsx_prop_ignore_case,\n        object_has_accessible_child,\n    },\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","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs#L10-L46","documentation":"This is the oxlint `jsx-a11y/alt-text` diagnostic for an `img` whose `alt` attribute exists but has an unusable value. The rule treats an `alt` as invalid when it has no value at all (`<img alt>`) or when it is an expression container evaluating to `null`/`undefined`. The point: alt is only useful when it is a real string (or an intentionally empty one).","triggerScenarios":"`img_rule` finds an `alt` prop (case-insensitive) but `is_valid_alt_prop` returns false: `get_prop_value` is `None` (bare attribute) or the JSX expression is `null`/`undefined` (`alt={undefined}`, `alt={null}`). Note the rule returns early once any `alt` prop exists, so missing aria fallbacks are not additionally reported.","commonSituations":"Conditionally computed alt (`alt={maybeAlt}` where the fallback branch yields `undefined`); spreading defaults then overriding with `alt={null}`; forgetting to give the attribute a value in JSX.","solutions":["Give alt a real value or `\"\"` for decorative images: `alt={maybeAlt ?? \"\"}`.","Remove bare `<img alt>` and write `alt=\"...\"`.","Check the expression feeding `alt={...}` never evaluates to `null`/`undefined`."],"exampleFix":"// before\n<img src={src} alt={undefined} />\n<img src={src} alt />\n\n// after\n<img src={src} alt={description} />\n<img src={src} alt=\"\" />","handlingStrategy":"validation","validationCode":"// Keep alt non-nullish at the boundary\nconst altText = maybeAlt ?? ''; // '' = decorative, never undefined\nreturn <img src={src} alt={altText} />;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Coalesce optional alt values: `alt={alt ?? ''}`.","Never write bare `<img alt>`; JSX attributes need values.","Type wrapper props as `alt: string` (not `string | undefined | null`) to push the guarantee to compile time."],"tags":["jsx-a11y","accessibility","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-14T00:17:10.932Z"}