MCPcopy Create free account
hub / github.com/angular/components / apply

Method apply

tools/tslint-rules/requireBreakingChangeVersionRule.ts:19–47  ·  view source on GitHub ↗
(sourceFile: ts.SourceFile)

Source from the content-addressed store, hash-verified

17 */
18export class Rule extends Lint.Rules.AbstractRule {
19 apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
20 return this.applyWithFunction(sourceFile, (ctx: Lint.WalkContext<any>) => {
21 utils.forEachComment(ctx.sourceFile, (file, {pos, end}) => {
22 const commentText = file.substring(pos, end);
23
24 // TODO(crisbeto): remove this check once most of the pending
25 // PRs start using `breaking-change`.
26 if (commentText.indexOf(DELETION_TARGET) > -1) {
27 ctx.addFailure(pos, end, `${DELETION_TARGET} has been replaced with ${BREAKING_CHANGE}.`);
28 return;
29 }
30
31 const breakingChangeIndex = commentText.indexOf(BREAKING_CHANGE);
32 const hasBreakingChange = breakingChangeIndex > -1;
33 const deprecatedIndex = commentText.indexOf(DEPRECATED);
34 const hasDeprecated = deprecatedIndex > -1;
35
36 if (!hasBreakingChange && hasDeprecated) {
37 ctx.addFailure(pos, end, `${DEPRECATED} marker has to have a ${BREAKING_CHANGE}.`);
38 } else if (hasBreakingChange && !/\d+\.\d+\.\d+/.test(commentText)) {
39 ctx.addFailure(pos, end, `${BREAKING_CHANGE} must have a version.`);
40 } else if (hasBreakingChange && !isCommentLineStart(commentText, breakingChangeIndex)) {
41 ctx.addFailure(pos, end, `${BREAKING_CHANGE} must be at the start of a comment line.`);
42 } else if (hasDeprecated && !isCommentLineStart(commentText, deprecatedIndex)) {
43 ctx.addFailure(pos, end, `${DEPRECATED} must be at the start of a comment line.`);
44 }
45 });
46 });
47 }
48}
49
50/** Checks whether a tag is at the start of a line in a comment. */

Callers

nothing calls this directly

Calls 1

isCommentLineStartFunction · 0.85

Tested by

no test coverage detected