Skip to content

Commit

Permalink
fix(rules): Fix message when a failure occurs (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
wKoza authored and mgechev committed Mar 6, 2018
1 parent c75c35c commit 5851306
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/templateConditionalComplexityRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule {
};

// tslint:disable-next-line:max-line-length
static COMPLEXITY_FAILURE_STRING = 'The condition complexity (cost \'%s\') exceeded the defined limit (cost \'%s\'). The conditional expression should be move in the component\'s template.';
static COMPLEXITY_FAILURE_STRING = 'The condition complexity (cost \'%s\') exceeded the defined limit (cost \'%s\'). The conditional expression should be moved into the component.';

static COMPLEXITY_MAX = 3;

Expand Down Expand Up @@ -86,7 +86,7 @@ class TemplateConditionalComplexityVisitor extends BasicTemplateAstVisitor {

if (complexity > complexityMax) {
const span = prop.sourceSpan;
let failureConfig: string[] = [String(complexity), String(Rule.COMPLEXITY_MAX)];
let failureConfig: string[] = [String(complexity), String(complexityMax)];
failureConfig.unshift(Rule.COMPLEXITY_FAILURE_STRING);
this.addFailure(this.createFailure(span.start.offset, span.end.offset - span.start.offset,
sprintf.apply(this, failureConfig))
Expand Down
2 changes: 1 addition & 1 deletion src/templateCyclomaticComplexityRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TemplateConditionalComplexityVisitor extends BasicTemplateAstVisitor {

if (this.complexity > complexityMax) {
const span = prop.sourceSpan;
let failureConfig: string[] = [String(Rule.COMPLEXITY_MAX)];
let failureConfig: string[] = [String(complexityMax)];
failureConfig.unshift(Rule.COMPLEXITY_FAILURE_STRING);
this.addFailure(this.createFailure(span.start.offset, span.end.offset - span.start.offset,
sprintf.apply(this, failureConfig))
Expand Down
9 changes: 4 additions & 5 deletions test/templateConditionalComplexityRule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// tslint:disable:max-line-length
import { assertSuccess, assertAnnotated } from './testHelper';
import { Replacement } from 'tslint';
import { expect } from 'chai';

describe('complexity', () => {
describe('success', () => {
Expand Down Expand Up @@ -94,8 +92,9 @@ describe('complexity', () => {
`;
assertAnnotated({
ruleName: 'template-conditional-complexity',
message: 'The condition complexity (cost \'5\') exceeded the defined limit (cost \'3\'). The conditional expression should be move in the component\'s template.',
source
message: 'The condition complexity (cost \'5\') exceeded the defined limit (cost \'4\'). The conditional expression should be moved into the component.',
source,
options: [4]
});
});

Expand All @@ -118,7 +117,7 @@ describe('complexity', () => {
`;
assertAnnotated({
ruleName: 'template-conditional-complexity',
message: 'The condition complexity (cost \'5\') exceeded the defined limit (cost \'3\'). The conditional expression should be move in the component\'s template.',
message: 'The condition complexity (cost \'5\') exceeded the defined limit (cost \'3\'). The conditional expression should be moved into the component.',
source
});
});
Expand Down
2 changes: 0 additions & 2 deletions test/templateCyclomaticComplexityRule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// tslint:disable:max-line-length
import { assertSuccess, assertAnnotated } from './testHelper';
import { Replacement } from 'tslint';
import { expect } from 'chai';

describe('cyclomatic complexity', () => {
describe('success', () => {
Expand Down

0 comments on commit 5851306

Please sign in to comment.