-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addition of eslint plugin #190
Conversation
@@ -0,0 +1,2 @@ | |||
registry=https://registry.npmjs.org/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so we should also delete the copy under /tsdoc/.npmrc
.
I think you're right though -- this probably predates the ADO publishing pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably actually predates this repo's migration to Rush. Let's clean these up in a follow-up PR.
eslint-plugin/package.json
Outdated
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You definitely want a CI build script here.
eslint-plugin/package.json
Outdated
"name": "eslint-plugin-tsdoc", | ||
"version": "0.1.0", | ||
"description": "eslint plugin for tsdoc", | ||
"private": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We expect to publish this plugin, no?
eslint-plugin/src/index.js
Outdated
@@ -0,0 +1,44 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be written in TypeScript.
eslint-plugin/tests/index.js
Outdated
@@ -0,0 +1,14 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our convention is to put tests under src/<relevant path>/tests/<featurename>.test.ts
.
This should also be written in TypeScript.
eslint-plugin/src/index.js
Outdated
var commentString = "/*" + commentBlock.value + "*/"; | ||
var results = tsDocParser.parseString(commentString).log; | ||
if (results._messages.length > 0) { | ||
results._messages.forEach(function (message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be more efficient to use a for(... of ...)
loop here.
eslint-plugin/src/index.js
Outdated
var commentBlock = commentBlocks[0]; | ||
var commentString = "/*" + commentBlock.value + "*/"; | ||
var results = tsDocParser.parseString(commentString).log; | ||
if (results._messages.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You actually don't need this check. If there are no entries in the _messages
property, the loop won't iterate.
eslint-plugin/src/index.js
Outdated
var commentString = "/*" + commentBlock.value + "*/"; | ||
var results = tsDocParser.parseString(commentString).log; | ||
if (results._messages.length > 0) { | ||
results._messages.forEach(function (message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties that begin with underscores (like _messages
) are private. Use a public property here.
eslint-plugin/src/index.js
Outdated
var results = tsDocParser.parseString(commentString).log; | ||
if (results._messages.length > 0) { | ||
results._messages.forEach(function (message) { | ||
context.report({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will report every TSDoc parse error as a separate linting violation, won't it? Is that what we want? Or do we want to report a single violation that says that the doc comment is invalid, and list the parse errors as additional information on that single violation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do want separate lint errors for each TSDoc error. This way the red squiggly underlines can be as accurate as possible.
eslint-plugin/src/index.js
Outdated
module.exports = { | ||
rules: { | ||
"tsdoc-comments": { | ||
meta: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include at least the type
and docs
properties here (https://github.com/eslint/eslint/blob/master/docs/developer-guide/working-with-rules.md#rule-basics).
I will make the suggested changes here and comment back when I am done. Thanks for the feedback. |
bedc828
to
21ac1fa
Compare
I believe I have made all the suggested improvements. Let me know if there are any more. |
21ac1fa
to
00d8f0f
Compare
eslint-plugin/package.json
Outdated
"private": false, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to run eslint
on this package as well. Maybe copy parts of the build script from tsdoc
.
eslint-plugin/src/index.ts
Outdated
}); | ||
|
||
module.exports = { | ||
rules: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use two-space indentation?
eslint-plugin/src/index.ts
Outdated
messageIds[messageId] = messageId + ": {{ unformattedText }}"; | ||
}); | ||
|
||
module.exports = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just be able to say exports = ...
.
module.exports = { | |
exports = { |
eslint-plugin/src/index.ts
Outdated
const messageIds: {[x: string]: string} = {}; | ||
|
||
allTsdocMessageIds.forEach((messageId: string) => { | ||
messageIds[messageId] = messageId + ": {{ unformattedText }}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use a template string here:
messageIds[messageId] = messageId + ": {{ unformattedText }}"; | |
messageIds[messageId] = `${messageId}: {{ unformattedText }}`; |
eslint-plugin/src/index.ts
Outdated
url: "https://github.com/microsoft/tsdoc" | ||
} | ||
}, | ||
create: function(context: eslint.Rule.RuleContext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a lambda function here.
create: function(context: eslint.Rule.RuleContext) { | |
create: (context: eslint.Rule.RuleContext) => { |
eslint-plugin/src/index.ts
Outdated
var commentBlock = commentBlocks[0]; | ||
var commentString = "/*" + commentBlock.value + "*/"; | ||
var results = tsDocParser.parseString(commentString).log; | ||
for (let message of results.messages) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (let message of results.messages) { | |
for (const message of results.messages) { |
eslint-plugin/src/tests/index.ts
Outdated
@@ -0,0 +1,26 @@ | |||
|
|||
import { RuleTester } from "eslint"; | |||
const rule = require("../index").rules["tsdoc-comments"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const rule = require("../index").rules["tsdoc-comments"]; | |
import * as rules from '../index'; | |
const rule: eslint.Rule /* or whatever the type is here */ = rules['tsdoc-comments']; |
eslint-plugin/package.json
Outdated
"license": "MIT", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "node tests/index.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path should now be lib/tests/index.js
.
Although it'd probably be best to include this in the build script so we run the test as part of the build.
"test": "node tests/index.js" | |
"test": "node lib/tests/index.js" |
eslint-plugin/package.json
Outdated
"@microsoft/tsdoc": "0.12.14" | ||
}, | ||
"devDependencies": { | ||
"@types/eslint": "^6.1.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@types/
packages don't follow semver. Pin this to the specific version.
"@types/eslint": "^6.1.3", | |
"@types/eslint": "6.1.3", |
eslint-plugin/src/index.ts
Outdated
messageIds[messageId] = messageId + ": {{ unformattedText }}"; | ||
}); | ||
|
||
module.exports = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful to ensure that the object we export is well-typed.
Thanks so much for putting this together! This rule will be really useful. Most of the remaining comments are fairly superficial, and they can probably be addressed in a follow-up PR if you like. |
1aaf298
to
3ac9f2f
Compare
I have made all the requested changes. It appears something with the build is failing in the |
3ac9f2f
to
692ad88
Compare
It's this old issue. The TSDoc repo was serving as a guinea pig for the Yarn package manager, but Yarn really doesn't play well with DefinitelyTyped. There's an active megathread where they're finally trying to sort this out. @iclanton I wonder if we should just switch to PNPM for the time being? I've pushed a fix to your branch. |
@@ -0,0 +1,2 @@ | |||
registry=https://registry.npmjs.org/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably actually predates this repo's migration to Rush. Let's clean these up in a follow-up PR.
This pull request adds an eslint plugin which validates tsdoc comment blocks. This should resolve #154