feat(linter): add unicorn/prefer-keyboard-event-key rule#16611
feat(linter): add unicorn/prefer-keyboard-event-key rule#16611camc314 merged 3 commits intooxc-project:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements the unicorn/prefer-keyboard-event-key linter rule, which enforces the use of the modern KeyboardEvent.key property over the deprecated keyCode, charCode, and which properties. The rule includes auto-fix capabilities that can automatically replace deprecated property accesses with the appropriate key comparisons when used in binary expressions.
Key Changes
- Adds comprehensive rule implementation with support for detecting deprecated properties in direct property access and destructuring patterns
- Implements auto-fix functionality that converts numeric key code comparisons to string key comparisons
- Includes extensive test coverage with 47 failing cases and 20 fix test cases
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/oxc_linter/src/rules/unicorn/prefer_keyboard_event_key.rs |
Complete rule implementation with detection logic, auto-fix, and comprehensive test suite |
crates/oxc_linter/src/rules.rs |
Registers the new rule in the linter's rule registry |
crates/oxc_linter/src/snapshots/unicorn_prefer_keyboard_event_key.snap |
Test snapshot containing expected diagnostic outputs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/oxc_linter/src/rules/unicorn/prefer_keyboard_event_key.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/unicorn/prefer_keyboard_event_key.rs
Outdated
Show resolved
Hide resolved
CodSpeed Performance ReportMerging #16611 will not alter performanceComparing Summary
Footnotes
|
6e1e4a1 to
438f8b2
Compare
crates/oxc_linter/src/rules/unicorn/prefer_keyboard_event_key.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/unicorn/prefer_keyboard_event_key.rs
Outdated
Show resolved
Hide resolved
camc314
left a comment
There was a problem hiding this comment.
Thanks for working on this! Unfortunately it looks like CI is failing as not all the test cases are passing
59bb678 to
7c241e0
Compare
This PR adds unicorn/prefer-keyboard-event-key rule, issue #684 [rule doc](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v62.0.0/docs/rules/prefer-keyboard-event-key.md) [rule source](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v62.0.0/rules/prefer-keyboard-event-key.js) --------- Co-authored-by: Cameron Clark <[email protected]>
…#16611) This PR adds unicorn/prefer-keyboard-event-key rule, issue oxc-project#684 [rule doc](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v62.0.0/docs/rules/prefer-keyboard-event-key.md) [rule source](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v62.0.0/rules/prefer-keyboard-event-key.js) --------- Co-authored-by: Cameron Clark <[email protected]>
This PR adds unicorn/prefer-keyboard-event-key rule, issue #684
rule doc
rule source