refactor(core): better failure message for explicit-query timing tslint rule (#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 #29258
This commit is contained in:
parent
8ef46f38f4
commit
90df7de54d
|
@ -14,6 +14,9 @@ import {NgQueryResolveVisitor} from '../angular/ng_query_visitor';
|
|||
import {QueryTiming} from '../angular/query-definition';
|
||||
import {getTransformedQueryCallExpr} from '../transform';
|
||||
|
||||
const FAILURE_MESSAGE = 'Query does explicitly specify its timing. Read more here: ' +
|
||||
'https://github.com/angular/angular/pull/28810';
|
||||
|
||||
/**
|
||||
* Rule that reports if an Angular "ViewChild" or "ContentChild" query is not explicitly
|
||||
* specifying its timing. The rule also provides TSLint automatic replacements that can
|
||||
|
@ -55,10 +58,12 @@ export class Rule extends Rules.TypedRule {
|
|||
// updated call expression node.
|
||||
const fix = new Replacement(queryExpr.getStart(), queryExpr.getWidth(), newText);
|
||||
const timingStr = timing === QueryTiming.STATIC ? 'static' : 'dynamic';
|
||||
const failureMessage = `${FAILURE_MESSAGE}. Based on analysis of the query it can be ` +
|
||||
`marked as "${timingStr}".`;
|
||||
|
||||
failures.push(new RuleFailure(
|
||||
sourceFile, queryExpr.getStart(), queryExpr.getWidth(),
|
||||
`Query is not explicitly marked as "${timingStr}"`, this.ruleName, fix));
|
||||
sourceFile, queryExpr.getStart(), queryExpr.getWidth(), failureMessage, this.ruleName,
|
||||
fix));
|
||||
});
|
||||
|
||||
return failures;
|
||||
|
|
|
@ -109,7 +109,7 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
|
|||
const failures = linter.getResult().failures;
|
||||
|
||||
expect(failures.length).toBe(1);
|
||||
expect(failures[0].getFailure()).toContain('Query is not explicitly marked as "static"');
|
||||
expect(failures[0].getFailure()).toMatch(/analysis of the query.*"static"/);
|
||||
});
|
||||
|
||||
it('should report non-explicit dynamic query definitions', () => {
|
||||
|
@ -126,6 +126,6 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
|
|||
const failures = linter.getResult().failures;
|
||||
|
||||
expect(failures.length).toBe(1);
|
||||
expect(failures[0].getFailure()).toContain('Query is not explicitly marked as "dynamic"');
|
||||
expect(failures[0].getFailure()).toMatch(/analysis of the query.*"dynamic"/);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue