Skip to content
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 with any expression #42

Closed
benadamstyles opened this issue Feb 21, 2018 · 3 comments
Closed

no-mutating-assign with any expression #42

benadamstyles opened this issue Feb 21, 2018 · 3 comments

Comments

@benadamstyles
Copy link

Thanks for this excellent plugin. Further to #17, I wonder if you'd consider allowing any function call as the first argument to Object.assign() (or at least add an option to allow this). For example, I think this would always be "functionally safe":

Object.assign(anyFunctionCall(_), {prop: 'value'})

If you're happy with the concept I'm happy to PR (although any hint you can give about what the eslint type of a function call would be, would be very helpful, as I've never written an eslint rule before)!

@graingert
Copy link
Collaborator

graingert commented Feb 21, 2018

not safe:

const globalObj = {};
globalObj.prop; // undefined
const anyFunctionCall = () => globalObj;
const newObj = Object.assign(anyFunctionCall(_), {prop: 'value'});
newObj.value; // 'value'
globalObj.prop; // 'value'

@graingert
Copy link
Collaborator

graingert commented Feb 21, 2018

safe:

const globalObj = {};
globalObj.prop; // undefined
const anyFunctionCall = () => globalObj;
const newObj = Object.assign({}, anyFunctionCall(_), {prop: 'value'});
newObj.value; // 'value'
globalObj.prop; // undefined

@benadamstyles
Copy link
Author

Yep my mistake!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants