Skip to content

Commit

Permalink
fix(linter): panic on invalid lang in a11y/lang. (#4630)
Browse files Browse the repository at this point in the history
fixes #4629
  • Loading branch information
rzvxa committed Aug 5, 2024
1 parent 439ce5b commit 94440ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jsx_a11y/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ fn is_valid_lang_prop(item: &JSXAttributeItem) -> bool {
!container.expression.is_expression() || !container.expression.is_undefined()
}
Some(JSXAttributeValue::StringLiteral(str)) => {
let language_tag = LanguageTag::parse(str.value.as_str()).unwrap();
language_tag.is_valid()
LanguageTag::parse(str.value.as_str()).as_ref().is_ok_and(LanguageTag::is_valid)
}
_ => true,
}
Expand Down Expand Up @@ -135,6 +134,7 @@ fn test() {

let fail = vec![
("<html lang='foo' />", None, None, None),
("<html lang='n'></html>", None, None, None),
("<html lang='zz-LL' />", None, None, None),
("<html lang={undefined} />", None, None, None),
("<Foo lang={undefined} />", None, Some(settings()), None),
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_linter/src/snapshots/lang.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Set a valid value for lang attribute.

eslint-plugin-jsx-a11y(lang): Lang attribute must have a valid value.
╭─[lang.tsx:1:7]
1<html lang='n'></html>
· ────────
╰────
help: Set a valid value for lang attribute.

eslint-plugin-jsx-a11y(lang): Lang attribute must have a valid value.
╭─[lang.tsx:1:7]
1<html lang='zz-LL' />
Expand Down

0 comments on commit 94440ad

Please sign in to comment.