Is there a warning for undocumented sections?

Viewed 1409

I am writing a crate that I plan to publish. When publishing, one of the most important thing (in my opinion) is to ensure the crate is well documented. Therefore my question : is there a warning to be turned on which warms undocumented sections of the code ?


E.g.: I typically think of something like #[warn(undocumented)].

2 Answers

Yes, such a lint exists. The rustc compiler provides the missing_docs lint, which warns about missing documentation on public items when enabled. The clippy linter provides the missing_docs_in_private_items lint, which additionally warns… well, you guessed it. Note that missing_docs_in_private_items warns for all items, so you don't need missing_docs if you enable it.

You can enable the lints using

#![warn(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]

for warnings or

#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]

for errors.

You are looking for the missing-docs lint in the Rust compiler.

Example:

#![warn(missing_docs)]

fn foo(bar: i32) {}

The output from the compiler:

warning: missing documentation for crate
 --> src/lib.rs:1:1
  |
1 | / #![warn(missing_docs)]
2 | |
3 | | fn foo(bar: i32) {}
  | |___________________^
  |

You may also find more lints in the rustc book.

Related