{"record":{"id":"8f7aaf553fd1184e","repo":"oxc-project/oxc","slug":"prefer-using-dataset-over-removeattribute","errorCode":null,"errorMessage":"Prefer using `dataset` over `removeAttribute`.","messagePattern":"Prefer using `dataset` over `removeAttribute`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs","lineNumber":30,"sourceCode":"    fixer::{RuleFix, RuleFixer},\n    rule::Rule,\n    utils::call_uses_optional_chain,\n};\n\nfn set(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer using `dataset` over `setAttribute`.\").with_label(span)\n}\n\nfn get(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer using `dataset` over `getAttribute`.\").with_label(span)\n}\n\nfn has(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer using `dataset` over `hasAttribute`.\").with_label(span)\n}\n\nfn remove(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer using `dataset` over `removeAttribute`.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferDomNodeDataset;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Use [`.dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) on DOM elements over `getAttribute(…)`, `.setAttribute(…)`, `.removeAttribute(…)` and `.hasAttribute(…)`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// 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.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:\n    /// ```javascript","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs#L12-L48","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs:30 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}