RFC: Handling of ambiguous comment blocks
See original GitHub issueConsider the following TypeScript source file:
/** [1]
* @file Copyright (c) Example Corporation
*/
/** [2]
* The Widget class
*/
// [3] TODO: This class needs to be refactored
export class Widget {
/** [4]
* The width of the Widget class
*/
// [5] private width: string;
/* [6] Renders the class */
public render(): void {
}
/**
* [7] The height of the widget
*/
public get height(): number {
}
// [8] This is a setter for the above getter
/**
* [9] Sets the height
*/
public set height(value: number) {
}
}
Which comments are associated with which API items?
We might expect a documentation tool to associate the comments as follows:
- Widget: Uses [2] as its doc comment
- Widget.render: No doc comment, but warn that [6] looks like it was intended to be JSDoc, and warn that [4] doesn’t seem to be attached to anything
- Widget.height: Normally setters/getters are documented as one API item, so use [7] and report a warning for [9]
Does this make sense? Is there an unambiguous algorithm for selecting the right comment?
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
RFC Errata Report » RFC Editor
RFC 5234, "Augmented BNF for Syntax Specifications: ABNF", January 2008. suggests that only ">" must not appear. Notes:
Read more >Requests for comments (RFCs) - Sourcegraph handbook
An “RFC” literally means a “Request for Comments. ... be used if a decision explicitly requires one of the bullets in the section...
Read more >RFC 8792 - Handling Long Lines in Content of Internet-Drafts ...
Handling Long Lines in Content of Internet-Drafts and RFCs (RFC 8792, June 2020)
Read more >6 RFCs for understanding how the internet works
July 6, 2018 | 2 Comments | 3 min read ... By giving the requirements a well-defined taxonomy, RFC 2119 helps avoid ambiguity....
Read more >Best practices for writing code comments - Stack Overflow Blog
I've seen students in upper-division computer science classes add a comment to each closed brace to indicate what block is ending:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
@packageDocumentation
and do some checks to make sure it’s not missing, nor are there more than one of them.It’s not great code, but you can see the implementation here: https://github.com/Microsoft/web-build-tools/blob/25d2894edaebb8fc30fe21f13cc691a5e8d78878/apps/api-extractor/src/aedoc/PackageDocComment.ts
I was thinking about revisiting this topic when we add support for namespaces introduced using
import * as n1 from ___
.I think there are two possible solutions.