-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Use singular array element variable name in autofix for no-for-loop
rule
#745
Conversation
c8078b9
to
ddf326c
Compare
ddf326c
to
05ab8ca
Compare
@fisker just updated to avoid using reserved JavaScript keywords. |
for (const case_ of cases) {} for (const element of cases) {} Which one do you prefer? |
@fisker no strong preference, either works for me. |
I prefer for (const case_ of cases) {} over for (const element of cases) {} And for (const function_ of functions) {} over for (const element of functions) {} If we decide to use |
I also prefer |
62b920a
to
dcbdfda
Compare
I kinda dislike both of them, since I think one should try not using identifiers like That being said, I also prefer the |
4914cc1
to
9fa0424
Compare
Rebased to take advantage of the |
…-loop` rule If the loop is iterating an array with a plural name (such as `plugins`), the generated element variable in the autofix could use the singular version of the array name (`plugin`), instead of just the generic name `element`.
9fa0424
to
830b456
Compare
invalid: [
...[
['plugin', 'plugins'],
['person', 'people'],
['element', 'list'],
].map(([elementName, arrayName]) =>
testCase(
`for(const i = 0; i < ${arrayName}.length; i++) {console.log(${arrayName}[i])}`,
`for(const ${elementName} of ${arrayName}) {console.log(${elementName})}`,
)
),
] Can you rewrite tests to this? So we can test more cases easier. |
I ask you again, don't squash! |
@fisker good idea, updated test cases. Sorry, squashing is a habit, I will try to avoid it. |
Add some words ends with |
Add a word that has more than one plural, |
Co-authored-by: fisker Cheung <lionkay@gmail.com>
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.
Looks good.
Nice work :) |
@bmish Do you interested in improving |
@fisker I'll see if I have a chance sometime, thanks for the idea. Can you file a ticket for now? |
If the loop is iterating an array with a plural name (such as
plugins
), the generated element variable in the autofix could use the singular version of the array name (plugin
), instead of just the generic nameelement
.Fixes #743. CC: @mongoose700