From cd8a7475226ea80336bf6b03b4b7ca6a54975352 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Mon, 25 Apr 2022 09:19:42 -0700 Subject: [PATCH] Enable strictNullChecks for extensions by default (#19197) * Strict null on extensions * fix test * Fail on no stdin --- extensions/admin-tool-ext-win/src/main.ts | 9 +++++---- .../src/test/extension.test.ts | 2 +- .../admin-tool-ext-win/src/test/stubs.ts | 8 ++++---- .../admin-tool-ext-win/src/test/utils.test.ts | 18 +++++++++--------- extensions/admin-tool-ext-win/src/utils.ts | 2 +- extensions/agent/tsconfig.json | 3 ++- extensions/azurecore/tsconfig.json | 3 ++- extensions/big-data-cluster/tsconfig.json | 1 + extensions/cms/tsconfig.json | 1 + extensions/dacpac/tsconfig.json | 3 ++- extensions/import/tsconfig.json | 1 + extensions/integration-tests/tsconfig.json | 1 + extensions/liveshare/tsconfig.json | 3 ++- extensions/mssql/tsconfig.json | 3 ++- extensions/notebook/tsconfig.json | 3 ++- extensions/schema-compare/tsconfig.json | 1 + extensions/tsconfig.base.json | 5 ++--- 17 files changed, 39 insertions(+), 28 deletions(-) diff --git a/extensions/admin-tool-ext-win/src/main.ts b/extensions/admin-tool-ext-win/src/main.ts index af1b790a24..37370271aa 100644 --- a/extensions/admin-tool-ext-win/src/main.ts +++ b/extensions/admin-tool-ext-win/src/main.ts @@ -82,6 +82,7 @@ async function handleLaunchSsmsMinGswDialogCommand(connectionContext?: azdata.Ob if (!connectionContext) { TelemetryReporter.sendErrorEvent(TelemetryViews.SsmsMinGsw, 'NoConnectionContext'); void vscode.window.showErrorMessage(localize('adminToolExtWin.noConnectionContextForGsw', "No ConnectionContext provided for handleLaunchSsmsMinPropertiesDialogCommand")); + return; } return launchSsmsDialog( @@ -101,7 +102,7 @@ async function launchSsmsDialog(action: string, connectionContext: azdata.Object return; } - let oeNode: azdata.objectexplorer.ObjectExplorerNode; + let oeNode: azdata.objectexplorer.ObjectExplorerNode | undefined; // Server node is a Connection node and so doesn't have the NodeInfo if (connectionContext.isConnectionNode) { oeNode = undefined; @@ -153,11 +154,11 @@ async function launchSsmsDialog(action: string, connectionContext: azdata.Object // Process has exited so remove from map of running processes runningProcesses.delete(proc.pid); const err = stderr.toString(); - if ((execException && execException.code !== 0) || err !== '') { + if ((execException?.code !== 0) || err !== '') { TelemetryReporter.sendErrorEvent( TelemetryViews.SsmsMinDialog, 'LaunchSsmsDialogError', - execException ? execException.code.toString() : '', + execException ? execException?.code?.toString() : '', getTelemetryErrorType(err)); } @@ -170,7 +171,7 @@ async function launchSsmsDialog(action: string, connectionContext: azdata.Object // If we're not using AAD the tool prompts for a password on stdin if (params.useAad !== true) { - proc.stdin.end(password ? password : ''); + proc.stdin!.end(password ? password : ''); } // Save the process into our map so we can make sure to stop them if we exit before shutting down diff --git a/extensions/admin-tool-ext-win/src/test/extension.test.ts b/extensions/admin-tool-ext-win/src/test/extension.test.ts index 8a11d5b93a..4c86814989 100644 --- a/extensions/admin-tool-ext-win/src/test/extension.test.ts +++ b/extensions/admin-tool-ext-win/src/test/extension.test.ts @@ -8,6 +8,6 @@ import * as vscode from 'vscode'; describe('Extension activate test', () => { it('Extension should activate correctly', async function (): Promise { - await vscode.extensions.getExtension('Microsoft.admin-tool-ext-win').activate(); + await vscode.extensions.getExtension('Microsoft.admin-tool-ext-win')!.activate(); }); }); diff --git a/extensions/admin-tool-ext-win/src/test/stubs.ts b/extensions/admin-tool-ext-win/src/test/stubs.ts index b193a8dc57..7273268fb7 100644 --- a/extensions/admin-tool-ext-win/src/test/stubs.ts +++ b/extensions/admin-tool-ext-win/src/test/stubs.ts @@ -11,7 +11,7 @@ import * as vscode from 'vscode'; */ export class ExtHostObjectExplorerNodeStub implements azdata.objectexplorer.ObjectExplorerNode { // Stub properties - private parent: azdata.objectexplorer.ObjectExplorerNode; + private parent: azdata.objectexplorer.ObjectExplorerNode | undefined; // Base properties public connectionId: string; @@ -24,10 +24,10 @@ export class ExtHostObjectExplorerNodeStub implements azdata.objectexplorer.Obje public metadata: azdata.ObjectMetadata; public errorMessage: string; - constructor(nodeName: string, nodeSchema: string, nodeType: string, parent: azdata.objectexplorer.ObjectExplorerNode) { + constructor(nodeName: string, nodeSchema: string, nodeType: string, parent?: azdata.objectexplorer.ObjectExplorerNode) { this.parent = parent; this.nodeType = nodeType; - this.metadata = { metadataType: undefined, metadataTypeName: undefined, name: nodeName, schema: nodeSchema, urn: undefined, parentName: undefined, parentTypeName: undefined }; + this.metadata = { metadataType: azdata.MetadataType.Table, metadataTypeName: 'MyMetadataTypeName', name: nodeName, schema: nodeSchema, urn: 'urn', parentName: undefined, parentTypeName: undefined }; } isExpanded(): Thenable { @@ -38,7 +38,7 @@ export class ExtHostObjectExplorerNodeStub implements azdata.objectexplorer.Obje throw new Error('Method not implemented'); } - setSelected(selected: boolean, clearOtherSelections: boolean = undefined): Thenable { + setSelected(selected: boolean, clearOtherSelections: boolean): Thenable { throw new Error('Method not implemented'); } diff --git a/extensions/admin-tool-ext-win/src/test/utils.test.ts b/extensions/admin-tool-ext-win/src/test/utils.test.ts index a4366bb784..200901e041 100644 --- a/extensions/admin-tool-ext-win/src/test/utils.test.ts +++ b/extensions/admin-tool-ext-win/src/test/utils.test.ts @@ -77,14 +77,14 @@ describe('buildUrn Method Tests', () => { it('Urn should be correct with Server and only Databases folder', async function (): Promise { const leafNode: ExtHostObjectExplorerNodeStub = - new ExtHostObjectExplorerNodeStub('MyServer', undefined, 'Server', undefined) - .createChild('Databases', undefined, 'Folder'); + new ExtHostObjectExplorerNodeStub('MyServer', 'MySchema', 'Server', undefined) + .createChild('Databases', '', 'Folder'); should(await buildUrn(leafNode)).equal('Server'); }); it('Urn should be correct with Server and Database node', async function (): Promise { const leafNode: ExtHostObjectExplorerNodeStub = - new ExtHostObjectExplorerNodeStub('Databases', undefined, 'Folder', undefined) + new ExtHostObjectExplorerNodeStub('Databases', 'MySchema', 'Folder', undefined) .createChild(dbName, dbSchema, 'Database'); should(await buildUrn(leafNode)).equal( `Server/Database[@Name='${escapedDbName}' and @Schema='${escapedDbSchema}']`); @@ -92,9 +92,9 @@ describe('buildUrn Method Tests', () => { it('Urn should be correct with Multiple levels of Nodes', async function (): Promise { const rootNode: ExtHostObjectExplorerNodeStub = - new ExtHostObjectExplorerNodeStub('Databases', undefined, 'Folder', undefined) + new ExtHostObjectExplorerNodeStub('Databases', 'MySchema', 'Folder', undefined) .createChild(dbName, dbSchema, 'Database') - .createChild('Tables', undefined, 'Folder') + .createChild('Tables', 'MySchema', 'Folder') .createChild(tableName, tableSchema, 'Table'); should(await buildUrn(rootNode)).equal( `Server/Database[@Name='${escapedDbName}' and @Schema='${escapedDbSchema}']/Table[@Name='${escapedTableName}' and @Schema='${escapedTableSchema}']`); @@ -102,10 +102,10 @@ describe('buildUrn Method Tests', () => { it('Urn should be correct with Multiple levels of Nodes without schemas', async function (): Promise { const rootNode: ExtHostObjectExplorerNodeStub = - new ExtHostObjectExplorerNodeStub('Databases', undefined, 'Folder', undefined) - .createChild(dbName, undefined, 'Database') - .createChild('Tables', undefined, 'Folder') - .createChild(tableName, undefined, 'Table'); + new ExtHostObjectExplorerNodeStub('Databases', '', 'Folder', undefined) + .createChild(dbName, '', 'Database') + .createChild('Tables', '', 'Folder') + .createChild(tableName, '', 'Table'); should(await buildUrn(rootNode)).equal( `Server/Database[@Name='${escapedDbName}']/Table[@Name='${escapedTableName}']`); }); diff --git a/extensions/admin-tool-ext-win/src/utils.ts b/extensions/admin-tool-ext-win/src/utils.ts index 9f3d0b99b0..15a63adf9f 100644 --- a/extensions/admin-tool-ext-win/src/utils.ts +++ b/extensions/admin-tool-ext-win/src/utils.ts @@ -126,7 +126,7 @@ export const nodeTypeToUrnNameMapping: { [oeNodeType: string]: SmoMapping } = { * Builds the URN string for a given ObjectExplorerNode in the form understood by SsmsMin * @param node The node to get the URN of */ -export async function buildUrn(node: azdata.objectexplorer.ObjectExplorerNode): Promise { +export async function buildUrn(node?: azdata.objectexplorer.ObjectExplorerNode): Promise { let urnNodes: string[] = []; while (node) { // Server is special since it's a connection node - always add it as the root diff --git a/extensions/agent/tsconfig.json b/extensions/agent/tsconfig.json index d6d11ebc79..6084e9f6fd 100644 --- a/extensions/agent/tsconfig.json +++ b/extensions/agent/tsconfig.json @@ -10,7 +10,8 @@ "experimentalDecorators": true, "moduleResolution": "node", "strict": false, - "noUnusedParameters": false + "noUnusedParameters": false, + "strictNullChecks": false }, "exclude": [ "node_modules" diff --git a/extensions/azurecore/tsconfig.json b/extensions/azurecore/tsconfig.json index af0ff34f21..0e7adb6838 100644 --- a/extensions/azurecore/tsconfig.json +++ b/extensions/azurecore/tsconfig.json @@ -6,7 +6,8 @@ "noUnusedParameters": false, "typeRoots": [ "./node_modules/@types" - ] + ], + "strictNullChecks": false }, "include": [ "src/**/*" diff --git a/extensions/big-data-cluster/tsconfig.json b/extensions/big-data-cluster/tsconfig.json index 5723216cb2..10d3ba40f1 100644 --- a/extensions/big-data-cluster/tsconfig.json +++ b/extensions/big-data-cluster/tsconfig.json @@ -16,6 +16,7 @@ ], "strict": false, "noUnusedParameters": false, + "strictNullChecks": false }, "exclude": [ "node_modules" diff --git a/extensions/cms/tsconfig.json b/extensions/cms/tsconfig.json index f3bbe20f9a..26e548b9c8 100644 --- a/extensions/cms/tsconfig.json +++ b/extensions/cms/tsconfig.json @@ -17,6 +17,7 @@ "declaration": false, "strict": false, "noUnusedParameters": false, + "strictNullChecks": false }, "exclude": [ "node_modules" diff --git a/extensions/dacpac/tsconfig.json b/extensions/dacpac/tsconfig.json index 53fe835f2f..bda62ffc0d 100644 --- a/extensions/dacpac/tsconfig.json +++ b/extensions/dacpac/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "outDir": "./out", "strict": false, - "noUnusedParameters": false + "noUnusedParameters": false, + "strictNullChecks": false }, "include": [ "src/**/*" diff --git a/extensions/import/tsconfig.json b/extensions/import/tsconfig.json index dfe9ac6698..770f9be7c7 100644 --- a/extensions/import/tsconfig.json +++ b/extensions/import/tsconfig.json @@ -13,6 +13,7 @@ "declaration": false, "strict": false, "noUnusedParameters": false, + "strictNullChecks": false }, "exclude": [ "node_modules" diff --git a/extensions/integration-tests/tsconfig.json b/extensions/integration-tests/tsconfig.json index 9010061148..cb71eb9795 100644 --- a/extensions/integration-tests/tsconfig.json +++ b/extensions/integration-tests/tsconfig.json @@ -10,6 +10,7 @@ "strict": false, "noUnusedParameters": false, "noImplicitAny": false, + "strictNullChecks": false }, "include": [ "src/**/*" diff --git a/extensions/liveshare/tsconfig.json b/extensions/liveshare/tsconfig.json index 53fe835f2f..bda62ffc0d 100644 --- a/extensions/liveshare/tsconfig.json +++ b/extensions/liveshare/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "outDir": "./out", "strict": false, - "noUnusedParameters": false + "noUnusedParameters": false, + "strictNullChecks": false }, "include": [ "src/**/*" diff --git a/extensions/mssql/tsconfig.json b/extensions/mssql/tsconfig.json index 53fe835f2f..bda62ffc0d 100644 --- a/extensions/mssql/tsconfig.json +++ b/extensions/mssql/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "outDir": "./out", "strict": false, - "noUnusedParameters": false + "noUnusedParameters": false, + "strictNullChecks": false }, "include": [ "src/**/*" diff --git a/extensions/notebook/tsconfig.json b/extensions/notebook/tsconfig.json index 8438e5775b..a7d5e3c2c3 100644 --- a/extensions/notebook/tsconfig.json +++ b/extensions/notebook/tsconfig.json @@ -10,7 +10,8 @@ "noUnusedParameters": false, "typeRoots": [ "./node_modules/@types" - ] + ], + "strictNullChecks": false }, "include": [ "src/**/*" diff --git a/extensions/schema-compare/tsconfig.json b/extensions/schema-compare/tsconfig.json index e41e750112..738ad8d9f0 100644 --- a/extensions/schema-compare/tsconfig.json +++ b/extensions/schema-compare/tsconfig.json @@ -17,6 +17,7 @@ "noUnusedParameters": false, "noImplicitReturns": false, "noUnusedLocals": false, + "strictNullChecks": false }, "exclude": [ "node_modules" diff --git a/extensions/tsconfig.base.json b/extensions/tsconfig.base.json index 5651d57263..c598293873 100644 --- a/extensions/tsconfig.base.json +++ b/extensions/tsconfig.base.json @@ -26,12 +26,11 @@ "strict": true, "exactOptionalPropertyTypes": false, "useUnknownInCatchVariables": false, - "alwaysStrict": true, - "noImplicitAny": true, "noImplicitReturns": true, "noImplicitOverride": true, "noUnusedLocals": true, "noUnusedParameters": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "strictNullChecks": true } }