From 03cf5fa9f1448298685f8638b1c05d8dad83ab94 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 10 May 2019 14:34:54 -0700 Subject: [PATCH] Enable strict mode for many samples --- .base-sample/tsconfig.json | 3 +- basic-multi-root-sample/src/extension.ts | 16 +++--- basic-multi-root-sample/tsconfig.json | 3 +- comment-sample/tsconfig.json | 1 + completions-sample/tsconfig.json | 1 + configuration-sample/src/extension.ts | 15 +++--- configuration-sample/tsconfig.json | 1 + contentprovider-sample/src/extension.ts | 2 +- contentprovider-sample/src/provider.ts | 7 +-- .../src/referencesDocument.ts | 6 +-- contentprovider-sample/tsconfig.json | 1 + decorator-sample/tsconfig.json | 1 + .../src/extension.ts | 7 ++- .../tsconfig.json | 1 + document-editing-sample/tsconfig.json | 1 + fsprovider-sample/src/fileSystemProvider.ts | 18 +++++-- fsprovider-sample/tsconfig.json | 1 + helloworld-sample/tsconfig.json | 1 + i18n-sample/tsconfig.json | 1 + .../client/src/extension.ts | 20 +++---- lsp-log-streaming-sample/server/src/server.ts | 10 ++-- lsp-log-streaming-sample/server/tsconfig.json | 1 + lsp-sample/server/tsconfig.json | 1 + progress-sample/tsconfig.json | 1 + quickinput-sample/package.json | 2 +- source-control-sample/src/extension.ts | 40 +++++++------- .../src/fiddleConfiguration.ts | 4 +- source-control-sample/src/fiddleRepository.ts | 4 +- .../src/fiddleSourceControl.ts | 10 ++-- statusbar-sample/tsconfig.json | 2 +- task-provider-sample/tsconfig.json | 1 + terminal-sample/src/extension.ts | 52 ++++++++++++++----- terminal-sample/tsconfig.json | 1 + tree-view-sample/src/jsonOutline.ts | 1 - vim-sample/src/motions.ts | 4 +- vim-sample/src/operators.ts | 2 +- vim-sample/src/words.ts | 2 +- virtual-document-sample/tsconfig.json | 4 +- webpack-sample/tsconfig.json | 1 + webview-sample/tsconfig.json | 1 + 40 files changed, 155 insertions(+), 96 deletions(-) diff --git a/.base-sample/tsconfig.json b/.base-sample/tsconfig.json index a374c9aa..21a5c821 100644 --- a/.base-sample/tsconfig.json +++ b/.base-sample/tsconfig.json @@ -5,7 +5,8 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, - "rootDir": "src" + "rootDir": "src", + "strict": true }, "exclude": ["node_modules", ".vscode-test"] } diff --git a/basic-multi-root-sample/src/extension.ts b/basic-multi-root-sample/src/extension.ts index 7e383b60..7491714c 100644 --- a/basic-multi-root-sample/src/extension.ts +++ b/basic-multi-root-sample/src/extension.ts @@ -17,7 +17,7 @@ export function activate(context: ExtensionContext) { context.subscriptions.push(workspace.onDidChangeWorkspaceFolders(e => updateStatus(status))); // Update status bar item based on events for configuration - context.subscriptions.push(workspace.onDidChangeConfiguration(e => this.updateStatus(status))); + context.subscriptions.push(workspace.onDidChangeConfiguration(e => updateStatus(status))); // Update status bar item based on events around the active editor context.subscriptions.push(window.onDidChangeActiveTextEditor(e => updateStatus(status))); @@ -30,9 +30,9 @@ export function activate(context: ExtensionContext) { function updateStatus(status: StatusBarItem): void { const info = getEditorInfo(); - status.text = info ? info.text : void 0; - status.tooltip = info ? info.tooltip : void 0; - status.color = info ? info.color : void 0; + status.text = info ? info.text || '' : ''; + status.tooltip = info ? info.tooltip : undefined; + status.color = info ? info.color : undefined; if (info) { status.show(); @@ -41,7 +41,7 @@ function updateStatus(status: StatusBarItem): void { } } -function getEditorInfo(): { text: string; tooltip: string; color: string; } { +function getEditorInfo(): { text?: string; tooltip?: string; color?: string; } | null { const editor = window.activeTextEditor; // If no workspace is opened or just a single folder, we return without any status label @@ -50,9 +50,9 @@ function getEditorInfo(): { text: string; tooltip: string; color: string; } { return null; } - let text: string; - let tooltip: string; - let color: string; + let text: string | undefined; + let tooltip: string | undefined; + let color: string | undefined; // If we have a file:// resource we resolve the WorkspaceFolder this file is from and update // the status accordingly. diff --git a/basic-multi-root-sample/tsconfig.json b/basic-multi-root-sample/tsconfig.json index 384ad19e..67641a1d 100644 --- a/basic-multi-root-sample/tsconfig.json +++ b/basic-multi-root-sample/tsconfig.json @@ -5,7 +5,8 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, - "rootDir": "." + "rootDir": ".", + "strict": true }, "exclude": ["node_modules", ".vscode-test"] } diff --git a/comment-sample/tsconfig.json b/comment-sample/tsconfig.json index a374c9aa..ef6be738 100644 --- a/comment-sample/tsconfig.json +++ b/comment-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules", ".vscode-test"] diff --git a/completions-sample/tsconfig.json b/completions-sample/tsconfig.json index c67e69b2..2473eaa2 100644 --- a/completions-sample/tsconfig.json +++ b/completions-sample/tsconfig.json @@ -7,6 +7,7 @@ "es6" ], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": [ diff --git a/configuration-sample/src/extension.ts b/configuration-sample/src/extension.ts index bb6df742..dc6bdc83 100644 --- a/configuration-sample/src/extension.ts +++ b/configuration-sample/src/extension.ts @@ -61,10 +61,10 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(e => { // 1) Get the configured glob pattern value for the current file - const value = vscode.workspace.getConfiguration('', e.uri).get('conf.resource.insertEmptyLastLine'); + const value: any = vscode.workspace.getConfiguration('', e.uri).get('conf.resource.insertEmptyLastLine'); // 2) Check if the current resource matches the glob pattern - const matches = value[e.fileName]; + const matches = value ? value[e.fileName] : undefined; // 3) If matches, insert empty last line if (matches) { @@ -91,9 +91,8 @@ export function activate(context: vscode.ExtensionContext) { const value = { ...currentValue, ...{ [currentDocument.fileName]: true } }; // 4) Update the configuration - await configuration.update('conf.resource.insertEmptyLastLine', value, target) + await configuration.update('conf.resource.insertEmptyLastLine', value, target); } - }); // Example 5: Updating Resource scoped Configuration @@ -118,7 +117,7 @@ export function activate(context: vscode.ExtensionContext) { if (target.target === vscode.ConfigurationTarget.WorkspaceFolder) { // 3) Getting the workspace folder - let workspaceFolder = await vscode.window.showWorkspaceFolderPick({ placeHolder: 'Pick Workspace Folder to which this setting should be applied' }) + let workspaceFolder = await vscode.window.showWorkspaceFolderPick({ placeHolder: 'Pick Workspace Folder to which this setting should be applied' }); if (workspaceFolder) { // 4) Get the configuration for the workspace folder @@ -140,7 +139,7 @@ export function activate(context: vscode.ExtensionContext) { // 4) Get the current value const currentValue = configuration.get('conf.resource.insertEmptyLastLine'); - const newValue = { ...currentValue, ...{ [value]: true } }; + const newValue = { ...currentValue, ...(value ? { [value]: true } : {}) }; // 3) Update the value in the target await vscode.workspace.getConfiguration().update('conf.resource.insertEmptyLastLine', newValue, target.target); @@ -154,7 +153,7 @@ export function activate(context: vscode.ExtensionContext) { // 3) Get the current value const currentValue = configuration.get('conf.resource.insertEmptyLastLine'); - const newValue = { ...currentValue, ...{ [value]: true } }; + const newValue = { ...currentValue, ...(value ? { [value]: true } : {}) }; // 4) Update the value in the User Settings await vscode.workspace.getConfiguration().update('conf.resource.insertEmptyLastLine', newValue, vscode.ConfigurationTarget.Global); @@ -170,7 +169,7 @@ export function activate(context: vscode.ExtensionContext) { const currentDocument = vscode.window.activeTextEditor.document; // 1) Get the configured glob pattern value for the current file - const value = vscode.workspace.getConfiguration('', currentDocument.uri).get('conf.resource.insertEmptyLastLine'); + const value: any = vscode.workspace.getConfiguration('', currentDocument.uri).get('conf.resource.insertEmptyLastLine'); // 2) Check if the current resource matches the glob pattern const matches = value[currentDocument.fileName]; diff --git a/configuration-sample/tsconfig.json b/configuration-sample/tsconfig.json index f782f289..2da94c32 100644 --- a/configuration-sample/tsconfig.json +++ b/configuration-sample/tsconfig.json @@ -7,6 +7,7 @@ "es6" ], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": [ diff --git a/contentprovider-sample/src/extension.ts b/contentprovider-sample/src/extension.ts index 97b0dafd..5b92cc64 100644 --- a/contentprovider-sample/src/extension.ts +++ b/contentprovider-sample/src/extension.ts @@ -21,7 +21,7 @@ export function activate(context: ExtensionContext) { // open the dynamic document, and shows it in the next editor const commandRegistration = commands.registerTextEditorCommand('editor.printReferences', editor => { const uri = encodeLocation(editor.document.uri, editor.selection.active); - return workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, editor.viewColumn + 1)); + return workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, editor.viewColumn! + 1)); }); context.subscriptions.push( diff --git a/contentprovider-sample/src/provider.ts b/contentprovider-sample/src/provider.ts index 2452fcd9..a3833cae 100644 --- a/contentprovider-sample/src/provider.ts +++ b/contentprovider-sample/src/provider.ts @@ -52,10 +52,11 @@ export default class Provider implements vscode.TextDocumentContentProvider, vsc // printing, and formatting references const [target, pos] = decodeLocation(uri); return vscode.commands.executeCommand('vscode.executeReferenceProvider', target, pos).then(locations => { + locations = locations || []; // sort by locations and shuffle to begin from target resource let idx = 0; - locations.sort(Provider._compareLocations).find((loc, i) => loc.uri.toString() === target.toString() && (idx = i) && true); + locations.sort(Provider._compareLocations).find((loc, i) => loc.uri.toString() === target.toString() && !!(idx = i) && true); locations.push(...locations.splice(0, idx)); // create document and return its early state @@ -71,11 +72,11 @@ export default class Provider implements vscode.TextDocumentContentProvider, vsc } else if (a.uri.toString() > b.uri.toString()) { return 1; } else { - return a.range.start.compareTo(b.range.start) + return a.range.start.compareTo(b.range.start); } } - provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentLink[] { + provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentLink[] | undefined { // While building the virtual document we have already created the links. // Those are composed from the range inside the document and a target uri // to which they point diff --git a/contentprovider-sample/src/referencesDocument.ts b/contentprovider-sample/src/referencesDocument.ts index 2c10a4dd..ee57a83f 100644 --- a/contentprovider-sample/src/referencesDocument.ts +++ b/contentprovider-sample/src/referencesDocument.ts @@ -13,7 +13,7 @@ export default class ReferencesDocument { private _lines: string[]; private _links: vscode.DocumentLink[]; - private _join: Thenable; + private _join?: Thenable; constructor(uri: vscode.Uri, locations: vscode.Location[], emitter: vscode.EventEmitter) { this._uri = uri; @@ -37,7 +37,7 @@ export default class ReferencesDocument { return this._links; } - join(): Thenable { + join(): Thenable | undefined { return this._join; } @@ -81,7 +81,7 @@ export default class ReferencesDocument { this._emitter.fire(this._uri); next(); }); - } + }; next(); }); } diff --git a/contentprovider-sample/tsconfig.json b/contentprovider-sample/tsconfig.json index 43668414..f219ad63 100644 --- a/contentprovider-sample/tsconfig.json +++ b/contentprovider-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules"] diff --git a/decorator-sample/tsconfig.json b/decorator-sample/tsconfig.json index 34156978..93f52a81 100644 --- a/decorator-sample/tsconfig.json +++ b/decorator-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules", ".vscode-test"] diff --git a/diagnostic-related-information-sample/src/extension.ts b/diagnostic-related-information-sample/src/extension.ts index e0246cb3..37640122 100644 --- a/diagnostic-related-information-sample/src/extension.ts +++ b/diagnostic-related-information-sample/src/extension.ts @@ -8,8 +8,11 @@ export function activate(context: vscode.ExtensionContext) { if (vscode.window.activeTextEditor) { updateDiagnostics(vscode.window.activeTextEditor.document, collection); } - context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(e => updateDiagnostics(e.document, collection))); - + context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => { + if (editor) { + updateDiagnostics(editor.document, collection); + } + })); } function updateDiagnostics(document: vscode.TextDocument, collection: vscode.DiagnosticCollection): void { diff --git a/diagnostic-related-information-sample/tsconfig.json b/diagnostic-related-information-sample/tsconfig.json index f782f289..2da94c32 100644 --- a/diagnostic-related-information-sample/tsconfig.json +++ b/diagnostic-related-information-sample/tsconfig.json @@ -7,6 +7,7 @@ "es6" ], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": [ diff --git a/document-editing-sample/tsconfig.json b/document-editing-sample/tsconfig.json index a374c9aa..ef6be738 100644 --- a/document-editing-sample/tsconfig.json +++ b/document-editing-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules", ".vscode-test"] diff --git a/fsprovider-sample/src/fileSystemProvider.ts b/fsprovider-sample/src/fileSystemProvider.ts index 76c68fce..d2ab77cd 100644 --- a/fsprovider-sample/src/fileSystemProvider.ts +++ b/fsprovider-sample/src/fileSystemProvider.ts @@ -16,7 +16,7 @@ export class File implements vscode.FileStat { size: number; name: string; - data: Uint8Array; + data?: Uint8Array; constructor(name: string) { this.type = vscode.FileType.File; @@ -71,7 +71,11 @@ export class MemFS implements vscode.FileSystemProvider { // --- manage file contents readFile(uri: vscode.Uri): Uint8Array { - return this._lookupAsFile(uri, false).data; + const data = this._lookupAsFile(uri, false).data; + if (data) { + return data; + } + throw vscode.FileSystemError.FileNotFound(); } writeFile(uri: vscode.Uri, content: Uint8Array, options: { create: boolean, overwrite: boolean }): void { @@ -200,18 +204,22 @@ export class MemFS implements vscode.FileSystemProvider { private _emitter = new vscode.EventEmitter(); private _bufferedEvents: vscode.FileChangeEvent[] = []; - private _fireSoonHandle: NodeJS.Timer; + private _fireSoonHandle?: NodeJS.Timer; readonly onDidChangeFile: vscode.Event = this._emitter.event; - watch(resource: vscode.Uri, opts): vscode.Disposable { + watch(_resource: vscode.Uri): vscode.Disposable { // ignore, fires for all changes... return new vscode.Disposable(() => { }); } private _fireSoon(...events: vscode.FileChangeEvent[]): void { this._bufferedEvents.push(...events); - clearTimeout(this._fireSoonHandle); + + if (this._fireSoonHandle) { + clearTimeout(this._fireSoonHandle); + } + this._fireSoonHandle = setTimeout(() => { this._emitter.fire(this._bufferedEvents); this._bufferedEvents.length = 0; diff --git a/fsprovider-sample/tsconfig.json b/fsprovider-sample/tsconfig.json index c15bdd4b..503ad3ef 100644 --- a/fsprovider-sample/tsconfig.json +++ b/fsprovider-sample/tsconfig.json @@ -6,6 +6,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "." }, "exclude": ["node_modules", ".vscode-test"] diff --git a/helloworld-sample/tsconfig.json b/helloworld-sample/tsconfig.json index a374c9aa..ef6be738 100644 --- a/helloworld-sample/tsconfig.json +++ b/helloworld-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules", ".vscode-test"] diff --git a/i18n-sample/tsconfig.json b/i18n-sample/tsconfig.json index c443f75c..3a77341e 100644 --- a/i18n-sample/tsconfig.json +++ b/i18n-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules", ".vscode-test"] diff --git a/lsp-log-streaming-sample/client/src/extension.ts b/lsp-log-streaming-sample/client/src/extension.ts index 99f4c83a..072c2b88 100644 --- a/lsp-log-streaming-sample/client/src/extension.ts +++ b/lsp-log-streaming-sample/client/src/extension.ts @@ -19,12 +19,12 @@ let client: LanguageClient; export function activate(context: ExtensionContext) { const socketPort = workspace.getConfiguration('languageServerExample').get('port', 7000); - let socket: WebSocket | null = null + let socket: WebSocket | null = null; commands.registerCommand('languageServerExample.startStreaming', () => { // Establish websocket connection - socket = new WebSocket(`ws://localhost:${socketPort}`) - }) + socket = new WebSocket(`ws://localhost:${socketPort}`); + }); // The server is implemented in node let serverModule = context.asAbsolutePath( @@ -46,27 +46,27 @@ export function activate(context: ExtensionContext) { }; // The log to send - let log = '' + let log = ''; const websocketOutputChannel: OutputChannel = { name: 'websocket', // Only append the logs but send them later append(value: string) { - log += value - console.log(value) + log += value; + console.log(value); }, appendLine(value: string) { - log += value + log += value; // Don't send logs until WebSocket initialization if (socket && socket.readyState === WebSocket.OPEN) { - socket.send(log) + socket.send(log); } - log = '' + log = ''; }, clear() {}, show() {}, hide() {}, dispose() {} - } + }; // Options to control the language client let clientOptions: LanguageClientOptions = { diff --git a/lsp-log-streaming-sample/server/src/server.ts b/lsp-log-streaming-sample/server/src/server.ts index 726b8624..d6fed694 100644 --- a/lsp-log-streaming-sample/server/src/server.ts +++ b/lsp-log-streaming-sample/server/src/server.ts @@ -36,13 +36,13 @@ connection.onInitialize((params: InitializeParams) => { // Does the client support the `workspace/configuration` request? // If not, we will fall back using global settings hasConfigurationCapability = - capabilities.workspace && !!capabilities.workspace.configuration; + !!capabilities.workspace && !!capabilities.workspace.configuration; hasWorkspaceFolderCapability = - capabilities.workspace && !!capabilities.workspace.workspaceFolders; - hasDiagnosticRelatedInformationCapability = + !!capabilities.workspace && !!capabilities.workspace.workspaceFolders; + hasDiagnosticRelatedInformationCapability = !!( capabilities.textDocument && capabilities.textDocument.publishDiagnostics && - capabilities.textDocument.publishDiagnostics.relatedInformation; + capabilities.textDocument.publishDiagnostics.relatedInformation); return { capabilities: { @@ -131,7 +131,7 @@ async function validateTextDocument(textDocument: TextDocument): Promise { // The validator creates diagnostics for all uppercase words length 2 and more let text = textDocument.getText(); let pattern = /\b[A-Z]{2,}\b/g; - let m: RegExpExecArray; + let m: RegExpExecArray | null; let problems = 0; let diagnostics: Diagnostic[] = []; diff --git a/lsp-log-streaming-sample/server/tsconfig.json b/lsp-log-streaming-sample/server/tsconfig.json index 7b07351a..1f419480 100644 --- a/lsp-log-streaming-sample/server/tsconfig.json +++ b/lsp-log-streaming-sample/server/tsconfig.json @@ -5,6 +5,7 @@ "module": "commonjs", "moduleResolution": "node", "sourceMap": true, + "strict": true, "outDir": "out", "rootDir": "src", "lib": ["es6"] diff --git a/lsp-sample/server/tsconfig.json b/lsp-sample/server/tsconfig.json index c08c0133..7e20d337 100644 --- a/lsp-sample/server/tsconfig.json +++ b/lsp-sample/server/tsconfig.json @@ -4,6 +4,7 @@ "module": "commonjs", "moduleResolution": "node", "sourceMap": true, + "strict": true, "outDir": "out", "rootDir": "src", "lib": ["es6"] diff --git a/progress-sample/tsconfig.json b/progress-sample/tsconfig.json index 43668414..f219ad63 100644 --- a/progress-sample/tsconfig.json +++ b/progress-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules"] diff --git a/quickinput-sample/package.json b/quickinput-sample/package.json index d29ad97b..3f6298a5 100644 --- a/quickinput-sample/package.json +++ b/quickinput-sample/package.json @@ -30,7 +30,7 @@ "devDependencies": { "@types/node": "10.3.6", "tslint": "^5.16.0", - "typescript": "2.9.2", + "typescript": "^3.4.5", "@types/vscode": "^1.32.0" } } diff --git a/source-control-sample/src/extension.ts b/source-control-sample/src/extension.ts index 6c2b4252..55c07378 100644 --- a/source-control-sample/src/extension.ts +++ b/source-control-sample/src/extension.ts @@ -49,7 +49,7 @@ export function activate(context: vscode.ExtensionContext) { })); } -async function pickSourceControl(): Promise { +async function pickSourceControl(): Promise { // todo: when/if the SourceControl exposes a 'selected' property, use that instead if (fiddleSourceControlRegister.size == 0) return undefined; @@ -85,13 +85,13 @@ async function tryOpenFiddle(context: vscode.ExtensionContext, fiddleId?: string } async function openFiddle(context: vscode.ExtensionContext, fiddleId?: string, workspaceUri?: vscode.Uri) { - if (fiddleSourceControlRegister.has(workspaceUri)) vscode.window.showErrorMessage("Another Fiddle was already open in this workspace. Open a new workspace first."); + if (workspaceUri && fiddleSourceControlRegister.has(workspaceUri)) vscode.window.showErrorMessage("Another Fiddle was already open in this workspace. Open a new workspace first."); if (!fiddleId) { - fiddleId = await vscode.window.showInputBox({ prompt: 'Paste JSFiddle ID and optionally version', placeHolder: 'slug or slug/version, e.g. u8B29/1', value: 'demo' }); + fiddleId = (await vscode.window.showInputBox({ prompt: 'Paste JSFiddle ID and optionally version', placeHolder: 'slug or slug/version, e.g. u8B29/1', value: 'demo' })) || ''; } - let workspaceFolder: vscode.WorkspaceFolder = + let workspaceFolder = workspaceUri ? vscode.workspace.getWorkspaceFolder(workspaceUri) : await selectWorkspaceFolder(context, fiddleId); @@ -122,7 +122,7 @@ function registerFiddleSourceControl(fiddleSourceControl: FiddleSourceControl, c if (fiddleSourceControlRegister.has(fiddleSourceControl.getWorkspaceFolder().uri)) { // the folder was already under source control - let previousSourceControl = fiddleSourceControlRegister.get(fiddleSourceControl.getWorkspaceFolder().uri); + const previousSourceControl = fiddleSourceControlRegister.get(fiddleSourceControl.getWorkspaceFolder().uri)!; previousSourceControl.dispose(); } @@ -135,7 +135,7 @@ function initializeFromConfigurationFile(context: vscode.ExtensionContext): void if (!vscode.workspace.workspaceFolders) return; vscode.workspace.workspaceFolders.forEach(folder => { - let configurationPath = path.join(folder.uri.fsPath, CONFIGURATION_FILE); + const configurationPath = path.join(folder.uri.fsPath, CONFIGURATION_FILE); exists(configurationPath, configFileExists => { if (configFileExists) { readFile(configurationPath, { flag: 'r' }, async (err, data) => { @@ -152,16 +152,16 @@ function initializeFromConfigurationFile(context: vscode.ExtensionContext): void }); } -async function selectWorkspaceFolder(context: vscode.ExtensionContext, fiddleId: string): Promise { - var selectedFolder: vscode.WorkspaceFolder; - var workspaceFolderUri: vscode.Uri; - var workspaceFolderIndex: number; +async function selectWorkspaceFolder(context: vscode.ExtensionContext, fiddleId: string): Promise { + var selectedFolder: vscode.WorkspaceFolder | undefined; + var workspaceFolderUri: vscode.Uri | undefined; + var workspaceFolderIndex: number | undefined; const fiddleConfiguration = parseFiddleId(fiddleId); if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1) { selectedFolder = await vscode.window.showWorkspaceFolderPick({ placeHolder: 'Pick workspace folder to create files in.' }); - if (!selectedFolder) return null; + if (!selectedFolder) return undefined; workspaceFolderIndex = selectedFolder.index; workspaceFolderUri = selectedFolder.uri; @@ -169,41 +169,43 @@ async function selectWorkspaceFolder(context: vscode.ExtensionContext, fiddleId: else if (!vscode.workspace.workspaceFolders) { let folderUris = await vscode.window.showOpenDialog({ canSelectFolders: true, canSelectFiles: false, canSelectMany: false, openLabel: 'Select folder' }); if (!folderUris) { - return null; + return undefined; } workspaceFolderUri = folderUris[0]; // was such workspace folder already open? - workspaceFolderIndex = vscode.workspace.workspaceFolders && firstIndex(vscode.workspace.workspaceFolders, folder1 => folder1.uri.toString() === workspaceFolderUri.toString()); + workspaceFolderIndex = vscode.workspace.workspaceFolders && firstIndex(vscode.workspace.workspaceFolders, (folder1: any) => folder1.uri.toString() === workspaceFolderUri!.toString()); // save folder configuration FiddleSourceControl.saveConfiguration(workspaceFolderUri, fiddleConfiguration); - selectedFolder = null; // the extension will get reloaded in the context of the newly open workspace + selectedFolder = undefined; // the extension will get reloaded in the context of the newly open workspace } else { selectedFolder = vscode.workspace.workspaceFolders[0]; } - let workSpacesToReplace = workspaceFolderIndex > -1 ? 1 : 0; + let workSpacesToReplace = typeof workspaceFolderIndex === 'number' && workspaceFolderIndex > -1 ? 1 : 0; if (workspaceFolderIndex === undefined || workspaceFolderIndex < 0) workspaceFolderIndex = 0; // replace or insert the workspace - vscode.workspace.updateWorkspaceFolders(workspaceFolderIndex, workSpacesToReplace, { uri: workspaceFolderUri }); + if (workspaceFolderUri) { + vscode.workspace.updateWorkspaceFolders(workspaceFolderIndex, workSpacesToReplace, { uri: workspaceFolderUri }); + } return selectedFolder; } -async function clearWorkspaceFolder(workspaceFolder: vscode.WorkspaceFolder): Promise { +async function clearWorkspaceFolder(workspaceFolder?: vscode.WorkspaceFolder): Promise { - if (!workspaceFolder) return null; + if (!workspaceFolder) return undefined; // check if the workspace is empty, or clear it let existingWorkspaceFiles = readdirSync(workspaceFolder.uri.fsPath); if (existingWorkspaceFiles.length > 0) { let answer = await vscode.window.showQuickPick(["Yes", "No"], { placeHolder: `Remove ${existingWorkspaceFiles.length} file(s) from the workspace before cloning the remote repository?` }); - if (answer === undefined) return null; + if (answer === undefined) return undefined; if (answer === "Yes") { existingWorkspaceFiles diff --git a/source-control-sample/src/fiddleConfiguration.ts b/source-control-sample/src/fiddleConfiguration.ts index 484d11c4..36a93e2a 100644 --- a/source-control-sample/src/fiddleConfiguration.ts +++ b/source-control-sample/src/fiddleConfiguration.ts @@ -1,6 +1,6 @@ -export class FiddleConfiguration { +export interface FiddleConfiguration { readonly slug: string; - readonly version: number; + readonly version?: number; } export function parseFiddleId(id: string): FiddleConfiguration { diff --git a/source-control-sample/src/fiddleRepository.ts b/source-control-sample/src/fiddleRepository.ts index 92845e09..b3ed1963 100644 --- a/source-control-sample/src/fiddleRepository.ts +++ b/source-control-sample/src/fiddleRepository.ts @@ -63,7 +63,7 @@ const DEMO: FiddleData[] = [ ]; // emulates prior versions mock-committed in previous sessions -var demoVersionOffset: number = undefined; +var demoVersionOffset: number | undefined = undefined; export async function downloadFiddle(slug: string, version: number | undefined): Promise { @@ -99,7 +99,7 @@ export async function downloadFiddle(slug: string, version: number | undefined): }); } -export async function uploadFiddle(slug: string, version: number, html: string, js: string, css: string): Promise { +export async function uploadFiddle(slug: string, version: number, html: string, js: string, css: string): Promise { if (slug === "demo") { // using mock fiddle diff --git a/source-control-sample/src/fiddleSourceControl.ts b/source-control-sample/src/fiddleSourceControl.ts index 6d1cc365..623a028d 100644 --- a/source-control-sample/src/fiddleSourceControl.ts +++ b/source-control-sample/src/fiddleSourceControl.ts @@ -12,8 +12,8 @@ export class FiddleSourceControl implements vscode.Disposable { private fiddleRepository: FiddleRepository; private latestFiddleVersion: number = Number.POSITIVE_INFINITY; // until actual value is established private _onRepositoryChange = new vscode.EventEmitter(); - private timeout: NodeJS.Timer; - private fiddle: Fiddle; + private timeout?: NodeJS.Timer; + private fiddle!: Fiddle; constructor(context: vscode.ExtensionContext, private readonly workspaceFolder: vscode.WorkspaceFolder, fiddle: Fiddle, overwrite: boolean) { this.jsFiddleScm = vscode.scm.createSourceControl('jsfiddle', 'JSFiddle #' + fiddle.slug, workspaceFolder.uri); @@ -211,7 +211,7 @@ export class FiddleSourceControl implements vscode.Disposable { async establishVersion(): Promise { let version = 0; let latestVersion = Number.NaN; - let currentFiddle: Fiddle = undefined; + let currentFiddle: Fiddle | undefined = undefined; while (true) { try { let latestFiddle = await downloadFiddle(this.fiddle.slug, version); @@ -229,7 +229,9 @@ export class FiddleSourceControl implements vscode.Disposable { this.latestFiddleVersion = latestVersion; // now we know the version of the current fiddle, let's set it - this.setFiddle(currentFiddle, false); + if (currentFiddle) { + this.setFiddle(currentFiddle, false); + } } diff --git a/statusbar-sample/tsconfig.json b/statusbar-sample/tsconfig.json index 022b83f3..2473eaa2 100644 --- a/statusbar-sample/tsconfig.json +++ b/statusbar-sample/tsconfig.json @@ -6,8 +6,8 @@ "lib": [ "es6" ], - "strict": true, "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": [ diff --git a/task-provider-sample/tsconfig.json b/task-provider-sample/tsconfig.json index b280543e..8556fe10 100644 --- a/task-provider-sample/tsconfig.json +++ b/task-provider-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "include": ["src"], diff --git a/terminal-sample/src/extension.ts b/terminal-sample/src/extension.ts index ae12afca..fedebd6e 100644 --- a/terminal-sample/src/extension.ts +++ b/terminal-sample/src/extension.ts @@ -13,7 +13,7 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.onDidOpenTerminal(terminal => { console.log("Terminal opened. Total count: " + (vscode.window).terminals.length); - (terminal).onDidWriteData(data => { + (terminal).onDidWriteData((data: any) => { console.log("Terminal data: ", data); }); }); @@ -42,31 +42,51 @@ export function activate(context: vscode.ExtensionContext) { // Terminal.hide context.subscriptions.push(vscode.commands.registerCommand('terminalTest.hide', () => { if (ensureTerminalExists()) { - selectTerminal().then(terminal => terminal.hide()); + selectTerminal().then(terminal => { + if (terminal) { + terminal.hide(); + } + }); } })); // Terminal.show context.subscriptions.push(vscode.commands.registerCommand('terminalTest.show', () => { if (ensureTerminalExists()) { - selectTerminal().then(terminal => terminal.show()); + selectTerminal().then(terminal => { + if (terminal) { + terminal.show(); + } + }); } })); context.subscriptions.push(vscode.commands.registerCommand('terminalTest.showPreserveFocus', () => { if (ensureTerminalExists()) { - selectTerminal().then(terminal => terminal.show(true)); + selectTerminal().then(terminal => { + if (terminal) { + terminal.show(true); + } + }); } })); // Terminal.sendText context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendText', () => { if (ensureTerminalExists()) { - selectTerminal().then(terminal => terminal.sendText("echo 'Hello world!'")); + selectTerminal().then(terminal => { + if (terminal) { + terminal.sendText("echo 'Hello world!'"); + } + }); } })); context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendTextNoNewLine', () => { if (ensureTerminalExists()) { - selectTerminal().then(terminal => terminal.sendText("echo 'Hello world!'", false)); + selectTerminal().then(terminal => { + if (terminal) { + terminal.sendText("echo 'Hello world!'", false); + } + }); } })); @@ -84,6 +104,9 @@ export function activate(context: vscode.ExtensionContext) { // Terminal.processId context.subscriptions.push(vscode.commands.registerCommand('terminalTest.processId', () => { selectTerminal().then(terminal => { + if (!terminal) { + return; + } terminal.processId.then((processId) => { if (processId) { vscode.window.showInformationMessage(`Terminal.processId: ${processId}`); @@ -109,6 +132,9 @@ export function activate(context: vscode.ExtensionContext) { // vscode.window.onDidWriteData context.subscriptions.push(vscode.commands.registerCommand('terminalTest.onDidWriteData', () => { selectTerminal().then(terminal => { + if (!terminal) { + return; + } vscode.window.showInformationMessage(`onDidWriteData listener attached for terminal: ${terminal.name}, check the devtools console to see events`); (terminal).onDidWriteData((data: string) => { console.log('onDidWriteData: ' + data); @@ -119,16 +145,16 @@ export function activate(context: vscode.ExtensionContext) { // vscode.window.onDidChangeTerminalDimensions context.subscriptions.push(vscode.commands.registerCommand('terminalTest.onDidChangeTerminalDimensions', () => { vscode.window.showInformationMessage(`Listening to onDidChangeTerminalDimensions, check the devtools console to see events`); - (vscode.window).onDidChangeTerminalDimensions((event) => { + (vscode.window).onDidChangeTerminalDimensions((event: any) => { console.log(`onDidChangeTerminalDimensions: terminal:${event.terminal.name}, columns=${event.dimensions.columns}, rows=${event.dimensions.rows}`); }); })); - let renderer; + let renderer: any | undefined; context.subscriptions.push(vscode.commands.registerCommand('terminalTest.terminalRendererCreate', () => { renderer = (vscode.window).createTerminalRenderer('renderer'); renderer.write(colorText('~~~ Hello world! ~~~')); - renderer.onDidChangeMaximumDimensions(dim => { + renderer.onDidChangeMaximumDimensions((dim: any) => { console.log(`Dimensions for renderer changed: columns=${dim.columns}, rows=${dim.rows}`); }); })); @@ -159,7 +185,7 @@ export function activate(context: vscode.ExtensionContext) { const shell = (vscode.window).createTerminalRenderer('fake shell'); shell.write('Type and press enter to echo the text\r\n\r\n'); let line = ''; - shell.onDidAcceptInput(data => { + shell.onDidAcceptInput((data: any) => { if (data === '\r') { shell.write(`\r\necho: "${colorText(line)}"\r\n\n`); line = ''; @@ -171,7 +197,7 @@ export function activate(context: vscode.ExtensionContext) { shell.terminal.show(); })); context.subscriptions.push(vscode.commands.registerCommand('terminalTest.maximumDimensions', () => { - renderer.maximumDimensions.then(dimensions => { + renderer.maximumDimensions.then((dimensions: any) => { vscode.window.showInformationMessage(`TerminalRenderer.maximumDimensions: columns=${dimensions.columns}, rows=${dimensions.rows}`); }); })); @@ -207,7 +233,7 @@ function colorText(text: string): string { return output; } -function selectTerminal(): Thenable { +function selectTerminal(): Thenable { interface TerminalQuickPickItem extends vscode.QuickPickItem { terminal: vscode.Terminal; } @@ -219,7 +245,7 @@ function selectTerminal(): Thenable { }; }); return vscode.window.showQuickPick(items).then(item => { - return item.terminal; + return item ? item.terminal : undefined; }); } diff --git a/terminal-sample/tsconfig.json b/terminal-sample/tsconfig.json index a374c9aa..ef6be738 100644 --- a/terminal-sample/tsconfig.json +++ b/terminal-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules", ".vscode-test"] diff --git a/tree-view-sample/src/jsonOutline.ts b/tree-view-sample/src/jsonOutline.ts index 20983b9b..64bb3f5b 100644 --- a/tree-view-sample/src/jsonOutline.ts +++ b/tree-view-sample/src/jsonOutline.ts @@ -1,7 +1,6 @@ import * as vscode from 'vscode'; import * as json from 'jsonc-parser'; import * as path from 'path'; -import { isNumber } from 'util'; export class JsonOutlineProvider implements vscode.TreeDataProvider { diff --git a/vim-sample/src/motions.ts b/vim-sample/src/motions.ts index 937dc936..42426013 100644 --- a/vim-sample/src/motions.ts +++ b/vim-sample/src/motions.ts @@ -10,9 +10,9 @@ import { Command, AbstractCommandDescriptor } from './common'; export class MotionState { - public anchor: Position; + public anchor: Position | null; public cursorDesiredCharacter: number; - public wordCharacterClass: WordCharacters; + public wordCharacterClass: WordCharacters | null; constructor() { this.cursorDesiredCharacter = -1; diff --git a/vim-sample/src/operators.ts b/vim-sample/src/operators.ts index 48d2942e..b4ba8ce9 100644 --- a/vim-sample/src/operators.ts +++ b/vim-sample/src/operators.ts @@ -217,7 +217,7 @@ class PutOperator extends Operator { let register = ctrl.getDeleteRegister(); if (!register) { // No delete register - beep!! - return; + return false; } let str = register.content; diff --git a/vim-sample/src/words.ts b/vim-sample/src/words.ts index 10f12daf..245e67ef 100644 --- a/vim-sample/src/words.ts +++ b/vim-sample/src/words.ts @@ -46,7 +46,7 @@ export class Words { return result; } - public static findNextWord(doc: TextDocument, pos: Position, wordCharacterClass: WordCharacters): IWord { + public static findNextWord(doc: TextDocument, pos: Position, wordCharacterClass: WordCharacters): IWord | null { let lineContent = doc.lineAt(pos.line).text; let wordType = WordType.NONE; diff --git a/virtual-document-sample/tsconfig.json b/virtual-document-sample/tsconfig.json index 022b83f3..2da94c32 100644 --- a/virtual-document-sample/tsconfig.json +++ b/virtual-document-sample/tsconfig.json @@ -6,12 +6,12 @@ "lib": [ "es6" ], - "strict": true, "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": [ "node_modules", ".vscode-test" ] -} +} \ No newline at end of file diff --git a/webpack-sample/tsconfig.json b/webpack-sample/tsconfig.json index 1ea19d39..4a24eef8 100644 --- a/webpack-sample/tsconfig.json +++ b/webpack-sample/tsconfig.json @@ -7,6 +7,7 @@ "es6" ], "sourceMap": true, + "strict": true, "rootDir": "src" }, "include": [ diff --git a/webview-sample/tsconfig.json b/webview-sample/tsconfig.json index a374c9aa..ef6be738 100644 --- a/webview-sample/tsconfig.json +++ b/webview-sample/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, + "strict": true, "rootDir": "src" }, "exclude": ["node_modules", ".vscode-test"]