{"record":{"id":"5d7bc731e0e20d49","repo":"oxc-project/oxc","slug":"use-key-instead-of-deprecated-prop","errorCode":null,"errorMessage":"Use `.key` instead of `.{deprecated_prop}`","messagePattern":"Use `\\.key` instead of `\\.(.+?)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_keyboard_event_key.rs","lineNumber":19,"sourceCode":"use phf::{Map, phf_map};\n\nuse oxc_allocator::{GetAddress, UnstableAddress};\nuse oxc_ast::{\n    AstKind,\n    ast::{\n        Argument, BindingPattern, BindingProperty, CallExpression, Expression, Function,\n        MemberExpression, PropertyKey,\n    },\n};\nuse oxc_codegen::CodegenOptions;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn prefer_keyboard_event_key_diagnostic(span: Span, deprecated_prop: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use `.key` instead of `.{deprecated_prop}`\"))\n        .with_help(format!(\"The `{deprecated_prop}` property is deprecated.\"))\n        .with_note(\"https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferKeyboardEventKey;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforces the use of [`KeyboardEvent#key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)\n    /// over [`KeyboardEvent#keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode),\n    /// which is deprecated.\n    ///\n    /// The `.key` property is also more semantic and readable.\n    ///\n    /// ### Why is this bad?","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_keyboard_event_key.rs#L1-L37","documentation":"Diagnostic from the unicorn/prefer-keyboard-event-key lint rule. It fires when code reads a deprecated KeyboardEvent property such as `keyCode`, `charCode`, or `which` (via member access or a destructured binding property); these are non-standard and deprecated, and `.key` is the standardized replacement. The message names the deprecated property actually used. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_keyboard_event_key.rs:19 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `event.keyCode`/`event.which`/`event.charCode` with `event.key`","Update key comparisons to the `event.key` value strings (e.g. `'Enter'`, `'Escape'`)","Destructure `key` instead of the deprecated property","Apply the rule's auto-fix, which maps known key codes to their `.key` equivalents"],"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"}