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-unused-labels` #5052

Closed
mysticatea opened this issue Jan 24, 2016 · 7 comments

Comments

Projects
None yet
4 participants
@mysticatea
Copy link
Member

commented Jan 24, 2016

This rule is similar to no-unused-vars.
This rule warns unused labels.

The following patterns are considered problems:

/*eslint no-unused-labels: 2*/

A: {                               /*error 'A:' is defined but never used.*/
    foo();
}

B: for (let i = 0; i < 10; ++i) {  /*error 'B:' is defined but never used.*/
    foo();
}

// I hope, in cases that we can use unlabeled break/continue.
C:                                 /*error 'C:' is defined but not needed.*/
for (let i = 0; i < 10; ++i) {
    if (foo()) {
        break C;
    }
    bar();
}

The following patterns are not considered problems:

/*eslint no-unused-labels: 2*/

A: {
    if (foo()) {
        break A;
    }
    bar();
}

B:
for (let i = 0; i < 10; ++i) {
    for (let j = 0; j < 10; ++j) {
        if (foo()) {
            break B;
        }
    }
    bar();
}
@mysticatea

This comment has been minimized.

Copy link
Member Author

commented Jan 24, 2016

This rule may be covering the domain of no-empty-label. Because the "empty" labels cannot be used.

@michaelficarra

This comment has been minimized.

Copy link
Member

commented Jan 24, 2016

With the C case, the label is redundant, but cannot be naively removed without also changing the break statement. @nzakas might have a problem with that.

@alberto

This comment has been minimized.

Copy link
Member

commented Jan 24, 2016

Maybe there should be a specific no-unneded-label rule to error on break C and leave it out from this one.

@nzakas

This comment has been minimized.

Copy link
Member

commented Jan 24, 2016

Yeah, might be best to break up cases A and B from C, just to be clear. The error on C seems like it would be on the break rather than the label.

@mysticatea

This comment has been minimized.

Copy link
Member Author

commented Jan 25, 2016

OK, I split out the C case from this proposal.

The following patterns are considered problems:

/*eslint no-unused-labels: 2*/

A: {                               /*error 'A:' is defined but never used.*/
    foo();
}

B: for (let i = 0; i < 10; ++i) {  /*error 'B:' is defined but never used.*/
    foo();
}

The following patterns are not considered problems:

/*eslint no-unused-labels: 2*/

A: {
    if (foo()) {
        break A;
    }
    bar();
}

B:
for (let i = 0; i < 10; ++i) {
    if (foo()) {
        break B;
    }
    bar();
}
@nzakas

This comment has been minimized.

Copy link
Member

commented Jan 25, 2016

Looks good. 👍

@mysticatea

This comment has been minimized.

Copy link
Member Author

commented Jan 27, 2016

I'm working on this.

@mysticatea mysticatea self-assigned this Jan 27, 2016

mysticatea added a commit to mysticatea/eslint that referenced this issue Jan 27, 2016

mysticatea added a commit to mysticatea/eslint that referenced this issue Jan 28, 2016

@nzakas nzakas closed this in #5081 Feb 1, 2016

nzakas added a commit that referenced this issue Feb 1, 2016

Merge pull request #5081 from mysticatea/no-unused-labels/new
New: `no-unused-labels` rule (fixes #5052)

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.