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

Add useAt option to autofix .lastObject to .at(-1) in no-get rule #1847

Merged
merged 3 commits into from May 31, 2023

Conversation

ArtixZ
Copy link
Contributor

@ArtixZ ArtixZ commented May 1, 2023

.lastObject autofix rule can be simplified as .lastObject ==> .at(-1).
We can lift the limit of handling only one .lastObject in path as well.

@bmish bmish changed the title No-get lastObject improvement Autofix .lastObject to .at(-1) in no-get rule May 1, 2023
@bmish
Copy link
Member

bmish commented May 1, 2023

This is a nice improvement. However, I don't think we can make this the default behavior until Node 16 becomes end-of-life in Sept, 2023. We could put this behind an option useAt (similar to useOptionalChaining) until then.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
https://github.com/nodejs/Release

@ArtixZ
Copy link
Contributor Author

ArtixZ commented May 2, 2023

@bmish Thanks for the advice. I'd assume the default value of useAt should be true, should it?

@bmish
Copy link
Member

bmish commented May 2, 2023

We need to keep this feature turned off by default until we drop the corresponding Node version support. So useAt option default to false for now.

@ArtixZ ArtixZ force-pushed the donzhu/no-get-lastObject-improvement branch from 511e895 to 63e0286 Compare May 17, 2023 23:14
lib/rules/no-get.js Outdated Show resolved Hide resolved
docs/rules/no-get.md Outdated Show resolved Hide resolved
docs/rules/no-get.md Outdated Show resolved Hide resolved
@bmish
Copy link
Member

bmish commented May 23, 2023

Looking forward to seeing this get in still! It's nearly finished.

@ArtixZ
Copy link
Contributor Author

ArtixZ commented May 31, 2023

Sorry I was sidetracked by other stuff. Will have an update today.

@bmish bmish mentioned this pull request May 31, 2023
@bmish bmish changed the title Autofix .lastObject to .at(-1) in no-get rule Add useAt option to autofix .lastObject to .at(-1) in no-get rule May 31, 2023
Copy link
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.

Thanks!

@bmish bmish merged commit 957879c into ember-cli:master May 31, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants