Skip to content

Commit 90df7de

Browse files
devversionmatsko
authored andcommitted
refactor(core): better failure message for explicit-query timing tslint rule (angular#29258)
Improves the failure message for the `explicit-query` timing TSLint rule that is used within Google. Currently it's not very clear what action developers need to take in order to resolve the lint failure manually. PR Close angular#29258
1 parent 8ef46f3 commit 90df7de

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/core/schematics/migrations/static-queries/google3/explicitQueryTimingRule.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {NgQueryResolveVisitor} from '../angular/ng_query_visitor';
1414
import {QueryTiming} from '../angular/query-definition';
1515
import {getTransformedQueryCallExpr} from '../transform';
1616

17+
const FAILURE_MESSAGE = 'Query does explicitly specify its timing. Read more here: ' +
18+
'https://github.com/angular/angular/pull/28810';
19+
1720
/**
1821
* Rule that reports if an Angular "ViewChild" or "ContentChild" query is not explicitly
1922
* specifying its timing. The rule also provides TSLint automatic replacements that can
@@ -55,10 +58,12 @@ export class Rule extends Rules.TypedRule {
5558
// updated call expression node.
5659
const fix = new Replacement(queryExpr.getStart(), queryExpr.getWidth(), newText);
5760
const timingStr = timing === QueryTiming.STATIC ? 'static' : 'dynamic';
61+
const failureMessage = `${FAILURE_MESSAGE}. Based on analysis of the query it can be ` +
62+
`marked as "${timingStr}".`;
5863

5964
failures.push(new RuleFailure(
60-
sourceFile, queryExpr.getStart(), queryExpr.getWidth(),
61-
`Query is not explicitly marked as "${timingStr}"`, this.ruleName, fix));
65+
sourceFile, queryExpr.getStart(), queryExpr.getWidth(), failureMessage, this.ruleName,
66+
fix));
6267
});
6368

6469
return failures;

packages/core/schematics/test/google3/explicit_query_timing_rule_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
109109
const failures = linter.getResult().failures;
110110

111111
expect(failures.length).toBe(1);
112-
expect(failures[0].getFailure()).toContain('Query is not explicitly marked as "static"');
112+
expect(failures[0].getFailure()).toMatch(/analysis of the query.*"static"/);
113113
});
114114

115115
it('should report non-explicit dynamic query definitions', () => {
@@ -126,6 +126,6 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
126126
const failures = linter.getResult().failures;
127127

128128
expect(failures.length).toBe(1);
129-
expect(failures[0].getFailure()).toContain('Query is not explicitly marked as "dynamic"');
129+
expect(failures[0].getFailure()).toMatch(/analysis of the query.*"dynamic"/);
130130
});
131131
});

0 commit comments

Comments
 (0)