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

Add no-object-as-default-parameter rule #633

Merged
merged 13 commits into from Jun 30, 2020
Merged

Add no-object-as-default-parameter rule #633

merged 13 commits into from Jun 30, 2020

Conversation

medusalix
Copy link
Contributor

@medusalix medusalix commented Mar 26, 2020

Simply reports any default-assignments of objects to function parameters as described in this comment.

Fixes #208


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


IssueHunt has been backed by the following sponsors. Become a sponsor

@fisker
Copy link
Collaborator

fisker commented Mar 27, 2020

How about name no-object-as-default

@medusalix medusalix changed the title Add disallow-objects-as-default rule Add no-object-as-default rule Mar 27, 2020
@fisker
Copy link
Collaborator

fisker commented Mar 27, 2020

On second though, will people think this rule forbid this following syntax?

export {
    object as default,
// ^
    foo as bar
};

@medusalix
Copy link
Contributor Author

medusalix commented Jun 6, 2020

I don't think users will mix that up. The description is pretty clear about the rule's purpose.

@sindresorhus
Copy link
Owner

I would name the rule no-object-as-default-parameter to make it clearer.

docs/rules/no-object-as-default.md Outdated Show resolved Hide resolved
rules/no-object-as-default.js Outdated Show resolved Hide resolved
@sindresorhus sindresorhus requested a review from fisker June 27, 2020 20:52
Copy link
Collaborator

@fisker fisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests about class/object methods.

rules/no-object-as-default.js Outdated Show resolved Hide resolved
medusalix and others added 3 commits June 28, 2020 13:39
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@medusalix medusalix changed the title Add no-object-as-default rule Add no-object-as-default-parameter rule Jun 28, 2020
@medusalix
Copy link
Contributor Author

medusalix commented Jun 28, 2020

Please add tests about class/object methods.

Could you please elaborate? I'm not quite sure what you mean.

rules/no-object-as-default-parameter.js Outdated Show resolved Hide resolved
rules/no-object-as-default-parameter.js Outdated Show resolved Hide resolved
@fisker
Copy link
Collaborator

fisker commented Jun 28, 2020

Please test

class A {
  method(foo = {bar:1}) {}
}
const A = class {
  method(foo = {bar:1}) {}
}
object = {
  method(foo = {bar:1}) {}
}

Maybe also constructor and getter setter

And

const foo = ([bar = {a = false, b = 123}]) => {};
const foo = ({bar: baz = {a = false, b = 123}}) => {};
const foo = ({foo = {a = false, b = 123}}) => {};

I'm on cellphone, didn't format well.

@medusalix
Copy link
Contributor Author

medusalix commented Jun 28, 2020

const foo = ({bar: baz = {a = false, b = 123}}) => {};
const foo = ({foo = {a = false, b = 123}}) => {};

Is this syntactically correct? It gives me Shorthand property assignments are valid only in destructuring patterns.

Maybe also constructor and getter setter

I've added tests for the constructor and setter, it doesn't seem like getters allow parameters.

@fisker
Copy link
Collaborator

fisker commented Jun 28, 2020

const adc = () => (foo = {bar: 1}); This one looks similar to default parameter, but it's not , let's add it to test too.

@fisker
Copy link
Collaborator

fisker commented Jun 28, 2020

const foo = ({bar: baz = {a = false, b = 123}}) => {};
const foo = ({foo = {a = false, b = 123}}) => {};

Is this syntactically correct? It gives me Shorthand property assignments are valid only in destructuring patterns.

Okay , if it's not valid, I mean to test deep destructuring.

Maybe also constructor and getter setter

I've added tests for the constructor and setter, it doesn't seem like getters allow parameters.

Okay.

@fisker
Copy link
Collaborator

fisker commented Jun 28, 2020

Looks good , I'll check again when I back to my laptop.

@medusalix
Copy link
Contributor Author

Thank you. I really appreciate your constructive feedback, it's always very helpful 👍.

Copy link
Collaborator

@fisker fisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one note.

@sindresorhus sindresorhus merged commit 9989d2d into sindresorhus:master Jun 30, 2020
@sindresorhus
Copy link
Owner

Great! Looks good to me too 👍

@medusalix medusalix deleted the disallow-objects-as-default branch June 30, 2020 08:11
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

Successfully merging this pull request may close these issues.

Rule proposal: No default parameter options
3 participants