-
-
Notifications
You must be signed in to change notification settings - Fork 738
feat(linter): add unicorn/prefer-keyboard-event-key rule #16611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(linter): add unicorn/prefer-keyboard-event-key rule #16611
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Unfortunately it looks like CI is failing as not all the test cases are passing
59bb678 to
7c241e0
Compare
camc314
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
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]>
This PR adds unicorn/prefer-keyboard-event-key rule, issue #684
rule doc
rule source