ci: add check for doc comment formatting
Which issue does this PR close?
Closes #16915.
Rationale for this change
This PR adds CI enforcement to ensure all code examples in documentation comments are properly formatted to maintain consistent code formatting, including examples in doc comments.
What changes are included in this PR?
This PR adds a new CI check in the check-fmt job that:
- Installs the nightly Rust toolchain
- Runs
cargo +nightly fmt --all -- --check --config format_code_in_doc_comments=true
Note: format_code_in_doc_comments is currently an unstable feature.
Are these changes tested?
The command is tested locally with:
Are there any user-facing changes?
No user-facing changes.
Hi @alamb ,
Following the discussion in PR #16916, I've prepared this PR to enable CI enforcement for doc comment formatting.
As you mentioned, we need to use the same version of cargo fmt to avoid conflicts. Since
format_code_in_doc_comments is only available in nightly, this PR uses cargo +nightly fmt consistently in CI.
This PR contains two commits:
- CI change: Install nightly toolchain and use
cargo +nightly fmt --all -- --check --config format_code_in_doc_comments=true - Format fixes: Apply nightly rustfmt formatting to all existing doc comment code examples
PTAL when you have chance. Thank you!
Hi @alamb ,
Sorry for the late response. I've moved the nightly fmt command to ci/scripts/rust_fmt.sh as suggested.
PTAL when you have chances, thanks!