Strict null scripting (#12126)

* strict null scripting

* fix compile

* fix tests

* fix icon
This commit is contained in:
Anthony Dresser
2020-09-04 18:04:08 -07:00
committed by GitHub
parent bbe5b98a2c
commit 503090856a
35 changed files with 427 additions and 403 deletions

View File

@@ -8,6 +8,8 @@ import * as azdata from 'azdata';
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import type { IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IconPath } from 'sql/platform/connection/common/connectionProfile';
export const SERVICE_ID = 'capabilitiesService';
export const HOST_NAME = 'azdata';
@@ -20,6 +22,7 @@ export const clientCapabilities = {
export interface ConnectionProviderProperties {
providerId: string;
iconPath?: URI | IconPath | { id: string, path: IconPath }[]
displayName: string;
notebookKernelAlias?: string;
azureResource?: string;

View File

@@ -13,7 +13,13 @@ import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilit
import { isString } from 'vs/base/common/types';
import { deepClone } from 'vs/base/common/objects';
import * as Constants from 'sql/platform/connection/common/constants';
import { find } from 'vs/base/common/arrays';
import { URI } from 'vs/base/common/uri';
export interface IconPath {
light: URI;
dark: URI;
}
// Concrete implementation of the IConnectionProfile interface
@@ -29,6 +35,8 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
public groupId?: string;
public saveProfile: boolean;
public iconPath?: IconPath;
public isDisconnecting: boolean = false;
public constructor(
@@ -49,7 +57,7 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
let capabilities = this.capabilitiesService.getCapabilities(model.providerName);
if (capabilities && capabilities.connection && capabilities.connection.connectionOptions) {
const options = capabilities.connection.connectionOptions;
let appNameOption = find(options, option => option.specialValueType === interfaces.ConnectionOptionSpecialType.appName);
let appNameOption = options.find(option => option.specialValueType === interfaces.ConnectionOptionSpecialType.appName);
if (appNameOption) {
let appNameKey = appNameOption.name;
this.options[appNameKey] = Constants.applicationName;
@@ -87,9 +95,13 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
}
private static nullCheckEqualsIgnoreCase(a: string, b: string) {
let bothNull: boolean = !a && !b;
return bothNull ? bothNull : equalsIgnoreCase(a, b);
private static nullCheckEqualsIgnoreCase(a?: string, b?: string) {
if (a && !b || b && !a) {
return false;
} else {
let bothNull: boolean = !a && !b;
return bothNull ? bothNull : equalsIgnoreCase(a!, b!);
}
}
public generateNewId() {

View File

@@ -152,7 +152,7 @@ export class ConnectionStatusManager {
//Check if the existing connection database name is different the one in the summary
if (connection.connectionProfile.databaseName !== summary.connectionSummary.databaseName) {
//Add the ownerUri with database name to the map if not already exists
connection.connectionProfile.databaseName = summary.connectionSummary.databaseName;
connection.connectionProfile.databaseName = summary.connectionSummary.databaseName!;
let prefix = Utils.getUriPrefix(summary.ownerUri);
let ownerUriWithDbName = Utils.generateUriWithPrefix(connection.connectionProfile, prefix);
if (!(ownerUriWithDbName in this._connections)) {
@@ -186,7 +186,7 @@ export class ConnectionStatusManager {
let connection = this._connections[changedConnInfo.connectionUri];
if (connection && connection.connectionProfile) {
connection.connectionProfile.serverName = changedConnInfo.connection.serverName;
connection.connectionProfile.databaseName = changedConnInfo.connection.databaseName;
connection.connectionProfile.databaseName = changedConnInfo.connection.databaseName!;
connection.connectionProfile.userName = changedConnInfo.connection.userName;
return connection.connectionProfile;
}

View File

@@ -137,6 +137,6 @@ export function findProfileInGroup(og: IConnectionProfile, groups: ConnectionPro
export function isMaster(profile: IConnectionProfile): boolean {
// TODO: the connection profile should have a property to indicate whether the connection is a server connection or database connection
// created issue to track the problem: https://github.com/Microsoft/azuredatastudio/issues/5193.
return (profile.providerName === mssqlProviderName && profile.databaseName.toLowerCase() === 'master')
|| (profile.providerName.toLowerCase() === 'pgsql' && profile.databaseName.toLowerCase() === 'postgres');
return (profile.providerName === mssqlProviderName && profile.databaseName?.toLowerCase() === 'master')
|| (profile.providerName.toLowerCase() === 'pgsql' && profile.databaseName?.toLowerCase() === 'postgres');
}

View File

@@ -138,7 +138,7 @@ suite('SQL ConnectionProfileInfo tests', () => {
assert.equal(conn.serverName, undefined);
conn.connectionName = connectionProfile.connectionName!;
conn.serverName = connectionProfile.serverName;
conn.databaseName = connectionProfile.databaseName;
conn.databaseName = connectionProfile.databaseName!;
conn.authenticationType = connectionProfile.authenticationType;
conn.password = connectionProfile.password;
conn.userName = connectionProfile.userName;

View File

@@ -141,7 +141,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
assert.equal(conn.serverName, undefined);
conn.connectionName = connectionProfile.connectionName!;
conn.serverName = connectionProfile.serverName;
conn.databaseName = connectionProfile.databaseName;
conn.databaseName = connectionProfile.databaseName!;
conn.authenticationType = connectionProfile.authenticationType;
conn.password = connectionProfile.password;
conn.userName = connectionProfile.userName;
@@ -157,7 +157,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
let conn = new ProviderConnectionInfo(capabilitiesService, mssqlProviderName);
assert.equal(conn.serverName, undefined);
conn.serverName = connectionProfile.serverName;
conn.databaseName = connectionProfile.databaseName;
conn.databaseName = connectionProfile.databaseName!;
conn.authenticationType = connectionProfile.authenticationType;
conn.password = connectionProfile.password;
conn.userName = connectionProfile.userName;