-
Notifications
You must be signed in to change notification settings - Fork 42
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
Make the generated file compliant with dtslint #108
Comments
To do this we'd have to parse the jsdoc strings or generate our own based on the data we output. Both of which seem like a lot of work just to appease a style linter. I don't think this is worth it. Also some of these seem like opinions. For example, I want all my files to end in a blank line. |
I believe that we can generate the comment from the /**
* The {Foo} class provides the most useful {#bar} function.
* @class Foo
*/
class Foo {
/**
* An helper function to say hello.
* @param {string|undefined} - An optional name (by default: 'World')
* @returns {string} - a {string} that says "Hello" to the given name
*/
hello(name = 'World') {
return `Hello ${name}`
}
} I will get the following (simplified) Doclet {
description: 'An helper function to say hello.',
params:
[ { description: 'An optional name (by default: \'World\')',
name: 'name',
defaultvalue: 'World' } ],
returns:
[ { type: [Object],
description: '- a {string} that says "Hello" to the given name' } ]
} Doclet {
description: 'The {Foo} class provides the most useful {#bar} function.'
} Here's an implementation (using template literals): function handleComment<T extends ts.Node>(doclet: IDocletBase, node: T): T
{
if (doclet.comment && doclet.comment.length > 4)
{
let description = '';
if (doclet.description) {
description = `\n * ${doclet.description}`;
}
let params = []
if (doclet.params) {
params = doclet.params.map((param) => `\n * @param ${param.description}`)
}
let returns = []
if (doclet.returns) {
returns = doclet.returns.map((ret) => `\n * @returns ${ret.description}`)
}
let comment = `*${description}${params.join('')}${returns.join('')}
`
const kind = ts.SyntaxKind.MultiLineCommentTrivia;
ts.addSyntheticLeadingComment(node, kind, comment, true);
}
return node;
}
Indeed, the official linter is opinionated.
I don't mind removing a final blank line in a post task. If you don't want to change the current output, maybe we can enable this feature using a configuration file? $ jsdoc -c dtslint-compliant-conf.json -t node_modules/tsd-jsdoc/dist What do you think? |
If jsdoc gives us what we need I'm open to a PR that changes the coments to pass linting. I think taking a dts config file to modify output might be a bit overkill unless we find ourselves implementing many different workarounds. |
Ok I'm working on it 👍 |
Here's a simple example:
And here's the generated file:
types.d.ts
Using dtslint:
As you can see we should do the following:
@class
,@namespace
...{string}
And here's the expected result:
types.d.ts
The text was updated successfully, but these errors were encountered: