{"record":{"id":"058935ee875c36ab","repo":"oxc-project/oxc","slug":"prefer-using-dataset-over-getattribute","errorCode":null,"errorMessage":"Prefer using `dataset` over `getAttribute`.","messagePattern":"Prefer using `dataset` over `getAttribute`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs","lineNumber":22,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::identifier::is_identifier_name;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    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    ///","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs#L4-L40","documentation":"Diagnostic from the unicorn/prefer-dom-node-dataset lint rule. It fires when `getAttribute()` is called with a `data-*` attribute name; reading through `element.dataset` is the idiomatic and type-consistent way to access such values (returning `undefined`/empty rather than `null`). The flagged input is the `getAttribute` 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:22 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `el.getAttribute('data-x')` with `el.dataset.x`","Convert dash-cased names to camelCase dataset keys","Apply the rule's auto-fix where the replacement is unambiguous"],"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-14T00:17:10.932Z"}