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

@@ -165,7 +165,8 @@
},
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^8.10.25",
"@types/node": "^10.12.12",
"@types/request": "^2.48.1",
"mocha": "^5.2.0",
"should": "^13.2.1",
"typemoq": "^2.1.0"

View File

@@ -10,7 +10,6 @@ import * as nls from 'vscode-nls';
import * as vscode from 'vscode';
import * as url from 'url';
import {
Arguments,
AzureAccount,
AzureAccountProviderMetadata,
AzureAccountSecurityTokenCollection,
@@ -27,17 +26,12 @@ export class AzureAccountProvider implements azdata.AccountProvider {
private static AadCommonTenant: string = 'common';
// MEMBER VARIABLES ////////////////////////////////////////////////////
private _args: Arguments;
private _autoOAuthCancelled: boolean;
private _commonAuthorityUrl: string;
private _inProgressAutoOAuth: InProgressAutoOAuth;
private _isInitialized: boolean;
constructor(private _metadata: AzureAccountProviderMetadata, private _tokenCache: TokenCache) {
this._args = {
host: this._metadata.settings.host,
clientId: this._metadata.settings.clientId
};
this._autoOAuthCancelled = false;
this._inProgressAutoOAuth = null;
this._isInitialized = false;
@@ -361,7 +355,7 @@ export class AzureAccountProvider implements azdata.AccountProvider {
};
// Setup the callback to resolve/reject this promise
let callback = (error, response, body: { error: any; value: any; }) => {
const callback: request.RequestCallback = (error, response, body: { error: any; value: any; }) => {
if (error || body.error) {
reject(error || JSON.stringify(body.error));
} else {

View File

@@ -136,7 +136,7 @@ export default class TokenCache implements adal.TokenCache {
&& entry1.resource === entry2.resource;
}
private static findByPartial(entry: adal.TokenResponse, query: object): boolean {
private static findByPartial(entry: adal.TokenResponse, query: { [key: string]: any }): boolean {
for (let key in query) {
if (entry[key] === undefined || entry[key] !== query[key]) {
return false;

View File

@@ -153,12 +153,6 @@ export class ApiWrapper {
return vscode.window.showSaveDialog(options);
}
public openTextDocument(uri: vscode.Uri): Thenable<vscode.TextDocument>;
public openTextDocument(options: { language?: string; content?: string; }): Thenable<vscode.TextDocument>;
public openTextDocument(uriOrOptions): Thenable<vscode.TextDocument> {
return vscode.workspace.openTextDocument(uriOrOptions);
}
public showTextDocument(document: vscode.TextDocument, column?: vscode.ViewColumn, preserveFocus?: boolean, preview?: boolean): Thenable<vscode.TextEditor> {
let options: vscode.TextDocumentShowOptions = {
viewColumn: column,
@@ -209,7 +203,7 @@ export class ApiWrapper {
return azdata.accounts.getAllAccounts();
}
public getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{}> {
public getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{ [key: string]: any }> {
return azdata.accounts.getSecurityToken(account, resource);
}

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 { ApiWrapper } from './apiWrapper';

View File

@@ -3,8 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Account, NodeInfo, AzureResource } from 'azdata';
import { TokenCredentials } from 'ms-rest';

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 nls from 'vscode-nls';
const localize = nls.loadMessageBundle();

View File

@@ -3,10 +3,8 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import ControllerBase from './controllerBase';
import { DidChangeAccountsParams } from 'azdata';
import { DidChangeAccountsParams, Account } from 'azdata';
import {
IAzureResourceCacheService,
@@ -39,7 +37,7 @@ export default class AzureResourceController extends ControllerBase {
const azureResourceTree = new AzureResourceTreeProvider(this.appContext);
this.extensionContext.subscriptions.push(this.apiWrapper.registerTreeDataProvider('azureResourceExplorer', azureResourceTree));
let previousAccounts = undefined;
let previousAccounts: Array<Account> = undefined;
this.appContext.getService<IAzureResourceAccountService>(AzureResourceServiceNames.accountService).onDidChangeAccounts((e: DidChangeAccountsParams) => {
// the onDidChangeAccounts event will trigger in many cases where the accounts didn't actually change
// the notifyNodeChanged event triggers a refresh which triggers a getChildren which can trigger this callback

View File

@@ -57,7 +57,7 @@ export function activate(extensionContext: vscode.ExtensionContext) {
} catch (e) {
console.error(`Initialization of Azure account extension storage failed: ${e}`);
console.error('Azure accounts will not be available');
return;
return undefined;
}
// Create the provider service and activate

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 TypeMoq from 'typemoq';
import * as azdata from 'azdata';
@@ -59,7 +57,7 @@ const mockResourceRootNode: azureResource.IAzureResourceNode = {
}
};
const mockTokens = {};
const mockTokens: { [key: string]: any } = {};
mockTokens[mockTenantId] = {
token: 'mock_token',
tokenType: 'Bearer'
@@ -80,14 +78,14 @@ const mockDatabases: AzureResourceDatabase[] = [
}
];
describe('AzureResourceDatabaseTreeDataProvider.info', function(): void {
describe('AzureResourceDatabaseTreeDataProvider.info', function (): void {
beforeEach(() => {
mockDatabaseService = TypeMoq.Mock.ofType<IAzureResourceDatabaseService>();
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
});
it('Should be correct when created.', async function(): Promise<void> {
it('Should be correct when created.', async function (): Promise<void> {
const treeDataProvider = new AzureResourceDatabaseTreeDataProvider(mockDatabaseService.object, mockApiWrapper.object, mockExtensionContext.object);
const treeItem = await treeDataProvider.getTreeItem(mockResourceRootNode);
@@ -98,7 +96,7 @@ describe('AzureResourceDatabaseTreeDataProvider.info', function(): void {
});
});
describe('AzureResourceDatabaseTreeDataProvider.getChildren', function(): void {
describe('AzureResourceDatabaseTreeDataProvider.getChildren', function (): void {
beforeEach(() => {
mockDatabaseService = TypeMoq.Mock.ofType<IAzureResourceDatabaseService>();
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
@@ -109,7 +107,7 @@ describe('AzureResourceDatabaseTreeDataProvider.getChildren', function(): void {
mockExtensionContext.setup((o) => o.asAbsolutePath(TypeMoq.It.isAnyString())).returns(() => TypeMoq.It.isAnyString());
});
it('Should return container node when element is undefined.', async function(): Promise<void> {
it('Should return container node when element is undefined.', async function (): Promise<void> {
const treeDataProvider = new AzureResourceDatabaseTreeDataProvider(mockDatabaseService.object, mockApiWrapper.object, mockExtensionContext.object);
const children = await treeDataProvider.getChildren();
@@ -127,7 +125,7 @@ describe('AzureResourceDatabaseTreeDataProvider.getChildren', function(): void {
should(child.treeItem.contextValue).equal('azure.resource.itemType.databaseContainer');
});
it('Should return resource nodes when it is container node.', async function(): Promise<void> {
it('Should return resource nodes when it is container node.', async function (): Promise<void> {
const treeDataProvider = new AzureResourceDatabaseTreeDataProvider(mockDatabaseService.object, mockApiWrapper.object, mockExtensionContext.object);
const children = await treeDataProvider.getChildren(mockResourceRootNode);

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 TypeMoq from 'typemoq';
import * as azdata from 'azdata';
@@ -59,7 +57,7 @@ const mockResourceRootNode: azureResource.IAzureResourceNode = {
}
};
const mockTokens = {};
const mockTokens: { [key: string]: any } = {};
mockTokens[mockTenantId] = {
token: 'mock_token',
tokenType: 'Bearer'
@@ -80,14 +78,14 @@ const mockDatabaseServers: AzureResourceDatabaseServer[] = [
}
];
describe('AzureResourceDatabaseServerTreeDataProvider.info', function(): void {
describe('AzureResourceDatabaseServerTreeDataProvider.info', function (): void {
beforeEach(() => {
mockDatabaseServerService = TypeMoq.Mock.ofType<IAzureResourceDatabaseServerService>();
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
});
it('Should be correct when created.', async function(): Promise<void> {
it('Should be correct when created.', async function (): Promise<void> {
const treeDataProvider = new AzureResourceDatabaseServerTreeDataProvider(mockDatabaseServerService.object, mockApiWrapper.object, mockExtensionContext.object);
const treeItem = await treeDataProvider.getTreeItem(mockResourceRootNode);
@@ -98,7 +96,7 @@ describe('AzureResourceDatabaseServerTreeDataProvider.info', function(): void {
});
});
describe('AzureResourceDatabaseServerTreeDataProvider.getChildren', function(): void {
describe('AzureResourceDatabaseServerTreeDataProvider.getChildren', function (): void {
beforeEach(() => {
mockDatabaseServerService = TypeMoq.Mock.ofType<IAzureResourceDatabaseServerService>();
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
@@ -109,7 +107,7 @@ describe('AzureResourceDatabaseServerTreeDataProvider.getChildren', function():
mockExtensionContext.setup((o) => o.asAbsolutePath(TypeMoq.It.isAnyString())).returns(() => TypeMoq.It.isAnyString());
});
it('Should return container node when element is undefined.', async function(): Promise<void> {
it('Should return container node when element is undefined.', async function (): Promise<void> {
const treeDataProvider = new AzureResourceDatabaseServerTreeDataProvider(mockDatabaseServerService.object, mockApiWrapper.object, mockExtensionContext.object);
const children = await treeDataProvider.getChildren();
@@ -127,7 +125,7 @@ describe('AzureResourceDatabaseServerTreeDataProvider.getChildren', function():
should(child.treeItem.contextValue).equal('azure.resource.itemType.databaseServerContainer');
});
it('Should return resource nodes when it is container node.', async function(): Promise<void> {
it('Should return resource nodes when it is container node.', async function (): Promise<void> {
const treeDataProvider = new AzureResourceDatabaseServerTreeDataProvider(mockDatabaseServerService.object, mockApiWrapper.object, mockExtensionContext.object);
const children = await treeDataProvider.getChildren(mockResourceRootNode);

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 TypeMoq from 'typemoq';
import * as azdata from 'azdata';
@@ -77,7 +75,7 @@ const mockSubscriptions = [mockSubscription1, mockSubscription2];
const mockFilteredSubscriptions = [mockSubscription1];
const mockTokens = {};
const mockTokens: { [key: string]: any } = {};
mockTokens[mockTenantId] = {
token: 'mock_token',
tokenType: 'Bearer'
@@ -87,7 +85,7 @@ const mockCredential = new TokenCredentials(mockTokens[mockTenantId].token, mock
let mockSubscriptionCache: azureResource.AzureResourceSubscription[] = [];
describe('AzureResourceAccountTreeNode.info', function(): void {
describe('AzureResourceAccountTreeNode.info', function (): void {
beforeEach(() => {
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
@@ -113,7 +111,7 @@ describe('AzureResourceAccountTreeNode.info', function(): void {
mockTenantService.setup((o) => o.getTenantId(TypeMoq.It.isAny())).returns(() => Promise.resolve(mockTenantId));
});
it('Should be correct when created.', async function(): Promise<void> {
it('Should be correct when created.', async function (): Promise<void> {
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
const accountTreeNodeId = `account_${mockAccount.key.accountId}`;
@@ -134,7 +132,7 @@ describe('AzureResourceAccountTreeNode.info', function(): void {
should(nodeInfo.iconType).equal(AzureResourceItemType.account);
});
it('Should be correct when there are subscriptions listed.', async function(): Promise<void> {
it('Should be correct when there are subscriptions listed.', async function (): Promise<void> {
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve(undefined));
@@ -154,7 +152,7 @@ describe('AzureResourceAccountTreeNode.info', function(): void {
should(nodeInfo.label).equal(accountTreeNodeLabel);
});
it('Should be correct when there are subscriptions filtered.', async function(): Promise<void> {
it('Should be correct when there are subscriptions filtered.', async function (): Promise<void> {
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve(mockFilteredSubscriptions));
@@ -175,7 +173,7 @@ describe('AzureResourceAccountTreeNode.info', function(): void {
});
});
describe('AzureResourceAccountTreeNode.getChildren', function(): void {
describe('AzureResourceAccountTreeNode.getChildren', function (): void {
beforeEach(() => {
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
@@ -201,7 +199,7 @@ describe('AzureResourceAccountTreeNode.getChildren', function(): void {
mockTenantService.setup((o) => o.getTenantId(TypeMoq.It.isAny())).returns(() => Promise.resolve(mockTenantId));
});
it('Should load subscriptions from scratch and update cache when it is clearing cache.', async function(): Promise<void> {
it('Should load subscriptions from scratch and update cache when it is clearing cache.', async function (): Promise<void> {
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve([]));
@@ -235,7 +233,7 @@ describe('AzureResourceAccountTreeNode.getChildren', function(): void {
}
});
it('Should load subscriptions from cache when it is not clearing cache.', async function(): Promise<void> {
it('Should load subscriptions from cache when it is not clearing cache.', async function (): Promise<void> {
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve(undefined));
@@ -256,7 +254,7 @@ describe('AzureResourceAccountTreeNode.getChildren', function(): void {
}
});
it('Should handle when there is no subscriptions.', async function(): Promise<void> {
it('Should handle when there is no subscriptions.', async function (): Promise<void> {
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(undefined));
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
@@ -272,7 +270,7 @@ describe('AzureResourceAccountTreeNode.getChildren', function(): void {
should(children[0].getNodeInfo().label).equal('No Subscriptions found.');
});
it('Should honor subscription filtering.', async function(): Promise<void> {
it('Should honor subscription filtering.', async function (): Promise<void> {
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve(mockFilteredSubscriptions));
@@ -290,7 +288,7 @@ describe('AzureResourceAccountTreeNode.getChildren', function(): void {
}
});
it('Should handle errors.', async function(): Promise<void> {
it('Should handle errors.', async function (): Promise<void> {
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
const mockError = 'Test error';
@@ -314,7 +312,7 @@ describe('AzureResourceAccountTreeNode.getChildren', function(): void {
});
});
describe('AzureResourceAccountTreeNode.clearCache', function() : void {
describe('AzureResourceAccountTreeNode.clearCache', function (): void {
beforeEach(() => {
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
@@ -340,7 +338,7 @@ describe('AzureResourceAccountTreeNode.clearCache', function() : void {
mockTenantService.setup((o) => o.getTenantId(TypeMoq.It.isAny())).returns(() => Promise.resolve(mockTenantId));
});
it('Should clear cache.', async function(): Promise<void> {
it('Should clear cache.', async function (): Promise<void> {
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
accountTreeNode.clearCache();
should(accountTreeNode.isClearingCache).true();

View File

@@ -3,11 +3,10 @@
"compilerOptions": {
"outDir": "./out",
"strict": false,
"alwaysStrict": false,
"noImplicitAny": false,
"noImplicitReturns": false,
"noUnusedLocals": false,
"noUnusedParameters": false
"noUnusedParameters": false,
"typeRoots": [
"./node_modules/@types"
]
},
"include": [
"src/**/*"

View File

@@ -2,20 +2,47 @@
# yarn lockfile v1
"@types/caseless@*":
version "0.12.2"
resolved "https://registry.yarnpkg.com/@types/caseless/-/caseless-0.12.2.tgz#f65d3d6389e01eeb458bd54dc8f52b95a9463bc8"
integrity sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==
"@types/form-data@*":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@types/form-data/-/form-data-2.2.1.tgz#ee2b3b8eaa11c0938289953606b745b738c54b1e"
integrity sha512-JAMFhOaHIciYVh8fb5/83nmuO/AHwmto+Hq7a9y8FzLDcC1KCU344XDOMEmahnrTFlHjgh4L0WJFczNIX2GxnQ==
dependencies:
"@types/node" "*"
"@types/mocha@^5.2.5":
version "5.2.5"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.5.tgz#8a4accfc403c124a0bafe8a9fc61a05ec1032073"
integrity sha512-lAVp+Kj54ui/vLUFxsJTMtWvZraZxum3w3Nwkble2dNuV5VnPA+Mi2oGX9XYJAaIvZi3tn3cbjS/qcJXRb6Bww==
"@types/node@^8.0.47":
version "8.10.39"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.39.tgz#e7e87ad00364dd7bc485c940926345b8ec1a26ca"
integrity sha512-rE7fktr02J8ybFf6eysife+WF+L4sAHWzw09DgdCebEu+qDwMvv4zl6Bc+825ttGZP73kCKxa3dhJOoGJ8+5mA==
"@types/node@*", "@types/node@^10.12.12":
version "10.14.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.4.tgz#1c586b991457cbb58fef51bc4e0cfcfa347714b5"
integrity sha512-DT25xX/YgyPKiHFOpNuANIQIVvYEwCWXgK2jYYwqgaMrYE6+tq+DtmMwlD3drl6DJbUwtlIDnn0d7tIn/EbXBg==
"@types/node@^8.10.25":
version "8.10.42"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.42.tgz#d3d8e738e13540a09b3f4a714dac1ffbf8939f7d"
integrity sha512-8LCqostMfYwQs9by1k21/P4KZp9uFQk3Q528y3qtPKQnCJmKz0Em3YzgeNjTNV1FVrG/7n/6j12d4UKg9zSgDw==
"@types/node@^8.0.47":
version "8.10.45"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.45.tgz#4c49ba34106bc7dced77ff6bae8eb6543cde8351"
integrity sha512-tGVTbA+i3qfXsLbq9rEq/hezaHY55QxQLeXQL2ejNgFAxxrgu8eMmYIOsRcl7hN1uTLVsKOOYacV/rcJM3sfgQ==
"@types/request@^2.48.1":
version "2.48.1"
resolved "https://registry.yarnpkg.com/@types/request/-/request-2.48.1.tgz#e402d691aa6670fbbff1957b15f1270230ab42fa"
integrity sha512-ZgEZ1TiD+KGA9LiAAPPJL68Id2UWfeSO62ijSXZjFJArVV+2pKcsVHmrcu+1oiE3q6eDGiFiSolRc4JHoerBBg==
dependencies:
"@types/caseless" "*"
"@types/form-data" "*"
"@types/node" "*"
"@types/tough-cookie" "*"
"@types/tough-cookie@*":
version "2.3.5"
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-2.3.5.tgz#9da44ed75571999b65c37b60c9b2b88db54c585d"
integrity sha512-SCcK7mvGi3+ZNz833RRjFIxrn4gI1PPR3NtuIS+6vMkvmsGjosqTJwRt5bAEFLRz+wtJMWv8+uOnZf2hi2QXTg==
adal-node@^0.1.28:
version "0.1.28"