Enable strictNullChecks for extensions by default (#19197)

* Strict null on extensions

* fix test

* Fail on no stdin
This commit is contained in:
Charles Gagnon
2022-04-25 09:19:42 -07:00
committed by GitHub
parent d0aae8e95b
commit cd8a747522
17 changed files with 39 additions and 28 deletions

View File

@@ -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

View File

@@ -8,6 +8,6 @@ import * as vscode from 'vscode';
describe('Extension activate test', () => {
it('Extension should activate correctly', async function (): Promise<void> {
await vscode.extensions.getExtension('Microsoft.admin-tool-ext-win').activate();
await vscode.extensions.getExtension('Microsoft.admin-tool-ext-win')!.activate();
});
});

View File

@@ -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<boolean> {
@@ -38,7 +38,7 @@ export class ExtHostObjectExplorerNodeStub implements azdata.objectexplorer.Obje
throw new Error('Method not implemented');
}
setSelected(selected: boolean, clearOtherSelections: boolean = undefined): Thenable<void> {
setSelected(selected: boolean, clearOtherSelections: boolean): Thenable<void> {
throw new Error('Method not implemented');
}

View File

@@ -77,14 +77,14 @@ describe('buildUrn Method Tests', () => {
it('Urn should be correct with Server and only Databases folder', async function (): Promise<void> {
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<void> {
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<void> {
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<void> {
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}']`);
});

View File

@@ -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<string> {
export async function buildUrn(node?: azdata.objectexplorer.ObjectExplorerNode): Promise<string> {
let urnNodes: string[] = [];
while (node) {
// Server is special since it's a connection node - always add it as the root

View File

@@ -10,7 +10,8 @@
"experimentalDecorators": true,
"moduleResolution": "node",
"strict": false,
"noUnusedParameters": false
"noUnusedParameters": false,
"strictNullChecks": false
},
"exclude": [
"node_modules"

View File

@@ -6,7 +6,8 @@
"noUnusedParameters": false,
"typeRoots": [
"./node_modules/@types"
]
],
"strictNullChecks": false
},
"include": [
"src/**/*"

View File

@@ -16,6 +16,7 @@
],
"strict": false,
"noUnusedParameters": false,
"strictNullChecks": false
},
"exclude": [
"node_modules"

View File

@@ -17,6 +17,7 @@
"declaration": false,
"strict": false,
"noUnusedParameters": false,
"strictNullChecks": false
},
"exclude": [
"node_modules"

View File

@@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "./out",
"strict": false,
"noUnusedParameters": false
"noUnusedParameters": false,
"strictNullChecks": false
},
"include": [
"src/**/*"

View File

@@ -13,6 +13,7 @@
"declaration": false,
"strict": false,
"noUnusedParameters": false,
"strictNullChecks": false
},
"exclude": [
"node_modules"

View File

@@ -10,6 +10,7 @@
"strict": false,
"noUnusedParameters": false,
"noImplicitAny": false,
"strictNullChecks": false
},
"include": [
"src/**/*"

View File

@@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "./out",
"strict": false,
"noUnusedParameters": false
"noUnusedParameters": false,
"strictNullChecks": false
},
"include": [
"src/**/*"

View File

@@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "./out",
"strict": false,
"noUnusedParameters": false
"noUnusedParameters": false,
"strictNullChecks": false
},
"include": [
"src/**/*"

View File

@@ -10,7 +10,8 @@
"noUnusedParameters": false,
"typeRoots": [
"./node_modules/@types"
]
],
"strictNullChecks": false
},
"include": [
"src/**/*"

View File

@@ -17,6 +17,7 @@
"noUnusedParameters": false,
"noImplicitReturns": false,
"noUnusedLocals": false,
"strictNullChecks": false
},
"exclude": [
"node_modules"

View File

@@ -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
}
}