feat: add template-valid-input-attributes#2764
feat: add template-valid-input-attributes#2764johanrd wants to merge 5 commits intoember-cli:masterfrom
Conversation
…ompatible with declared type
…ck; tests for UPPERCASE attrs
| @@ -0,0 +1,170 @@ | |||
| 'use strict'; | |||
|
|
|||
| // Logic adapted from html-validate (MIT), Copyright 2017 David Sveningsson. | |||
There was a problem hiding this comment.
why are we copying someone else's work here?
There was a problem hiding this comment.
okay, the note is slightly off, perhaps.
The logic part is not ported (the ESLint visitor and Glimmer AST traversal). What was ported was the restricted data table (attribute → allowed types). The table is an encoding of HTML spec §4.10.5.1 and others (e.g. HTML Media Capture for capture).
Did look for options to import instead of copy, but restricted isn't exported from html-validate's public API. The annotation in the source could be updated to say "Data table ported from" rather than "Logic adapted from" to reflect this more accurately?
There was a problem hiding this comment.
moved the attribution to be more local to the actual restricted data table
There was a problem hiding this comment.
another and more viable solution perhaps: https://github.com/johanrd/html-validate-ember
Note
This is part of a series where Claude has audited
eslint-plugin-emberagainst jsx-a11y, vuejs-accessibility, angular-eslint, lit-a11y and html-validate,ember-template-lint, and the HTML and WCAG specs.Rules table ported from html-validate
input-attributes(MIT), Copyright 2017 David Sveningsson.Adds
template-valid-input-attributes: flags<input>attributes whose applicability is conditional ontypewhen the declaredtypedoesn't permit them. For example,patternontype="number"is silently ignored by the browser.Premise
HTML spec §4.10.5.1 — States of the
typeattribute pins most attributes to specific type states.patternis only defined for Text / Search / URL / Telephone / E-mail / Password.acceptis only for File Upload.min/max/stepapply only to Date / Month / Week / Time / Local Date and Time / Number / Range. When an author writes<input type="number" pattern="\d+">, thepatternattribute is ignored by the browser without any error — a silent failure class.Implementation
RESTRICTEDtable maps each restricted attribute to the set oftypestates that accept it. The table is ported verbatim from html-validate and spot-verified against the HTML spec per-state tables. For each<input>the visitor resolves the static type and checks each attribute against the table. Missing or valuelesstyperesolves to the Text state (per HTML §4.10.5.1.2), so attributes are still validated against text-state restrictions. Dynamictype(e.g.type={{this.t}}) is skipped.Restricted attributes checked:
accept,alt,capture,checked,dirname,height,list,max,maxlength,min,minlength,multiple,pattern,placeholder,readonly,required,size,src,step,width.Flags
Allows
Prior art
input-attributes— direct port (same attribute/type table, same skip-on-dynamic-type behavior)Opt-in: not added to any preset config.