From 2521b52011e2495d324eec6d92bdb88bc5e3bb0f Mon Sep 17 00:00:00 2001
From: Yuji Sugiura <6259812+leaysgur@users.noreply.github.com>
Date: Fri, 9 Feb 2024 21:55:50 +0900
Subject: [PATCH] fix(linter/jsx_a11y): Ensure plugin settings are used (#2359)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Currently, some of the rules did not use `settings`, so make sure they
do.
- [x] Align implementation of `getElementType()`
- (This is the only util that depends on `settings`)
Original rules which use `getElementType()` are:
- [x] ๐
๐ปโโ๏ธ accessible-emoji
- [x] โ
alt-text
- [x] ๐
๐ปโโ๏ธ anchor-ambiguous-text
- [x] โ
anchor-has-content
- [x] anchor-is-valid
- TODO: `from_configuration()` not implemented => #2361
- [x] ๐๐ปโโ๏ธ aria-activedescendant-has-tabindex
- [x] ๐๐ปโโ๏ธ aria-role
- [x] ๐๐ปโโ๏ธ aria-unsupported-elements
- [x] autocomplete-valid
- TODO: `from_configuration()` not implemented and needed for this =>
#2362
- [x] ๐๐ปโโ๏ธ click-events-have-key-events
- [x] ๐
๐ปโโ๏ธ control-has-associated-label
- [x] heading-has-content
- TODO: 1 test should be failed but passes ๐ค => #2360
- [x] ๐๐ปโโ๏ธ html-has-lang
- [x] โ
iframe-has-title
- [x] ๐๐ปโโ๏ธ img-redundant-alt
- [x] ๐
๐ปโโ๏ธ interactive-supports-focus
- [x] ๐
๐ปโโ๏ธ label-has-associated-control
- [x] ๐
๐ปโโ๏ธ label-has-for
- [x] ๐๐ปโโ๏ธ lang
- [x] ๐๐ปโโ๏ธ media-has-caption
- [x] โ
no-aria-hidden-on-focusable
- [x] ๐๐ปโโ๏ธ no-autofocus
- [x] ๐๐ปโโ๏ธ no-distracting-elements
- [x] ๐
๐ปโโ๏ธ no-interactive-element-to-noninteractive-role
- [x] ๐
๐ปโโ๏ธ no-noninteractive-element-interactions
- [x] ๐
๐ปโโ๏ธ no-noninteractive-element-to-interactive-role
- [x] ๐
๐ปโโ๏ธ no-noninteractive-tabindex
- [x] ๐
๐ปโโ๏ธ no-onchange
- [x] ๐๐ปโโ๏ธ no-redundant-roles
- [x] ๐
๐ปโโ๏ธ no-static-element-interactions
- [x] โ
prefer-tag-over-role
- [x] ๐๐ปโโ๏ธ role-has-required-aria-props
- [x] ๐๐ปโโ๏ธ role-supports-aria-props
- [x] ๐๐ปโโ๏ธ scope
๐
๐ปโโ๏ธ = Not implemented yet by oxlint / โ
= Fixed by this PR / ๐๐ปโโ๏ธ =
Already used
---
.../oxc_linter/src/rules/jsx_a11y/alt_text.rs | 345 +++++++++---------
.../src/rules/jsx_a11y/anchor_has_content.rs | 53 +--
.../src/rules/jsx_a11y/anchor_is_valid.rs | 107 +++---
.../src/rules/jsx_a11y/heading_has_content.rs | 92 +++--
.../src/rules/jsx_a11y/iframe_has_title.rs | 56 ++-
.../jsx_a11y/no_aria_hidden_on_focusable.rs | 15 +-
.../rules/jsx_a11y/prefer_tag_over_role.rs | 38 +-
crates/oxc_linter/src/snapshots/alt_text.snap | 7 +
.../src/snapshots/anchor_has_content.snap | 7 +
.../src/snapshots/anchor_is_valid.snap | 7 +
.../src/snapshots/heading_has_content.snap | 7 +
.../src/snapshots/iframe_has_title.snap | 7 +
crates/oxc_linter/src/utils/react.rs | 26 +-
13 files changed, 433 insertions(+), 334 deletions(-)
diff --git a/crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs b/crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs
index 627f0f37f..de1e88090 100644
--- a/crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs
+++ b/crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs
@@ -1,6 +1,6 @@
use oxc_ast::{
ast::{
- JSXAttributeItem, JSXAttributeValue, JSXChild, JSXElement, JSXElementName, JSXExpression,
+ JSXAttributeItem, JSXAttributeValue, JSXChild, JSXElement, JSXExpression,
JSXExpressionContainer, JSXOpeningElement,
},
AstKind,
@@ -12,7 +12,9 @@ use oxc_diagnostics::{
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
-use crate::utils::{get_prop_value, get_string_literal_prop_value, has_jsx_prop_lowercase};
+use crate::utils::{
+ get_element_type, get_prop_value, get_string_literal_prop_value, has_jsx_prop_lowercase,
+};
use crate::{context::LintContext, rule::Rule, AstNode};
#[derive(Debug, Error, Diagnostic)]
@@ -163,8 +165,7 @@ impl Rule for AltText {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let AstKind::JSXOpeningElement(jsx_el) = node.kind() else { return };
- let JSXElementName::Identifier(iden) = &jsx_el.name else { return };
- let name = iden.name.as_str();
+ let Some(name) = &get_element_type(ctx, jsx_el) else { return };
//
if let Some(custom_tags) = &self.img {
@@ -356,7 +357,7 @@ fn input_type_image_rule<'a>(node: &'a JSXOpeningElement<'a>, ctx: &LintContext<
fn test() {
use crate::tester::Tester;
- fn array() -> serde_json::Value {
+ fn config() -> serde_json::Value {
serde_json::json!([{
"img": ["Thumbnail", "Image"],
"object": ["Object"],
@@ -366,177 +367,179 @@ fn test() {
}
let pass = vec![
- (r#"
;"#, None),
- (r#"
;"#, None),
- (r"
;", None),
- (r#"
;"#, None),
- (r"
;", None),
- (r#"
;"#, None),
- (r#"
;"#, None),
- (r#"
"#, None),
- (r"", None),
- (r"