A data- attribute is read or written through getAttribute or setAttribute instead of dataset
What it finds
element.dataset exposes the data- attributes of an element as properties, with their names in camel case. getAttribute("data-user-id") does the same with a string that has to be kept in sync by hand.
Reported are calls of getAttribute, setAttribute, hasAttribute and removeAttribute whose first argument is a string literal starting with data-.
From the rule's source, data_attribute_via_get_attribute.rs.
export function id(el: HTMLElement) { return el.getAttribute("data-user-id");tx0 reports: data-user-id is available as a property of dataset} Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:data-attribute-via-get-attribute" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:data-attribute-via-get-attribute] reason="..."tx0 explain tx0/ts:data-attribute-via-get-attribute shows the same in the terminal. Found a false positive? Report it.