chore: add lint and clang-format

This commit is contained in:
Victor Berchet 2016-06-07 09:50:35 -07:00 committed by vsavkin
parent 56f8c95ee9
commit dadd5ddded
6 changed files with 89 additions and 9 deletions

View File

@ -0,0 +1,3 @@
Language: JavaScript
BasedOnStyle: Google
ColumnLimit: 100

View File

@ -12,7 +12,9 @@
"build_npm": "rm -rf dist && tsc -p tsconfig.publish.es5.json && tsc -p tsconfig.publish.es6.json", "build_npm": "rm -rf dist && tsc -p tsconfig.publish.es5.json && tsc -p tsconfig.publish.es6.json",
"postbuild_npm": "cp package.json README.md dist/ && npm run rewrite_npm_package", "postbuild_npm": "cp package.json README.md dist/ && npm run rewrite_npm_package",
"rewrite_npm_package": "node --harmony_destructuring tools/rewrite-published-package.js", "rewrite_npm_package": "node --harmony_destructuring tools/rewrite-published-package.js",
"build_bundle": "cp -r src router && tsc typings/index.d.ts src/router.ts --rootDir . --module system -t es5 --outFile dist/bundles/router.js --moduleResolution node --emitDecoratorMetadata --experimentalDecorators" "build_bundle": "cp -r src router && tsc typings/index.d.ts src/router.ts --rootDir . --module system -t es5 --outFile dist/bundles/router.js --moduleResolution node --emitDecoratorMetadata --experimentalDecorators",
"lint": "tslint \"src/**/*.ts\"",
"format": "clang-format -style=file -i --glob=src/**/*.ts"
}, },
"keywords": [ "keywords": [
"angular2", "angular2",
@ -62,7 +64,10 @@
"tsd": "^0.6.5", "tsd": "^0.6.5",
"typescript": "^1.9.0-dev.20160409", "typescript": "^1.9.0-dev.20160409",
"typings": "^1.0.4", "typings": "^1.0.4",
"zone.js": "^0.6.6" "zone.js": "^0.6.6",
"clang-format": "^1.0.35",
"tslint": "^3.6.0",
"codelyzer": "0.0.14"
}, },
"typings": "build/src/index.d.ts" "typings": "build/src/index.d.ts"
} }

View File

@ -7,7 +7,7 @@ export interface Route {
path?: string; path?: string;
component: Type | string; component: Type | string;
outlet?: string; outlet?: string;
canActivate?: any[], canActivate?: any[];
canDeactivate?: any[], canDeactivate?: any[];
children?: Route[]; children?: Route[];
} }

View File

@ -2,7 +2,7 @@ import { UrlTree, UrlSegment } from './url_tree';
import { flatten, first, merge } from './utils/collection'; import { flatten, first, merge } from './utils/collection';
import { TreeNode } from './utils/tree'; import { TreeNode } from './utils/tree';
import { RouterStateSnapshot, ActivatedRouteSnapshot } from './router_state'; import { RouterStateSnapshot, ActivatedRouteSnapshot } from './router_state';
import { Params, PRIMARY_OUTLET } from './shared'; import { PRIMARY_OUTLET } from './shared';
import { RouterConfig, Route } from './config'; import { RouterConfig, Route } from './config';
import { Type } from '@angular/core'; import { Type } from '@angular/core';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
@ -35,7 +35,7 @@ function constructActivatedRoute(match: MatchResult): TreeNode<ActivatedRouteSna
children.sort((a, b) => { children.sort((a, b) => {
if (a.value.outlet === PRIMARY_OUTLET) return -1; if (a.value.outlet === PRIMARY_OUTLET) return -1;
if (b.value.outlet === PRIMARY_OUTLET) return 1; if (b.value.outlet === PRIMARY_OUTLET) return 1;
return a.value.outlet.localeCompare(b.value.outlet) return a.value.outlet.localeCompare(b.value.outlet);
}); });
return [new TreeNode<ActivatedRouteSnapshot>(activatedRoute, children)]; return [new TreeNode<ActivatedRouteSnapshot>(activatedRoute, children)];
} }

View File

@ -63,7 +63,7 @@ export class Router {
*/ */
constructor(private rootComponentType:Type, private resolver: ComponentResolver, private urlSerializer: UrlSerializer, private outletMap: RouterOutletMap, private location: Location, private injector: Injector, private config: RouterConfig) { constructor(private rootComponentType:Type, private resolver: ComponentResolver, private urlSerializer: UrlSerializer, private outletMap: RouterOutletMap, private location: Location, private injector: Injector, private config: RouterConfig) {
this.routerEvents = new Subject<Event>(); this.routerEvents = new Subject<Event>();
this.currentUrlTree = createEmptyUrlTree() this.currentUrlTree = createEmptyUrlTree();
this.currentRouterState = createEmptyState(this.rootComponentType); this.currentRouterState = createEmptyState(this.rootComponentType);
} }
@ -275,7 +275,7 @@ class GuardChecks {
if (this.checks.length === 0) return of(true); if (this.checks.length === 0) return of(true);
return forkJoin(this.checks.map(s => { return forkJoin(this.checks.map(s => {
if (s instanceof CanActivate) { if (s instanceof CanActivate) {
return this.runCanActivate(s.route) return this.runCanActivate(s.route);
} else if (s instanceof CanDeactivate) { } else if (s instanceof CanDeactivate) {
return this.runCanDeactivate(s.component, s.route); return this.runCanDeactivate(s.component, s.route);
} else { } else {
@ -316,7 +316,7 @@ class GuardChecks {
private deactivateOutletAndItChildren(route: ActivatedRouteSnapshot, outlet: RouterOutlet): void { private deactivateOutletAndItChildren(route: ActivatedRouteSnapshot, outlet: RouterOutlet): void {
if (outlet && outlet.isActivated) { if (outlet && outlet.isActivated) {
forEach(outlet.outletMap._outlets, (v, k) => this.deactivateOutletAndItChildren(v, outlet.outletMap._outlets[k])); forEach(outlet.outletMap._outlets, (v, k) => this.deactivateOutletAndItChildren(v, outlet.outletMap._outlets[k]));
this.checks.push(new CanDeactivate(outlet.component, route)) this.checks.push(new CanDeactivate(outlet.component, route));
} }
} }

View File

@ -0,0 +1,72 @@
{
"rulesDirectory": ["node_modules/codelyzer"],
"rules": {
"max-line-length": [true, 100],
"no-inferrable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"indent": [
true,
"spaces"
],
"eofline": true,
"no-duplicate-variable": true,
"no-eval": true,
"no-arg": true,
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-bitwise": true,
"no-shadowed-variable": true,
"no-unused-expression": true,
"no-unused-variable": true,
"one-line": [
true,
"check-catch",
"check-else",
"check-open-brace",
"check-whitespace"
],
"quotemark": [
true,
"single",
"avoid-escape"
],
"semicolon": [true, "always"],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"curly": true,
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-trailing-underscore"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"component-selector-name": [true, "kebab-case"],
"component-selector-type": [true, "element"],
"host-parameter-decorator": true,
"input-parameter-decorator": true,
"output-parameter-decorator": true,
"attribute-parameter-decorator": true,
"input-property-directive": true,
"output-property-directive": true
}
}