-
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
Less strict parsing for @param tags #128
Comments
This might be a little overly strict. Consider this example: /** Represents a 2D vector. */
public class Vector {
/** The first component of the vector */
public x: number;
/** The second component of the vector */
public y: number;
/**
* Constructs a new instance of the `Vector` class
* @param x - the first component of the vector
* @param y - the second component of the vector
*/
public constructor(x: number, y: number) {
}
} Would we really want to insist that the person write this
Hmm... I hadn't thought of that one. Tools like API Extractor could normalize this automatically when they generate the .d.ts files, but yeah, I can see the value of doing this in the source code.
Agreed. My motivation for being strict about parsing I'll point out that today the @microsoft/tsdoc library only looks at comments -- it has no idea what the function parameters are, or even whether the comment is for a class or function etc. When the dust settles on API Extractor 7, I'd like to consider whether it would be useful to provide some context to @microsoft/tsdoc so that we can move some of this validation down into the library. We might get better error messages that way.
Hrmmm... the example you linked to doesn't use // good
/**
* make() returns a new element
* based on the passed-in tag name
*/
function make(tag) {
// ...
return element;
} |
Oops on the link; edited above and replaced with a jsdoc one that's more applicable.
I should have worded that better; i was thinking more about "if you provide comments for one param, you should provide them for all". Or, if someone modifies a signature but the comments don't match (e.g. they're out of order, some are unrecognized or missing) then that could be caught. Totally agree we definitely don't want it to be frictiony by erroring on things that are not useful to correct. :) |
Normalize `@param name description` to be `@param name - description` See microsoft/tsdoc#128
Normalize `@param name description` to be `@param name - description` See microsoft/tsdoc#128
Normalize `@param name description` to be `@param name - description` See microsoft/tsdoc#128
This still seems to be an issue for |
I tagged it for follow up. If it's easy maybe I can tackle this in the next round of work on the parser. |
Locally I wrote a patch for var hyphenExcerpt;
var spacingAfterHyphenExcerpt;
if (tokenReader.peekTokenKind() === Token_1.TokenKind.Hyphen) {
tokenReader.readToken();
hyphenExcerpt = tokenReader.extractAccumulatedSequence();
// TODO: Only read one space
spacingAfterHyphenExcerpt = this._tryReadSpacingAndNewlines(tokenReader);
}
else if (tokenReader.peekTokenKind() !== Token_1.TokenKind.AsciiWord) {
tokenReader.backtrackToMarker(startMarker);
this._parserContext.log.addMessageForTokenSequence("tsdoc-param-tag-missing-hyphen" /* ParamTagMissingHyphen */, 'The @param block should be followed by a parameter name and then a hyphen', docBlockTag.getTokenSequence(), docBlockTag);
return new nodes_1.DocParamBlock({
configuration: this._configuration,
blockTag: docBlockTag,
parameterName: ''
});
} Essentially, it allows |
I formalized my patch above and added additional parsing support for |
This fix was published with TSDoc 0.12.18. Thanks @rbuckton for making the PR! |
@pgonzal and I were talking in an email thread about parsing params in api-extractor/tsdoc, and suggested I log an issue here to track the param parsing concerns.
Goals for param parsing should be;
Examples that should work:
It is nice to stay consistent with param documentation, but the tools should also be resilient in the parsing and let formatting cleanup be the duty of tools like Prettier.
There might be a strict mode which enforces the VSCode default jsdoc comments. but please do not deviate from what most other open source projects snap to (the second example above.)
See Airbnb specs for their guidance as an example. Look at React jsdoc comments. etc
https://github.com/airbnb/javascript#comments
The text was updated successfully, but these errors were encountered: