Commit 5520b407 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(html5): add missing attributes on `<input>` element (for `no-unknown-attributes`)

refs #360
parent d3739ec5
Loading
Loading
Loading
Loading
Loading
+1 −28
Original line number Diff line number Diff line
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`docs/rules/no-unknown-attributes.md inline validation: correct 1`] = `
[
  {
    "errorCount": 1,
    "filePath": "inline",
    "messages": [
      {
        "column": 20,
        "context": {
          "attr": "name",
          "tagName": "input",
        },
        "line": 2,
        "message": "Attribute "name" is not allowed on <input> element",
        "offset": 59,
        "ruleId": "no-unknown-attributes",
        "ruleUrl": "https://html-validate.org/rules/no-unknown-attributes.html",
        "selector": "input",
        "severity": 2,
        "size": 4,
      },
    ],
    "source": "<div id="foo" class="bar" hidden></div>
<input type="text" name="username" />",
    "warningCount": 0,
  },
]
`;
exports[`docs/rules/no-unknown-attributes.md inline validation: correct 1`] = `[]`;

exports[`docs/rules/no-unknown-attributes.md inline validation: incorrect 1`] = `
[
+1070 −1074

File changed.

Preview size limit exceeded, changes collapsed.

+55 −0
Original line number Diff line number Diff line
@@ -1573,9 +1573,18 @@ export default {
			return type === "submit" || type === "image";
		},
		attributes: {
			accept: {},
			align: {
				deprecated: true,
			},
			alpha: {
				boolean: true,
			},
			alt: {},
			autocapitalize: {
				enum: ["off", "none", "on", "sentences", "words", "characters"],
			},
			autocomplete: {},
			autofocus: {
				boolean: true,
			},
@@ -1586,6 +1595,9 @@ export default {
			checked: {
				boolean: true,
			},
			colorspace: {
				enum: ["limited-srgb", "display-p3"],
			},
			datafld: {
				deprecated: true,
			},
@@ -1595,9 +1607,14 @@ export default {
			datasrc: {
				deprecated: true,
			},
			dirname: {},
			disabled: {
				boolean: true,
			},
			form: {
				enum: [validId],
				reference: "id",
			},
			formaction: {
				allowed: allowedIfAttributeHasValue("type", ["submit", "image"], {
					defaultValue: "submit",
@@ -1626,6 +1643,9 @@ export default {
				}),
				enum: ["/[^_].*/", "_blank", "_self", "_parent", "_top"],
			},
			height: {
				enum: ["/\\d+/"],
			},
			hspace: {
				deprecated: true,
			},
@@ -1639,15 +1659,46 @@ export default {
				enum: [validId],
				reference: "id",
			},
			max: {
				enum: ["/.+/"],
			},
			maxlength: {
				enum: ["/\\d+/"],
			},
			min: {
				enum: ["/.+/"],
			},
			minlength: {
				enum: ["/\\d+/"],
			},
			multiple: {
				boolean: true,
			},
			name: {
				enum: ["/.+/"],
			},
			pattern: {},
			placeholder: {},
			popovertarget: {
				enum: [validId],
				reference: "id",
			},
			popovertargetaction: {
				enum: ["toggle", "show", "hide"],
			},
			readonly: {
				boolean: true,
			},
			required: {
				boolean: true,
			},
			size: {
				enum: ["/\\d+/"],
			},
			src: {
				enum: ["/.+/"],
			},
			step: {},
			type: {
				enum: [
					"button",
@@ -1677,9 +1728,13 @@ export default {
			usemap: {
				deprecated: true,
			},
			value: {},
			vspace: {
				deprecated: true,
			},
			width: {
				enum: ["/\\d+/"],
			},
		},
		aria: {
			/* eslint-disable-next-line complexity -- the standard is complicated */
+76 −1
Original line number Diff line number Diff line
@@ -8,10 +8,58 @@ interface RuleContext {

const restricted = new Map<string, string[]>([
	["accept", ["file"]],
	["alpha", ["color"]],
	["alt", ["image"]],
	[
		"autocapitalize",
		[
			"button",
			"checkbox",
			"color",
			"date",
			"datetime-local",
			"file",
			"hidden",
			"image",
			"month",
			"number",
			"radio",
			"range",
			"reset",
			"search",
			"submit",
			"tel",
			"text",
			"time",
			"week",
		],
	],
	[
		"autocomplete",
		[
			"color",
			"date",
			"datetime-local",
			"email",
			"file",
			"hidden",
			"image",
			"month",
			"number",
			"password",
			"range",
			"search",
			"tel",
			"text",
			"time",
			"url",
			"week",
		],
	],
	["capture", ["file"]],
	["checked", ["checkbox", "radio"]],
	["dirname", ["text", "search"]],
	["colorspace", ["color"]],
	["dirname", ["hidden", "text", "search", "url", "tel", "email"]],
	["height", ["image"]],
	[
		"list",
@@ -38,6 +86,8 @@ const restricted = new Map<string, string[]>([
	["multiple", ["email", "file"]],
	["pattern", ["text", "search", "url", "tel", "email", "password"]],
	["placeholder", ["text", "search", "url", "tel", "email", "password", "number"]],
	["popovertarget", ["button"]],
	["popovertargetaction", ["button"]],
	[
		"readonly",
		[
@@ -78,6 +128,31 @@ const restricted = new Map<string, string[]>([
	["size", ["text", "search", "url", "tel", "email", "password"]],
	["src", ["image"]],
	["step", ["date", "month", "week", "time", "datetime-local", "number", "range"]],
	[
		"value",
		[
			"button",
			"checkbox",
			"color",
			"date",
			"datetime-local",
			"email",
			"hidden",
			"month",
			"number",
			"password",
			"radio",
			"range",
			"reset",
			"search",
			"submit",
			"tel",
			"text",
			"time",
			"url",
			"week",
		],
	],
	["width", ["image"]],
]);

+0 −4
Original line number Diff line number Diff line
@@ -112,10 +112,6 @@
	<input type="submit" checked>
	<input type="image" checked alt="lorem ipsum">
	<input type="reset" checked>
	<input type="hidden" dirname="myname">
	<input type="url" dirname="myname">
	<input type="tel" dirname="myname">
	<input type="email" dirname="myname">
	<input type="password" dirname="myname">
	<input type="date" dirname="myname">
	<input type="month" dirname="myname">