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

Rule Proposal: no-empty-pattern [$10] #3668

Closed
mysticatea opened this issue Sep 5, 2015 · 11 comments
Closed

Rule Proposal: no-empty-pattern [$10] #3668

mysticatea opened this issue Sep 5, 2015 · 11 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bounty Someone has posted a bounty for this issue on BountySource enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before rule Relates to ESLint's core rules

Comments

@mysticatea
Copy link
Member

Spawned from #3658.

The following code does not raise an syntax error.

let {a: {}} = foo;

But it's considered developer's intent is below.
Because an empty ObjectPattern effects nothing.

let {a = {}} = foo;

So this proposal defines new no-empty-pattern rule.
This rule considers the following patterns as warnings:

let {} = foo;
let [] = foo;
let {a: {}} = foo;
let {a: []} = foo;
function foo({}) {}
function foo([]) {}
function foo({a: {}}) {}
function foo({a: []}) {}

This rule does not consider the following patterns as warnings:

let {a = {}} = foo;
let {a = []} = foo;
function foo({a = {}}) {}
function foo({a = []}) {}

I'm not sure this rule name is good.

Did you help close this issue? Go claim the $10 bounty on Bountysource.

@mysticatea mysticatea added enhancement This change enhances an existing feature of ESLint triage An ESLint team member will look at this issue soon rule Relates to ESLint's core rules labels Sep 5, 2015
@mysticatea
Copy link
Member Author

import {} from "foo"; is the similar one.

@mysticatea
Copy link
Member Author

Is no-empty-declaration a good name?
These patterns does not declare any variable.

EDIT: I had forgotten let {a, b: {}} = foo;

@ilyavolodin
Copy link
Member

What about var and const? I assume those are going to be affected too?

@nzakas nzakas added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Sep 5, 2015
@mysticatea
Copy link
Member Author

Yes, this rule covers var and const.

I thought this rule is super simple.

return {
    "ObjectPattern": function(node) {
        if (node.properties.length === 0) {
            context.report(node, "Unexpected empty object pattern.");
        }
    },
    "ArrayPattern": function(node) {
        if (node.elements.length === 0) {
            context.report(node, "Unexpected empty array pattern.");
        }
    }
};

@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Sep 6, 2015
@nzakas
Copy link
Member

nzakas commented Sep 6, 2015

Yeah, seems like a good idea

@mysticatea mysticatea added the good first issue Good for people who haven't worked on ESLint before label Sep 18, 2015
@nzakas nzakas changed the title Rule Proposal: no-empty-pattern Rule Proposal: no-empty-pattern [$10] Sep 26, 2015
@nzakas nzakas added the bounty Someone has posted a bounty for this issue on BountySource label Sep 26, 2015
@alberto
Copy link
Member

alberto commented Sep 29, 2015

@mysticatea are you working on this?

@mysticatea
Copy link
Member Author

@alberto No yet. I am happy if you work on this :)

@alberto
Copy link
Member

alberto commented Sep 29, 2015

Thanks, I'll give it a try. :)

ilyavolodin added a commit that referenced this issue Oct 5, 2015
New: no-empty-pattern rule (fixes #3668)
@nzakas
Copy link
Member

nzakas commented Oct 6, 2015

@alberto
Copy link
Member

alberto commented Oct 6, 2015

That should go to @mysticatea, it was all his code. :)

@nzakas
Copy link
Member

nzakas commented Oct 6, 2015

Okay, @mysticatea there's money for you!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bounty Someone has posted a bounty for this issue on BountySource enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants