tsdoc/README.md

124 строки
9.6 KiB
Markdown
Исходник Обычный вид История

2018-03-21 03:59:58 +03:00
# TSDoc
2018-03-01 03:16:56 +03:00
2018-03-21 03:59:58 +03:00
> A doc comment standard for TypeScript
2019-02-04 04:20:23 +03:00
[![Build Status](https://dev.azure.com/RushStack/Gearbox%20GitHub%20Projects/_apis/build/status/tsdoc/TSDoc%20CI%20Build?branchName=master)](https://dev.azure.com/RushStack/Gearbox%20GitHub%20Projects/_build/latest?definitionId=5&branchName=master)
2018-03-21 03:59:58 +03:00
### What is TSDoc?
2018-03-21 05:35:04 +03:00
**TSDoc** is a proposal to standardize the doc comments used in [TypeScript](http://www.typescriptlang.org/) source files. It allows different tools to extract content from comments without getting confused by each other's syntax. The **TSDoc** notation looks pretty familiar:
2018-03-21 03:59:58 +03:00
```typescript
2018-09-05 03:47:07 +03:00
export class Statistics {
/**
* Returns the average of two numbers.
*
* @remarks
* This method is part of the {@link core-library#Statistics | Statistics subsystem}.
2018-09-05 03:47:07 +03:00
*
* @param x - The first input number
* @param y - The second input number
* @returns The arithmetic mean of `x` and `y`
*
* @beta
*/
public static getAverage(x: number, y: number): number {
return (x + y) / 2.0;
}
}
2018-03-21 03:59:58 +03:00
```
We are developing a library package [@microsoft/tsdoc](https://www.npmjs.com/package/@microsoft/tsdoc) that provides an open source reference implementation of a parser. Using this library is an easy way to ensure that your tool is 100% compatible with the standard.
2018-03-21 03:59:58 +03:00
2019-11-05 10:23:59 +03:00
&#x1F44B; ***Give it a try!** The <a target="_blank" href="https://microsoft.github.io/tsdoc/">TSDoc Playground</a> provides an interactive showcase of our parser!*
2018-03-21 03:59:58 +03:00
### Why do we need TSDoc?
2018-03-21 05:35:04 +03:00
This scenario originally arose from projects at Microsoft that are processed by multiple tools:
2018-03-21 03:59:58 +03:00
2018-03-21 05:15:29 +03:00
- [Visual Studio Code](https://code.visualstudio.com): an editor that supports syntax highlighting and interactive refactoring for TypeScript doc comments
- [TypeDoc](https://github.com/TypeStrong/typedoc): an API reference website generator that extracts its content from doc comments
2018-10-10 09:59:38 +03:00
- [DocFX](https://dotnet.github.io/docfx/): an integrated pipeline that ingests API reference content for many different programming languages, but then applies its own Markdown renderer and custom tag parsing
2018-03-21 05:15:29 +03:00
- [API Extractor](https://aka.ms/extractor): a build tool that tracks TypeScript API review workflows and generates *.d.ts rollups for third-party SDKs
2018-03-21 03:59:58 +03:00
2018-03-21 05:35:04 +03:00
These are just examples. Many other tools in today's web developer community want to interact with TypeScript doc comments. Each of these tools accepts a syntax that is loosely based on [JSDoc](http://usejsdoc.org), but encounters frustrating incompatibilities when attempting to coexist with other parsers.
2018-03-21 03:59:58 +03:00
*Why can't JSDoc be the standard?* Unfortunately the JSDoc grammar is not rigorously specified, but rather inferred from the behavior of a particular implementation. The majority of the standard JSDoc tags are preoccupied with providing type annotations for plain JavaScript, which is an irrelevant concern for a strongly-typed language such as TypeScript. **TSDoc** addresses these limitations while also tackling a more sophisticated set of goals.
2018-03-21 03:59:58 +03:00
2018-03-21 03:59:58 +03:00
### What are the goals?
2018-03-21 05:35:04 +03:00
The TSDoc specification aims to meet these requirements:
2018-03-21 03:59:58 +03:00
- **Designed for TypeScript**: ...while aligning as closely as possible with the familiar JSDoc notations we know and love.
2018-10-11 01:51:17 +03:00
- **Markdown integration**: Doc comments may incorporate [CommonMark](http://commonmark.org) notations for rich text elements such as boldface, code fences, headings, tables, etc. (This turned out to be the toughest requirement, since the Markdown grammar is very irregular and very dependent on context.) TSDoc makes special accommodations for entrenched pipelines (e.g. GitHub Pages) that expect to bring their own Markdown renderer to the party.
2018-03-21 03:59:58 +03:00
- **Common core**: Common tags such as `@param` and `@returns` will have consistent behavior across all tools.
2018-03-21 05:15:29 +03:00
- **Extensible**: Each tool can supplement the core tags with custom tags for specialized scenarios.
- **Interoperable**: The TSDoc standard guarantees that unsupported custom tags won't interfere with parsing of other content. TSDoc also eliminates Markdown ambiguities. (Are backticks allowed inside a `{@link}` tag? What happens if there is only one backtick? etc.)
2020-04-29 19:31:58 +03:00
- **Multi-package support**: Many teams ship a collection of NPM packages that work together and are documented as a set. The cross-referencing syntax (e.g. `{@link}` or `{@inheritDoc}`) needs a portable way to reference API items imported from other packages. We also define *package.json* metadata that enables tooling to detect whether a dependency's *.d.ts doc comments should be parsed as TSDoc or not.
2018-03-21 05:35:04 +03:00
- **Open standard**: TSDoc is an open source, community-driven standard. You are encouraged to contribute your own ideas and pull requests.
2018-03-21 03:59:58 +03:00
2018-03-21 05:15:29 +03:00
The **@microsoft/tsdoc** library package brings in some additional goals:
- **"Strict" and "Lax" modes**: Many projects dont have the time/desire to change their existing code, so they want a "*lax*" mode that makes a best attempt to render their doc comments as-is. Other projects want a "*strict*" mode that ensures consistent syntax everywhere and catches typos that might result in rendering errors. Some projects want to be "*strict*" eventually, but they can't migrate everything overnight; they need a "*transitional*" mode similar to tslint suppressions.
- **Comment-emitter for roundtripping**: The parser reads doc comments as input and produces an abstract syntax tree (AST) as output. This should be reversible: given an AST input (possibly with modifications), the library can regenerate the corresponding doc comment.
- **Self-contained**: The implementation will be small, fast, and self-contained. It will not have a dependency on the TypeScript compiler API. Doc comments will be received as a plain text string, and the AST will be a simple JavaScript tree object. This makes it easier for tools to accept **@microsoft/tsdoc** as a dependency.
2018-03-21 05:15:29 +03:00
2018-10-11 01:51:17 +03:00
### How do I get started with TSDoc?
2018-03-21 03:59:58 +03:00
2018-10-11 03:13:50 +03:00
NOTE: The **@microsoft/tsdoc** library is intended to be incorporated into other build tools that analyze TypeScript source code, such as the projects linked below. (By itself, the TSDoc library is not a documentation tool that you can use directly.)
2018-10-11 01:51:17 +03:00
- Check out the [TSDoc Playground](https://microsoft.github.io/tsdoc/) for a cool interactive demo of TSDoc! :-)
- The library [@microsoft/tsdoc](https://www.npmjs.com/package/@microsoft/tsdoc) provides a TSDoc parser that you can use in your own projects. The source code for this library can be found in the [/tsdoc](./tsdoc/) folder.
- The [/api-demo](./api-demo/) folder has a small demo project illustrating how to invoke the **@microsoft/tsdoc** library.
2019-11-05 11:10:12 +03:00
- We also provide an ESLint plugin [eslint-plugin-tsdoc](https://www.npmjs.com/package/eslint-plugin-tsdoc) that you can use to validate your source code.
2018-10-11 01:51:17 +03:00
- See [Contributing.md](./Contributing.md) for instructions for building, debugging, and contributing to TSDoc.
- We're using [GitHub issues](https://github.com/Microsoft/tsdoc/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) to discuss the TSDoc specification, library design, and project roadmap.
2018-03-21 03:59:58 +03:00
### Who's involved?
2018-03-21 03:59:58 +03:00
The collaborators currently driving the TSDoc standard are:
- [TypeScript](http://www.typescriptlang.org) compiler group at Microsoft
- [API Extractor](https://aka.ms/extractor) project owners
2018-03-21 03:59:58 +03:00
- [TypeDoc](http://typedoc.org) maintainers
- [DocFX](https://dotnet.github.io/docfx/) pipeline owners
2018-03-23 20:50:46 +03:00
- [SimplrJS](https://simplrjs.com/) developers, who maintain the [ts-docs-gen](https://github.com/SimplrJS/ts-docs-gen) tool
- [Tom Dale](https://github.com/tomdale), who's working on the documentation engine for [Ember.js](https://www.emberjs.com), [Glimmer.js](https://glimmerjs.com), and other projects
- [Rob Eisenberg](https://github.com/EisenbergEffect), who's working on the documentation engine for [Aurelia](http://aurelia.io/).
2018-03-21 03:59:58 +03:00
2018-10-11 01:51:17 +03:00
### Where are we on the roadmap?
**Already completed:**
- Write up all the interesting design questions as "RFC" GitHub issues to collect community feedback
- Arrive at an initial consensus on the basic approach and strategy for TSDoc
- Develop an initial feature-complete prototype of the **@microsoft/tsdoc** library and publish the NPM package
2018-10-11 03:13:50 +03:00
- Convert Microsoft's API Extractor tool to use **@microsoft/tsdoc** (replacing its proprietary AEDoc engine); this demonstrates that TSDoc can meet the needs of [a large production documentation web site](https://docs.microsoft.com/en-us/javascript/api/sp-core-library?view=sp-typescript-latest)
2018-10-11 01:51:17 +03:00
**What's next:**
- Write up an initial draft of the TSDoc spec document, which outlines the proposed standard
- Collect community feedback and integrate it into the draft, then publish the first "official" 1.0 spec
- Review the **@microsoft/tsdoc** API with various integrators, including TypeScript and VS Code
- Publish the first "1.0.0" stable release of the **@microsoft/tsdoc** package
- Help onboard various partners
2018-03-21 03:59:58 +03:00
## Contributing
2018-03-01 03:16:56 +03:00
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.