Skip to content

Commit 5851306

Browse files
wKozamgechev
authored andcommitted
fix(rules): Fix message when a failure occurs (#534)
1 parent c75c35c commit 5851306

4 files changed

+7
-10
lines changed

src/templateConditionalComplexityRule.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule {
3131
};
3232

3333
// tslint:disable-next-line:max-line-length
34-
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.';
34+
static COMPLEXITY_FAILURE_STRING = 'The condition complexity (cost \'%s\') exceeded the defined limit (cost \'%s\'). The conditional expression should be moved into the component.';
3535

3636
static COMPLEXITY_MAX = 3;
3737

@@ -86,7 +86,7 @@ class TemplateConditionalComplexityVisitor extends BasicTemplateAstVisitor {
8686

8787
if (complexity > complexityMax) {
8888
const span = prop.sourceSpan;
89-
let failureConfig: string[] = [String(complexity), String(Rule.COMPLEXITY_MAX)];
89+
let failureConfig: string[] = [String(complexity), String(complexityMax)];
9090
failureConfig.unshift(Rule.COMPLEXITY_FAILURE_STRING);
9191
this.addFailure(this.createFailure(span.start.offset, span.end.offset - span.start.offset,
9292
sprintf.apply(this, failureConfig))

src/templateCyclomaticComplexityRule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TemplateConditionalComplexityVisitor extends BasicTemplateAstVisitor {
6363

6464
if (this.complexity > complexityMax) {
6565
const span = prop.sourceSpan;
66-
let failureConfig: string[] = [String(Rule.COMPLEXITY_MAX)];
66+
let failureConfig: string[] = [String(complexityMax)];
6767
failureConfig.unshift(Rule.COMPLEXITY_FAILURE_STRING);
6868
this.addFailure(this.createFailure(span.start.offset, span.end.offset - span.start.offset,
6969
sprintf.apply(this, failureConfig))

test/templateConditionalComplexityRule.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// tslint:disable:max-line-length
22
import { assertSuccess, assertAnnotated } from './testHelper';
3-
import { Replacement } from 'tslint';
4-
import { expect } from 'chai';
53

64
describe('complexity', () => {
75
describe('success', () => {
@@ -94,8 +92,9 @@ describe('complexity', () => {
9492
`;
9593
assertAnnotated({
9694
ruleName: 'template-conditional-complexity',
97-
message: 'The condition complexity (cost \'5\') exceeded the defined limit (cost \'3\'). The conditional expression should be move in the component\'s template.',
98-
source
95+
message: 'The condition complexity (cost \'5\') exceeded the defined limit (cost \'4\'). The conditional expression should be moved into the component.',
96+
source,
97+
options: [4]
9998
});
10099
});
101100

@@ -118,7 +117,7 @@ describe('complexity', () => {
118117
`;
119118
assertAnnotated({
120119
ruleName: 'template-conditional-complexity',
121-
message: 'The condition complexity (cost \'5\') exceeded the defined limit (cost \'3\'). The conditional expression should be move in the component\'s template.',
120+
message: 'The condition complexity (cost \'5\') exceeded the defined limit (cost \'3\'). The conditional expression should be moved into the component.',
122121
source
123122
});
124123
});

test/templateCyclomaticComplexityRule.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// tslint:disable:max-line-length
22
import { assertSuccess, assertAnnotated } from './testHelper';
3-
import { Replacement } from 'tslint';
4-
import { expect } from 'chai';
53

64
describe('cyclomatic complexity', () => {
75
describe('success', () => {

0 commit comments

Comments
 (0)