Skip to content

Commit

Permalink
chore(core): Add prefer-const tslint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
jrsquared committed Apr 11, 2017
1 parent 3a66ffc commit 2b07d34
Show file tree
Hide file tree
Showing 135 changed files with 618 additions and 610 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {AWSProviderSettings} from '../aws.settings';

class AmazonApplicationNameValidator implements IApplicationNameValidator {
private validateSpecialCharacters(name: string, errors: string[]): void {
let pattern = /^[a-zA-Z_0-9.]*$/g;
const pattern = /^[a-zA-Z_0-9.]*$/g;
if (!pattern.test(name)) {
errors.push('Only dot(.) and underscore(_) special characters are allowed.');
}
}

private validateClassicLock(warnings: string[]): void {
let lockoutDate = AWSProviderSettings.classicLaunchLockout;
const lockoutDate = AWSProviderSettings.classicLaunchLockout;
if (lockoutDate && lockoutDate < new Date().getTime()) {
warnings.push('New applications deployed to AWS are restricted to VPC; you cannot create server groups, ' +
'load balancers, or security groups in EC2 Classic.');
Expand All @@ -38,7 +38,7 @@ class AmazonApplicationNameValidator implements IApplicationNameValidator {
if (name.length >= 248) {
warnings.push('You will not be able to include a stack or detail field for clusters or security groups.');
} else {
let remaining = 248 - name.length;
const remaining = 248 - name.length;
warnings.push(`If you plan to include a stack or detail field for clusters, you will only
have ~${remaining} characters to do so.`);
}
Expand All @@ -53,7 +53,7 @@ class AmazonApplicationNameValidator implements IApplicationNameValidator {
for load balancer names is 32 (currently: ${name.length} characters). With separators ("-"), you will not
be able to add a stack and detail field to any load balancer.`);
} else {
let remaining = 30 - name.length;
const remaining = 30 - name.length;
warnings.push(`If you plan to create load balancers for this application, be aware that the character limit
for load balancer names is 32. You will only have ~${remaining} characters to add a stack or detail
field to any load balancer.`);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/appengine/appengine.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {CLOUD_PROVIDER_REGISTRY, CloudProviderRegistry} from 'core/cloudProvider

import './logo/appengine.logo.less';

let templates = require.context('./', true, /\.html$/);
const templates = require.context('./', true, /\.html$/);
templates.keys().forEach(function(key) {
templates(key);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {HELP_CONTENTS_REGISTRY, HelpContentsRegistry} from 'core/help/helpConten
export const APPENGINE_HELP_CONTENTS_REGISTRY = 'spinnaker.appengine.helpContents.registry';
module(APPENGINE_HELP_CONTENTS_REGISTRY, [HELP_CONTENTS_REGISTRY])
.run((helpContentsRegistry: HelpContentsRegistry) => {
let helpContents = [
const helpContents = [
{
key: 'appengine.serverGroup.repositoryUrl',
value: `The full URL to the git repository containing the source files for this deployment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class AppengineInstanceDetailsController {
}

public terminateInstance(): void {
let instance = cloneDeep(this.instance) as any;
let shortName = `${this.instance.name.substring(0, 10)}...`;
const instance = cloneDeep(this.instance) as any;
const shortName = `${this.instance.name.substring(0, 10)}...`;
instance.placement = {};
instance.instanceId = instance.name;

let taskMonitor = {
const taskMonitor = {
application: this.app,
title: 'Terminating ' + shortName,
onTaskComplete: function() {
Expand All @@ -67,7 +67,7 @@ class AppengineInstanceDetailsController {
}
};

let submitMethod = () => {
const submitMethod = () => {
return this.instanceWriter.terminateInstance(instance, this.app, {cloudProvider: 'appengine'});
};

Expand All @@ -81,20 +81,20 @@ class AppengineInstanceDetailsController {
}

private retrieveInstance(instance: InstanceFromStateParams): IPromise<IAppengineInstance> {
let instanceLocatorPredicate = (dataSource: InstanceContainer) => {
const instanceLocatorPredicate = (dataSource: InstanceContainer) => {
return dataSource.instances.some((possibleMatch) => possibleMatch.id === instance.instanceId);
};

let dataSources: InstanceContainer[] = flattenDeep([
const dataSources: InstanceContainer[] = flattenDeep([
this.app.getDataSource('serverGroups').data,
this.app.getDataSource('loadBalancers').data,
this.app.getDataSource('loadBalancers').data.map((loadBalancer) => loadBalancer.serverGroups),
]);

let instanceContainer = dataSources.find(instanceLocatorPredicate);
const instanceContainer = dataSources.find(instanceLocatorPredicate);

if (instanceContainer) {
let recentHistoryExtraData: {[key: string]: string} = {
const recentHistoryExtraData: {[key: string]: string} = {
region: instanceContainer.region,
account: instanceContainer.account,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class AppengineLoadBalancerAdvancedSettingsCtrl implements ng.IComponentControll
if (this.loadBalancer.splitDescription.allocationDescriptions.length !== 1) {
return true;
} else {
let targetServerGroupName = this.loadBalancer.splitDescription.allocationDescriptions[0].serverGroupName;
let targetServerGroup = this.loadBalancer.serverGroups.find(candidate => candidate.name === targetServerGroupName);
const targetServerGroupName = this.loadBalancer.splitDescription.allocationDescriptions[0].serverGroupName;
const targetServerGroup = this.loadBalancer.serverGroups.find(candidate => candidate.name === targetServerGroupName);

if (targetServerGroup) {
return !targetServerGroup.allowsGradualTrafficMigration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppengineLoadBalancerSettingsController implements ng.IComponentController
}

public addAllocation(): void {
let remainingServerGroups = this.serverGroupsWithoutAllocation();
const remainingServerGroups = this.serverGroupsWithoutAllocation();
if (remainingServerGroups.length) {
this.loadBalancer.splitDescription.allocationDescriptions.push({serverGroupName: remainingServerGroups[0], allocation: 0, locatorType: 'fromExisting'});
if (this.loadBalancer.splitDescription.allocationDescriptions.length > 1 && !this.loadBalancer.splitDescription.shardBy) {
Expand Down Expand Up @@ -60,8 +60,8 @@ class AppengineLoadBalancerSettingsController implements ng.IComponentController
}

private serverGroupsWithoutAllocation(): string[] {
let serverGroupsWithAllocation = this.loadBalancer.splitDescription.allocationDescriptions.map(description => description.serverGroupName);
let allServerGroups = this.loadBalancer.serverGroups.map(serverGroup => serverGroup.name);
const serverGroupsWithAllocation = this.loadBalancer.splitDescription.allocationDescriptions.map(description => description.serverGroupName);
const allServerGroups = this.loadBalancer.serverGroups.map(serverGroup => serverGroup.name);
return difference(allServerGroups, serverGroupsWithAllocation);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AppengineStageAllocationLabelCtrl implements ng.IComponentController {
private allocationDescription: IAppengineAllocationDescription;

private static mapTargetCoordinateToLabel(targetCoordinate: string): string {
let target = StageConstants.TARGET_LIST.find(t => t.val === targetCoordinate);
const target = StageConstants.TARGET_LIST.find(t => t.val === targetCoordinate);
if (target) {
return target.label;
} else {
Expand All @@ -31,7 +31,7 @@ class AppengineStageAllocationLabelCtrl implements ng.IComponentController {
break;
case 'targetCoordinate':
if (this.allocationDescription.cluster && this.allocationDescription.target) {
let targetLabel = AppengineStageAllocationLabelCtrl.mapTargetCoordinateToLabel(this.allocationDescription.target);
const targetLabel = AppengineStageAllocationLabelCtrl.mapTargetCoordinateToLabel(this.allocationDescription.target);
this.inputViewValue = `${targetLabel} (${this.allocationDescription.cluster})`;
} else {
this.inputViewValue = null;
Expand Down Expand Up @@ -63,7 +63,7 @@ class AppengineStageAllocationConfigurationRowCtrl implements ng.IComponentContr
public static get $inject() { return ['appListExtractorService']; }

constructor(private appListExtractorService: any) {
let clusterFilter = this.appListExtractorService.clusterFilterForCredentialsAndRegion(this.account, this.region);
const clusterFilter = this.appListExtractorService.clusterFilterForCredentialsAndRegion(this.account, this.region);
this.clusterList = this.appListExtractorService.getClusters([this.application], clusterFilter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AppengineLoadBalancerWizardController {
}

public submit(): any {
let description = cloneDeep(this.loadBalancer);
const description = cloneDeep(this.loadBalancer);
description.mapAllocationsToDecimals();
delete description.serverGroups;

Expand Down Expand Up @@ -119,7 +119,7 @@ class AppengineLoadBalancerWizardController {
}

this.$uibModalInstance.dismiss();
let newStateParams = {
const newStateParams = {
name: this.loadBalancer.name,
accountId: this.loadBalancer.credentials,
region: this.loadBalancer.region,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class AppengineLoadBalancerDetailsController {
}

public deleteLoadBalancer(): void {
let taskMonitor = {
const taskMonitor = {
application: this.app,
title: 'Deleting ' + this.loadBalancer.name,
};

let submitMethod = () => {
const submitMethod = () => {
const loadBalancer: ILoadBalancerDeleteDescription = {
cloudProvider: this.loadBalancer.cloudProvider,
loadBalancerName: this.loadBalancer.name,
Expand Down Expand Up @@ -109,14 +109,14 @@ class AppengineLoadBalancerDetailsController {
}

private getConfirmationModalBodyHtml(): string {
let serverGroupNames = this.loadBalancer.serverGroups.map(serverGroup => serverGroup.name);
let hasAny = serverGroupNames ? serverGroupNames.length > 0 : false;
let hasMoreThanOne = serverGroupNames ? serverGroupNames.length > 1 : false;
const serverGroupNames = this.loadBalancer.serverGroups.map(serverGroup => serverGroup.name);
const hasAny = serverGroupNames ? serverGroupNames.length > 0 : false;
const hasMoreThanOne = serverGroupNames ? serverGroupNames.length > 1 : false;

// HTML accepted by the confirmationModalService is static (i.e., not managed by angular).
if (hasAny) {
if (hasMoreThanOne) {
let listOfServerGroupNames = serverGroupNames.map(name => `<li>${name}</li>`).join('');
const listOfServerGroupNames = serverGroupNames.map(name => `<li>${name}</li>`).join('');
return `
<div class="alert alert-warning">
<p>
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/modules/appengine/loadBalancer/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AppengineLoadBalancerUpsertDescription implements ILoadBalancerUpse
public serverGroups?: any[];

public static convertTrafficSplitToTrafficSplitDescription(split: IAppengineTrafficSplit): IAppengineTrafficSplitDescription {
let allocationDescriptions = reduce(split.allocations, (acc: IAppengineAllocationDescription[], allocation: number, serverGroupName: string) => {
const allocationDescriptions = reduce(split.allocations, (acc: IAppengineAllocationDescription[], allocation: number, serverGroupName: string) => {
return acc.concat({serverGroupName, allocation, locatorType: 'fromExisting'});
}, []);

Expand Down Expand Up @@ -85,15 +85,15 @@ export class AppengineLoadBalancerTransformer {
.map((instance: any) => this.transformInstance(instance, loadBalancer));
});

let activeServerGroups = filter(loadBalancer.serverGroups, {isDisabled: false});
const activeServerGroups = filter(loadBalancer.serverGroups, {isDisabled: false});
loadBalancer.instances = chain(activeServerGroups).map('instances').flatten().value() as Instance[];
return this.$q.resolve(loadBalancer);
}

public convertLoadBalancerForEditing(loadBalancer: IAppengineLoadBalancer,
application: Application): ng.IPromise<IAppengineLoadBalancer> {
return application.getDataSource('loadBalancers').ready().then(() => {
let upToDateLoadBalancer = application.getDataSource('loadBalancers').data.find((candidate: ILoadBalancer) => {
const upToDateLoadBalancer = application.getDataSource('loadBalancers').data.find((candidate: ILoadBalancer) => {
return candidate.name === loadBalancer.name &&
(candidate.account === loadBalancer.account || candidate.account === loadBalancer.credentials);
});
Expand All @@ -110,7 +110,7 @@ export class AppengineLoadBalancerTransformer {
}

private buildInstanceCounts(serverGroups: ServerGroup[]): InstanceCounts {
let instanceCounts: InstanceCounts = chain(serverGroups)
const instanceCounts: InstanceCounts = chain(serverGroups)
.map('instances')
.flatten()
.reduce((acc: InstanceCounts, instance: any) => {
Expand All @@ -129,7 +129,7 @@ export class AppengineLoadBalancerTransformer {
instance.account = loadBalancer.account;
instance.region = loadBalancer.region;
instance.loadBalancers = [loadBalancer.name];
let health = instance.health || {};
const health = instance.health || {};
instance.healthState = get(instance, 'health.state') || 'OutOfService';
instance.health = [health];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class AppengineStageCtrl {
}

public setStageRegion(): void {
let selected = this.$scope.accounts.find((account) => account.name === this.$scope.stage.credentials);
const selected = this.$scope.accounts.find((account) => account.name === this.$scope.stage.credentials);
if (selected && selected.name) {
this.accountService.getAccountDetails(selected.name)
.then((accountDetails: IAppengineAccount) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AppengineEditLoadBalancerStageCtrl {
}

public editLoadBalancer(index: number) {
let config = this.cloudProviderRegistry.getValue('appengine', 'loadBalancer');
const config = this.cloudProviderRegistry.getValue('appengine', 'loadBalancer');
this.$uibModal.open({
templateUrl: config.createLoadBalancerTemplateUrl,
controller: `${config.createLoadBalancerController} as ctrl`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class AppengineLoadBalancerChoiceModalCtrl {
}

public submit(): void {
let config = this.cloudProviderRegistry.getValue('appengine', 'loadBalancer');
let updatedLoadBalancerPromise = this.$uibModal.open({
const config = this.cloudProviderRegistry.getValue('appengine', 'loadBalancer');
const updatedLoadBalancerPromise = this.$uibModal.open({
templateUrl: config.createLoadBalancerTemplateUrl,
controller: `${config.createLoadBalancerController} as ctrl`,
size: 'lg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AppengineShrinkClusterStageCtrl extends AppengineStageCtrl {
super.setStageCloudProvider();
super.setStageCredentials();

let stage = $scope.stage as IAppengineShrinkClusterStage;
const stage = $scope.stage as IAppengineShrinkClusterStage;
if (stage.shrinkToSize === undefined) {
stage.shrinkToSize = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ export class AppengineServerGroupCommandBuilder {
public buildNewServerGroupCommand(app: Application,
selectedProvider = 'appengine',
mode = 'create'): IPromise<IAppengineServerGroupCommand> {
let dataToFetch = {
const dataToFetch = {
accounts: this.accountService.getAllAccountDetailsForProvider('appengine'),
};

let viewState: IViewState = {
const viewState: IViewState = {
mode: mode,
submitButtonLabel: this.getSubmitButtonLabel(mode),
disableStrategySelection: mode === 'create' ? true : false,
};

return this.$q.all(dataToFetch)
.then((backingData: any) => {
let credentials: string = this.getCredentials(backingData.accounts, app);
let region: string = this.getRegion(backingData.accounts, credentials);
const credentials: string = this.getCredentials(backingData.accounts, app);
const region: string = this.getRegion(backingData.accounts, credentials);

return {
application: app.name,
Expand Down Expand Up @@ -115,17 +115,17 @@ export class AppengineServerGroupCommandBuilder {
}

private getCredentials(accounts: IAppengineAccount[], application: Application): string {
let accountNames: string[] = (accounts || []).map((account) => account.name);
let defaultCredentials: string = AppengineProviderSettings.defaults.account;
let firstApplicationAccount: string = intersection(application.accounts || [], accountNames)[0];
const accountNames: string[] = (accounts || []).map((account) => account.name);
const defaultCredentials: string = AppengineProviderSettings.defaults.account;
const firstApplicationAccount: string = intersection(application.accounts || [], accountNames)[0];

return accountNames.includes(defaultCredentials) ?
defaultCredentials :
(firstApplicationAccount || 'my-appengine-account');
}

private getRegion(accounts: IAppengineAccount[], credentials: string): string {
let account = accounts.find((_account) => _account.name === credentials);
const account = accounts.find((_account) => _account.name === credentials);
return account ? account.region : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AppengineServerGroupBasicSettingsCtrl {
}

public onAccountChange(): void {
let account = this.findAccountInBackingData();
const account = this.findAccountInBackingData();
if (account) {
this.$scope.command.gitCredentialType = account.supportedGitCredentialTypes[0];
} else {
Expand All @@ -52,7 +52,7 @@ class AppengineServerGroupBasicSettingsCtrl {
}

public getSupportedGitCredentialTypes(): GitCredentialType[] {
let account = this.findAccountInBackingData();
const account = this.findAccountInBackingData();
if (account) {
return account.supportedGitCredentialTypes;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class AppengineCloneServerGroupCtrl {
}

public submit(): ng.IPromise<any> {
let mode = this.$scope.command.viewState.mode;
const mode = this.$scope.command.viewState.mode;
if (['editPipeline', 'createPipeline'].includes(mode)) {
return this.$uibModalInstance.close(this.$scope.command);
} else {
let command = copy(this.$scope.command);
const command = copy(this.$scope.command);
// Make sure we're sending off a create operation, because there's no such thing as clone for App Engine.
command.viewState.mode = 'create';
let submitMethod = () => this.serverGroupWriter.cloneServerGroup(command, this.$scope.application);
const submitMethod = () => this.serverGroupWriter.cloneServerGroup(command, this.$scope.application);
this.taskMonitor.submit(submitMethod);

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class AppengineConfigFileConfigurerCtrl implements ng.IComponentController {
public mapTabToSpaces(event: any) {
if (event.which === 9) {
event.preventDefault();
let cursorPosition = event.target.selectionStart;
let inputValue = event.target.value;
const cursorPosition = event.target.selectionStart;
const inputValue = event.target.value;
event.target.value = `${inputValue.substring(0, cursorPosition)} ${inputValue.substring(cursorPosition)}`;
event.target.selectionStart += 2;
}
Expand Down
Loading

0 comments on commit 2b07d34

Please sign in to comment.