Skip to content

Commit a032b01

Browse files
authored
Merge pull request #194 from microsoft/octogonz/eslint-plugin-updates
eslint-plugin-tsdoc: A couple minor improvements
2 parents d2e776f + cefd48a commit a032b01

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "eslint-plugin-tsdoc",
5+
"comment": "Improve error location accuracy",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "eslint-plugin-tsdoc",
10+
"email": "4673363+octogonz@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "eslint-plugin-tsdoc",
5+
"comment": "Generalize the TSDoc parser configuration to allow any standard tag",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "eslint-plugin-tsdoc",
10+
"email": "4673363+octogonz@users.noreply.github.com"
11+
}

eslint-plugin/src/index.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11

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";
311
import { allTsdocMessageIds } from "@microsoft/tsdoc/lib/parser/TSDocMessageId";
412
import * as eslint from "eslint";
513
import * as ESTree from "estree";
@@ -31,16 +39,41 @@ const plugin: IPlugin = {
3139
}
3240
},
3341
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+
3565
const sourceCode: eslint.SourceCode = context.getSourceCode();
3666
const checkCommentBlocks: (node: ESTree.Node) => void = function (node: ESTree.Node) {
3767
const commentToken: eslint.AST.Token | null = sourceCode.getJSDocComment(node);
3868
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;
4171
for (const message of results.messages) {
4272
context.report({
43-
loc: commentToken.loc,
73+
loc: {
74+
start: sourceCode.getLocFromIndex(message.textRange.pos),
75+
end: sourceCode.getLocFromIndex(message.textRange.end)
76+
},
4477
messageId: message.messageId,
4578
data: {
4679
unformattedText: message.unformattedText

0 commit comments

Comments
 (0)