Skip to content

linter: eslint(no-fallthrough) breaks on multi-line case statements #21320

@zachkirsch

Description

@zachkirsch

What version of Oxlint are you using?

1.58.0

What command did you run?

oxlint

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

// Replace this with your actual config file contents.
// It can be helpful to keep it minimal, if possible, but please ensure that it actually reproduces the issue you're reporting.
{
  ...
  "rules": {
    "no-fallthrough": "error"
  }
}

What happened?

I noticed that sometimes when my case statement extends multiple lines, I get an incorrect error from the eslint(no-fallthrough) rule.

This works fine:

switch (color) {
  case Color.Red:
  case Color.Blue:
  case Color.Green:
    break;
  default:
    break;
}

but this causes a lint error (sorry for the contrived example):

const A = {
  B: {
    Red: "A",
    Green: "B",
    SuperDuperLongEnumValueWhoseNameIsWayTooLongTooFitOnOneLineSoItStretchesOntoTwoLinesAndBreaksOxlint:
      "C",
  },
};

declare const color: keyof typeof A.B;
switch (color) {
  case A.B.Red:
  case A.B
    .SuperDuperLongEnumValueWhoseNameIsWayTooLongTooFitOnOneLineSoItStretchesOntoTwoLinesAndBreaksOxlint:
  case A.B.Green: // <-- lint error here: Expected a `break` statement before `case`
    break;
  default:
    break;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions