{"record":{"id":"08c2d76bc3379e0f","repo":"oxc-project/oxc","slug":"prefer-using-dataset-over-setattribute","errorCode":null,"errorMessage":"Prefer using `dataset` over `setAttribute`.","messagePattern":"Prefer using `dataset` over `setAttribute`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs","lineNumber":18,"sourceCode":"use cow_utils::CowUtils;\nuse oxc_ast::{AstKind, ast::Argument};\nuse oxc_codegen::CodegenOptions;\nuse 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!(","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs#L1-L36","documentation":"Diagnostic from the unicorn/prefer-dom-node-dataset lint rule. It fires when `setAttribute()` is used to store a `data-*` attribute on an element; the `element.dataset` API is the dedicated interface for those attributes and handles value serialization automatically. The flagged input is the `setAttribute` call whose first argument is a `data-`-prefixed name. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs:18 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `el.setAttribute('data-x', v)` with `el.dataset.x = v`","Convert dash-cased attribute names to camelCase dataset keys (`data-user-id` -> `dataset.userId`)","Apply the rule's auto-fix, which rewrites the call to a dataset assignment"],"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"}