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

New: Add no-unreachable-loop rule (fixes #12381) #12660

Merged
merged 2 commits into from Jun 13, 2020
Merged

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Dec 13, 2019

What is the purpose of this pull request? (put an "X" next to item)

[X] New rule

fixes #12381

Examples of incorrect code for this rule:

/*eslint no-unreachable-loop: "error"*/

while (foo) {
    doSomething(foo);
    foo = foo.parent;
    break;
}

function verifyList(head) {
    let item = head;
    do {
        if (verify(item)) {
            return true;
        } else {
            return false;
        }
    } while (item)
}

function findSomething(arr) {
    for (var i = 0; i < arr.length; i++) {
        if (isSomething(arr[i])) {
            return arr[i];
        } else {
            throw new Error("Doesn't exist.");
        }
    }
}

for (key in obj) {
    if (key.startsWith("_")) {
        break;
    }
    firstKey = key;
    firstValue = obj[key];
    break;
}

for (foo of bar) {
    if (foo.id === id) {
        doSomething(foo);
    }
    break;
}

What changes did you make? (Give an overview)

new rule: no-unreachable-loop

Is there anything you'd like reviewers to focus on?

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Dec 13, 2019
@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Dec 13, 2019
@aladdin-add aladdin-add self-requested a review May 25, 2020 10:34
@nzakas
Copy link
Member

nzakas commented Jun 11, 2020

@mdjermanovic are you still working on this?

@mdjermanovic
Copy link
Member Author

Yes, sorry I didn't have much time last week,

Copy link
Member

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! better to have one more reviewer on this~

@nzakas nzakas merged commit b550330 into master Jun 13, 2020
@nzakas nzakas deleted the no-unreachable-loop branch June 13, 2020 00:12
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 11, 2020
@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 Dec 11, 2020
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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New rule proposal: no-unreachable-loop
4 participants