mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: detect todos in public comments (#4059)
* build: detect todos in public comments * Creates a naive rule that checks all multi-line comments and reports failures once it detects TODOs inside of it. * This means that TODOs always need to placed inside of single-line comments. Fixes #4026
This commit is contained in:
committed by
Jeremy Elbourn
parent
dbe2c33afc
commit
a773515c56
@@ -0,0 +1,34 @@
|
||||
const ts = require('typescript');
|
||||
const utils = require('tsutils');
|
||||
const Lint = require('tslint');
|
||||
|
||||
const ERROR_MESSAGE =
|
||||
'A TODO may only appear in inline (//) style comments. ' +
|
||||
'This is meant to prevent a TODO from being accidentally included in any public API docs.';
|
||||
|
||||
/**
|
||||
* Rule that walks through all comments inside of the library and adds failures when it
|
||||
* detects TODO's inside of multi-line comments. TODOs need to be placed inside of single-line
|
||||
* comments.
|
||||
*/
|
||||
class Rule extends Lint.Rules.AbstractRule {
|
||||
|
||||
apply(sourceFile) {
|
||||
return this.applyWithWalker(new NoExposedTodoWalker(sourceFile, this.getOptions()));
|
||||
}
|
||||
}
|
||||
|
||||
class NoExposedTodoWalker extends Lint.RuleWalker {
|
||||
|
||||
visitSourceFile(sourceFile) {
|
||||
utils.forEachComment(sourceFile, (fullText, commentRange) => {
|
||||
let isTodoComment = fullText.substring(commentRange.pos, commentRange.end).includes('TODO');
|
||||
|
||||
if (commentRange.kind === ts.SyntaxKind.MultiLineCommentTrivia && isTodoComment) {
|
||||
this.addFailureAt(commentRange.pos, commentRange.end - commentRange.pos, ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.Rule = Rule;
|
||||
Reference in New Issue
Block a user