Skip to content

Commit 8559324

Browse files
authored
Use more optional chaining in TS extension (microsoft#152271)
Use optional chaining in TS extension Also removes `prefer-const` since this is now enabled globally
1 parent 4fc5d76 commit 8559324

File tree

10 files changed

+14
-14
lines changed

10 files changed

+14
-14
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"rules": {
3-
"prefer-const": "error"
3+
"@typescript-eslint/prefer-optional-chain": "warn"
44
}
55
}

extensions/typescript-language-features/src/languageFeatures/codeLens/baseCodeLensProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function getSymbolRange(
8888
}
8989

9090
// In older versions, we have to calculate this manually. See #23924
91-
const span = item.spans && item.spans[0];
91+
const span = item.spans?.[0];
9292
if (!span) {
9393
return undefined;
9494
}

extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class TypeScriptSignatureHelpProvider implements vscode.SignatureHelpProvider {
6464

6565
private getActiveParameter(info: Proto.SignatureHelpItems): number {
6666
const activeSignature = info.items[info.selectedItemIndex];
67-
if (activeSignature && activeSignature.isVariadic) {
67+
if (activeSignature?.isVariadic) {
6868
return Math.min(info.argumentIndex, activeSignature.parameters.length - 1);
6969
}
7070
return info.argumentIndex;

extensions/typescript-language-features/src/languageFeatures/tagClosing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TagClosing extends Disposable {
5353
return;
5454
}
5555

56-
const activeDocument = vscode.window.activeTextEditor && vscode.window.activeTextEditor.document;
56+
const activeDocument = vscode.window.activeTextEditor?.document;
5757
if (document !== activeDocument) {
5858
return;
5959
}

extensions/typescript-language-features/src/tsServer/versionProvider.electron.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class DiskTypeScriptVersionProvider implements ITypeScriptVersionProvider
2828
public get globalVersion(): TypeScriptVersion | undefined {
2929
if (this.configuration?.globalTsdk) {
3030
const globals = this.loadVersionsFromSetting(TypeScriptVersionSource.UserSetting, this.configuration.globalTsdk);
31-
if (globals && globals.length) {
31+
if (globals?.length) {
3232
return globals[0];
3333
}
3434
}
@@ -37,7 +37,7 @@ export class DiskTypeScriptVersionProvider implements ITypeScriptVersionProvider
3737

3838
public get localVersion(): TypeScriptVersion | undefined {
3939
const tsdkVersions = this.localTsdkVersions;
40-
if (tsdkVersions && tsdkVersions.length) {
40+
if (tsdkVersions?.length) {
4141
return tsdkVersions[0];
4242
}
4343

extensions/typescript-language-features/src/typescriptServiceClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
883883
this.loadingIndicator.reset();
884884

885885
const diagnosticEvent = event as Proto.DiagnosticEvent;
886-
if (diagnosticEvent.body && diagnosticEvent.body.diagnostics) {
886+
if (diagnosticEvent.body?.diagnostics) {
887887
this._onDiagnosticsReceived.fire({
888888
kind: getDignosticsKind(event),
889889
resource: this.toResource(diagnosticEvent.body.file),

extensions/typescript-language-features/src/utils/async.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class Delayer<T> {
1313

1414
public defaultDelay: number;
1515
private timeout: any; // Timer
16-
private completionPromise: Promise<T | null> | null;
16+
private completionPromise: Promise<T | undefined> | null;
1717
private onSuccess: ((value: T | PromiseLike<T> | undefined) => void) | null;
1818
private task: ITask<T> | null;
1919

@@ -25,7 +25,7 @@ export class Delayer<T> {
2525
this.task = null;
2626
}
2727

28-
public trigger(task: ITask<T>, delay: number = this.defaultDelay): Promise<T | null> {
28+
public trigger(task: ITask<T>, delay: number = this.defaultDelay): Promise<T | undefined> {
2929
this.task = task;
3030
if (delay >= 0) {
3131
this.cancelTimeout();
@@ -37,7 +37,7 @@ export class Delayer<T> {
3737
}).then(() => {
3838
this.completionPromise = null;
3939
this.onSuccess = null;
40-
const result = this.task && this.task();
40+
const result = this.task?.();
4141
this.task = null;
4242
return result;
4343
});

extensions/typescript-language-features/src/utils/codeAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function getEditForCodeAction(
1212
client: ITypeScriptServiceClient,
1313
action: Proto.CodeAction
1414
): vscode.WorkspaceEdit | undefined {
15-
return action.changes && action.changes.length
15+
return action.changes?.length
1616
? typeConverters.WorkspaceEdit.fromFileCodeEdits(client, action.changes)
1717
: undefined;
1818
}
@@ -36,7 +36,7 @@ export async function applyCodeActionCommands(
3636
commands: ReadonlyArray<{}> | undefined,
3737
token: vscode.CancellationToken,
3838
): Promise<boolean> {
39-
if (commands && commands.length) {
39+
if (commands?.length) {
4040
for (const command of commands) {
4141
await client.execute('applyCodeActionCommand', { command }, token);
4242
}

extensions/typescript-language-features/src/utils/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export enum TsServerLogLevel {
1515

1616
export namespace TsServerLogLevel {
1717
export function fromString(value: string): TsServerLogLevel {
18-
switch (value && value.toLowerCase()) {
18+
switch (value?.toLowerCase()) {
1919
case 'normal':
2020
return TsServerLogLevel.Normal;
2121
case 'terse':

extensions/typescript-language-features/src/utils/telemetry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class VSCodeTelemetryReporter implements TelemetryReporter {
5555

5656
@memoize
5757
private get reporter(): VsCodeTelemetryReporter | null {
58-
if (this.packageInfo && this.packageInfo.aiKey) {
58+
if (this.packageInfo?.aiKey) {
5959
this._reporter = new VsCodeTelemetryReporter(
6060
this.packageInfo.name,
6161
this.packageInfo.version,

0 commit comments

Comments
 (0)