diff --git a/crates/oxc_linter/src/rules/jsx_a11y/html_has_lang.rs b/crates/oxc_linter/src/rules/jsx_a11y/html_has_lang.rs index ed4612045f0e2e..c6aa85567f9e5d 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/html_has_lang.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/html_has_lang.rs @@ -1,5 +1,5 @@ use oxc_ast::{ - ast::{JSXAttributeItem, JSXAttributeValue, JSXElementName}, + ast::{JSXAttributeItem, JSXAttributeValue, JSXElementName, JSXExpression}, AstKind, }; use oxc_diagnostics::OxcDiagnostic; @@ -83,9 +83,19 @@ impl Rule for HtmlHasLang { fn is_valid_lang_prop(item: &JSXAttributeItem) -> bool { match get_prop_value(item) { - Some(JSXAttributeValue::ExpressionContainer(container)) => { - !container.expression.is_expression() || !container.expression.is_undefined() - } + Some(JSXAttributeValue::ExpressionContainer(container)) => match &container.expression { + JSXExpression::EmptyExpression(_) + | JSXExpression::NullLiteral(_) + | JSXExpression::BooleanLiteral(_) + | JSXExpression::NumericLiteral(_) => false, + JSXExpression::Identifier(id) => id.name != "undefined", + JSXExpression::StringLiteral(str) => !str.value.as_str().is_empty(), + JSXExpression::TemplateLiteral(t) => { + !t.expressions.is_empty() + || t.quasis.iter().filter(|q| !q.value.raw.is_empty()).count() > 0 + } + _ => true, + }, Some(JSXAttributeValue::StringLiteral(str)) => !str.value.as_str().is_empty(), _ => true, } @@ -109,6 +119,9 @@ fn test() { (r"
;", None, None, None), (r#"