Skip to content

Commit

Permalink
(core) adding typescript linting
Browse files Browse the repository at this point in the history
* add linting to ts build
* fix existing warnings in code base
  • Loading branch information
icfantv committed Oct 4, 2016
1 parent f1d15b0 commit b1d362c
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
typings
/dist
/transpiled
/xmloutput
test-results.xml
npm-debug.log
Expand Down
21 changes: 10 additions & 11 deletions app/scripts/modules/core/application/application.model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {ApplicationDataSource} from "./service/applicationDataSource";
import {ApplicationDataSource} from './service/applicationDataSource';
import {Subject} from 'rxjs';

export class Application {

[k:string]: any;

constructor(private applicationName: string, private scheduler: any, private $q: ng.IQService, private $log: ng.ILogService) {}
[k: string]: any;

/**
* A collection of all available data sources for the given application
Expand Down Expand Up @@ -61,6 +59,12 @@ export class Application {
*/
public notFound: boolean = false;

private refreshStream: Subject<any> = new Subject();

private refreshFailureStream: Subject<any> = new Subject();

constructor(private applicationName: string, private scheduler: any, private $q: ng.IQService, private $log: ng.ILogService) {}

/**
* Returns a data source based on its key. Data sources can be accessed on the application directly via the key,
* e.g. application.serverGroups, but this is the preferred access method, as it allows type inference
Expand Down Expand Up @@ -122,10 +126,6 @@ export class Application {
});
}

private refreshStream: Subject<any> = new Subject();

private refreshFailureStream: Subject<any> = new Subject();

private applicationLoadError(err: Error): void {
this.$log.error(err, 'Failed to load application, will retry on next scheduler execution.');
this.refreshFailureStream.next(err);
Expand All @@ -151,7 +151,7 @@ export class Application {
let results = new Map<string, string>();
let sources = this.dataSources.filter(d => d[field] !== undefined);
let providers = sources.map(ds => ds.data.map(d => d[ds.providerField])).filter(p => p.length > 0);
let allProviders: any; //typescript made me do it this way
let allProviders: any; // typescript made me do it this way
allProviders = _.union<string[]>(...providers);
allProviders.forEach((provider: string) => {
let vals = sources
Expand All @@ -167,7 +167,6 @@ export class Application {

private setDefaults(): void {
this.defaultCredentials = this.extractProviderDefault('credentialsField');
this.defaultRegions = this.extractProviderDefault('regionField')
this.defaultRegions = this.extractProviderDefault('regionField');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as _ from 'lodash';

import {module} from 'angular';

import {DataSourceConfig} from './applicationDataSource.ts'
import {DataSourceConfig} from './applicationDataSource.ts';

export class ApplicationDataSourceRegistry {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import {Application} from '../application.model.ts';

export class DataSourceConfig {

constructor(config:any) {
Object.assign(this, config);
}

/**
* unique value for this data source; the data source will be available on the Application directly via this key,
* e.g. if the key is "serverGroups", you can access the data source via application.serverGroups
Expand Down Expand Up @@ -117,24 +113,13 @@ export class DataSourceConfig {
* to the field name that represents the provider on each data item.
*/
public providerField: string;
}

