Skip to content
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(lint): add rule useAtIndex #4120

Merged
merged 50 commits into from
Oct 9, 2024
Merged

Conversation

GunseiKPaseri
Copy link
Contributor

@GunseiKPaseri GunseiKPaseri commented Sep 29, 2024

Summary

Implement useAtIndex(unicorn/prefer-at)

closes #3943

Making some slight changes.

  • Ignore X.slice(-1, unknown)[0]
  • Fix foo[foo.length - a - b]
  • Unsupport lodash
  • Unsupoprt option (checkAllIndexAccess, getLastElementFunctions)

Test Plan

  • Added tests and snapshots

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Sep 29, 2024
Copy link

codspeed-hq bot commented Sep 29, 2024

CodSpeed Performance Report

Merging #4120 will improve performances by 7.04%

Comparing GunseiKPaseri:use-at-index (387634a) with main (d2273a6)

Summary

⚡ 2 improvements
✅ 103 untouched benchmarks

Benchmarks breakdown

Benchmark main GunseiKPaseri:use-at-index Change
pure_9395922602181450299.css[cached] 3.6 ms 3.4 ms +6.79%
db_17847247775464589309.json[uncached] 16.1 ms 15.1 ms +7.04%

Copy link
Member

@Conaclos Conaclos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I left my first comments. I will make a second pass once these comments are addressed.

crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
GunseiKPaseri and others added 4 commits October 3, 2024 15:14
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
Copy link
Member

@Conaclos Conaclos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the comments are addressed I think we can merge your contribution :)

crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_at_index.rs Outdated Show resolved Hide resolved
Comment on lines +391 to +392
) -> Option<(AnyJsExpression, Vec<AnyJsExpression>)> {
let mut right_list = vec![];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid allocating a Vec by using std::iter::successors.
We could clone the iterator at call site if we need to iterate over it several times.

This is a refactor that we can delay to a future PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I didn't know the appropriate way to use successors while simultaneously obtaining the final expression.

GunseiKPaseri and others added 7 commits October 9, 2024 23:11
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
Co-authored-by: Victorien Elvinger <victorien@elvinger.fr>
@Conaclos
Copy link
Member

Conaclos commented Oct 9, 2024

@GunseiKPaseri Looks good to me. Could you merge main in your PR and solve conflicts? This will allow us to merge your PR :)

@Conaclos Conaclos merged commit 3364640 into biomejs:main Oct 9, 2024
12 checks passed
@Conaclos Conaclos added the A-Changelog Area: changelog label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 Implement useAtIndex - unicorn/prefer-at
3 participants