GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

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

fix(rules): `no-redundant-for` should only target `<label>`

parent 69fe8388
......@@ -24,6 +24,14 @@ describe("rule no-redundant-for", () => {
expect(report).toBeValid();
});
it("should not report error for other elements", () => {
expect.assertions(1);
const report = htmlvalidate.validateString(
'<custom-element for="foo"><input id="foo"></custom-element>'
);
expect(report).toBeValid();
});
it("should report error when <label> references wrapped element", () => {
expect.assertions(2);
const report = htmlvalidate.validateString(
......
......@@ -13,6 +13,11 @@ export default class NoRedundantFor extends Rule {
this.on("element:ready", (event: ElementReadyEvent) => {
const { target } = event;
/* only handle <label> */
if (target.tagName !== "label") {
return;
}
/* ignore label without for or dynamic value */
const attr = target.getAttribute("for");
if (!attr || attr.isDynamic) {
......
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