-
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
RFC: Handling of ambiguous comment blocks #6
Comments
Here is how TypeDoc parses the example. (note: this was edited to reflect what TypeDoc actually does)
The getter/setter is rendered as one api item in TypeDoc but you can toggle between the items to see their documentation I would expect [2] to not be used. I think [6] also should not be used. Only having one API item and using [7] for getter/setters makes sense to me. Concatenating [7] and [9] is another option. In general, I would recommend limiting the number of warnings. I wouldn't want to get complaints that I commented out [5]. In this case [6] does seem like a mistake but how do you tell the intention? Using export class Config {}
/* The following classes need to be reviewed for reason x */
export class WidgetA {}
export class WidgetB {} Another parsing consideration is extra lines. /** I think TypeDoc will use this on `Widget` even though there is a blank line */
export class Widget { } |
After testing out my expectations, you can see that TypeDoc only pays attention to comments that begin with |
@aciccarello the only usage of a single comment between symbol and JSDoc is tslint disable next line |
Yes, the tslint use case seem significant. I don't think TSDoc should do anything too tslint specific though. How else could you avoid messing with documentation by commenting out a class property? /**
* Some documentation
*/
export class MyClass {
/** this documentation should be applied */
// tslint:disable-next-line
someNameTslintDoesntLike: string;
/** documentation */
// prop = 'initializer';
thisShouldntHaveDocumentation: string;
} |
I think there are two possible solutions.
class Foo {
/**
* Some documentation for `bar`.
*/
public bar: string;
/**
* This JSDoc comment block is not part of `bar2`.
* WARN developer for floating JSDoc comment block.
*/
public bar2: string;
/**
* Same goes here like in `bar2` example.
* This JSDoc comment block is not part of `bar3`.
* WARN developer for floating JSDoc comment block.
*/
// tslint:disable-next-line
public bar3: string;
}
class Foo {
/**
* Some documentation for `bar`.
*/
public bar: string;
/**
* This JSDoc comment block is not part of `bar2`.
* WARN developer for a floating JSDoc comment block.
*/
public bar2: string;
/**
* JSDoc for `bar3`.
*/
// tslint:disable-next-line
public bar3: string;
/**
* JSDoc comment will be assigned for `bar5`. But it was intended for commented property `bar4`.
*/
//public bar4: string;
public bar5: string;
/**
* WARN developer for a floating JSDoc comment block.
*/
/**
* Some documentation for `bar6`.
*/
public bar6: string;
} |
I think this situation, where commented property documentation gets applied the next property as they are not separated by an empty line, shouldn't be much of a concern for us: class Foo {
/**
* JSDoc comment will be assigned for `bar5`. But it was intended for commented property `bar4`.
*/
//public bar4: string;
public bar5: string;
} This could be easily solved with a TSLint rule ensuring that declarations have at least one line separating them. Would that be too intrusive for others? I'm sure I could live with it. |
I think I'm leaning towards requiring whitespace aftwards to prevent documentation shifting to the next variable. While I often write my properties in a tight group, those groupings already get harder to read if there are doc comments. A TSLint rule would seem appropriate for preventing these types of errors. You could even have a rule which warns on a class Foo {
/** This comment is clearly about `bar1` */
bar1: string;
bar2: string;
/** This comment is not great for readability */
bar3: string;
bar4: string;
/**
* Documentation that is not applied correctly
*/
// bar5: string; // ts-lint throws "TSDoc comments falling through"
bar6: string;
} |
BTW the api-demo/src/advancedDemo.ts demo illustrates an approach for collecting comments. The compiler itself already discards some of the weirder places where |
@octogonz I'm curious if you have thought any more about file level doc comments? In TypeStrong/typedoc#603 users have noted that they expect the first comment of the file to be for the entire file, however there is plenty of ambiguity as to what is acceptable without having a standard format. |
We don't use files-as-namespacs in any of the projects I work on, although I've had external requests for this feature that seem reasonable. API Extractor does rely on file-level comments from the entry point of a package to document the package itself. However, I would be super paranoid about blindly publishing the "first" comment we encounter. What if it's a copyright banner or other junk that wasn't intended for customers to see? Or what if we counted wrong, because of the weird way that trivia gets parsed by the compiler (and often omitted from the .d.ts file)? For these reasons we insist on the file comment containing a TSDoc tag It's not great code, but you can see the implementation here: I was thinking about revisiting this topic when we add support for namespaces introduced using |
Consider the following TypeScript source file:
Which comments are associated with which API items?
We might expect a documentation tool to associate the comments as follows:
Does this make sense? Is there an unambiguous algorithm for selecting the right comment?
The text was updated successfully, but these errors were encountered: