Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lint/useAriaPropsSupportedByRole): add rule #3644

Merged
merged 11 commits into from
Aug 26, 2024
33 changes: 25 additions & 8 deletions crates/biome_aria/src/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,14 @@ impl<'a> AriaRoles {
"marquee" => &MarqueeRole as &dyn AriaRoleDefinition,
"math" => &MathRole as &dyn AriaRoleDefinition,
"menu" => &ListRole as &dyn AriaRoleDefinition,
"menuitem" => {
let type_values = attributes.get("type")?;
match type_values.first()?.as_str() {
"checkbox" => &MenuItemCheckboxRole as &dyn AriaRoleDefinition,
"radio" => &MenuItemRadioRole as &dyn AriaRoleDefinition,
_ => &MenuItemRole as &dyn AriaRoleDefinition,
}
}
"meter" => &MeterRole as &dyn AriaRoleDefinition,
"nav" => &NavigationRole as &dyn AriaRoleDefinition,
"ul" | "ol" => &ListRole as &dyn AriaRoleDefinition,
Expand Down Expand Up @@ -1311,6 +1319,22 @@ impl<'a> AriaRoles {
role_candidate.concepts_by_role()
}

/// Given an element name and attributes, it returns the role associated with that element.
/// If no explicit role attribute is present, an implicit role is returned.
pub fn get_role_by_element_name(
&self,
element_name: &str,
attributes: &FxHashMap<String, Vec<String>>,
) -> Option<&'static dyn AriaRoleDefinition> {
attributes
.get("role")
.and_then(|role| role.first())
.map_or_else(
|| self.get_implicit_role(element_name, attributes),
|r| self.get_role(r),
)
}

pub fn is_not_static_element(
&self,
element_name: &str,
Expand All @@ -1333,14 +1357,7 @@ impl<'a> AriaRoles {
return true;
}

// if the element has a interactive role, it is considered interactive.
let role_name = attributes
.get("role")
.and_then(|role| role.first())
.map_or_else(
|| self.get_implicit_role(element_name, attributes),
|r| self.get_role(r),
);
let role_name = self.get_role_by_element_name(element_name, attributes);

match role_name.map(|role| role.type_name()) {
Some("biome_aria::roles::PresentationRole" | "biome_aria::roles::GenericRole") => false,
Expand Down
22 changes: 10 additions & 12 deletions crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading