Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome_js_analyzer): handle JsTemplateExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkldshv committed Dec 17, 2022
1 parent 2ac0598 commit 646cf7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
22 changes: 14 additions & 8 deletions crates/rome_js_analyze/src/analyzers/a11y/use_html_lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,30 @@ fn is_valid_lang_attribute(attr: JsxAttribute) -> Option<()> {
if let AnyJsxAttributeValue::JsxExpressionAttributeValue(expression) = attribute_value {
let expression = expression.expression().ok()?;

if let Some(identifier_expression) = expression.as_js_identifier_expression() {
if !identifier_expression.text().is_empty() {
if expression.as_js_identifier_expression().is_some() {
return Some(());
}

if let Some(template_expression) = expression.as_js_template_expression() {
let template_element = template_expression
.elements()
.into_iter()
.find(|element| element.as_js_template_chunk_element().is_some());

if template_element.is_some() {
return Some(());
}
return None;
};
}

let bool_expression = expression
expression
.as_any_js_literal_expression()?
.as_js_boolean_literal_expression();
if bool_expression.is_some() {
return None;
}

let string_expression = expression
.as_any_js_literal_expression()?
.as_js_string_literal_expression()?;
let string_expression_text = string_expression.inner_string_text().ok()?;

if string_expression_text.is_empty() {
return None;
}
Expand Down
1 change: 1 addition & 0 deletions crates/rome_js_analyze/tests/specs/a11y/useHtmlLang.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{/* valid */}
<html lang="en"></html>
<html lang={"en"}></html>
<html lang={`en`}></html>
<html lang={lang}></html>
<html {...props}></html>
<html lang="" {...props}></html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ expression: useHtmlLang.jsx
{/* valid */}
<html lang="en"></html>
<html lang={"en"}></html>
<html lang={`en`}></html>
<html lang={lang}></html>
<html {...props}></html>
<html lang="" {...props}></html>
Expand Down

0 comments on commit 646cf7e

Please sign in to comment.