Skip to content

Commit

Permalink
chore(plugin): tslint cleanup
Browse files Browse the repository at this point in the history
A few formatting related warnings relating to tslint rule violations.
  • Loading branch information
Vheissu committed Feb 5, 2018
1 parent 35fe5ce commit d65af73
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 62 deletions.
42 changes: 21 additions & 21 deletions src/aurelia-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {join} from 'aurelia-path';
import { join } from 'aurelia-path';
import deepExtend from './deep-extend';
import { WindowInfo } from './window-info';

Expand Down Expand Up @@ -88,7 +88,7 @@ export class AureliaConfiguration {
setCascadeMode(bool: boolean = true) {
this.cascade_mode = bool;
}

/**
* Used to override default window information during contruction.
* Should only be used during unit testing, no need to set it up in normal
Expand Down Expand Up @@ -167,7 +167,7 @@ export class AureliaConfiguration {
// Loop over supplied environments
for (let env in this.environments) {
// Get environment hostnames
let hostnames = this.environments[env];
let hostnames = this.environments[ env ];

// Make sure we have hostnames
if (hostnames) {
Expand Down Expand Up @@ -221,8 +221,8 @@ export class AureliaConfiguration {
let currentObject = baseObject;

splitKey.forEach((key) => {
if (currentObject[key]) {
currentObject = currentObject[key];
if (currentObject[ key ]) {
currentObject = currentObject[ key ];
} else {
throw 'Key ' + key + ' not found';
}
Expand All @@ -247,16 +247,16 @@ export class AureliaConfiguration {
if (key.indexOf('.') === -1) {
// Using default environment
if (!this.environmentEnabled()) {
return this.obj[key] ? this.obj[key] : defaultValue;
return this.obj[ key ] ? this.obj[ key ] : defaultValue;
}

if (this.environmentEnabled()) {
// Value exists in environment
if (this.environmentExists() && this.obj[this.environment][key]) {
returnVal = this.obj[this.environment][key];
if (this.environmentExists() && this.obj[ this.environment ][ key ]) {
returnVal = this.obj[ this.environment ][ key ];
// Get default value from non-namespaced section if enabled
} else if (this.cascade_mode && this.obj[key]) {
returnVal = this.obj[key];
} else if (this.cascade_mode && this.obj[ key ]) {
returnVal = this.obj[ key ];
}

return returnVal;
Expand All @@ -266,20 +266,20 @@ export class AureliaConfiguration {
if (this.environmentEnabled()) {
if (this.environmentExists()) {
try {
return this.getDictValue(this.obj[this.environment], key);
return this.getDictValue(this.obj[ this.environment ], key);
} catch {
// nested key, env exists, key is not in environment
if (this.cascade_mode) {
try {
return this.getDictValue(this.obj, key);
} catch {}
} catch { }
}
}
}
} else {
try {
return this.getDictValue(this.obj, key);
} catch {}
} catch { }
}
}

Expand All @@ -295,17 +295,17 @@ export class AureliaConfiguration {
*/
set(key: string, val: string) {
if (key.indexOf('.') === -1) {
this.obj[key] = val;
this.obj[ key ] = val;
} else {
let splitKey = key.split('.');
let parent = splitKey[0];
let child = splitKey[1];
let parent = splitKey[ 0 ];
let child = splitKey[ 1 ];

if (this.obj[parent] === undefined) {
this.obj[parent] = {};
if (this.obj[ parent ] === undefined) {
this.obj[ parent ] = {};
}

this.obj[parent][child] = val;
this.obj[ parent ][ child ] = val;
}
}

Expand Down Expand Up @@ -398,7 +398,7 @@ export class AureliaConfiguration {
}
xhr.open('GET', pathClosure, true);

xhr.onreadystatechange = function() {
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
let data = JSON.parse(this.responseText);
action(data);
Expand All @@ -412,7 +412,7 @@ export class AureliaConfiguration {
}
};

xhr.onerror = function() {
xhr.onerror = function () {
reject(`Configuration file could not be found or loaded: ${pathClosure}`);
};

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {FrameworkConfiguration} from 'aurelia-framework';
import {AureliaConfiguration} from './aurelia-configuration';
import { FrameworkConfiguration } from 'aurelia-framework';
import { AureliaConfiguration } from './aurelia-configuration';

export function configure(aurelia: FrameworkConfiguration, configCallback?: (config: AureliaConfiguration) => Promise<any>) {
let instance = aurelia.container.get(AureliaConfiguration) as AureliaConfiguration;
let promise: Promise<any> | null = null;

// Do we have a callback function?
if (configCallback !== undefined && typeof(configCallback) === 'function') {
if (configCallback !== undefined && typeof (configCallback) === 'function') {
promise = Promise.resolve(configCallback(instance));
} else {
promise = Promise.resolve();
Expand All @@ -19,4 +19,4 @@ export function configure(aurelia: FrameworkConfiguration, configCallback?: (con
});
}

export {AureliaConfiguration};
export { AureliaConfiguration };
64 changes: 32 additions & 32 deletions test/unit/aurelia-configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ describe('Configuration class', () => {

it('set multiple environments', () => {
let environments = {
development: ['localhost', 'dev.local'],
staging: ['staging.website.com', 'test.staging.website.com'],
production: ['website.com']
development: [ 'localhost', 'dev.local' ],
staging: [ 'staging.website.com', 'test.staging.website.com' ],
production: [ 'website.com' ]
};
spyOn(configInstance, 'check');
configInstance.setEnvironments(environments);
Expand Down Expand Up @@ -71,11 +71,11 @@ describe('Configuration class', () => {

it('environment check function', () => {
let environments = {
development: ['localhost', 'dev.local'],
staging: ['staging.website.com', 'test.staging.website.com'],
production: ['website.com']
development: [ 'localhost', 'dev.local' ],
staging: [ 'staging.website.com', 'test.staging.website.com' ],
production: [ 'website.com' ]
};

configInstance.setEnvironments(environments);

configInstance.check();
Expand All @@ -85,10 +85,10 @@ describe('Configuration class', () => {

it('works with the same url but different port (using Karma port)', () => {
let environments = {
dev1: ['localhost'],
dev2: ['localhost:9876'],
dev1: [ 'localhost' ],
dev2: [ 'localhost:9876' ],
};

configInstance.setAll({
'test': 'fallback',
'dev1': {
Expand All @@ -98,21 +98,21 @@ describe('Configuration class', () => {
'test': 'dev2'
}
});

configInstance.setEnvironments(environments);

configInstance.check();
const test = configInstance.get('test');
expect(test).toEqual('dev2');
});

it('works with the different url but same ports', () => {
let environments = {
local: ['localhost:9000'],
qa: ['www.qa.com:9000'],
prod: ['www.prod.com:9000'],
local: [ 'localhost:9000' ],
qa: [ 'www.qa.com:9000' ],
prod: [ 'www.prod.com:9000' ],
};

configInstance.setAll({
'test': 'fallback',
'local': {
Expand All @@ -125,7 +125,7 @@ describe('Configuration class', () => {
'test': 'prod'
}
});

configInstance.setEnvironments(environments);
// Test to see if our local dev config works
let window = new WindowInfo();
Expand All @@ -136,7 +136,7 @@ describe('Configuration class', () => {
configInstance.check();
const testLocal = configInstance.get('test');
expect(testLocal).toEqual('local');

// Test to see if our qa config works
window.hostName = 'www.qa.com';
configInstance.setWindow(window);
Expand All @@ -154,14 +154,14 @@ describe('Configuration class', () => {

it('works with a base path', () => {
let environments = {
local: ['localhost'],
qa: ['www.qa.com'],
qaMaster: ['www.qa.com/master'],
qaFeature1: ['www.qa.com/feature1'],
qaFeature1SubFeature1: ['www.qa.com/feature1/subfeature1'],
qaFeature1SubFeature2: ['www.qa.com/feature1/subfeature2'],
local: [ 'localhost' ],
qa: [ 'www.qa.com' ],
qaMaster: [ 'www.qa.com/master' ],
qaFeature1: [ 'www.qa.com/feature1' ],
qaFeature1SubFeature1: [ 'www.qa.com/feature1/subfeature1' ],
qaFeature1SubFeature2: [ 'www.qa.com/feature1/subfeature2' ],
};

configInstance.setAll({
'test': 'fallback',
'local': {
Expand All @@ -183,7 +183,7 @@ describe('Configuration class', () => {
'test': 'qaFeature1SubFeature2'
}
});

configInstance.setEnvironments(environments);
// Test to see if we don't set basePathMode=true that everything works as expected
let window = new WindowInfo();
Expand All @@ -194,7 +194,7 @@ describe('Configuration class', () => {
configInstance.check();
let testNonBasePathMode = configInstance.get('test');
expect(testNonBasePathMode).toEqual('local');

window.hostName = 'www.qa.com';
window.pathName = '/master';
window.port = '';
Expand Down Expand Up @@ -245,11 +245,11 @@ describe('Configuration class', () => {
expect(configInstance.getDictValue(nestedDict, 'nested1.nested2.nested21')).toEqual('nested21');

expect(
configInstance.getDictValue(nestedDict['nested1'], 'nested2.nested21'),
configInstance.getDictValue(nestedDict[ 'nested1' ], 'nested2.nested21'),
).toEqual('nested21');

expect(
configInstance.getDictValue(nestedDict['nested1']['nested2'], 'nested21'),
configInstance.getDictValue(nestedDict[ 'nested1' ][ 'nested2' ], 'nested21'),
).toEqual('nested21');

expect(
Expand All @@ -274,7 +274,7 @@ describe('Configuration class', () => {
expect(configInstance.get('nested1.nested2.nested21')).toEqual('nested21');
expect(
configInstance.get('nested1.nested2')
).toEqual({'nested21': 'nested21'});
).toEqual({ 'nested21': 'nested21' });
expect(
configInstance.get('nested1.nested2.nested21')
).toEqual('nested21');
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('Configuration class', () => {
expect(configInstance.get('nested1.nested2.nested21')).toEqual('nested21e');
expect(
configInstance.get('nested1.nested2')
).toEqual({'nested21': 'nested21e'});
).toEqual({ 'nested21': 'nested21e' });
expect(
configInstance.get('nested1.nested2.nested21')
).toEqual('nested21e');
Expand Down
10 changes: 5 additions & 5 deletions test/unit/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {configure} from '../../src/index';
import {AureliaConfiguration} from '../../src/aurelia-configuration';
import { configure } from '../../src/index';
import { AureliaConfiguration } from '../../src/aurelia-configuration';

let AureliaStub = {
container: {
Expand All @@ -9,7 +9,7 @@ let AureliaStub = {
}
};

(<any>window).callback = function(config: any) {
(<any>window).callback = function (config: any) {
return config;
}

Expand All @@ -22,9 +22,9 @@ describe('Index', () => {

it('expect callback to be called', () => {
configure(AureliaStub as any, (<any>window).callback);

// expect((<any>window).callback).toHaveBeenCalledWith(new AureliaConfiguration);
expect((<any>window).callback(new AureliaConfiguration)).toEqual(new AureliaConfiguration);
});

});

0 comments on commit d65af73

Please sign in to comment.