Commit c06ae674 authored by David Sveningsson's avatar David Sveningsson

fix(rules): attr-case no longer reports duplicate errors for dynamic attributes

fixes #48
parent 5170a445
Pipeline #80850408 passed with stages
in 9 minutes and 1 second
import HtmlValidate from "../htmlvalidate";
import "../matchers";
import { processAttribute } from "../transform/mocks/attribute";
describe("rule attr-case", () => {
let htmlvalidate: HtmlValidate;
......@@ -120,6 +121,22 @@ describe("rule attr-case", () => {
});
});
it("should not report duplicate errors for dynamic attributes", () => {
htmlvalidate = new HtmlValidate({
rules: { "attr-case": "error" },
});
const report = htmlvalidate.validateString('<input dynamic-fooBar="foo">', {
processAttribute,
});
expect(report).toBeInvalid();
expect(report).toHaveErrors([
{
ruleId: "attr-case",
message: 'Attribute "dynamic-fooBar" should be lowercase',
},
]);
});
it("should throw error if configured with invalid value", () => {
htmlvalidate = new HtmlValidate({
rules: { "attr-case": ["error", { style: "foobar" }] },
......
......@@ -29,6 +29,13 @@ class AttrCase extends Rule {
return;
}
/* ignore case for dynamic attributes, the original attributes will be
* checked instead (this prevents duplicated errors for the same source
* attribute) */
if (event.originalAttribute) {
return;
}
const letters = event.key.replace(/[^a-z]+/gi, "");
if (!letters.match(this.pattern)) {
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