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

prefer-array-find rule autofixer could singularize variable name #822

Closed
bmish opened this issue Sep 4, 2020 · 3 comments · Fixed by #1243
Closed

prefer-array-find rule autofixer could singularize variable name #822

bmish opened this issue Sep 4, 2020 · 3 comments · Fixed by #1243

Comments

@bmish
Copy link
Sponsor Collaborator

bmish commented Sep 4, 2020

The autofixer for prefer-array-find could be updated to singularize the variable name since the variable now refers to a single item instead of an array in the following situation.

Before:

const calls = calls.filter((call) => call.isFoo);
assert.ok(calls[0].isBar);

After autofix (current):

const calls = calls.find((call) => call.isFoo);
assert.ok(calls.isBar);

After autofix (desired):

const call = calls.find((call) => call.isFoo);
assert.ok(call.isBar);

This fix would be similar to the singularization performed in the no-for-loop rule as a result of #745.

@fisker
Copy link
Collaborator

fisker commented Sep 19, 2020

I did metion this variable rename in the original proposal.

The name may confuse people const allTrueArray = array.filter(foo) -> const allTrueArray = array.find(foo) the allTrueArray is not an array anymore.

#730 (comment)

I forgot why I didn't consider rename it, but I remember there is a good reason maybe not.

@fisker
Copy link
Collaborator

fisker commented Sep 22, 2020

PR welcome.

@bmish
Copy link
Sponsor Collaborator Author

bmish commented May 7, 2021

I have opened a fix in #1243.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants