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

refactor: use Array.prototype.at() to get last elements #17949

Merged
merged 1 commit into from Jan 4, 2024

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:

Per node.green, String/Array.prototype.at() is available in all versions of Node.js that ESLint v9 supports.

This enables the unicorn/prefer-at rule with the default behavior to enforce the use of .at() with negative indexes, and updates code to use, for example, tokens.at(-1) instead of tokens[tokens.length - 1].

What changes did you make? (Give an overview)

Enabled the rule and ran autofix.

Is there anything you'd like reviewers to focus on?

@eslint-github-bot eslint-github-bot bot added the chore This change is not user-facing label Jan 4, 2024
Copy link

netlify bot commented Jan 4, 2024

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 889ed2b
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/6595f7945580da0007db989e

@mdjermanovic mdjermanovic marked this pull request as ready for review January 4, 2024 00:16
@mdjermanovic mdjermanovic requested a review from a team as a code owner January 4, 2024 00:16
Copy link
Sponsor Member

@bmish bmish left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@snitin315 snitin315 added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jan 4, 2024
@snitin315 snitin315 merged commit df200e1 into main Jan 4, 2024
17 checks passed
@snitin315 snitin315 deleted the enable-prefer-at branch January 4, 2024 03:10
@fisker
Copy link
Contributor

fisker commented Jan 4, 2024

Reminder: Array#at() is slower in Node.js v16 and v18. prettier/prettier#14396 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion chore This change is not user-facing
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

4 participants