{"record":{"id":"41a1335921032a70","repo":"oxc-project/oxc","slug":"prefer-using-dataset-over-hasattribute","errorCode":null,"errorMessage":"Prefer using `dataset` over `hasAttribute`.","messagePattern":"Prefer using `dataset` over `hasAttribute`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs","lineNumber":26,"sourceCode":"\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    ///\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    ///","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs#L8-L44","documentation":"Diagnostic from the unicorn/prefer-dom-node-dataset lint rule. It fires when `hasAttribute()` is called with a `data-*` name; `name in el.dataset` (or checking the dataset value) is the idiomatic presence check for dataset entries. The flagged input is the `hasAttribute` call whose argument is a `data-`-prefixed string. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs:26 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `el.hasAttribute('data-x')` with `'x' in el.dataset`","Use the camelCase key form when converting dash-cased attribute names","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-14T00:17:10.932Z"}