-
-
Notifications
You must be signed in to change notification settings - Fork 524
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 eslint/dot-notation
#9344
base: main
Are you sure you want to change the base?
Conversation
Relates to oxc-project#479 Rule details: https://eslint.org/docs/latest/rules/dot-notation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
add eslint/dot-notation
eslint/dot-notation
I think there are some possible improvements. One is: instead of |
Perhaps we can take inspiration from rolldown/rolldown#3677. I’ll review it later. |
CodSpeed Performance ReportMerging #9344 will not alter performanceComparing Summary
|
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 the contribution! I've made a few suggestions to help this rule better fit the style of our codebase as well as perform better.
); | ||
|
||
/// List of ES3 keywords. | ||
const KEYWORDS: &[&str] = &[ |
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.
given the size of this, I'd recommend using hash set instead. here's an example: https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/valid_typeof.rs#L141
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.
good point, I was curious so I ran benchmarks for linear search vs using match
(which i suspect might be doing a binary search) and using phf_set
.
test tests::bench_linear ... bench: 18.53 ns/iter (+/- 2.30)
test tests::bench_match ... bench: 2.01 ns/iter (+/- 0.13)
test tests::bench_set ... bench: 10.67 ns/iter (+/- 0.89)
I changed the implementation to a is_keyword
function that uses match
.
btw, for the valid_typeof link that you mentioned above, I ran the same benchmark with that list of valid types. looks like the set lookup takes significantly longer in that case presumably because the number of elements is much smaller. recommend we change that implementation to a matches!
as well.
test tests::bench_valid_type_linear ... bench: 0.29 ns/iter (+/- 0.03)
test tests::bench_valid_type_match ... bench: 0.28 ns/iter (+/- 0.03)
test tests::bench_valid_type_set ... bench: 10.81 ns/iter (+/- 1.01)
ref: https://gist.github.com/ammubhave/ca9f531f0e3760616f664f4230da7983
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.
We have similar code in the minifier where you can copy from https://github.com/oxc-project/oxc/blob/main/crates/oxc_minifier/src/peephole/convert_to_dotted_properties.rs
Relates to #479
Rule details: https://eslint.org/docs/latest/rules/dot-notation