Commit 95e77486 authored by Stefan Kalscheuer's avatar Stefan Kalscheuer
Browse files

fix: make prefer-button tag and attribute checks case-insensitive

parent 2e46586b
......@@ -80,6 +80,16 @@ describe("rule prefer-button", () => {
);
});
it("should report error when using type submit in uppercase", () => {
expect.assertions(2);
const report = htmlvalidate.validateString('<INPUT TYPE="SUBMIT">');
expect(report).toBeInvalid();
expect(report).toHaveError(
"prefer-button",
'Prefer to use <button> instead of <input type="submit"> when adding buttons'
);
});
it("should not report error when using submit keyword in other attributes", () => {
expect.assertions(1);
const report = htmlvalidate.validateString(
......
......@@ -78,12 +78,12 @@ export default class PreferButton extends Rule<RuleContext, RuleOptions> {
const node = event.target;
/* only handle input elements */
if (node.tagName !== "input") {
if (node.tagName.toLowerCase() !== "input") {
return;
}
/* only handle type attribute */
if (event.key !== "type") {
if (event.key.toLowerCase() !== "type") {
return;
}
......@@ -93,17 +93,18 @@ export default class PreferButton extends Rule<RuleContext, RuleOptions> {
}
/* ignore types configured to be ignored */
if (this.isKeywordIgnored(event.value)) {
const type = event.value.toLowerCase();
if (this.isKeywordIgnored(type)) {
return;
}
/* only values matching known type triggers error */
if (!types.includes(event.value)) {
if (!types.includes(type)) {
return;
}
const context: RuleContext = { type: event.value };
const message = `Prefer to use <button> instead of <input type="${event.value}"> when adding buttons`;
const context: RuleContext = { type: type };
const message = `Prefer to use <button> instead of <input type="${type}"> when adding buttons`;
this.report(node, message, event.valueLocation, context);
});
}
......
Supports Markdown
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