export class ApplicationDataSource {

constructor(config: DataSourceConfig, private application: Application, private $q?: ng.IQService, private $log?: ng.ILogService, private $filter?: any) {
constructor(config: any) {
Object.assign(this, config);
if (!config.sref && config.visible !== false) {
this.sref = '.insight.' + config.key;
}

if (!config.label && this.$filter) {
this.label = this.$filter('robotToHuman')(config.key);
}

if (!config.activeState) {
this.activeState = '**' + this.sref + '.**';
}
}
}

export class ApplicationDataSource {

/**
* Index Signature
Expand Down Expand Up @@ -259,6 +244,10 @@ export class ApplicationDataSource {
*/
public loader: {(any: any): ng.IPromise<any>};

private refreshStream: Subject<any> = new Subject();

private refreshFailureStream: Subject<any> = new Subject();

/**
* Called when a method mutates some item in the data source's data, e.g. when a running execution is updated
* independent of the execution data source's refresh cycle
Expand All @@ -267,6 +256,21 @@ export class ApplicationDataSource {
this.refreshStream.next(null);
}

constructor(config: DataSourceConfig, private application: Application, private $q?: ng.IQService, private $log?: ng.ILogService, private $filter?: any) {
Object.assign(this, config);
if (!config.sref && config.visible !== false) {
this.sref = '.insight.' + config.key;
}

if (!config.label && this.$filter) {
this.label = this.$filter('robotToHuman')(config.key);
}

if (!config.activeState) {
this.activeState = '**' + this.sref + '.**';
}
}

/**
* A method that allows another method to be called the next time the data source refreshes
*
Expand Down Expand Up @@ -397,9 +401,4 @@ export class ApplicationDataSource {
}
}
}

private refreshStream: Subject<any> = new Subject();

private refreshFailureStream: Subject<any> = new Subject();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export class ChaosMonkeyExceptionsController {

static get $inject() { return ['accountService', '$q']; }

public constructor(private accountService: any, private $q: ng.IQService) {}

public accounts: any[] = [];
public regionsByAccount: any;
public config: any;
public configChanged: () => void;

public constructor(private accountService: any, private $q: ng.IQService) {}

public addException(): void {
this.config.exceptions = this.config.exceptions || [];
this.config.exceptions.push({});
Expand All @@ -21,7 +21,7 @@ export class ChaosMonkeyExceptionsController {

public removeException(index): void {
this.config.exceptions.splice(index, 1);
this.configChanged()
this.configChanged();
};

public $onInit(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ChaosMonkeyNewApplicationConfigController {
if (this.enabled) {
this.applicationConfig.chaosMonkey = {
enabled: this.enabled
}
};
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

import { module } from 'angular';

import { BuildInfo } from '../../domain'
import { BuildInfo } from '../../domain';

const MODULE_NAME = 'spinnaker.core.delivery.buildDisplayName.filter';

Expand All @@ -11,12 +9,12 @@ export function buildDisplayName() {
if (!input) {
return '';
}
var formattedInput = '';
if( input.fullDisplayName !== undefined ) {
let formattedInput = '';
if (input.fullDisplayName !== undefined) {
formattedInput = input.fullDisplayName.split('#' + input.number).pop();
}
return formattedInput;
};
};
}

module(MODULE_NAME, [])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { has } from 'lodash';
import { module } from 'angular';
import { Execution } from '../../domain'

import { Execution } from '../../domain';

export function executionUserFilter() {
return function (input: Execution): string {
Expand All @@ -14,11 +14,11 @@ export function executionUserFilter() {
}
return user;
};
};
}

const MODULE_NAME = 'spinnaker.core.delivery.executionUser.filter';

module(MODULE_NAME, [])
.filter('executionUser', executionUserFilter);

export default MODULE_NAME
export default MODULE_NAME;
3 changes: 1 addition & 2 deletions app/scripts/modules/core/domain/health.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import { LoadBalancer } from "./loadBalancer";
import { LoadBalancer } from './loadBalancer';

export class Health {
type: string;
Expand Down
4 changes: 1 addition & 3 deletions app/scripts/modules/core/domain/loadBalancer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { InstanceCounts } from './instanceCounts';


export class LoadBalancer {

constructor(
Expand All @@ -10,8 +9,7 @@ export class LoadBalancer {
public region?: string,
public account?: string,
public serverGroups?: any[],
public healthState?:string,
public healthState?: string,
public instanceCounts?: InstanceCounts,
) { }

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Application } from '../application/application.model.ts';
import { Application } from '../application/application.model';
import {
LoadBalancer,
ServerGroup,
Health
} from '../domain';
import {InstanceCounts} from "../domain/instanceCounts";
import {InstanceCounts} from '../domain/instanceCounts';

export class LoadBalancersTagController implements ng.IComponentController {

Expand All @@ -21,7 +21,7 @@ export class LoadBalancersTagController implements ng.IComponentController {
.find((lb: LoadBalancer): boolean => {
return lb.name === lbName
&& lb.account === serverGroup.account
&& lb.region === serverGroup.region
&& lb.region === serverGroup.region;
});

return this.buildLoadBalancer(match);
Expand All @@ -35,7 +35,7 @@ export class LoadBalancersTagController implements ng.IComponentController {
}

let loadBalancer: LoadBalancer = new LoadBalancer(match.name, match.vpcId);
loadBalancer.instanceCounts = <InstanceCounts>{up:0, down: 0, succeeded: 0, failed: 0, unknown: 0};
loadBalancer.instanceCounts = <InstanceCounts>{up: 0, down: 0, succeeded: 0, failed: 0, unknown: 0};

this.serverGroup.instances.forEach(instance => {
let lbHealth: Health = instance.health.find(h => h.type === 'LoadBalancer');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import { module } from 'angular';
import { StageContext } from '../../../../domain/stageContext.ts'
import { StageContext } from '../../../../domain/stageContext';

const MODULE_NAME = 'spinnaker.core.pipeline.clusterName.filter';

Expand All @@ -12,9 +11,9 @@ export function clusterNameFilter(namingService: any): any {
}
return namingService.getClusterName(input.application, input.stack, input.freeFormDetails);
};
};
}

module(MODULE_NAME, [])
.filter('clusterName', clusterNameFilter);

export default MODULE_NAME
export default MODULE_NAME;
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* From angular-ui-select demo: http://plnkr.co/edit/juqoNOt1z1Gb349XabQ2
*/
'use strict';

/**
* AngularJS default filter with the following expression:
* "person in people | filter: {name: $select.search, age: $select.search}"
Expand All @@ -12,18 +10,18 @@

import { module } from 'angular';

const MODULE_NAME ='spinnaker.core.presentation.anyFieldFilter';
const MODULE_NAME = 'spinnaker.core.presentation.anyFieldFilter';

export function anyFieldFilter() {
return function(items: any, props: any): any[] {
let out: any[] = [];

if (angular.isArray(items)) {
items.forEach(function (item) {
let itemMatches: boolean = false;
let itemMatches = false;

let keys: any[] = Object.keys(props);
for (var i = 0; i < keys.length; i++) {
for (let i = 0; i < keys.length; i++) {
let prop: any = keys[i];
let text: string = (<any>props)[prop].toLowerCase();
if (item[prop] && item[prop].toString().toLowerCase().indexOf(text) !== -1) {
Expand All @@ -42,7 +40,7 @@ export function anyFieldFilter() {
}

return out;
}
};
}

module(MODULE_NAME, [])
Expand Down
8 changes: 3 additions & 5 deletions app/scripts/modules/core/task/displayableTasks.filter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

import { module } from 'angular';

import { TaskStep } from '../domain/taskStep.ts'
import { TaskStep } from '../domain/taskStep';

export function displayableTaskFilter() {
var blacklist = [
let blacklist = [
'stageStart', 'stageEnd'
];
return function (input: TaskStep[]) {
Expand All @@ -15,7 +13,7 @@ export function displayableTaskFilter() {
});
}
};
};
}

const MODULE_NAME = 'spinnaker.pipelines.stages.core.displayableTasks.filter';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GceLoadBalancingPolicySelectorController implements ng.IComponentControlle
_.set(this, propertyName, viewValue / 100);
};

public setView (propertyName:string , modelValue: number): void {
public setView (propertyName: string , modelValue: number): void {
this[propertyName] = this.decimalToPercent(modelValue);
};

Expand Down
1 change: 0 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = function(config) {
'./node_modules/jquery/dist/jquery.js',
'./node_modules/angular/angular.js',
'./node_modules/angular-mocks/angular-mocks.js',
//'app/**/*.spec.js',
'settings.js',
'test/test_index.js'
],
Expand Down
Loading

0 comments on commit b1d362c

Please sign in to comment.