Skip to content

Commit 3e6e6b0

Browse files
committed
Update eslint-plugin to use tsdoc-config
1 parent 4e71b24 commit 3e6e6b0

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

eslint-plugin/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"test": "node lib/tests/index.js"
2727
},
2828
"dependencies": {
29-
"@microsoft/tsdoc": "0.12.15"
29+
"@microsoft/tsdoc": "0.12.15",
30+
"@microsoft/tsdoc-config": "0.12.15"
3031
},
3132
"devDependencies": {
3233
"@rushstack/eslint-config": "0.4.0",

eslint-plugin/src/index.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import {
88
TSDocTagSyntaxKind,
99
ParserContext
1010
} from "@microsoft/tsdoc";
11+
import {
12+
TSDocConfigFile
13+
} from '@microsoft/tsdoc-config';
1114
import * as eslint from "eslint";
1215
import * as ESTree from "estree";
1316

14-
const messageIds: {[x: string]: string} = {};
17+
const tsdocMessageIds: {[x: string]: string} = {};
1518

1619
const defaultTSDocConfiguration: TSDocConfiguration = new TSDocConfiguration()
1720
defaultTSDocConfiguration.allTsdocMessageIds.forEach((messageId: string) => {
18-
messageIds[messageId] = `${messageId}: {{ unformattedText }}`;
21+
tsdocMessageIds[messageId] = `${messageId}: {{unformattedText}}`;
1922
});
2023

2124
interface IPlugin {
@@ -28,7 +31,7 @@ const plugin: IPlugin = {
2831
// from the NPM package name, and then appending this string.
2932
"syntax": {
3033
meta: {
31-
messages: messageIds,
34+
messages: tsdocMessageIds,
3235
type: "problem",
3336
docs: {
3437
description: "Validates that TypeScript documentation comments conform to the TSDoc standard",
@@ -41,24 +44,32 @@ const plugin: IPlugin = {
4144
create: (context: eslint.Rule.RuleContext) => {
4245
const tsdocConfiguration: TSDocConfiguration = new TSDocConfiguration();
4346

44-
// Create a lax configuration that allows every standard tag regardless of standardization group
45-
tsdocConfiguration.setSupportForTags(StandardTags.allDefinitions, true);
47+
const sourceFilePath: string = context.getFilename();
48+
const tsdocConfigFile: TSDocConfigFile = TSDocConfigFile.loadForFolder(sourceFilePath);
49+
50+
if (!tsdocConfigFile.fileNotFound) {
51+
tsdocConfigFile.configureParser(tsdocConfiguration);
52+
} else {
53+
// If we weren't able to find a tsdoc-config.json file, then by default we will use a lax configuration
54+
// that allows every standard tag regardless of standardization group.
55+
tsdocConfiguration.setSupportForTags(StandardTags.allDefinitions, true);
4656

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);
57+
// Also allow the three AEDoc tags.
58+
tsdocConfiguration.addTagDefinitions([
59+
new TSDocTagDefinition({
60+
tagName: '@betaDocumentation',
61+
syntaxKind: TSDocTagSyntaxKind.ModifierTag
62+
}),
63+
new TSDocTagDefinition({
64+
tagName: '@internalRemarks',
65+
syntaxKind: TSDocTagSyntaxKind.BlockTag
66+
}),
67+
new TSDocTagDefinition({
68+
tagName: '@preapproved',
69+
syntaxKind: TSDocTagSyntaxKind.ModifierTag
70+
})
71+
], true);
72+
}
6273

6374
const tsdocParser: TSDocParser = new TSDocParser(tsdocConfiguration);
6475

0 commit comments

Comments
 (0)