Commit ee354a00 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(rules): dont report elements where the tag is already correct

refs #65
parent facdafe8
......@@ -33,6 +33,11 @@ describe("rule prefer-native-element", () => {
expect(report).toBeValid();
});
it("should not report error when element has redundant role", () => {
const report = htmlvalidate.validateString('<main role="main"></main>');
expect(report).toBeValid();
});
it("should report error when using role with native equivalent element", () => {
const report = htmlvalidate.validateString('<div role="main"></div>');
expect(report).toBeInvalid();
......
......@@ -78,8 +78,14 @@ class PreferNativeElement extends Rule<RuleContext, RuleOptions> {
return;
}
/* report error */
/* dont report when the element is already of the right type but has a
* redundant role, such as <main role="main"> */
const replacement = mapping[role];
if (event.target.is(replacement)) {
return;
}
/* report error */
const context: RuleContext = { role, replacement };
const location = this.getLocation(event);
this.report(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment