Skip to content

Commit 9533d09

Browse files
committed
refactor(linter): remove duplicate ARIA property lists (#10326)
Removes some additional duplication of ARIA properties in other lint rules.
1 parent 67bd7aa commit 9533d09

File tree

2 files changed

+4
-73
lines changed

2 files changed

+4
-73
lines changed

crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use oxc_ast::{AstKind, ast::JSXAttributeItem};
33
use oxc_diagnostics::OxcDiagnostic;
44
use oxc_macros::declare_oxc_lint;
55
use oxc_span::Span;
6-
use phf::phf_set;
76

87
use crate::{
98
AstNode, LintContext,
10-
globals::RESERVED_HTML_TAG,
9+
globals::{RESERVED_HTML_TAG, is_valid_aria_property},
1110
rule::Rule,
1211
utils::{get_element_type, get_jsx_attribute_name},
1312
};
@@ -59,7 +58,7 @@ impl Rule for AriaUnsupportedElements {
5958
};
6059
let attr_name = get_jsx_attribute_name(&attr.name);
6160
let attr_name = attr_name.cow_to_ascii_lowercase();
62-
if INVALID_ATTRIBUTES.contains(&attr_name) {
61+
if attr_name == "role" || is_valid_aria_property(&attr_name) {
6362
ctx.diagnostic_with_fix(
6463
aria_unsupported_elements_diagnostic(attr.span, &attr_name),
6564
|fixer| fixer.delete(&attr.span),
@@ -71,58 +70,6 @@ impl Rule for AriaUnsupportedElements {
7170
}
7271
}
7372

74-
const INVALID_ATTRIBUTES: phf::Set<&'static str> = phf_set! {
75-
"aria-activedescendant",
76-
"aria-atomic",
77-
"aria-autocomplete",
78-
"aria-busy",
79-
"aria-checked",
80-
"aria-colcount",
81-
"aria-colindex",
82-
"aria-colspan",
83-
"aria-controls",
84-
"aria-current",
85-
"aria-describedby",
86-
"aria-details",
87-
"aria-disabled",
88-
"aria-dropeffect",
89-
"aria-errormessage",
90-
"aria-expanded",
91-
"aria-flowto",
92-
"aria-grabbed",
93-
"aria-haspopup",
94-
"aria-hidden",
95-
"aria-invalid",
96-
"aria-keyshortcuts",
97-
"aria-label",
98-
"aria-labelledby",
99-
"aria-level",
100-
"aria-live",
101-
"aria-modal",
102-
"aria-multiline",
103-
"aria-multiselectable",
104-
"aria-orientation",
105-
"aria-owns",
106-
"aria-placeholder",
107-
"aria-posinset",
108-
"aria-pressed",
109-
"aria-readonly",
110-
"aria-relevant",
111-
"aria-required",
112-
"aria-roledescription",
113-
"aria-rowcount",
114-
"aria-rowindex",
115-
"aria-rowspan",
116-
"aria-selected",
117-
"aria-setsize",
118-
"aria-sort",
119-
"aria-valuemax",
120-
"aria-valuemin",
121-
"aria-valuenow",
122-
"aria-valuetext",
123-
"role",
124-
};
125-
12673
#[test]
12774
fn test() {
12875
use crate::tester::Tester;

crates/oxc_linter/src/rules/react/no_unknown_property.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use serde::Deserialize;
1616
use crate::{
1717
AstNode,
1818
context::{ContextHost, LintContext},
19+
globals::is_valid_aria_property,
1920
rule::Rule,
2021
utils::get_jsx_attribute_name,
2122
};
@@ -308,23 +309,6 @@ const DOM_PROPERTIES_NAMES: Set<&'static str> = phf_set! {
308309
"onPointerUpCapture",
309310
};
310311

311-
const ARIA_PROPERTIES: Set<&'static str> = phf_set! {
312-
// See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes
313-
// Global attributes
314-
"aria-atomic", "aria-braillelabel", "aria-brailleroledescription", "aria-busy", "aria-controls", "aria-current",
315-
"aria-describedby", "aria-description", "aria-details",
316-
"aria-disabled", "aria-dropeffect", "aria-errormessage", "aria-flowto", "aria-grabbed", "aria-haspopup",
317-
"aria-hidden", "aria-invalid", "aria-keyshortcuts", "aria-label", "aria-labelledby", "aria-live",
318-
"aria-owns", "aria-relevant", "aria-roledescription",
319-
// Widget attributes
320-
"aria-autocomplete", "aria-checked", "aria-expanded", "aria-level", "aria-modal", "aria-multiline", "aria-multiselectable",
321-
"aria-orientation", "aria-placeholder", "aria-pressed", "aria-readonly", "aria-required", "aria-selected",
322-
"aria-sort", "aria-valuemax", "aria-valuemin", "aria-valuenow", "aria-valuetext",
323-
// Relationship attributes
324-
"aria-activedescendant", "aria-colcount", "aria-colindex", "aria-colindextext", "aria-colspan",
325-
"aria-posinset", "aria-rowcount", "aria-rowindex", "aria-rowindextext", "aria-rowspan", "aria-setsize",
326-
};
327-
328312
const DOM_ATTRIBUTES_TO_CAMEL: Map<&'static str, &'static str> = phf_map! {
329313
"accept-charset" => "acceptCharset",
330314
"class" => "className",
@@ -527,7 +511,7 @@ impl Rule for NoUnknownProperty {
527511
}
528512
return;
529513
}
530-
if ARIA_PROPERTIES.contains(&actual_name) || !is_valid_html_tag {
514+
if is_valid_aria_property(&actual_name) || !is_valid_html_tag {
531515
return;
532516
}
533517
let name = normalize_attribute_case(&actual_name);

0 commit comments

Comments
 (0)