Skip to content

Commit

Permalink
fix(finnish): Use Angular defaults.
Browse files Browse the repository at this point in the history
And add defaults for interface methods that return Observable.
  • Loading branch information
cartant committed May 1, 2018
1 parent 3f9379d commit 4f1401e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 4 deletions.
16 changes: 16 additions & 0 deletions fixtures/v5/finnish-whitelist/fixture-angular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Observable } from "rxjs/Observable";
import { Subject } from "rxjs/Subject";
import { of } from "rxjs/observable/of";

class EventEmitter<T> extends Subject<T> {}

class Something {
public somethingChanged: EventEmitter<any>;
public canActivate(): Observable<any> { return of(); }
public canActivateChild(): Observable<any> { return of(); }
public canDeactivate(): Observable<any> { return of(); }
public canLoad(): Observable<any> { return of(); }
public intercept(): Observable<any> { return of(); }
public resolve(): Observable<any> { return of(); }
public validate(): Observable<any> { return of(); }
}
2 changes: 1 addition & 1 deletion fixtures/v5/finnish-whitelist/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"skipLibCheck": true,
"target": "es5"
},
"include": ["fixture.ts", "fixture-blacklist.ts"]
"include": ["fixture.ts", "fixture-angular.ts", "fixture-blacklist.ts"]
}
8 changes: 8 additions & 0 deletions fixtures/v5/finnish-whitelist/tslint-angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaultSeverity": "error",
"jsRules": {},
"rules": {
"rxjs-finnish": { "severity": "error" }
},
"rulesDirectory": "../../../build/rules"
}
14 changes: 14 additions & 0 deletions fixtures/v6/finnish-whitelist/fixture-angular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { of, Subject, Observable } from "rxjs";

class EventEmitter<T> extends Subject<T> {}

class Something {
public somethingChanged: EventEmitter<any>;
public canActivate(): Observable<any> { return of(); }
public canActivateChild(): Observable<any> { return of(); }
public canDeactivate(): Observable<any> { return of(); }
public canLoad(): Observable<any> { return of(); }
public intercept(): Observable<any> { return of(); }
public resolve(): Observable<any> { return of(); }
public validate(): Observable<any> { return of(); }
}
2 changes: 1 addition & 1 deletion fixtures/v6/finnish-whitelist/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"skipLibCheck": true,
"target": "es5"
},
"include": ["fixture.ts", "fixture-blacklist.ts"]
"include": ["fixture.ts", "fixture-angular.ts", "fixture-blacklist.ts"]
}
8 changes: 8 additions & 0 deletions fixtures/v6/finnish-whitelist/tslint-angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaultSeverity": "error",
"jsRules": {},
"rules": {
"rxjs-finnish": { "severity": "error" }
},
"rulesDirectory": "../../../build/rules"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"dist:clean": "rimraf dist",
"lint": "tslint --project tsconfig.json source/**/*.ts",
"prepublishOnly": "yarn run test && yarn run dist",
"test": "yarn run lint && yarn run test:build && yarn run test:non-fixtures && yarn run test:fixtures-v5 && yarn run test:fixtures-v6 && yarn run test:fixtures-v6-compat",
"_test": "yarn run lint && yarn run test:build && yarn run test:non-fixtures && yarn run test:fixtures-v5 && yarn run test:fixtures-v6 && yarn run test:fixtures-v6-compat",
"test": "yarn run lint && yarn run test:build && yarn run test:fixtures-v5",
"test:build": "yarn run test:clean && tsc -p tsconfig.json",
"test:clean": "rimraf build",
"test:fixtures-v5": "yarn --cwd ./fixtures/v5 install && yarn --cwd ./fixtures/v5 upgrade && cross-env RXJS_TSLINT_FIXTURES_DIR=./fixtures/v5 mocha build/**/*-spec.js",
Expand Down
7 changes: 7 additions & 0 deletions source/fixtures-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ describe(`${fixtureVersion} fixtures`, function (): void {
expect(result).to.have.property("errorCount", 2);
result.failures.forEach(failure => expect(failure).to.have.property("ruleName", "rxjs-finnish"));
});

it("should not effect 'rxjs-finnish' errors, by default, for Angular interfaces and types", () => {

const result = lint("finnish-whitelist", "tslint-angular.json", "fixture-angular.ts");

expect(result).to.have.property("errorCount", 0);
});
});

describe("finnish-with-$", () => {
Expand Down
10 changes: 9 additions & 1 deletion source/rules/rxjsFinnishRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import * as ts from "typescript";
import * as tsutils from "tsutils";
import { couldBeType } from "../support/util";

const defaultNamesRegExp = /^(canActivate|canActivateChild|canDeactivate|canLoad|intercept|resolve|validate)$/;
const defaultTypesRegExp = /^EventEmitter$/;

export class Rule extends Lint.Rules.TypedRule {

public static metadata: Lint.IRuleMetadata = {
Expand Down Expand Up @@ -67,15 +70,20 @@ class Walker extends Lint.ProgramAwareRuleWalker {
Object.entries(options.names).forEach(([key, validate]: [string, boolean]) => {
this.names.push({ regExp: new RegExp(key), validate });
});
} else {
this.names.push({ regExp: defaultNamesRegExp, validate: false });
}
if (options.types) {
Object.entries(options.types).forEach(([key, validate]: [string, boolean]) => {
this.types.push({ regExp: new RegExp(key), validate });
});
} else {
this.types.push({ regExp: /^EventEmitter$/, validate: true });
this.types.push({ regExp: defaultTypesRegExp, validate: false });
}
this.validate = { ...this.validate, ...options };
} else {
this.names.push({ regExp: defaultNamesRegExp, validate: false });
this.types.push({ regExp: defaultTypesRegExp, validate: false });
}
}

Expand Down

0 comments on commit 4f1401e

Please sign in to comment.