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
no-mutating-assign and functions #17
Comments
Hi @jdiamond! From what I see in the Object.assign documentation, the first parameter must be an object. Since functions are objects, this is valid, and I guess I could see some use-cases for it. We could allow (arrow) function expressions, since no variable is mutated. Did you happen to notice it or do you have a use-case where this rule bothered you? |
Hi @jfmengels, Thanks for looking into it. I did discover this while working on "real" code so I think it's a valid use-case, but my problem is definitely self-imposed. I'm working on a React app and am defining modules containing stateless functional components (just functions). Those normally look like this:
I have the "no-unused-expression" rule turned on which prevents me from mutating
This works in my app, but now I have to disable the "no-mutating-assign" rule to avoid the lint errors. |
I just published v2.3.0 with this change. Let me know if that solves it for you :) By the way, I don't see how the /* eslint fp/no-mutation: ["error", {"exceptions": [{"property": "propTypes"}]}] */
function Component(props) {
// ...
}
Component.propTypes = {
// ...
}; Your way is safer, but I'm mentioning in case you end up finding your current method too confusing for newcomers or hard to read. |
Hey thanks! I upgraded and was able to remove my comments disabling the rule. You're right that I didn't know about the Thanks again for the awesome plugin! |
I think this is probably acceptable for function literals as long as they are only accessible after mutation. |
I can see: const foo = Object.assign(function foo(ham) { }, { $inject: ['ham'] }); being preferred to: const foo = function foo(ham) { };
foo.$inject = ['ham']; |
IIRC, @jfmengels did make the change for your first example to work without triggering this error. |
This doesn't pass the no-mutating-assign rule:
Should it be allowed?
The text was updated successfully, but these errors were encountered: