Skip to content

attr-pattern

Reports an attribute name that does not match the option pattern, a regex that by default allows letters, digits, - and : in either case. An underscore, for example, is reported (data_x).

A naming rule for attributes keeps custom data attributes and framework attributes uniform. A name outside the usual character set is most often a typing error that the browser silently accepts as a new attribute.

To fix, rename the attribute, or change the pattern.

Reported
...
<input name="fooBar">
...
<input name="foo[]">
<p fooBar="x" data-X="y" a_b="c"></p>
angular:
lint:
rules:
attr-pattern:
level: warn # off (default), warn, error
options:
pattern: "(?i)^[a-z0-9:-]+$"
html:
lint:
rules:
attr-pattern:
level: warn # off (default), warn, error
options:
pattern: "(?i)^[a-z0-9:-]+$"
svelte:
lint:
rules:
attr-pattern:
level: warn # off (default), warn, error
options:
pattern: "(?i)^[a-z0-9:-]+$"
vue:
lint:
rules:
attr-pattern:
level: warn # off (default), warn, error
options:
pattern: "(?i)^[a-z0-9:-]+$"
Option Type Default Description
pattern string "(?i)^[a-z0-9:-]+$" The regex the value must match.

Suppress one line with sudsy-disable-next-line attr-pattern in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
html-validate attr-pattern full