|
1 | 1 |
|
2 |
| -import { ParserMessageLog, TSDocParser } from "@microsoft/tsdoc"; |
| 2 | +import { |
| 3 | + ParserMessageLog, |
| 4 | + TSDocParser, |
| 5 | + TextRange, |
| 6 | + TSDocConfiguration, |
| 7 | + StandardTags, |
| 8 | + TSDocTagDefinition, |
| 9 | + TSDocTagSyntaxKind |
| 10 | +} from "@microsoft/tsdoc"; |
3 | 11 | import { allTsdocMessageIds } from "@microsoft/tsdoc/lib/parser/TSDocMessageId";
|
4 | 12 | import * as eslint from "eslint";
|
5 | 13 | import * as ESTree from "estree";
|
@@ -31,16 +39,41 @@ const plugin: IPlugin = {
|
31 | 39 | }
|
32 | 40 | },
|
33 | 41 | create: (context: eslint.Rule.RuleContext) => {
|
34 |
| - const tsDocParser: TSDocParser = new TSDocParser(); |
| 42 | + const tsdocConfiguration: TSDocConfiguration = new TSDocConfiguration(); |
| 43 | + |
| 44 | + // Create a lax configuration that allows every standard tag regardless of standardization group |
| 45 | + tsdocConfiguration.setSupportForTags(StandardTags.allDefinitions, true); |
| 46 | + |
| 47 | + // Also add the three AEDoc tags |
| 48 | + tsdocConfiguration.addTagDefinitions([ |
| 49 | + new TSDocTagDefinition({ |
| 50 | + tagName: '@betaDocumentation', |
| 51 | + syntaxKind: TSDocTagSyntaxKind.ModifierTag |
| 52 | + }), |
| 53 | + new TSDocTagDefinition({ |
| 54 | + tagName: '@internalRemarks', |
| 55 | + syntaxKind: TSDocTagSyntaxKind.BlockTag |
| 56 | + }), |
| 57 | + new TSDocTagDefinition({ |
| 58 | + tagName: '@preapproved', |
| 59 | + syntaxKind: TSDocTagSyntaxKind.ModifierTag |
| 60 | + }) |
| 61 | + ], true); |
| 62 | + |
| 63 | + const tsdocParser: TSDocParser = new TSDocParser(tsdocConfiguration); |
| 64 | + |
35 | 65 | const sourceCode: eslint.SourceCode = context.getSourceCode();
|
36 | 66 | const checkCommentBlocks: (node: ESTree.Node) => void = function (node: ESTree.Node) {
|
37 | 67 | const commentToken: eslint.AST.Token | null = sourceCode.getJSDocComment(node);
|
38 | 68 | if (commentToken) {
|
39 |
| - const commentString: string = "/*" + commentToken.value + "*/"; |
40 |
| - const results: ParserMessageLog = tsDocParser.parseString(commentString).log; |
| 69 | + const textRange: TextRange = TextRange.fromStringRange(sourceCode.text, commentToken.range[0], commentToken.range[1]); |
| 70 | + const results: ParserMessageLog = tsdocParser.parseRange(textRange).log; |
41 | 71 | for (const message of results.messages) {
|
42 | 72 | context.report({
|
43 |
| - loc: commentToken.loc, |
| 73 | + loc: { |
| 74 | + start: sourceCode.getLocFromIndex(message.textRange.pos), |
| 75 | + end: sourceCode.getLocFromIndex(message.textRange.end) |
| 76 | + }, |
44 | 77 | messageId: message.messageId,
|
45 | 78 | data: {
|
46 | 79 | unformattedText: message.unformattedText
|
|
0 commit comments