diff --git a/crates/rome_js_analyze/src/analyzers/a11y/use_alt_text.rs b/crates/rome_js_analyze/src/analyzers/a11y/use_alt_text.rs
index 6f959d7e712..8b8228d1003 100644
--- a/crates/rome_js_analyze/src/analyzers/a11y/use_alt_text.rs
+++ b/crates/rome_js_analyze/src/analyzers/a11y/use_alt_text.rs
@@ -1,5 +1,5 @@
use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic};
-use rome_console::markup;
+use rome_console::{fmt::Display, fmt::Formatter, markup};
use rome_js_syntax::{jsx_ext::AnyJsxElement, TextRange};
use rome_rowan::AstNode;
@@ -57,6 +57,15 @@ pub enum ValidatedElement {
Input,
}
+impl Display for ValidatedElement {
+ fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> {
+ match self {
+ ValidatedElement::Object => fmt.write_markup(markup!("title")),
+ _ => fmt.write_markup(markup!("alt")),
+ }
+ }
+}
+
impl Rule for UseAltText {
type Query = Ast;
type State = (ValidatedElement, TextRange);
@@ -120,14 +129,9 @@ impl Rule for UseAltText {
fn diagnostic(_ctx: &RuleContext, state: &Self::State) -> Option {
let (validate_element, range) = state;
- let message = match validate_element {
- ValidatedElement::Object => markup!(
- "Provide a text alternative through the ""title"", ""aria-label"" or ""aria-labelledby"" attribute"
- ).to_owned(),
- _ => markup!(
- "Provide a text alternative through the ""alt"", ""aria-label"" or ""aria-labelledby"" attribute"
- ).to_owned(),
- };
+ let message = markup!(
+ "Provide a text alternative through the "{{validate_element}}", ""aria-label"" or ""aria-labelledby"" attribute"
+ ).to_owned();
Some(
RuleDiagnostic::new(rule_category!(), range, message).note(markup! {
"Meaningful alternative text on elements helps users relying on screen readers to understand content's purpose within a page."