(sourceFile: ts.SourceFile)
| 17 | */ |
| 18 | export 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. */ |
nothing calls this directly
no test coverage detected