False-positive on date.setDate() in a loop
See original GitHub issueWhat version of ESLint are you using?
"eslint": "^2.10.2",
"eslint-friendly-formatter": "^2.0.5",
"eslint-loader": "^1.3.0",
"eslint-plugin-html": "^1.3.0",
"eslint-config-standard": "^5.1.0",
"eslint-plugin-promise": "^1.0.8",
"eslint-plugin-standard": "^1.3.2",
What parser (default, Babel-ESLint, etc.) are you using?
“babel-eslint”: “^6.1.2”,
Please show your full configuration:
I am using generated vue-webpack project https://github.com/vuejs-templates/webpack
What did you do? Please include the actual source code causing the issue.
while (start <= end) {
dates.push(new Date(start))
start.setDate(start.getDate() + 1)
}
What did you expect to happen?
It should go through eslint checks without any errors.
What actually happened? Please include the actual, raw output from ESLint.
✘ http://eslint.org/docs/rules/no-unmodified-loop-condition ‘start’ is not modified in this loop
…/src/utils/DateUtils.js:163:12 while (start <= end) { ^✘ http://eslint.org/docs/rules/no-unmodified-loop-condition ‘end’ is not modified in this loop
…/src/utils/DateUtils.js:163:21 while (start <= end) { ^
The solutions suggested:
- By @ilyavolodin
while (start <= end) {
dates.push(new Date(start))
start = start.getDate() + 1;
}
while (start.valueOf() <= end.valueOf())?
- By @platinumazure (my favorite one)
while (start <= end) { // eslint-disable-line no-unmodified-loop-condition
dates.push(new Date(start))
start.setDate(start.getDate() + 1)
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (11 by maintainers)
Top GitHub Comments
@feross @kaicataldo Here it is. Sorry I didn’t write it up sooner, been busy. Hopefully that’s sufficient 😃
I don’t think we should allow arbitrary information in the
eslint-disable
comments - having to parse what is config and what isn’t would make it error prone. My recommendation would be to put another comment before theeslint-disable-next-line
comment.