xojs/xo

default-case & @typescript-eslint/switch-exhaustiveness-check conflict with each other

Closed this issue ยท 3 comments

Hello ๐Ÿ‘‹

I'm seeing what I think is a regression from xo 0.56.0 in xo 0.57.0. Previously, code like this would pass:

type Colour = 'red' | 'green' | 'blue';

function unknownColour(colour: never): never {
	throw new Error(`Unknown colour "${colour as string}"!`);
}

function colourToHex(colour: Colour) {
	switch (colour) {
		case 'red': {
			return '#ff0000';
		}

		case 'green': {
			return '#008000';
		}

		case 'blue': {
			return '#0000ff';
		}

		default: {
			return unknownColour(colour);
		}
	}
}

xo 0.57.0 instead throws back the following warning for this code:

  src/index.ts:21:3
  โœ–  21:3  The switch statement is exhaustive, so the default case is unnecessary.  @typescript-eslint/switch-exhaustiveness-check

But yet, if we delete the default case we see this warning instead:

  src/index.ts:8:2
  โœ–  8:2  Expected a default case.  default-case

Is this kind of code considered an anti-pattern now or did I find a bug?

Yes I had to disable/customize switch-exhaustiveness-check in my case

https://github.com/pixiebrix/eslint-config-pixiebrix/pull/231/files

Many thanks ๐Ÿ‘