Skip to content

Commit ca27dc9

Browse files
authored
Merge pull request #192 from microsoft/octogonz/publish-eslint-plugin-tsdoc
Enable publishing for eslint-plugin-tsdoc
2 parents d238eb1 + 6a16f62 commit ca27dc9

File tree

7 files changed

+123
-28
lines changed

7 files changed

+123
-28
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ NOTE: The **@microsoft/tsdoc** library is intended to be incorporated into other
7272
- Check out the [TSDoc Playground](https://microsoft.github.io/tsdoc/) for a cool interactive demo of TSDoc! :-)
7373
- The library [@microsoft/tsdoc](https://www.npmjs.com/package/@microsoft/tsdoc) provides a TSDoc parser that you can use in your own projects. The source code for this library can be found in the [/tsdoc](./tsdoc/) folder.
7474
- The [/api-demo](./api-demo/) folder has a small demo project illustrating how to invoke the **@microsoft/tsdoc** library.
75+
- We also provide an ESLint plugin [eslint-plugin-tsdoc](https://www.npmjs.com/package/eslint-plugin-tsdoc) that you can use to validate your source code.
7576
- See [Contributing.md](./Contributing.md) for instructions for building, debugging, and contributing to TSDoc.
7677
- We're using [GitHub issues](https://github.com/Microsoft/tsdoc/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) to discuss the TSDoc specification, library design, and project roadmap.
7778

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": "Initial release of plugin",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "eslint-plugin-tsdoc",
10+
"email": "bafolts@users.noreply.github.com"
11+
}

eslint-plugin/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# eslint-plugin-tsdoc
2+
3+
This ESLint plugin provides a rule for validating that TypeScript doc comments conform to the
4+
[TSDoc specification](https://github.com/microsoft/tsdoc).
5+
6+
## Usage
7+
8+
1. Configure ESLint for your TypeScript project. See the instructions provided by the
9+
[typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) project.
10+
You will end up with some dependencies like this:
11+
12+
**my-project/package.json** (example)
13+
```ts
14+
{
15+
"name": "my-project",
16+
"version": "1.0.0",
17+
"dependencies": {},
18+
"devDependencies": {
19+
"@typescript-eslint/eslint-plugin": "~2.6.1",
20+
"@typescript-eslint/parser": "~2.6.1",
21+
"eslint": "~6.6.0",
22+
"typescript": "~3.7.2"
23+
},
24+
"scripts": {
25+
"lint": "eslint -f unix \"src/**/*.{ts,tsx}\""
26+
}
27+
}
28+
```
29+
30+
2. Add the `eslint-plugin-tsdoc` dependency to your project:
31+
32+
```bash
33+
$ cd my-project
34+
$ npm install --save-dev eslint-plugin-tsdoc
35+
```
36+
37+
3. In your ESLint config file, add the `"eslint-plugin-tsdoc"` package to your `plugins` field,
38+
and enable the `"tsdoc/syntax"` rule. For example:
39+
40+
**my-project/.eslintrc.js** (example)
41+
```ts
42+
module.exports = {
43+
plugins: [
44+
"@typescript-eslint/eslint-plugin",
45+
"eslint-plugin-tsdoc"
46+
],
47+
extends: [
48+
'plugin:@typescript-eslint/recommended'
49+
],
50+
parser: '@typescript-eslint/parser',
51+
parserOptions: {
52+
project: "./tsconfig.json",
53+
tsconfigRootDir: __dirname,
54+
ecmaVersion: 2018,
55+
sourceType: "module"
56+
},
57+
rules: {
58+
"tsdoc/syntax": "warn"
59+
}
60+
};
61+
```
62+
63+
This package is maintained by the TSDoc project. If you have questions or feedback, please
64+
[let us know](https://github.com/microsoft/tsdoc/issues)!

eslint-plugin/package.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
{
22
"name": "eslint-plugin-tsdoc",
3-
"version": "0.1.0",
4-
"description": "eslint plugin for tsdoc",
5-
"private": false,
3+
"version": "0.0.0",
4+
"description": "An ESLint plugin that validates TypeScript doc comments",
5+
"keywords": [
6+
"TypeScript",
7+
"documentation",
8+
"doc",
9+
"comments",
10+
"JSDoc",
11+
"TSDoc",
12+
"ESLint",
13+
"plugin"
14+
],
615
"license": "MIT",
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/microsoft/tsdoc/tree/master/eslint-plugin"
19+
},
20+
"homepage": "https://github.com/microsoft/tsdoc",
21+
"main": "lib/index.js",
22+
"typings": "lib/index.d.ts",
723
"scripts": {
824
"build": "node ./build.js",
925
"lint": "eslint -f unix \"src/**/*.{ts,tsx}\"",

eslint-plugin/src/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ interface IPlugin {
1414
rules: {[x: string]: eslint.Rule.RuleModule};
1515
}
1616

17-
export const plugin: IPlugin = {
17+
const plugin: IPlugin = {
1818
rules: {
19-
"tsdoc-comments": {
19+
// NOTE: The actual ESLint rule name will be "tsdoc/syntax". It is calculated by deleting "eslint-plugin-"
20+
// from the NPM package name, and then appending this string.
21+
"syntax": {
2022
meta: {
2123
messages: messageIds,
2224
type: "problem",
2325
docs: {
24-
description: "Validates tsdoc comments",
25-
category: "Typescript",
26+
description: "Validates that TypeScript documentation comments conform to the TSDoc standard",
27+
category: "Stylistic Issues",
28+
// This package is experimental
2629
recommended: false,
2730
url: "https://github.com/microsoft/tsdoc"
2831
}
@@ -31,16 +34,13 @@ export const plugin: IPlugin = {
3134
const tsDocParser: TSDocParser = new TSDocParser();
3235
const sourceCode: eslint.SourceCode = context.getSourceCode();
3336
const checkCommentBlocks: (node: ESTree.Node) => void = function (node: ESTree.Node) {
34-
const commentBlocks: ESTree.Comment[] = sourceCode.getCommentsBefore(node).filter(function (comment: ESTree.Comment) {
35-
return comment.type === "Block";
36-
});
37-
if (commentBlocks.length > 0) {
38-
const commentBlock: ESTree.Comment = commentBlocks[0];
39-
const commentString: string = "/*" + commentBlock.value + "*/";
37+
const commentToken: eslint.AST.Token | null = sourceCode.getJSDocComment(node);
38+
if (commentToken) {
39+
const commentString: string = "/*" + commentToken.value + "*/";
4040
const results: ParserMessageLog = tsDocParser.parseString(commentString).log;
4141
for (const message of results.messages) {
4242
context.report({
43-
node: node,
43+
loc: commentToken.loc,
4444
messageId: message.messageId,
4545
data: {
4646
unformattedText: message.unformattedText
@@ -58,3 +58,5 @@ export const plugin: IPlugin = {
5858
}
5959
}
6060
}
61+
62+
export = plugin;

eslint-plugin/src/tests/index.ts

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

22
import { RuleTester } from "eslint";
3-
import { plugin } from "../index";
3+
import * as plugin from "../index";
44

55
const ruleTester: RuleTester = new RuleTester({
66
env: {
77
es6: true
88
}
99
});
10-
ruleTester.run("tsdoc-comments", plugin.rules["tsdoc-comments"], {
10+
ruleTester.run("syntax", plugin.rules.syntax, {
1111
valid: [
1212
"/**\nA great function!\n */\nfunction foobar() {}\n",
1313
"/**\nA great class!\n */\nclass FooBar {}\n"

rush.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
// "tools", // non-shipping projects that are part of the developer toolchain
154154
// "prototypes" // experiments that should mostly be ignored by the review process
155155
// ],
156-
//
156+
//
157157
// /**
158158
// * A list of NPM package scopes that will be excluded from review.
159159
// * We recommend to exclude TypeScript typings (the "@types" scope), because
@@ -269,7 +269,7 @@
269269
// * The folder name for this variant.
270270
// */
271271
// "variantName": "old-sdk",
272-
//
272+
//
273273
// /**
274274
// * An informative description
275275
// */
@@ -308,19 +308,19 @@
308308
// * The NPM package name of the project (must match package.json)
309309
// */
310310
// "packageName": "my-app",
311-
//
311+
//
312312
// /**
313313
// * The path to the project folder, relative to the rush.json config file.
314314
// */
315315
// "projectFolder": "apps/my-app",
316-
//
316+
//
317317
// /**
318318
// * An optional category for usage in the "browser-approved-packages.json"
319319
// * and "nonbrowser-approved-packages.json" files. The value must be one of the
320320
// * strings from the "reviewCategories" defined above.
321321
// */
322322
// "reviewCategory": "production",
323-
//
323+
//
324324
// /**
325325
// * A list of local projects that appear as devDependencies for this project, but cannot be
326326
// * locally linked because it would create a cyclic dependency; instead, the last published
@@ -329,40 +329,40 @@
329329
// "cyclicDependencyProjects": [
330330
// // "my-toolchain"
331331
// ],
332-
//
332+
//
333333
// /**
334334
// * If true, then this project will be ignored by the "rush check" command.
335335
// * The default value is false.
336336
// */
337337
// // "skipRushCheck": false,
338-
//
338+
//
339339
// /**
340340
// * A flag indicating that changes to this project will be published to npm, which affects
341341
// * the Rush change and publish workflows. The default value is false.
342342
// * NOTE: "versionPolicyName" and "shouldPublish" are alternatives; you cannot specify them both.
343343
// */
344344
// // "shouldPublish": false,
345-
//
345+
//
346346
// /**
347347
// * An optional version policy associated with the project. Version policies are defined
348348
// * in "version-policies.json" file. See the "rush publish" documentation for more info.
349349
// * NOTE: "versionPolicyName" and "shouldPublish" are alternatives; you cannot specify them both.
350350
// */
351351
// // "versionPolicyName": ""
352352
// },
353-
//
353+
//
354354
// {
355355
// "packageName": "my-controls",
356356
// "projectFolder": "libraries/my-controls",
357357
// "reviewCategory": "production"
358358
// },
359-
//
359+
//
360360
// {
361361
// "packageName": "my-toolchain",
362362
// "projectFolder": "tools/my-toolchain",
363363
// "reviewCategory": "tools"
364364
// }
365-
365+
366366
{
367367
"packageName": "api-demo",
368368
"projectFolder": "api-demo"
@@ -378,7 +378,8 @@
378378
},
379379
{
380380
"packageName": "eslint-plugin-tsdoc",
381-
"projectFolder": "eslint-plugin"
381+
"projectFolder": "eslint-plugin",
382+
"shouldPublish": true
382383
}
383384
]
384385
}

0 commit comments

Comments
 (0)