Skip to content

Latest commit

 

History

History
46 lines (29 loc) · 1.43 KB

no-quoteless-attributes.md

File metadata and controls

46 lines (29 loc) · 1.43 KB

no-quoteless-attributes

✅ The extends: 'recommended' property in a configuration file enables this rule.

In HTML, all attribute values are considered strings, regardless of whether they are quoted or not.

The following two examples are identical from the perspective of the browser:

<div data-foo=asdf></div>
<div data-foo="asdf"></div>

This fact makes the following HTML very confusing:

<input disabled=false>

In this case, the simple presence of the disabled attribute means that the <input> is disabled and setting the value to false doesn't do the obvious thing.

This is just one (of many) cases where the default "string" based parsing of attributes in HTML can trip folks up.

This rule attempts to make this situation slightly better by at least ensuring that all attribute values are quoted. This obviously doesn't fix the 🧌y nature of HTML here but it does ensure that you still see the quotes (which should hopefully help remind you that these are strings and not values).

Examples

This rule forbids the following (note that someValue could have been intended either as a string or expression):

<div data-foo=someValue></div>

This rule allows the following:

<div data-foo="someValue"></div>
<div data-foo={{someValue}}></div>

References