Skip to content

Commit

Permalink
fix(ban): Include ban explanation in failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Apr 30, 2018
1 parent a588a96 commit 5e993fe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fixtures/v6/ban-observables/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"rules": {
"rxjs-ban-observables": {
"options": [{
"concat": true,
"concat": "Explanation for concat",
"merge": true
}],
"severity": "error"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/v6/ban-operators/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"rules": {
"rxjs-ban-operators": {
"options": [{
"concat": true,
"concat": "Explanation for concat",
"merge": true
}],
"severity": "error"
Expand Down
12 changes: 10 additions & 2 deletions source/fixtures-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,11 @@ describe(`${fixtureVersion} fixtures`, function (): void {
const result = lint("ban-observables", "tslint.json");

expect(result).to.have.property("errorCount", 2);
result.failures.forEach(failure => expect(failure).to.have.property("ruleName", "rxjs-ban-observables"));
result.failures.forEach(failure => {
expect(failure).to.have.property("ruleName", "rxjs-ban-observables");
const message = failure.getFailure();
expect(/concat/.test(message)).to.equal(/Explanation for concat/.test(message));
});
});
});

Expand All @@ -747,7 +751,11 @@ describe(`${fixtureVersion} fixtures`, function (): void {
const result = lint("ban-operators", "tslint.json");

expect(result).to.have.property("errorCount", 2);
result.failures.forEach(failure => expect(failure).to.have.property("ruleName", "rxjs-ban-operators"));
result.failures.forEach(failure => {
expect(failure).to.have.property("ruleName", "rxjs-ban-operators");
const message = failure.getFailure();
expect(/concat/.test(message)).to.equal(/Explanation for concat/.test(message));
});
});
});

Expand Down
6 changes: 4 additions & 2 deletions source/rules/rxjsBanObservablesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ class Walker extends UsedWalker {

const { _bans } = this;
for (let b = 0, length = _bans.length; b < length; ++b) {
if (_bans[b].regExp.test(name)) {
return `${Rule.FAILURE_STRING}: ${name}`;
const ban = _bans[b];
if (ban.regExp.test(name)) {
const explanation = ban.explanation ? `: ${ban.explanation}` : "";
return `${Rule.FAILURE_STRING}: ${name}${explanation}`;
}
}
return undefined;
Expand Down
6 changes: 4 additions & 2 deletions source/rules/rxjsBanOperatorsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ class Walker extends UsedWalker {

const { _bans } = this;
for (let b = 0, length = _bans.length; b < length; ++b) {
if (_bans[b].regExp.test(name)) {
return `${Rule.FAILURE_STRING}: ${name}`;
const ban = _bans[b];
if (ban.regExp.test(name)) {
const explanation = ban.explanation ? `: ${ban.explanation}` : "";
return `${Rule.FAILURE_STRING}: ${name}${explanation}`;
}
}
return undefined;
Expand Down

0 comments on commit 5e993fe

Please sign in to comment.