Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [switch-exhaustiveness-check] suggest with qualified name#10697

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoshuaKGoldberg merged 4 commits intotypescript-eslint:mainfromyeonjuan:fix#7747
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,6 +142,16 @@ export default createRule<Options, MessageIds>({
return;
}

function typeToString(type: ts.Type): string {
return checker.typeToString(
type,
undefined,
ts.TypeFormatFlags.AllowUniqueESSymbolType |
ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope |
ts.TypeFormatFlags.UseFullyQualifiedType,
);
}

function getSwitchMetadata(node: TSESTree.SwitchStatement): SwitchMetadata {
const defaultCase = node.cases.find(
switchCase => switchCase.test == null,
Expand DownExpand Up@@ -230,7 +240,7 @@ export default createRule<Options, MessageIds>({
.map(missingType =>
tsutils.isTypeFlagSet(missingType, ts.TypeFlags.ESSymbolLike)
? `typeof ${missingType.getSymbol()?.escapedName as string}`
:checker.typeToString(missingType),
: typeToString(missingType),
)
.join(' | '),
},
Expand DownExpand Up@@ -282,7 +292,7 @@ export default createRule<Options, MessageIds>({
)
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
missingBranchName!
:checker.typeToString(missingBranchType);
: typeToString(missingBranchType);

if (
symbolName &&
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
export namespace A {
export enum B {
C,
D,
}
}
3 changes: 2 additions & 1 deletionpackages/eslint-plugin/tests/fixtures/tsconfig.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,7 @@
"mixed-enums-decl.ts",
"react.tsx",
"var-declaration.ts",
"errors.ts"
"errors.ts",
"switch-exhaustiveness-check.ts"
]
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2947,5 +2947,87 @@ switch (literal) {
},
],
},
{
code: `
export namespace A {
export enum B {
C,
D,
}
}
declare const foo: A.B;
switch (foo) {
case A.B.C: {
break;
}
}
`,
errors: [
{
column: 17,
data: {
missingBranches: 'A.B.D',
},
line: 9,
messageId: 'switchIsNotExhaustive',
suggestions: [
{
messageId: 'addMissingCases',
output: `
export namespace A {
export enum B {
C,
D,
}
}
declare const foo: A.B;
switch (foo) {
case A.B.C: {
break;
}
case A.B.D: { throw new Error('Not implemented yet: A.B.D case') }
}
`,
},
],
},
],
},
{
code: `
import { A } from './switch-exhaustiveness-check';
declare const foo: A.B;
switch (foo) {
case A.B.C: {
break;
}
}
`,
errors: [
{
column: 17,
data: {
missingBranches: 'A.B.D',
},
line: 4,
messageId: 'switchIsNotExhaustive',
suggestions: [
{
messageId: 'addMissingCases',
output: `
import { A } from './switch-exhaustiveness-check';
declare const foo: A.B;
switch (foo) {
case A.B.C: {
break;
}
case A.B.D: { throw new Error('Not implemented yet: A.B.D case') }
}
`,
},
],
},
],
},
],
});
Loading

[8]ページ先頭

©2009-2025 Movatter.jp