-
Notifications
You must be signed in to change notification settings - Fork 751
build(lint): migrate away from forEach (WIP) #6277
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
Conversation
| 'aws-toolkits/no-console-log': 'error', | ||
| 'aws-toolkits/no-json-stringify-in-log': 'error', | ||
| 'aws-toolkits/no-printf-mismatch': 'error', | ||
| 'aws-toolkits/no-foreach': 'error', |
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.
We depend on eslint-plugin-unicorn so I think we can use this rule: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-for-each.md
in .eslintrc.js where we enable the rule, let's put a comment like:
// Discourage `.forEach` because it can lead to accidental, incorrect use of async callbacks.
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.
Good idea! That rule also comes with a way to auto-fix most cases so I switched over to it completely here: #6281
| const requestId = resp.$response.requestId | ||
| logStr += `\n${indent('RequestID: ', 4)}${requestId},\n${indent('Customizations:', 4)}` | ||
| resp.customizations.forEach((c, index) => { | ||
| for (const [c, index] of enumerate(resp.customizations)) { |
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.
Does using enumerate() mean we are iterating the collection twice? Does this work instead:
for (const [index, element] of array.entries()) {
|
Moved to #6281 |
Problem
forEach can lead to race conditions with async methods, and is often used instead of
map,find,some,reduce,flatMap, etc...Solution
Add a lint rule for forEach and migrate away from it.
feature/xbranches will not be squash-merged at release time.