oxc-project/oxc · error · OxcDiagnostic
Prefer using `dataset` over `removeAttribute`.
Error message
Prefer using `dataset` over `removeAttribute`.
What it means
Diagnostic from the unicorn/prefer-dom-node-dataset lint rule. It fires when `removeAttribute()` is called with a `data-*` name; deleting the corresponding `element.dataset` property is the idiomatic removal. The flagged input is the `removeAttribute` call with a `data-`-prefixed argument. It is a lint suggestion, not a runtime error.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs:30
fixer::{RuleFix, RuleFixer},
rule::Rule,
utils::call_uses_optional_chain,
};
fn set(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer using `dataset` over `setAttribute`.").with_label(span)
}
fn get(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer using `dataset` over `getAttribute`.").with_label(span)
}
fn has(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer using `dataset` over `hasAttribute`.").with_label(span)
}
fn remove(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer using `dataset` over `removeAttribute`.").with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct PreferDomNodeDataset;
declare_oxc_lint!(
/// ### What it does
///
/// Use [`.dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) on DOM elements over `getAttribute(…)`, `.setAttribute(…)`, `.removeAttribute(…)` and `.hasAttribute(…)`.
///
/// ### Why is this bad?
///
/// The `dataset` property is a map of strings that contains all the `data-*` attributes from the element. It is a convenient way to access all of them at once.
///
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```javascriptView on GitHub (pinned to e1e7af627c)
Solutions
- Replace `el.removeAttribute('data-x')` with `delete el.dataset.x`
- Convert dash-cased names to camelCase dataset keys
- Apply the rule's auto-fix
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs:30 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/8f7aaf553fd1184e.
Report an issue: GitHub.