-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Clean up mess for --show-coverage documentation #90438
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,6 +348,18 @@ Using this flag looks like this: | |
$ rustdoc src/lib.rs -Z unstable-options --show-coverage | ||
``` | ||
|
||
It generates something like this: | ||
|
||
```bash | ||
+-------------------------------------+------------+------------+------------+------------+ | ||
| File | Documented | Percentage | Examples | Percentage | | ||
+-------------------------------------+------------+------------+------------+------------+ | ||
| lib.rs | 4 | 100.0% | 1 | 25.0% | | ||
+-------------------------------------+------------+------------+------------+------------+ | ||
| Total | 4 | 100.0% | 1 | 25.0% | | ||
+-------------------------------------+------------+------------+------------+------------+ | ||
``` | ||
|
||
If you want to determine how many items in your crate are documented, pass this flag to rustdoc. | ||
When it receives this flag, it will count the public items in your crate that have documentation, | ||
and print out the counts and a percentage instead of generating docs. | ||
|
@@ -367,17 +379,25 @@ Some methodology notes about what rustdoc counts in this metric: | |
Public items that are not documented can be seen with the built-in `missing_docs` lint. Private | ||
items that are not documented can be seen with Clippy's `missing_docs_in_private_items` lint. | ||
|
||
### `-w`/`--output-format`: output format | ||
Calculating code examples follows these rules: | ||
|
||
When using | ||
[`--show-coverage`](https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#--show-coverage-get-statistics-about-code-documentation-coverage), | ||
passing `--output-format json` will display the coverage information in JSON format. For example, | ||
here is the JSON for a file with one documented item and one undocumented item: | ||
1. These items aren't accounted by default: | ||
* struct/union field | ||
* enum variant | ||
* constant | ||
* static | ||
* typedef | ||
2. If one of the previously listed items has a code example, then it'll be counted. | ||
|
||
#### JSON output | ||
|
||
When using `--output-format json` with this option, it will display the coverage information in | ||
JSON format. For example, here is the JSON for a file with one documented item and one | ||
undocumented item: | ||
|
||
```rust | ||
/// This item has documentation | ||
pub fn foo() {} | ||
|
||
camelid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub fn no_documentation() {} | ||
``` | ||
|
||
|
@@ -387,10 +407,16 @@ pub fn no_documentation() {} | |
|
||
Note that the third item is the crate root, which in this case is undocumented. | ||
|
||
When not using `--show-coverage`, `--output-format json` emits documentation in the experimental | ||
### `-w`/`--output-format`: output format | ||
|
||
`--output-format json` emits documentation in the experimental | ||
[JSON format](https://github.com/rust-lang/rfcs/pull/2963). `--output-format html` has no effect, | ||
and is also accepted on stable toolchains. | ||
|
||
It can also be used with `--show-coverage`. Take a look at its | ||
[documentation](#--show-coverage-get-statistics-about-code-documentation-coverage) for more | ||
information. | ||
|
||
### `--enable-per-target-ignores`: allow `ignore-foo` style filters for doctests | ||
|
||
Using this flag looks like this: | ||
|
@@ -441,39 +467,6 @@ $ rustdoc src/lib.rs -Z unstable-options --runtool valgrind | |
|
||
Another use case would be to run a test inside an emulator, or through a Virtual Machine. | ||
|
||
### `--show-coverage`: get statistics about code documentation coverage | ||
|
||
This option allows you to get a nice overview over your code documentation coverage, including both | ||
doc-comments and code examples in the doc-comments. Example: | ||
|
||
```bash | ||
$ rustdoc src/lib.rs -Z unstable-options --show-coverage | ||
+-------------------------------------+------------+------------+------------+------------+ | ||
| File | Documented | Percentage | Examples | Percentage | | ||
+-------------------------------------+------------+------------+------------+------------+ | ||
| lib.rs | 4 | 100.0% | 1 | 25.0% | | ||
+-------------------------------------+------------+------------+------------+------------+ | ||
| Total | 4 | 100.0% | 1 | 25.0% | | ||
+-------------------------------------+------------+------------+------------+------------+ | ||
Comment on lines
-450
to
-457
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you keep this example and put it in the merged section? |
||
``` | ||
|
||
You can also use this option with the `--output-format` one: | ||
|
||
```bash | ||
$ rustdoc src/lib.rs -Z unstable-options --show-coverage --output-format json | ||
{"lib.rs":{"total":4,"with_docs":4,"total_examples":4,"with_examples":1}} | ||
``` | ||
|
||
Calculating code examples follows these rules: | ||
|
||
1. These items aren't accounted by default: | ||
* struct/union field | ||
* enum variant | ||
* constant | ||
* static | ||
* typedef | ||
2. If one of the previously listed items has a code example, then it'll be counted. | ||
Comment on lines
-467
to
-475
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like there's corresponding docs in the new section about this? Maybe move this part to the new section as well? |
||
|
||
### `--with-examples`: include examples of uses of items as documentation | ||
|
||
This option, combined with `--scrape-examples-target-crate` and | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.