bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
33.81k stars 3.3k forks source link

Add doc-writing advice to Contributing guide #4754

Open alice-i-cecile opened 2 years ago

alice-i-cecile commented 2 years ago

Initial notes from Discord:

  1. The first line of doc comments should be a minimal description.
  2. Details of what the documented function / type do belong in their own paragraphs, separated by a line break.
  3. If the usage is not immediately clear, or if there are subtle gotchas, add doc tests
  4. If a method panics, mention that under a Warning header.
  5. If a method or struct is unsafe, you must include a Safety header
  6. Link to related types that are commonly used with or are alternatives to the documented type using [DocLinks].

These should be stored in a sibling to https://github.com/bevyengine/bevy/blob/main/.github/contributing/engine_style_guide.md, which should be linked in https://github.com/bevyengine/bevy/blob/main/CONTRIBUTING.md

Nilirad commented 2 years ago

There are also some tips in the rustdoc book about writing good API documentation.

Nilirad commented 2 years ago

Some interesting tips from recent experience and discussion with @alice-i-cecile:

alice-i-cecile commented 2 years ago

More thoughts on stuff to add:

Nilirad commented 2 years ago

Another useful pattern that I recently adopted: when documenting a data type, put under a “Usage” section:

Nilirad commented 2 years ago

In some cases I found useful to create should_panic doctests. A system can be made easily run to check if it panics with the following pattern:

/// # let mut my_system = bevy_ecs::system::IntoSystem::into_system(my_system_function);
/// # let mut world = World::new();
/// # my_system.initialize(&mut world);
/// # my_system.run((), &mut world);
Nilirad commented 2 years ago

If we end up using the advice of breaking lines at sentence/clause-level, we also should remove the wrap_comments option from rustfmt.toml. Otherwise, that would end up breaking comments where we don't want to.

The option is currently commented, however it is presented as being potentially uncommented on need (probably for some occasional workflows).