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
Why assignment to property of function parameter is bad style. #1217
Comments
Since express does require this, you currently can only disable the rule entirely, on a per-file basis, or on a per-line/per-function basis. eslint has an option proposed to cover this: eslint/eslint#6505 Once that's enabled, we'll likely enable it by default to cover |
Thank you sir. |
(the question's answered, but reopening to track the eslint rule change) |
@zhangchitc You are not reassigning the parameter, you are just creating a property on the object. Because of this, you can allow it today with |
Yes, but |
Just a quick update, this has been merged and will be released in the next version of ESLint (which I believe is tomorrow): eslint/eslint#6505 (comment) |
Another example is router.get('/', (ctx) => {
ctx.status = 200;
}); |
The next release of eslint-config-airbnb-base, and likely eslint-config-airbnb, will include this loosening of no-param-reassign. |
|
@jbruni Airbnb's config makes many profound design choices for you; that's the point. If you don't agree with them, you can easily override rules and/or fork the guide. |
Guys does anybody knows how to set up eslit for showing error if I modify value from param array ? const checkIsValid = (id, array) => {
for (let i = 0; i < array.length; i++) {
const item = array[i];
if (item.param) {
item.value = null;
item.payment = null;
}
}
return array;
}; |
@kholiavko-roman that’s pushing the limits of static analysis; you may want to try eslint-plugin-immutable, but it’s not very reliable due to the way the language works. |
@kholiavko-roman Or try TypeScript and something like jonaskello/tslint-immutable. |
Thanks for reply. I think I will try eslint-plugin-immutable for the first. |
Otherwise with koa context (`ctx`) it's too tedious. I'm happy to use `ignorePropertyModificationsFor` and whitelist `ctx` and other common names as a strictier alternative infos: - https://eslint.org/docs/rules/no-param-reassign - airbnb/javascript#1217 (comment)
Node.js web service
Often used, can not be avoided.
How should I do?
The text was updated successfully, but these errors were encountered: