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

Turn on no-fallthrough rule #11093

Merged
merged 2 commits into from Feb 7, 2020

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Feb 4, 2020

Q                       A
License MIT

Turn on the no-fallthrough ESLint rules, which is included in the eslint:recommended preset.

Related: #11089 (comment)

@JLHwung JLHwung added PR: Internal 🏠 A type of pull request used for our changelog categories area: eslint labels Feb 4, 2020
@@ -36,6 +36,7 @@ module.exports = function(api) {
case "standalone":
includeRegeneratorRuntime = true;
unambiguousSources.push("packages/babel-runtime/regenerator");
// fall through
Copy link
Member

Choose a reason for hiding this comment

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

I hate that prettier doesn't include this comment, since conceptually it's a control flow statement similar to break/continue.

Copy link
Member

Choose a reason for hiding this comment

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

Classic ambiguous comment indentation 😆


// yes: { [NODE]: "" }
// no: { NODE: "" }
// depends: { NODE }
// depends: { key: NODE }
// fall through
Copy link
Member

Choose a reason for hiding this comment

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

@kaicataldo The comment on line 57 is not enough. Could eslint/eslint#10608 be reopened? 🙏 😅

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should allow it to be either the first or last, but not the middle? I know it's unlikely, but I think it would be good to avoid something like this triggering it:

/* eslint no-fallthrough: ["error", { "commentPattern": "fall-through[\\s\\w]*not allowed" }] */

switch(foo) {
    case 1:
        doSomething();
        // We don't want to fall through here
        // because fall-through is not allowed,
        // oh look, a run on sentence.

    default:
        doSomething();
}

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this code already have that problem?

/* eslint no-fallthrough: ["error", { "commentPattern": "fall-through[\\s\\w]*not allowed" }] */

switch(foo) {
    case 1:
        doSomething();
        // We don't want to fall through here because fall-through is not allowed.

    default:
        doSomething();
}

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it would. Might just be me, but the grouped line comments seem more error prone. It probably is the same thing in practice, though.

@nicolo-ribaudo nicolo-ribaudo merged commit 0b3dea8 into babel:master Feb 7, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the turn-on-no-fallthrough branch February 7, 2020 21:05
rajasekarm pushed a commit to rajasekarm/babel that referenced this pull request Feb 17, 2020
* chore: turn on no-fallthrough

* chore: fix no-fallthrough errors
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 10, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: eslint outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants