Skip to content

Commit

Permalink
Add tslint to prebuild process
Browse files Browse the repository at this point in the history
* build(lint): Added tslint as prebuild step

* chore(lint): Fixed all linting errors
  • Loading branch information
MikeRyanDev authored and brandonroberts committed Apr 4, 2016
1 parent 446aaf2 commit 0b7f9f0
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 77 deletions.
6 changes: 3 additions & 3 deletions lib/component-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ComponentRenderer {
const providers = Injector.resolve(instruction.providers);
const component = instruction.component;

return { providers, component, ref, dcl }
return { providers, component, ref, dcl };
})
.mergeMap(instruction => this.renderComponent(instruction))
.let<ComponentRef>(compose(...this._postMiddleware));
Expand All @@ -86,11 +86,11 @@ export class ComponentRenderer {
}

loadComponentForRoute(route: Route) {
if( !!route.component ) {
if ( !!route.component ) {
return Observable.of(route.component);
}

else if( !!route.loadComponent ) {
else if ( !!route.loadComponent ) {
return fromCallback(route.loadComponent);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const createGuard = createFactoryProvider<Guard>('@ngrx/router Guard');
export const guardMiddleware = createMiddleware(function(injector: Injector) {
return (route$: Observable<TraversalCandidate>) => route$
.mergeMap<TraversalCandidate>(({ route, params, isTerminal }) => {
if( !!route.guards && Array.isArray(route.guards) && route.guards.length > 0 ) {
if ( !!route.guards && Array.isArray(route.guards) && route.guards.length > 0 ) {
const guards: Guard[] = route.guards
.map(provider => injector.resolveAndInstantiate(provider));

Expand All @@ -43,12 +43,12 @@ export const guardMiddleware = createMiddleware(function(injector: Injector) {
.observeOn(asap)
.every(value => !!value)
.map(passed => {
if( passed ) {
if ( passed ) {
return { route, params };
}

return { route: null, params, isTerminal };
})
});
}

return Observable.of({ route, params, isTerminal });
Expand Down
2 changes: 1 addition & 1 deletion lib/link-active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ActiveOptions {
private _sub: any;

constructor(
@Query(LinkTo) public links:QueryList<LinkTo>,
@Query(LinkTo) public links: QueryList<LinkTo>,
public element: ElementRef,
public location$: Location,
public renderer: Renderer
Expand Down
6 changes: 3 additions & 3 deletions lib/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export interface LocationChange {
* ```
*/
@Injectable()
export class Location extends ReplaySubject<LocationChange>{
export class Location extends ReplaySubject<LocationChange> {
private _baseHref: string;

constructor(public platformStrategy: LocationStrategy) {
super(1);

platformStrategy.onPopState(event => this._update('pop'));

var browserBaseHref = this.platformStrategy.getBaseHref();
const browserBaseHref = this.platformStrategy.getBaseHref();
this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
this._update('push');
}
Expand Down Expand Up @@ -162,7 +162,7 @@ function normalizeQuery(query: any) {
}

function normalizeQueryParams(params: string): string {
return (params.length > 0 && params.substring(0, 1) != '?') ? ('?' + params) : params;
return (params.length > 0 && params.substring(0, 1) !== '?') ? ('?' + params) : params;
}

export const LOCATION_PROVIDERS = [
Expand Down
62 changes: 31 additions & 31 deletions lib/match-pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export interface Params {
[param: string]: string | string[];
}

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
function escapeRegExp(input: string) {
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

function escapeSource(string) {
return escapeRegExp(string).replace(/\/+/g, '/+')
function escapeSource(input: string) {
return escapeRegExp(input).replace(/\/+/g, '/+');
}

export interface CompiledPattern {
Expand All @@ -38,32 +38,32 @@ function _compilePattern(pattern: string): CompiledPattern {
regexpSource += escapeSource(pattern.slice(lastIndex, match.index));
}

if( match[1] ) {
if ( match[1] ) {
regexpSource += '([^/]+)';
paramNames.push(match[1]);
}
else if( match[0] === '**' ) {
else if ( match[0] === '**' ) {
regexpSource += '(.*)';
paramNames.push('splat');
}
else if( match[0] === '*' ) {
else if ( match[0] === '*' ) {
regexpSource += '(.*?)';
paramNames.push('splat');
}
else if( match[0] === '(' ) {
else if ( match[0] === '(' ) {
regexpSource += '(?:';
}
else if( match[0] === ')' ) {
else if ( match[0] === ')' ) {
regexpSource += ')?';
}

tokens.push(match[0]);
lastIndex = matcher.lastIndex;
}

if( lastIndex !== pattern.length ) {
tokens.push(pattern.slice(lastIndex, pattern.length))
regexpSource += escapeSource(pattern.slice(lastIndex, pattern.length))
if ( lastIndex !== pattern.length ) {
tokens.push(pattern.slice(lastIndex, pattern.length));
regexpSource += escapeSource(pattern.slice(lastIndex, pattern.length));
}

return {
Expand All @@ -74,10 +74,10 @@ function _compilePattern(pattern: string): CompiledPattern {
};
}

const CompiledPatternsCache: { [pattern: string]: CompiledPattern } = {}
const CompiledPatternsCache: { [pattern: string]: CompiledPattern } = {};

export function compilePattern(pattern) {
if( !(pattern in CompiledPatternsCache) ) {
if ( !(pattern in CompiledPatternsCache) ) {
CompiledPatternsCache[pattern] = _compilePattern(pattern);
}

Expand Down Expand Up @@ -106,10 +106,10 @@ export function compilePattern(pattern) {
*/
export function matchPattern(pattern: string, pathname: string) {
// Make leading slashes consistent between pattern and pathname.
if( pattern.charAt(0) !== '/' ) {
if ( pattern.charAt(0) !== '/' ) {
pattern = `/${pattern}`;
}
if( pathname.charAt(0) !== '/' ) {
if ( pathname.charAt(0) !== '/' ) {
pathname = `/${pathname}`;
}

Expand All @@ -127,14 +127,14 @@ export function matchPattern(pattern: string, pathname: string) {
let remainingPathname: string;
let paramValues: string[];

if( match != null ) {
const matchedPath = match[0]
remainingPathname = pathname.substr(matchedPath.length)
if ( match != null ) {
const matchedPath = match[0];
remainingPathname = pathname.substr(matchedPath.length);

// If we didn't match the entire pathname, then make sure that the match we
// did get ends at a path separator (potentially the one we added above at
// the beginning of the path, if the actual match was empty).
if(
if (
remainingPathname &&
matchedPath.charAt(matchedPath.length - 1) !== '/'
) {
Expand Down Expand Up @@ -189,38 +189,38 @@ export function formatPattern(pattern: string, params: Params = {}) {
let paramName: string;
let paramValue;

for(let i = 0, len = tokens.length; i < len; ++i) {
token = tokens[i]
for (let i = 0, len = tokens.length; i < len; ++i) {
token = tokens[i];

if (token === '*' || token === '**') {
paramValue = Array.isArray(params['splat']) ?
params['splat'][splatIndex++] :
params['splat'];

if( paramValue != null || parenCount > 0 ) {
if ( paramValue != null || parenCount > 0 ) {
console.error('Missing splat #%s for path "%s"', splatIndex, pattern);
}

if( paramValue != null ) {
if ( paramValue != null ) {
pathname += encodeURI(paramValue);
}
}
else if( token === '(' ) {
parenCount += 1
else if ( token === '(' ) {
parenCount += 1;
}
else if( token === ')' ) {
parenCount -= 1
else if ( token === ')' ) {
parenCount -= 1;
}
else if( token.charAt(0) === ':' ) {
else if ( token.charAt(0) === ':' ) {
paramName = token.substring(1);
paramValue = params[paramName];

if( !(paramValue != null || parenCount > 0) ) {
if ( !(paramValue != null || parenCount > 0) ) {
console.error('Missing "%s" parameter for path "%s"',
paramName, pattern);
}

if( paramValue != null ) {
if ( paramValue != null ) {
pathname += encodeURIComponent(paramValue);
}
}
Expand Down
20 changes: 10 additions & 10 deletions lib/match-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface Match {
};

export interface TraversalCandidate {
route: Route,
route: Route;
params: any;
isTerminal: boolean;
}
Expand All @@ -43,7 +43,7 @@ export class RouteTraverser {
constructor(
@Inject(TRAVERSAL_MIDDLEWARE) private _middleware: Middleware[],
@Inject(ROUTES) private _routes: Routes
){ }
) { }

find(pathname: string) {
return this._matchRoutes(this._routes, pathname);
Expand Down Expand Up @@ -86,7 +86,7 @@ export class RouteTraverser {
* would have been.
*/
return Observable
.merge(...seekers)
.merge<Match>(...seekers)
.toArray()
.map(matches => {
const valid = matches
Expand All @@ -106,7 +106,7 @@ export class RouteTraverser {
): Observable<Match> {
const pattern = route.path || '';

if( pattern.charAt(0) === '/' ) {
if ( pattern.charAt(0) === '/' ) {
remainingPathname = pathname;
paramNames = [];
paramValues = [];
Expand All @@ -126,20 +126,20 @@ export class RouteTraverser {
route,
params: assignParams(paramNames, paramValues),
isTerminal: remainingPathname === '' && !!route.path
}
};
})
.let<TraversalCandidate>(compose(...this._middleware))
.filter(({ route }) => !!route)
.mergeMap(({ route, params, isTerminal }) => {
if( isTerminal ) {
if ( isTerminal ) {
const match: Match = {
routes: [ route ],
params
};

return getIndexRoute(route)
.map(indexRoute => {
if( !!indexRoute ) {
if ( !!indexRoute ) {
match.routes.push(indexRoute);
}

Expand All @@ -148,15 +148,15 @@ export class RouteTraverser {
}

return getChildRoutes(route)
.mergeMap(childRoutes => this._matchRoutes(
.mergeMap<Match>(childRoutes => this._matchRoutes(
childRoutes,
pathname,
remainingPathname,
paramNames,
paramValues
))
.map(match => {
if( !!match ) {
if ( !!match ) {
match.routes.unshift(route);

return match;
Expand All @@ -178,7 +178,7 @@ export function assignParams(paramNames: string[], paramValues: string[]) {
return paramNames.reduce(function (params, paramName, index) {
const paramValue = paramValues && paramValues[index];

if( Array.isArray(params[paramName]) ){
if ( Array.isArray(params[paramName]) ) {
params[paramName].push(paramValue);
}
else if (paramName in params) {
Expand Down
12 changes: 6 additions & 6 deletions lib/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { OpaqueToken, Provider, provide, Injector } from 'angular2/core';
import { compose, createFactoryProvider } from './util';

export interface Middleware {
(input$: Observable<any>): Observable<any>
(input$: Observable<any>): Observable<any>;
}

export const identity: Middleware = t => t
export const identity: Middleware = t => t;

export function createMiddleware(
useFactory: (...deps: any[]) => Middleware, deps?: any[]
Expand All @@ -23,17 +23,17 @@ export function createMiddleware(
}

export function provideMiddlewareForToken(token) {
function isProvider(t: any): t is Provider{
function isProvider(t: any): t is Provider {
return t instanceof Provider;
}

return function(..._middleware: Array<Middleware | Provider>): Provider[] {
const provider = provide(token, {
multi: true,
deps: [ Injector ],
useFactory(injector: Injector){
useFactory(injector: Injector) {
const middleware = _middleware.map(m => {
if(isProvider(m)){
if (isProvider(m)) {
return injector.get(m.token);
}

Expand All @@ -47,5 +47,5 @@ export function provideMiddlewareForToken(token) {
const providers = _middleware.filter(isProvider) as Provider[];

return [ ...providers, provider ];
}
};
}
4 changes: 2 additions & 2 deletions lib/query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { stringify as stringifyQueryParams } from 'query-string';
import { Location} from './location';
import { RouteSet } from './route-set';

export class QueryParams extends ReplaySubject<{ [param: string]: any }>{
constructor(private _location: Location){
export class QueryParams extends ReplaySubject<{ [param: string]: any }> {
constructor(private _location: Location) {
super(1);
}

Expand Down
Loading

0 comments on commit 0b7f9f0

Please sign in to comment.