Enable stricter compile options on extensions (#5044)

* enable stricter compile settings in extensions

* more strict compile

* formatting

* formatting

* revert some changes

* formtting

* formatting
This commit is contained in:
Anthony Dresser
2019-04-23 11:18:00 -07:00
committed by GitHub
parent c66b349cec
commit 58959ef35e
51 changed files with 196 additions and 294 deletions

View File

@@ -38,7 +38,7 @@ export async function strictFindFreePort(options: StrictPortFindOptions): Promis
* @param max - max number
* @return a random integer
*/
function getRandomInt(min, max): number {
function getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}

View File

@@ -19,7 +19,7 @@ export function getLivyUrl(serverName: string, port: string): string {
}
export async function mkDir(dirPath: string, outputChannel?: vscode.OutputChannel): Promise<void> {
if (!await fs.exists(dirPath)) {
if (!await fs.pathExists(dirPath)) {
if (outputChannel) {
outputChannel.appendLine(localize('mkdirOutputMsg', '... Creating {0}', dirPath));
}

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import * as azdata from 'azdata';
@@ -34,7 +32,7 @@ export class ConfigurePythonDialog {
private _setupComplete: Deferred<void>;
constructor(private apiWrapper: ApiWrapper, private outputChannel: vscode.OutputChannel, private jupyterInstallation: JupyterServerInstallation) {
constructor(private apiWrapper: ApiWrapper, private jupyterInstallation: JupyterServerInstallation) {
this._setupComplete = new Deferred<void>();
}

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as vscode from 'vscode';
import * as azdata from 'azdata';
import * as os from 'os';
@@ -124,7 +122,7 @@ function findNextUntitledEditorName(): string {
async function openNotebook(): Promise<void> {
try {
let filter = {};
let filter: { [key: string]: Array<string> } = {};
// TODO support querying valid notebook file types
filter[localize('notebookFiles', "Notebooks")] = ['ipynb'];
let file = await vscode.window.showOpenDialog({

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as should from 'should';
import * as vscode from 'vscode';
import * as assert from 'assert';

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { nb } from 'azdata';
import * as vscode from 'vscode';
@@ -54,7 +52,7 @@ export class NotebookCompletionItemProvider implements vscode.CompletionItemProv
if (sessions && sessions.length > 0) {
let session = sessions.find(session => session.path === info.notebook.uri.path);
if (!session) {
return;
return undefined;
}
return session.kernel;
}
@@ -63,6 +61,7 @@ export class NotebookCompletionItemProvider implements vscode.CompletionItemProv
// If an exception occurs, swallow it currently
return undefined;
}
return undefined;
}
private findMatchingCell(document: vscode.TextDocument, allDocuments: nb.NotebookDocument[]): INewIntellisenseInfo {

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as path from 'path';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
@@ -118,8 +116,8 @@ export class JupyterController implements vscode.Disposable {
private async handleOpenNotebookTask(profile: azdata.IConnectionProfile): Promise<void> {
let notebookFileTypeName = localize('notebookFileType', 'Notebooks');
let filter = {};
filter[notebookFileTypeName] = 'ipynb';
let filter: { [key: string]: Array<string> } = {};
filter[notebookFileTypeName] = ['ipynb'];
let uris = await this.apiWrapper.showOpenDialog({
filters: filter,
canSelectFiles: true,
@@ -207,8 +205,8 @@ export class JupyterController implements vscode.Disposable {
}
public doConfigurePython(jupyterInstaller: JupyterServerInstallation): void {
let pythonDialog = new ConfigurePythonDialog(this.apiWrapper, this.outputChannel, jupyterInstaller);
pythonDialog.showDialog().catch(err => {
let pythonDialog = new ConfigurePythonDialog(this.apiWrapper, jupyterInstaller);
pythonDialog.showDialog().catch((err: any) => {
this.apiWrapper.showErrorMessage(utils.getErrorMessage(err));
});
}

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as nls from 'vscode-nls';
@@ -102,7 +100,7 @@ export default class JupyterServerInstallation {
.replace('#bundleversion', bundleVersion)
.replace('#extension', process.platform === constants.winPlatform ? 'zip' : 'tar.gz');
let pythonDownloadUrl = undefined;
let pythonDownloadUrl: string = undefined;
switch (utils.getOSPlatform()) {
case utils.Platform.Windows:
pythonDownloadUrl = 'https://go.microsoft.com/fwlink/?linkid=2074021';
@@ -117,9 +115,7 @@ export default class JupyterServerInstallation {
}
let pythonPackagePathLocal = this._pythonInstallationPath + '/' + packageName;
let self = undefined;
return new Promise((resolve, reject) => {
self = this;
backgroundOperation.updateStatus(azdata.TaskStatus.InProgress, msgDownloadPython(platformId, pythonDownloadUrl));
fs.mkdirs(this._pythonInstallationPath, (err) => {
if (err) {
@@ -169,7 +165,7 @@ export default class JupyterServerInstallation {
reject(err);
}
}
decompress(pythonPackagePathLocal, self._pythonInstallationPath).then(files => {
decompress(pythonPackagePathLocal, this._pythonInstallationPath).then(files => {
//Delete zip/tar file
fs.unlink(pythonPackagePathLocal, (err) => {
if (err) {
@@ -310,7 +306,7 @@ export default class JupyterServerInstallation {
*/
public async promptForPythonInstall(): Promise<void> {
if (!JupyterServerInstallation.isPythonInstalled(this.apiWrapper)) {
let pythonDialog = new ConfigurePythonDialog(this.apiWrapper, this.outputChannel, this);
let pythonDialog = new ConfigurePythonDialog(this.apiWrapper, this);
return pythonDialog.showDialog(true);
}
}

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { nb, ServerInfo, connection, IConnectionProfile } from 'azdata';
import { Session, Kernel } from '@jupyterlab/services';
import * as fs from 'fs-extra';
@@ -148,6 +146,7 @@ export class JupyterSessionManager implements nb.SessionManager {
if (this._sessionManager && !this._sessionManager.isDisposed) {
return this._sessionManager.shutdown(id);
}
return undefined;
}
public shutdownAll(): Promise<void> {
@@ -247,7 +246,6 @@ export class JupyterSession implements nb.ISession {
await this.getClusterEndpoint(connection.id, KNOX_ENDPOINT_KNOX) ||
await this.getClusterEndpoint(connection.id, KNOX_ENDPOINT_GATEWAY);
if (!clusterEndpoint) {
let kernelDisplayName: string = await this.getKernelDisplayName();
return Promise.reject(new Error(localize('connectionNotValid', 'Spark kernels require a connection to a SQL Server big data cluster master instance.')));
}
connection.options[KNOX_ENDPOINT_SERVER] = clusterEndpoint.ipAddress;
@@ -270,11 +268,6 @@ export class JupyterSession implements nb.ISession {
}
}
private async getKernelDisplayName(): Promise<string> {
let spec = await this.kernel.getSpec();
return spec.display_name;
}
private isSparkKernel(kernelName: string): boolean {
return kernelName && kernelName.toLowerCase().indexOf('spark') > -1;
}

View File

@@ -246,8 +246,8 @@ export class PerNotebookServerInstance implements IServerInstance {
this.childProcess = this.spawnJupyterProcess(install, startCommand);
let stdErrLog: string = '';
// Add listeners for the process exiting prematurely
let onErrorBeforeStartup = (err) => reject(err);
let onExitBeforeStart = (err) => {
let onErrorBeforeStartup = (err: any) => reject(err);
let onExitBeforeStart = (err: any) => {
if (!this.isStarted) {
reject(localize('notebookStartProcessExitPremature', 'Notebook process exited prematurely with error: {0}, StdErr Output: {1}', err, stdErrLog));
}
@@ -372,7 +372,7 @@ export class PerNotebookServerInstance implements IServerInstance {
}
private getEnvWithConfigPaths(env: {}): any {
let newEnv = Object.assign({}, env);
let newEnv: { [key: string]: string } = Object.assign({}, env);
newEnv['JUPYTER_CONFIG_DIR'] = this.instanceConfigRoot;
newEnv['JUPYTER_PATH'] = this.instanceDataRoot;
return newEnv;

View File

@@ -1,11 +1,7 @@
'use strict';
// This code is originally from https://github.com/DonJayamanne/bowerVSCode
// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE
import { window, OutputChannel } from 'vscode';
import * as Constants from '../common/constants';
import * as nodeUtil from 'util';
import { window } from 'vscode';
import PromptFactory from './factory';
import EscapeException from './escapeException';
import { IQuestion, IPrompter, IPromptCallback } from './question';
@@ -13,95 +9,12 @@ import { IQuestion, IPrompter, IPromptCallback } from './question';
// Supports simple pattern for prompting for user input and acting on this
export default class CodeAdapter implements IPrompter {
private outChannel: OutputChannel;
private outBuffer: string = '';
private messageLevelFormatters = {};
constructor() {
// TODO Decide whether output channel logging should be saved here?
this.outChannel = window.createOutputChannel(Constants.outputChannelName);
// this.outChannel.clear();
}
public logError(message: any): void {
let line = `error: ${message.message}\n Code - ${message.code}`;
this.outBuffer += `${line}\n`;
this.outChannel.appendLine(line);
}
// private formatInfo(message: any) {
// const prefix = `${message.level}: (${message.id}) `;
// if (message.id === "json") {
// let jsonString = JSON.stringify(message.data, undefined, 4);
// return `${prefix}${message.message}\n${jsonString}`;
// }
// else {
// return `${prefix}${message.message}`;
// }
// }
// private formatAction(message: any) {
// const prefix = `info: ${message.level}: (${message.id}) `;
// return `${prefix}${message.message}`;
// }
private formatMessage(message: any): string {
const prefix = `${message.level}: (${message.id}) `;
return `${prefix}${message.message}`;
}
// private formatConflict(message: any) {
// var msg = message.message + ':\n';
// var picks = (<any[]>message.data.picks);
// var pickCount = 1;
// picks.forEach((pick) => {
// let pickMessage = (pickCount++).toString() + "). " + pick.endpoint.name + "#" + pick.endpoint.target;
// if (pick.pkgMeta._resolution && pick.pkgMeta._resolution.tag) {
// pickMessage += " which resolved to " + pick.pkgMeta._resolution.tag
// }
// if (Array.isArray(pick.dependants) && pick.dependants.length > 0) {
// pickMessage += " and is required by ";
// pick.dependants.forEach((dep) => {
// pickMessage += " " + dep.endpoint.name + "#" + dep.endpoint.target;
// });
// }
// msg += " " + pickMessage + "\n";
// });
// var prefix = (message.id === "solved"? "info" : "warn") + `: ${message.level}: (${message.id}) `;
// return prefix + msg;
// }
public log(message: any): void {
let line: string = '';
if (message && typeof (message.level) === 'string') {
let formatter: (a: any) => string = this.formatMessage;
if (this.messageLevelFormatters[message.level]) {
formatter = this.messageLevelFormatters[message.level];
}
line = formatter(message);
} else {
line = nodeUtil.format(arguments);
}
this.outBuffer += `${line}\n`;
this.outChannel.appendLine(line);
}
public clearLog(): void {
this.outChannel.clear();
}
public showLog(): void {
this.outChannel.show();
}
// TODO define question interface
private fixQuestion(question: any): any {
if (question.type === 'checkbox' && Array.isArray(question.choices)) {
// For some reason when there's a choice of checkboxes, they aren't formatted properly
// Not sure where the issue is
question.choices = question.choices.map(item => {
question.choices = question.choices.map((item: any) => {
if (typeof (item) === 'string') {
return { checked: false, name: item, value: item };
} else {
@@ -118,6 +31,7 @@ export default class CodeAdapter implements IPrompter {
let response: T = answers[question.name];
return response || undefined;
}
return undefined;
});
}
@@ -139,7 +53,7 @@ export default class CodeAdapter implements IPrompter {
// }
if (!question.shouldPrompt || question.shouldPrompt(answers) === true) {
return prompt.render().then(result => {
return prompt.render().then((result: any) => {
answers[question.name] = result;
if (question.onAnswered) {

View File

@@ -1,5 +1,3 @@
'use strict';
// This code is originally from https://github.com/DonJayamanne/bowerVSCode
// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE
@@ -16,7 +14,7 @@ export default class CheckboxPrompt extends Prompt {
}
public render(): any {
let choices = this._question.choices.reduce((result, choice) => {
let choices = this._question.choices.reduce((result: any, choice: any) => {
let choiceName = choice.name || choice;
result[`${choice.checked === true ? figures.radioOn : figures.radioOff} ${choiceName}`] = choice;
return result;
@@ -40,7 +38,7 @@ export default class CheckboxPrompt extends Prompt {
return this.render();
}
return this._question.choices.reduce((result2, choice) => {
return this._question.choices.reduce((result2: any, choice: any) => {
if (choice.checked === true) {
result2.push(choice.value);
}

View File

@@ -1,5 +1,3 @@
'use strict';
// This code is originally from https://github.com/DonJayamanne/bowerVSCode
// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE
@@ -39,7 +37,7 @@ export default class ExpandPrompt extends Prompt {
});
}
private renderNameValueChoice(choices: INameValueChoice[]): any {
const choiceMap = this._question.choices.reduce((result, choice) => {
const choiceMap = this._question.choices.reduce((result: any, choice: any) => {
result[choice.name] = choice.value;
return result;
}, {});

View File

@@ -1,5 +1,3 @@
'use strict';
// This code is originally from https://github.com/DonJayamanne/bowerVSCode
// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE
@@ -14,7 +12,7 @@ export default class ListPrompt extends Prompt {
}
public render(): any {
const choices = this._question.choices.reduce((result, choice) => {
const choices = this._question.choices.reduce((result: any, choice: any) => {
result[choice.name] = choice.value;
return result;
}, {});

View File

@@ -3,11 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
export async function assertThrowsAsync(fn, regExp): Promise<void> {
export async function assertThrowsAsync(fn: () => Promise<any>, msg: string): Promise<void> {
let f = () => {
// Empty
};
@@ -16,6 +14,6 @@ export async function assertThrowsAsync(fn, regExp): Promise<void> {
} catch (e) {
f = () => { throw e; };
} finally {
assert.throws(f, regExp);
assert.throws(f, msg);
}
}

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as vscode from 'vscode';
import * as should from 'should';
import * as TypeMoq from 'typemoq';
@@ -33,7 +31,6 @@ let expectedNotebookContent: INotebook = {
nbformat: 5,
nbformat_minor: 0
};
let notebookContentString = JSON.stringify(expectedNotebookContent);
function verifyMatchesExpectedNotebook(notebook: nb.INotebookContents): void {
should(notebook.cells).have.length(1, 'Expected 1 cell');

View File

@@ -3,11 +3,8 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as should from 'should';
import * as TypeMoq from 'typemoq';
import * as vscode from 'vscode';
import * as stream from 'stream';
import { ChildProcess } from 'child_process';
import 'mocha';
@@ -73,8 +70,8 @@ describe('Jupyter server instance', function (): void {
it('Should have URI info after start', async function (): Promise<void> {
// Given startup will succeed
let process = setupSpawn({
sdtout: (listener) => undefined,
stderr: (listener) => listener(successMessage)
sdtout: (listener: (msg: string) => void) => { },
stderr: (listener: (msg: string) => void) => listener(successMessage)
});
mockUtils.setup(u => u.spawn(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => <ChildProcess>process.object);
@@ -103,9 +100,9 @@ describe('Jupyter server instance', function (): void {
it('Should throw if error before startup', async function (): Promise<void> {
let error = 'myerr';
let process = setupSpawn({
sdtout: (listener) => undefined,
stderr: (listener) => listener(successMessage),
error: (listener) => setTimeout(() => listener(new Error(error)), 10)
sdtout: (listener: (msg: string) => void) => { },
stderr: (listener: (msg: string) => void) => listener(successMessage),
error: (listener: (msg: string | Error) => void) => setTimeout(() => listener(new Error(error)), 10)
});
mockUtils.setup(u => u.spawn(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => <ChildProcess>process.object);
@@ -117,7 +114,7 @@ describe('Jupyter server instance', function (): void {
it('Should throw if exit before startup', async function (): Promise<void> {
let code = -1234;
let process = setupSpawn({
exit: (listener) => listener(code)
exit: (listener: (msg: string | number) => void) => listener(code)
});
mockUtils.setup(u => u.spawn(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => <ChildProcess>process.object);
@@ -130,8 +127,8 @@ describe('Jupyter server instance', function (): void {
it('Should call stop with correct port on close', async function (): Promise<void> {
// Given startup will succeed
let process = setupSpawn({
sdtout: (listener) => undefined,
stderr: (listener) => listener(successMessage)
sdtout: (listener: (msg: string) => void) => { },
stderr: (listener: (msg: string) => void) => listener(successMessage)
});
mockUtils.setup(u => u.spawn(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => <ChildProcess>process.object);
@@ -159,8 +156,8 @@ describe('Jupyter server instance', function (): void {
mockUtils.setup(u => u.copy(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve());
let process = setupSpawn({
sdtout: (listener) => undefined,
stderr: (listener) => listener(successMessage)
sdtout: (listener: (msg: string) => void) => { },
stderr: (listener: (msg: string) => void) => listener(successMessage)
});
mockUtils.setup(u => u.spawn(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => <ChildProcess>process.object);

View File

@@ -3,9 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import * as should from 'should';
import * as TypeMoq from 'typemoq';
import * as vscode from 'vscode';