Skip to content

Commit 50aeca5

Browse files
author
Kartik Raj
authored
Fix all typescript errors when compiled in strict mode #7 (#4423)
* more corrections * Merge conflicts * corrections * Delete jupyterServerManager.unit.test.ts * corrections * CI * more corrections * corrections * corrections * correct
1 parent 6561f29 commit 50aeca5

15 files changed

Lines changed: 76 additions & 90 deletions

File tree

src/client/datascience/jupyter/liveshare/serverCache.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ import { IAsyncDisposable, IConfigurationService } from '../../../common/types';
1212
import { INotebookServer, INotebookServerOptions } from '../../types';
1313

1414
export class ServerCache implements IAsyncDisposable {
15-
private cache : Map<string, INotebookServer> = new Map<string, INotebookServer>();
15+
private cache: Map<string, INotebookServer> = new Map<string, INotebookServer>();
1616
private emptyKey = uuid();
1717

1818
constructor(
1919
private configService: IConfigurationService,
2020
private workspace: IWorkspaceService,
2121
private fileSystem: IFileSystem
22-
) {}
22+
) { }
2323

24-
public async get(options?: INotebookServerOptions) : Promise<INotebookServer | undefined> {
24+
public async get(options?: INotebookServerOptions): Promise<INotebookServer | undefined> {
2525
const fixedOptions = await this.generateDefaultOptions(options);
2626
const key = this.generateKey(fixedOptions);
2727
if (this.cache.has(key)) {
2828
return this.cache.get(key);
2929
}
3030
}
3131

32-
public async set(result: INotebookServer, disposeCallback: () => void, options?: INotebookServerOptions) : Promise<void> {
32+
public async set(result: INotebookServer, disposeCallback: () => void, options?: INotebookServerOptions): Promise<void> {
3333
const fixedOptions = await this.generateDefaultOptions(options);
3434
const key = this.generateKey(fixedOptions);
3535

@@ -52,25 +52,24 @@ export class ServerCache implements IAsyncDisposable {
5252
};
5353
}
5454

55-
public async dispose() : Promise<void> {
56-
// tslint:disable-next-line:no-unused-variable
57-
for (const [k, s] of this.cache) {
55+
public async dispose(): Promise<void> {
56+
for (const [, s] of this.cache) {
5857
await s.dispose();
5958
}
6059
this.cache.clear();
6160
}
6261

63-
public async generateDefaultOptions(options? : INotebookServerOptions) : Promise<INotebookServerOptions> {
62+
public async generateDefaultOptions(options?: INotebookServerOptions): Promise<INotebookServerOptions> {
6463
return {
6564
uri: options ? options.uri : undefined,
66-
useDefaultConfig : options ? options.useDefaultConfig : true, // Default for this is true.
67-
usingDarkTheme : options ? options.usingDarkTheme : undefined,
68-
purpose : options ? options.purpose : uuid(),
69-
workingDir : options && options.workingDir ? options.workingDir : await this.calculateWorkingDirectory()
65+
useDefaultConfig: options ? options.useDefaultConfig : true, // Default for this is true.
66+
usingDarkTheme: options ? options.usingDarkTheme : undefined,
67+
purpose: options ? options.purpose : uuid(),
68+
workingDir: options && options.workingDir ? options.workingDir : await this.calculateWorkingDirectory()
7069
};
7170
}
7271

73-
private generateKey(options?: INotebookServerOptions) : string {
72+
private generateKey(options?: INotebookServerOptions): string {
7473
if (!options) {
7574
return this.emptyKey;
7675
} else {

src/client/datascience/liveshare/postOffice.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ interface IMessageArgs {
1919
export class PostOffice implements IAsyncDisposable {
2020

2121
private name: string;
22-
private started : Promise<vsls.LiveShare | null>;
23-
private hostServer : vsls.SharedService | null = null;
24-
private guestServer : vsls.SharedServiceProxy | null = null;
25-
private currentRole : vsls.Role = vsls.Role.None;
22+
private started: Promise<vsls.LiveShare | null>;
23+
private hostServer: vsls.SharedService | null = null;
24+
private guestServer: vsls.SharedServiceProxy | null = null;
25+
private currentRole: vsls.Role = vsls.Role.None;
2626
private currentPeerCount: number = 0;
27-
private peerCountChangedEmitter : vscode.EventEmitter<number> = new vscode.EventEmitter<number>();
28-
private commandMap : { [key: string] : { thisArg: any; callback(...args: any[]) : void } } = {};
27+
private peerCountChangedEmitter: vscode.EventEmitter<number> = new vscode.EventEmitter<number>();
28+
private commandMap: { [key: string]: { thisArg: any; callback(...args: any[]): void } } = {};
2929

3030
constructor(
3131
name: string,
@@ -41,7 +41,7 @@ export class PostOffice implements IAsyncDisposable {
4141
return this.currentPeerCount;
4242
}
4343

44-
public get peerCountChanged() : vscode.Event<number> {
44+
public get peerCountChanged(): vscode.Event<number> {
4545
return this.peerCountChangedEmitter.event;
4646
}
4747

@@ -57,7 +57,7 @@ export class PostOffice implements IAsyncDisposable {
5757
this.guestServer = null;
5858
}
5959

60-
public async postCommand(command: string, ...args: any[]) : Promise<void> {
60+
public async postCommand(command: string, ...args: any[]): Promise<void> {
6161
// Make sure startup finished
6262
const api = await this.started;
6363
let skipDefault = false;
@@ -88,7 +88,7 @@ export class PostOffice implements IAsyncDisposable {
8888
}
8989
}
9090

91-
public async registerCallback(command: string, callback: (...args: any[]) => void, thisArg?: any) : Promise<void> {
91+
public async registerCallback(command: string, callback: (...args: any[]) => void, thisArg?: any): Promise<void> {
9292
const api = await this.started;
9393

9494
// For a guest, make sure to register the notification
@@ -100,11 +100,11 @@ export class PostOffice implements IAsyncDisposable {
100100
this.commandMap[command] = { callback, thisArg };
101101
}
102102

103-
private createBroadcastArgs(command: string, ...args: any[]) : IMessageArgs {
103+
private createBroadcastArgs(command: string, ...args: any[]): IMessageArgs {
104104
return { args: JSON.stringify([command, ...args]) };
105105
}
106106

107-
private translateArgs(api: vsls.LiveShare, command: string, ...args: any[]) : IMessageArgs {
107+
private translateArgs(api: vsls.LiveShare, command: string, ...args: any[]): IMessageArgs {
108108
// Make sure to eliminate all .toJSON functions on our arguments. Otherwise they're stringified incorrectly
109109
for (let a = 0; a <= args.length; a += 1) {
110110
// Eliminate this on only object types (https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript)
@@ -130,12 +130,12 @@ export class PostOffice implements IAsyncDisposable {
130130
return { args: JSON.stringify(copyArgs) };
131131
}
132132

133-
private escapeCommandName(command: string) : string {
133+
private escapeCommandName(command: string): string {
134134
// Replace . with $ instead.
135135
return command.replace(/\./g, '$');
136136
}
137137

138-
private unescapeCommandName(command: string) : string {
138+
private unescapeCommandName(command: string): string {
139139
// Turn $ back into .
140140
return command.replace(/\$/g, '.');
141141
}
@@ -153,7 +153,7 @@ export class PostOffice implements IAsyncDisposable {
153153
}
154154
}
155155

156-
private getCallback(command: string) : ((...args: any[]) => void) | undefined {
156+
private getCallback(command: string): ((...args: any[]) => void) | undefined {
157157
let callback = this.commandMap.hasOwnProperty(command) ? this.commandMap[command].callback : undefined;
158158
if (callback) {
159159
// Bind the this arg if necessary
@@ -166,7 +166,7 @@ export class PostOffice implements IAsyncDisposable {
166166
return callback;
167167
}
168168

169-
private async startCommandServer() : Promise<vsls.LiveShare | null> {
169+
private async startCommandServer(): Promise<vsls.LiveShare | null> {
170170
const api = await this.liveShareApi.getApi();
171171
if (api !== null) {
172172
api.onDidChangeSession(() => this.onChangeSession(api).ignoreErrors());
@@ -177,7 +177,7 @@ export class PostOffice implements IAsyncDisposable {
177177
return api;
178178
}
179179

180-
private async onChangeSession(api: vsls.LiveShare) : Promise<void> {
180+
private async onChangeSession(api: vsls.LiveShare): Promise<void> {
181181
// Startup or shutdown our connection to the other side
182182
if (api.session) {
183183
if (this.currentRole !== api.session.role) {
@@ -209,7 +209,7 @@ export class PostOffice implements IAsyncDisposable {
209209
}
210210
}
211211

212-
private async onChangePeers(api: vsls.LiveShare) : Promise<void> {
212+
private async onChangePeers(api: vsls.LiveShare): Promise<void> {
213213
let newPeerCount = 0;
214214
if (api.session) {
215215
newPeerCount = api.peers.length;
@@ -226,7 +226,7 @@ export class PostOffice implements IAsyncDisposable {
226226
if (a.args.length > 0) {
227227
const jsonArray = JSON.parse(a.args) as JSONArray;
228228
if (jsonArray !== null && jsonArray.length >= 2) {
229-
const firstArg = jsonArray[0]; // More stupid hygiene problems.
229+
const firstArg = jsonArray[0]!; // More stupid hygiene problems.
230230
const command = firstArg !== null ? firstArg.toString() : '';
231231

232232
// Args need to be translated from guest to host

src/client/providers/jediProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { IS_WINDOWS } from '../common/platform/constants';
1717
import { IPythonExecutionFactory } from '../common/process/types';
1818
import { BANNER_NAME_PROPOSE_LS, IConfigurationService, ILogger, IPythonExtensionBanner, IPythonSettings } from '../common/types';
1919
import { createDeferred, Deferred } from '../common/utils/async';
20-
import { debounce, swallowExceptions } from '../common/utils/decorators';
20+
import { swallowExceptions } from '../common/utils/decorators';
2121
import { StopWatch } from '../common/utils/stopWatch';
2222
import { IEnvironmentVariablesProvider } from '../common/variables/types';
2323
import { IInterpreterService } from '../interpreter/contracts';
@@ -296,7 +296,7 @@ export class JediProxy implements Disposable {
296296
this.additionalAutoCompletePaths = await this.buildAutoCompletePaths();
297297
this.restartLanguageServer().ignoreErrors();
298298
}
299-
@debounce(1500)
299+
// @debounce(1500)
300300
@swallowExceptions('JediProxy')
301301
private async environmentVariablesChangeHandler() {
302302
const newAutoComletePaths = await this.buildAutoCompletePaths();

src/client/unittests/pytest/services/testMessageService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,13 @@ export class TestMessageService implements ITestMessageService {
246246
}
247247
// Found the line to process.
248248
parentScopeStartIndex = suiteDefLineIndex;
249-
parentIndentation = indentation;
249+
parentIndentation = indentation!;
250250

251251
// Invert the index to get the unreversed equivalent.
252252
const realIndex = (reversedTestFileLines.length - 1) - suiteDefLineIndex;
253-
const startChar = indentation + classPrefix.length;
253+
const startChar = indentation! + classPrefix.length;
254254
const suiteStartPos = new Position(realIndex, startChar);
255-
const suiteEndPos = new Position(realIndex, (startChar + suiteName.length));
255+
const suiteEndPos = new Position(realIndex, (startChar + suiteName!.length));
256256
const suiteRange = new Range(suiteStartPos, suiteEndPos);
257257
const suiteLocation = new Location(testFileUri, suiteRange);
258258
suiteLocationStackFrameDetails.push({ location: suiteLocation, lineText: testFile.getText(suiteRange) });

src/test/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// tslint:disable:no-console no-require-imports no-var-requires
66

7-
import * as arch from 'arch';
87
import * as assert from 'assert';
98
import * as fs from 'fs-extra';
109
import * as glob from 'glob';
@@ -32,6 +31,7 @@ export const rootWorkspaceUri = getWorkspaceRoot();
3231

3332
export const PYTHON_PATH = getPythonPath();
3433

34+
const arch = require('arch');
3535
export const IS_64_BIT = arch() === 'x64';
3636

3737
export enum OSType {

src/test/common/installer/installer.invalidPath.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ suite('Module Installer - Invalid Paths', () => {
8383
persistValue.setup(pv => pv.value).returns(() => false);
8484
persistValue.setup(pv => pv.updateValue(TypeMoq.It.isValue(true)));
8585
persistentState.setup(ps =>
86-
ps.createGlobalPersistentState(TypeMoq.It.isAnyString(), TypeMoq.It.isValue(undefined))
86+
ps.createGlobalPersistentState<boolean>(TypeMoq.It.isAnyString(), TypeMoq.It.isValue(undefined))
8787
).returns(() => persistValue.object);
8888
await installer.promptToInstall(product.value, resource);
8989
productPathService.verifyAll();

src/test/common/platform/platformService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ suite('PlatformService', () => {
5757

5858
test('is64bit', async () => {
5959
// tslint:disable-next-line:no-require-imports
60-
const arch = require('arch') as typeof import('arch');
60+
const arch = require('arch');
6161

6262
const hostReports64Bit = arch() === 'x64';
6363
const svc = new PlatformService();

src/test/datascience/notebook.functional.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { JupyterExecutionFactory } from '../../client/datascience/jupyter/jupyte
2323
import { IRoleBasedObject, RoleBasedFactory } from '../../client/datascience/jupyter/liveshare/roleBasedFactory';
2424
import {
2525
CellState,
26-
ICell,
2726
IConnection,
2827
IJupyterExecution,
2928
IJupyterKernelSpec,
@@ -207,7 +206,7 @@ suite('Jupyter notebook tests', () => {
207206
// Catch exceptions. Throw a specific assertion if the promise fails
208207
try {
209208
const testDir = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'datascience');
210-
const server = await jupyterExecution.connectToNotebookServer({ usingDarkTheme, useDefaultConfig, workingDir: testDir, purpose: purpose ? purpose : '1'});
209+
const server = await jupyterExecution.connectToNotebookServer({ usingDarkTheme, useDefaultConfig, workingDir: testDir, purpose: purpose ? purpose : '1' });
211210
if (expectFailure) {
212211
assert.ok(false, `Expected server to not be created`);
213212
}
@@ -255,7 +254,7 @@ suite('Jupyter notebook tests', () => {
255254
const uri = connString as string;
256255

257256
// We have a connection string here, so try to connect jupyterExecution to the notebook server
258-
const server = await jupyterExecution.connectToNotebookServer({ uri, useDefaultConfig: true, purpose: ''});
257+
const server = await jupyterExecution.connectToNotebookServer({ uri, useDefaultConfig: true, purpose: '' });
259258
if (!server) {
260259
assert.fail('Failed to connect to remote server');
261260
}
@@ -492,9 +491,7 @@ suite('Jupyter notebook tests', () => {
492491
const finishedPromise = createDeferred();
493492
let error;
494493
const observable = server!.executeObservable(code, 'foo.py', 0, uuid(), false);
495-
let cells: ICell[] = [];
496494
observable.subscribe(c => {
497-
cells = c;
498495
if (c.length > 0 && c[0].state === CellState.error) {
499496
finishedBefore = !interrupted;
500497
finishedPromise.resolve();
@@ -590,17 +587,17 @@ while keep_going:
590587
await sleep(100);
591588

592589
// Try with something we can interrupt
593-
let interruptResult = await interruptExecute(server, returnable, 1000, 1000);
590+
await interruptExecute(server, returnable, 1000, 1000);
594591

595592
// Try again with something that doesn't return. However it should finish before
596593
// we get to our own sleep. Note: We need the print so that the test knows something happened.
597-
interruptResult = await interruptExecute(server, fourSecondSleep, 7000, 7000);
594+
await interruptExecute(server, fourSecondSleep, 7000, 7000);
598595

599596
// Try again with something that doesn't return. Make sure it times out
600-
interruptResult = await interruptExecute(server, fourSecondSleep, 100, 7000);
597+
await interruptExecute(server, fourSecondSleep, 100, 7000);
601598

602599
// The tough one, somethign that causes a kernel reset.
603-
interruptResult = await interruptExecute(server, kill, 1000, 1000);
600+
await interruptExecute(server, kill, 1000, 1000);
604601
});
605602

606603
testMimeTypes(

src/test/linters/lint.provider.test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ suite('Linting - Provider', () => {
9797
document.setup(x => x.uri).returns(() => vscode.Uri.file('test.py'));
9898
document.setup(x => x.languageId).returns(() => 'python');
9999

100-
// tslint:disable-next-line:no-unused-variable
101-
const provider = new LinterProvider(context.object, serviceContainer);
100+
// tslint:disable-next-line:no-unused-expression
101+
new LinterProvider(context.object, serviceContainer);
102102
emitter.fire(document.object);
103103
engine.verify(x => x.lintDocument(document.object, 'auto'), TypeMoq.Times.once());
104104
});
@@ -108,8 +108,8 @@ suite('Linting - Provider', () => {
108108
document.setup(x => x.uri).returns(() => vscode.Uri.file('test.py'));
109109
document.setup(x => x.languageId).returns(() => 'python');
110110

111-
// tslint:disable-next-line:no-unused-variable
112-
const provider = new LinterProvider(context.object, serviceContainer);
111+
// tslint:disable-next-line:no-unused-expression
112+
new LinterProvider(context.object, serviceContainer);
113113
emitter.fire(document.object);
114114
engine.verify(x => x.lintDocument(document.object, 'save'), TypeMoq.Times.once());
115115
});
@@ -119,8 +119,8 @@ suite('Linting - Provider', () => {
119119
document.setup(x => x.uri).returns(() => vscode.Uri.file('test.cs'));
120120
document.setup(x => x.languageId).returns(() => 'csharp');
121121

122-
// tslint:disable-next-line:no-unused-variable
123-
const provider = new LinterProvider(context.object, serviceContainer);
122+
// tslint:disable-next-line:no-unused-expression
123+
new LinterProvider(context.object, serviceContainer);
124124
emitter.fire(document.object);
125125
engine.verify(x => x.lintDocument(document.object, 'save'), TypeMoq.Times.never());
126126
});
@@ -130,8 +130,8 @@ suite('Linting - Provider', () => {
130130
document.setup(x => x.uri).returns(() => vscode.Uri.file('test.cs'));
131131
document.setup(x => x.languageId).returns(() => 'csharp');
132132

133-
// tslint:disable-next-line:no-unused-variable
134-
const provider = new LinterProvider(context.object, serviceContainer);
133+
// tslint:disable-next-line:no-unused-expression
134+
new LinterProvider(context.object, serviceContainer);
135135
emitter.fire(document.object);
136136
engine.verify(x => x.lintDocument(document.object, 'save'), TypeMoq.Times.never());
137137
});
@@ -140,8 +140,8 @@ suite('Linting - Provider', () => {
140140
const e = new vscode.EventEmitter<void>();
141141
interpreterService.setup(x => x.onDidChangeInterpreter).returns(() => e.event);
142142

143-
// tslint:disable-next-line:no-unused-variable
144-
const provider = new LinterProvider(context.object, serviceContainer);
143+
// tslint:disable-next-line:no-unused-expression
144+
new LinterProvider(context.object, serviceContainer);
145145
e.fire();
146146
engine.verify(x => x.lintOpenPythonFiles(), TypeMoq.Times.once());
147147
});
@@ -151,8 +151,8 @@ suite('Linting - Provider', () => {
151151
document.setup(x => x.uri).returns(() => vscode.Uri.file('.pylintrc'));
152152

153153
await lm.setActiveLintersAsync([Product.pylint]);
154-
// tslint:disable-next-line:no-unused-variable
155-
const provider = new LinterProvider(context.object, serviceContainer);
154+
// tslint:disable-next-line:no-unused-expression
155+
new LinterProvider(context.object, serviceContainer);
156156
emitter.fire(document.object);
157157

158158
const deferred = createDeferred<void>();
@@ -173,7 +173,8 @@ suite('Linting - Provider', () => {
173173

174174
docManager.setup(x => x.textDocuments).returns(() => closed ? [] : [document.object]);
175175
// tslint:disable-next-line:prefer-const no-unused-variable
176-
const provider = new LinterProvider(context.object, serviceContainer);
176+
// tslint:disable-next-line:no-unused-expression
177+
new LinterProvider(context.object, serviceContainer);
177178

178179
emitter.fire(document.object);
179180
const timesExpected = closed ? TypeMoq.Times.once() : TypeMoq.Times.never();

0 commit comments

Comments
 (0)