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

Update @typescript-eslint/parser to v7 #2313

Merged
merged 2 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@babel/core": "^7.23.6",
"@babel/eslint-parser": "^7.23.3",
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
"@typescript-eslint/parser": "^6.15.0",
"@typescript-eslint/parser": "^7.5.0",
"ava": "^6.0.1",
"c8": "^8.0.1",
"chalk": "^5.3.0",
Expand Down
18 changes: 2 additions & 16 deletions rules/no-useless-switch-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,17 @@ const create = context => ({
* SwitchStatement(switchStatement) {
const {cases} = switchStatement;

// TypeScript allows multiple `default` cases
const defaultCases = cases.filter(switchCase => switchCase.test === null);
if (defaultCases.length !== 1) {
return;
}

const [defaultCase] = defaultCases;

// We only check cases where the last case is the `default` case
if (defaultCase !== cases.at(-1)) {
if (cases.length < 2 || cases.at(-1).test !== null) {
return;
}

const uselessCases = [];

for (let index = cases.length - 2; index >= 0; index--) {
const node = cases[index];
if (isEmptySwitchCase(node)) {
uselessCases.unshift(node);
} else {
if (!isEmptySwitchCase(node)) {
break;
}
}

for (const node of uselessCases) {
yield {
node,
loc: getSwitchCaseHeadLocation(node, context.sourceCode),
Expand Down
17 changes: 0 additions & 17 deletions test/no-useless-switch-case.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,3 @@ test.snapshot({
`,
],
});

test.typescript({
valid: [
outdent`
switch (1) {
default:
handleDefaultCase1();
break;
case 1:
default:
handleDefaultCase2();
break;
}
`,
],
invalid: [],
});