Enable no-case-declarations in codebase (#139243)

Fixes #139236

This can catch tricky programming mistakes that cause a runtime error. See 7e266b2c42 as an example of the type of bug this can prevent
This commit is contained in:
Matt Bierner
2021-12-15 17:15:35 -08:00
committed by GitHub
parent f589173345
commit e7b3724e0c
68 changed files with 233 additions and 158 deletions

View File

@@ -69,11 +69,12 @@ export class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLens
}
switch (item.kind) {
case PConst.Kind.function:
case PConst.Kind.function: {
const showOnAllFunctions = vscode.workspace.getConfiguration(this.modeId).get<boolean>('referencesCodeLens.showOnAllFunctions');
if (showOnAllFunctions) {
return getSymbolRange(document, item);
}
}
// fallthrough
case PConst.Kind.const:

View File

@@ -816,10 +816,10 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
case '#': // Workaround for https://github.com/microsoft/TypeScript/issues/36367
return this.client.apiVersion.lt(API.v381) ? undefined : '#';
case ' ':
case ' ': {
const space: Proto.CompletionsTriggerCharacter = ' ';
return this.client.apiVersion.gte(API.v430) ? space : undefined;
}
case '.':
case '"':
case '\'':

View File

@@ -167,7 +167,7 @@ class BufferSynchronizer {
private updatePending(resource: vscode.Uri, op: BufferOperation): boolean {
switch (op.type) {
case BufferOperationType.Close:
case BufferOperationType.Close: {
const existing = this._pending.get(resource);
switch (existing?.type) {
case BufferOperationType.Open:
@@ -175,6 +175,7 @@ class BufferSynchronizer {
return false; // Open then close. No need to do anything
}
break;
}
}
if (this._pending.has(resource)) {

View File

@@ -148,7 +148,7 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
}
break;
case 'event':
case 'event': {
const event = message as Proto.Event;
if (event.event === 'requestCompleted') {
const seq = (event as Proto.RequestCompletedEvent).body.request_seq;
@@ -162,7 +162,7 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
this._onEvent.fire(event);
}
break;
}
default:
throw new Error(`Unknown message type ${message.type} received`);
}

View File

@@ -866,7 +866,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
switch (event.event) {
case EventName.syntaxDiag:
case EventName.semanticDiag:
case EventName.suggestionDiag:
case EventName.suggestionDiag: {
// This event also roughly signals that projects have been loaded successfully (since the TS server is synchronous)
this.loadingIndicator.reset();
@@ -879,34 +879,32 @@ export default class TypeScriptServiceClient extends Disposable implements IType
});
}
break;
}
case EventName.configFileDiag:
this._onConfigDiagnosticsReceived.fire(event as Proto.ConfigFileDiagnosticEvent);
break;
case EventName.telemetry:
{
const body = (event as Proto.TelemetryEvent).body;
this.dispatchTelemetryEvent(body);
break;
case EventName.telemetry: {
const body = (event as Proto.TelemetryEvent).body;
this.dispatchTelemetryEvent(body);
break;
}
case EventName.projectLanguageServiceState: {
const body = (event as Proto.ProjectLanguageServiceStateEvent).body!;
if (this.serverState.type === ServerState.Type.Running) {
this.serverState.updateLanguageServiceEnabled(body.languageServiceEnabled);
}
case EventName.projectLanguageServiceState:
{
const body = (event as Proto.ProjectLanguageServiceStateEvent).body!;
if (this.serverState.type === ServerState.Type.Running) {
this.serverState.updateLanguageServiceEnabled(body.languageServiceEnabled);
}
this._onProjectLanguageServiceStateChanged.fire(body);
break;
}
case EventName.projectsUpdatedInBackground:
this._onProjectLanguageServiceStateChanged.fire(body);
break;
}
case EventName.projectsUpdatedInBackground: {
this.loadingIndicator.reset();
const body = (event as Proto.ProjectsUpdatedInBackgroundEvent).body;
const resources = body.openFiles.map(file => this.toResource(file));
this.bufferSyncSupport.getErr(resources);
break;
}
case EventName.beginInstallTypes:
this._onDidBeginInstallTypings.fire((event as Proto.BeginInstallTypesEvent).body);
break;
@@ -936,7 +934,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
private dispatchTelemetryEvent(telemetryData: Proto.TelemetryEventBody): void {
const properties: { [key: string]: string } = Object.create(null);
switch (telemetryData.telemetryEventName) {
case 'typingsInstalled':
case 'typingsInstalled': {
const typingsInstalledPayload: Proto.TypingsInstalledTelemetryEventPayload = (telemetryData.payload as Proto.TypingsInstalledTelemetryEventPayload);
properties['installedPackages'] = typingsInstalledPayload.installedPackages;
@@ -947,8 +945,8 @@ export default class TypeScriptServiceClient extends Disposable implements IType
properties['typingsInstallerVersion'] = typingsInstalledPayload.typingsInstallerVersion;
}
break;
default:
}
default: {
const payload = telemetryData.payload;
if (payload) {
Object.keys(payload).forEach((key) => {
@@ -962,6 +960,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
});
}
break;
}
}
if (telemetryData.telemetryEventName === 'projectInfo') {
if (this.serverState.type === ServerState.Type.Running) {

View File

@@ -49,7 +49,7 @@ function getTagBodyText(
const text = convertLinkTags(tag.text, filePathConverter);
switch (tag.name) {
case 'example':
case 'example': {
// check for caption tags, fix for #79704
const captionTagMatches = text.match(/<caption>(.*?)<\/caption>\s*(\r\n|\n)/);
if (captionTagMatches && captionTagMatches.index === 0) {
@@ -57,7 +57,8 @@ function getTagBodyText(
} else {
return makeCodeblock(text);
}
case 'author':
}
case 'author': {
// fix obsucated email address, #80898
const emailMatch = text.match(/(.+)\s<([-.\w]+@[-.\w]+)>/);
@@ -66,6 +67,7 @@ function getTagBodyText(
} else {
return `${emailMatch[1]} ${emailMatch[2]}`;
}
}
case 'default':
return makeCodeblock(text);
}
@@ -81,7 +83,7 @@ function getTagDocumentation(
case 'augments':
case 'extends':
case 'param':
case 'template':
case 'template': {
const body = (convertLinkTags(tag.text, filePathConverter)).split(/^(\S+)\s*-?\s*/);
if (body?.length === 3) {
const param = body[1];
@@ -92,6 +94,7 @@ function getTagDocumentation(
}
return label + (doc.match(/\r\n|\n/g) ? ' \n' + processInlineTags(doc) : ` \u2014 ${processInlineTags(doc)}`);
}
}
}
// Generic tag