Enable `--document-private-items` for `ruff_python_formatter`

Summary
--

I wanted to use a link to a preview function to help remember to update some
documentation in #21385, but I noticed that we weren't enforcing doc checks for
private items. I had Claude take the first stab here, but I ended up having to
go back through most of the changes to get the correct links.

The first commit makes everything compile, mostly by adding `(path::to::item)`
entries to the links, or removing brackets when the items aren't public enough.
There were only a couple of cases where I think things were renamed, and I tried
to find the new name for the type that was referenced (e.g.
`FlatBinaryExpressionSlice`).

The second commit rewraps the lines that were now too long and fixes a couple of
very small typos I noticed.

Test Plan
--

CI on this PR
This commit is contained in:
Brent Westbrook 2025-12-10 14:00:56 -05:00
parent f3714fd3c1
commit 94e0418006
No known key found for this signature in database
18 changed files with 33 additions and 33 deletions

View File

@ -298,7 +298,7 @@ jobs:
# sync, not just public items. Eventually we should do this for all # sync, not just public items. Eventually we should do this for all
# crates; for now add crates here as they are warning-clean to prevent # crates; for now add crates here as they are warning-clean to prevent
# regression. # regression.
- run: cargo doc --no-deps -p ty_python_semantic -p ty -p ty_test -p ruff_db --document-private-items - run: cargo doc --no-deps -p ty_python_semantic -p ty -p ty_test -p ruff_db -p ruff_python_formatter --document-private-items
env: env:
# Setting RUSTDOCFLAGS because `cargo doc --check` isn't yet implemented (https://github.com/rust-lang/cargo/issues/10025). # Setting RUSTDOCFLAGS because `cargo doc --check` isn't yet implemented (https://github.com/rust-lang/cargo/issues/10025).
RUSTDOCFLAGS: "-D warnings" RUSTDOCFLAGS: "-D warnings"

View File

@ -36,7 +36,7 @@ impl Debug for DebugComment<'_> {
} }
} }
/// Pretty-printed debug representation of [`Comments`]. /// Pretty-printed debug representation of [`Comments`](super::Comments).
pub(crate) struct DebugComments<'a> { pub(crate) struct DebugComments<'a> {
comments: &'a CommentsMap<'a>, comments: &'a CommentsMap<'a>,
source_code: SourceCode<'a>, source_code: SourceCode<'a>,

View File

@ -504,7 +504,7 @@ impl InOrderEntry {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct OutOfOrderEntry { struct OutOfOrderEntry {
/// Index into the [`MultiMap::out_of_order`] vector at which offset the leading vec is stored. /// Index into the [`MultiMap::out_of_order_parts`] vector at which offset the leading vec is stored.
leading_index: usize, leading_index: usize,
_count: Count<OutOfOrderEntry>, _count: Count<OutOfOrderEntry>,
} }

View File

@ -2,7 +2,7 @@ use ruff_python_ast::AnyNodeRef;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
/// Used as key into the [`MultiMap`] storing the comments per node by [`Comments`]. /// Used as key into the [`MultiMap`](super::MultiMap) storing the comments per node by [`Comments`](super::Comments).
/// ///
/// Implements equality and hashing based on the address of the [`AnyNodeRef`] to get fast and cheap /// Implements equality and hashing based on the address of the [`AnyNodeRef`] to get fast and cheap
/// hashing/equality comparison. /// hashing/equality comparison.

View File

@ -1974,7 +1974,7 @@ fn handle_unary_op_comment<'a>(
/// ) /// )
/// ``` /// ```
/// ///
/// The comment will be attached to the [`Arguments`] node as a dangling comment, to ensure /// The comment will be attached to the [`Arguments`](ast::Arguments) node as a dangling comment, to ensure
/// that it remains on the same line as open parenthesis. /// that it remains on the same line as open parenthesis.
/// ///
/// Similarly, given: /// Similarly, given:
@ -1984,7 +1984,7 @@ fn handle_unary_op_comment<'a>(
/// ] = ... /// ] = ...
/// ``` /// ```
/// ///
/// The comment will be attached to the [`TypeParams`] node as a dangling comment, to ensure /// The comment will be attached to the [`TypeParams`](ast::TypeParams) node as a dangling comment, to ensure
/// that it remains on the same line as open bracket. /// that it remains on the same line as open bracket.
fn handle_bracketed_end_of_line_comment<'a>( fn handle_bracketed_end_of_line_comment<'a>(
comment: DecoratedComment<'a>, comment: DecoratedComment<'a>,

View File

@ -174,7 +174,7 @@ impl<'ast> SourceOrderVisitor<'ast> for CommentsVisitor<'ast, '_> {
/// A comment decorated with additional information about its surrounding context in the source document. /// A comment decorated with additional information about its surrounding context in the source document.
/// ///
/// Used by [`CommentStyle::place_comment`] to determine if this should become a [leading](self#leading-comments), [dangling](self#dangling-comments), or [trailing](self#trailing-comments) comment. /// Used by [`place_comment`] to determine if this should become a [leading](self#leading-comments), [dangling](self#dangling-comments), or [trailing](self#trailing-comments) comment.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct DecoratedComment<'a> { pub(crate) struct DecoratedComment<'a> {
enclosing: AnyNodeRef<'a>, enclosing: AnyNodeRef<'a>,
@ -465,7 +465,7 @@ pub(super) enum CommentPlacement<'a> {
/// ///
/// [`preceding_node`]: DecoratedComment::preceding_node /// [`preceding_node`]: DecoratedComment::preceding_node
/// [`following_node`]: DecoratedComment::following_node /// [`following_node`]: DecoratedComment::following_node
/// [`enclosing_node`]: DecoratedComment::enclosing_node_id /// [`enclosing_node`]: DecoratedComment::enclosing_node
/// [trailing comment]: self#trailing-comments /// [trailing comment]: self#trailing-comments
/// [leading comment]: self#leading-comments /// [leading comment]: self#leading-comments
/// [dangling comment]: self#dangling-comments /// [dangling comment]: self#dangling-comments

View File

@ -166,7 +166,7 @@ impl InterpolatedStringState {
} }
} }
/// Returns `true` if the interpolated string state is [`NestedInterpolatedElement`]. /// Returns `true` if the interpolated string state is [`Self::NestedInterpolatedElement`].
pub(crate) fn is_nested(self) -> bool { pub(crate) fn is_nested(self) -> bool {
matches!(self, Self::NestedInterpolatedElement(..)) matches!(self, Self::NestedInterpolatedElement(..))
} }

View File

@ -1096,7 +1096,7 @@ impl OperandIndex {
} }
/// Returns the index of the operand's right operator. The method always returns an index /// Returns the index of the operand's right operator. The method always returns an index
/// even if the operand has no right operator. Use [`BinaryCallChain::get_operator`] to test if /// even if the operand has no right operator. Use [`FlatBinaryExpressionSlice::get_operator`] to test if
/// the operand has a right operator. /// the operand has a right operator.
fn right_operator(self) -> OperatorIndex { fn right_operator(self) -> OperatorIndex {
OperatorIndex::new(self.0 + 1) OperatorIndex::new(self.0 + 1)

View File

@ -56,8 +56,8 @@ pub(crate) enum Parenthesize {
/// Adding parentheses is desired to prevent the comments from wandering. /// Adding parentheses is desired to prevent the comments from wandering.
IfRequired, IfRequired,
/// Same as [`Self::IfBreaks`] except that it uses [`parenthesize_if_expands`] for expressions /// Same as [`Self::IfBreaks`] except that it uses [`parenthesize_if_expands`](crate::builders::parenthesize_if_expands) for expressions
/// with the layout [`NeedsParentheses::BestFit`] which is used by non-splittable /// with the layout [`OptionalParentheses::BestFit`] which is used by non-splittable
/// expressions like literals, name, and strings. /// expressions like literals, name, and strings.
/// ///
/// Use this layout over `IfBreaks` when there's a sequence of `maybe_parenthesize_expression` /// Use this layout over `IfBreaks` when there's a sequence of `maybe_parenthesize_expression`
@ -65,8 +65,8 @@ pub(crate) enum Parenthesize {
/// first expression and `IfBreaksParenthesized` for the rest. /// first expression and `IfBreaksParenthesized` for the rest.
IfBreaksParenthesized, IfBreaksParenthesized,
/// Same as [`Self::IfBreaksParenthesized`] but uses [`parenthesize_if_expands`] for nested /// Same as [`Self::IfBreaksParenthesized`] but uses [`parenthesize_if_expands`](crate::builders::parenthesize_if_expands) for nested
/// [`maybe_parenthesized_expression`] calls unlike other layouts that always omit parentheses /// [`maybe_parenthesized_expression`](crate::expression::maybe_parenthesize_expression) calls unlike other layouts that always omit parentheses
/// when outer parentheses are present. /// when outer parentheses are present.
IfBreaksParenthesizedNested, IfBreaksParenthesizedNested,
} }

View File

@ -214,7 +214,7 @@ impl Format<PyFormatContext<'_>> for MaybeParenthesizePattern<'_> {
} }
} }
/// This function is very similar to [`can_omit_optional_parentheses`] with the only difference that it is for patterns /// This function is very similar to [`can_omit_optional_parentheses`](crate::expression::can_omit_optional_parentheses) with the only difference that it is for patterns
/// and not expressions. /// and not expressions.
/// ///
/// The base idea of the omit optional parentheses layout is to prefer using parentheses of sub-patterns /// The base idea of the omit optional parentheses layout is to prefer using parentheses of sub-patterns

View File

@ -72,7 +72,7 @@ impl FormatNodeRule<PatternArguments> for FormatPatternArguments {
} }
} }
/// Returns `true` if the pattern (which is the only argument to a [`PatternMatchClass`]) is /// Returns `true` if the pattern (which is the only argument to a [`PatternMatchClass`](ruff_python_ast::PatternMatchClass)) is
/// parenthesized. Used to avoid falsely assuming that `x` is parenthesized in cases like: /// parenthesized. Used to avoid falsely assuming that `x` is parenthesized in cases like:
/// ```python /// ```python
/// case Point2D(x): ... /// case Point2D(x): ...

View File

@ -23,7 +23,7 @@ use crate::{FormatModuleError, PyFormatOptions, format_module_source};
/// ///
/// The returned formatted range guarantees to cover at least `range` (excluding whitespace), but the range might be larger. /// The returned formatted range guarantees to cover at least `range` (excluding whitespace), but the range might be larger.
/// Some cases in which the returned range is larger than `range` are: /// Some cases in which the returned range is larger than `range` are:
/// * The logical lines in `range` use a indentation different from the configured [`IndentStyle`] and [`IndentWidth`]. /// * The logical lines in `range` use a indentation different from the configured [`IndentStyle`] and [`IndentWidth`](ruff_formatter::IndentWidth).
/// * `range` is smaller than a logical lines and the formatter needs to format the entire logical line. /// * `range` is smaller than a logical lines and the formatter needs to format the entire logical line.
/// * `range` falls on a single line body. /// * `range` falls on a single line body.
/// ///
@ -130,14 +130,14 @@ pub fn format_range(
/// ///
/// ### Possible docstrings /// ### Possible docstrings
/// Strings that are suspected to be docstrings are excluded from the search to format the enclosing suite instead /// Strings that are suspected to be docstrings are excluded from the search to format the enclosing suite instead
/// so that the formatter's docstring detection in [`FormatSuite`] correctly detects and formats the docstrings. /// so that the formatter's docstring detection in [`FormatSuite`](crate::statement::suite::FormatSuite) correctly detects and formats the docstrings.
/// ///
/// ### Compound statements with a simple statement body /// ### Compound statements with a simple statement body
/// Don't include simple-statement bodies of compound statements `if True: pass` because the formatter /// Don't include simple-statement bodies of compound statements `if True: pass` because the formatter
/// must run [`FormatClauseBody`] to determine if the body should be collapsed or not. /// must run `FormatClauseBody` to determine if the body should be collapsed or not.
/// ///
/// ### Incorrectly indented code /// ### Incorrectly indented code
/// Code that uses indentations that don't match the configured [`IndentStyle`] and [`IndentWidth`] are excluded from the search, /// Code that uses indentations that don't match the configured [`IndentStyle`] and [`IndentWidth`](ruff_formatter::IndentWidth) are excluded from the search,
/// because formatting such nodes on their own can lead to indentation mismatch with its sibling nodes. /// because formatting such nodes on their own can lead to indentation mismatch with its sibling nodes.
/// ///
/// ## Suppression comments /// ## Suppression comments
@ -279,11 +279,11 @@ enum EnclosingNode<'a> {
/// ///
/// ## Compound statements with simple statement bodies /// ## Compound statements with simple statement bodies
/// Similar to [`find_enclosing_node`], exclude the compound statement's body if it is a simple statement (not a suite) from the search to format the entire clause header /// Similar to [`find_enclosing_node`], exclude the compound statement's body if it is a simple statement (not a suite) from the search to format the entire clause header
/// with the body. This ensures that the formatter runs [`FormatClauseBody`] that determines if the body should be indented.s /// with the body. This ensures that the formatter runs `FormatClauseBody` that determines if the body should be indented.
/// ///
/// ## Non-standard indentation /// ## Non-standard indentation
/// Node's that use an indentation that doesn't match the configured [`IndentStyle`] and [`IndentWidth`] are excluded from the search. /// Node's that use an indentation that doesn't match the configured [`IndentStyle`] and [`IndentWidth`](ruff_formatter::IndentWidth) are excluded from the search.
/// This is because the formatter always uses the configured [`IndentStyle`] and [`IndentWidth`], resulting in the /// This is because the formatter always uses the configured [`IndentStyle`] and [`IndentWidth`](ruff_formatter::IndentWidth), resulting in the
/// formatted nodes using a different indentation than the unformatted sibling nodes. This would be tolerable /// formatted nodes using a different indentation than the unformatted sibling nodes. This would be tolerable
/// in non whitespace sensitive languages like JavaScript but results in lexical errors in Python. /// in non whitespace sensitive languages like JavaScript but results in lexical errors in Python.
/// ///
@ -713,9 +713,9 @@ impl Format<PyFormatContext<'_>> for FormatEnclosingNode<'_> {
} }
} }
/// Computes the level of indentation for `indentation` when using the configured [`IndentStyle`] and [`IndentWidth`]. /// Computes the level of indentation for `indentation` when using the configured [`IndentStyle`] and [`IndentWidth`](ruff_formatter::IndentWidth).
/// ///
/// Returns `None` if the indentation doesn't conform to the configured [`IndentStyle`] and [`IndentWidth`]. /// Returns `None` if the indentation doesn't conform to the configured [`IndentStyle`] and [`IndentWidth`](ruff_formatter::IndentWidth).
/// ///
/// # Panics /// # Panics
/// If `offset` is outside of `source`. /// If `offset` is outside of `source`.

View File

@ -184,7 +184,7 @@ impl Format<PyFormatContext<'_>> for FormatTargetWithEqualOperator<'_> {
/// No parentheses are added for `short` because it fits into the configured line length, regardless of whether /// No parentheses are added for `short` because it fits into the configured line length, regardless of whether
/// the comment exceeds the line width or not. /// the comment exceeds the line width or not.
/// ///
/// This logic isn't implemented in [`place_comment`] by associating trailing statement comments to the expression because /// This logic isn't implemented in `place_comment` by associating trailing statement comments to the expression because
/// doing so breaks the suite empty lines formatting that relies on trailing comments to be stored on the statement. /// doing so breaks the suite empty lines formatting that relies on trailing comments to be stored on the statement.
#[derive(Debug)] #[derive(Debug)]
pub(super) enum FormatStatementsLastExpression<'a> { pub(super) enum FormatStatementsLastExpression<'a> {
@ -202,7 +202,7 @@ pub(super) enum FormatStatementsLastExpression<'a> {
/// ] = some_long_value /// ] = some_long_value
/// ``` /// ```
/// ///
/// This layout is preferred over [`RightToLeft`] if the left is unsplittable (single keyword like `return` or a Name) /// This layout is preferred over [`Self::RightToLeft`] if the left is unsplittable (single keyword like `return` or a Name)
/// because it has better performance characteristics. /// because it has better performance characteristics.
LeftToRight { LeftToRight {
/// The right side of an assignment or the value returned in a return statement. /// The right side of an assignment or the value returned in a return statement.
@ -1083,7 +1083,7 @@ impl Format<PyFormatContext<'_>> for InterpolatedString<'_> {
/// For legibility, we discuss only the case of f-strings below, but the /// For legibility, we discuss only the case of f-strings below, but the
/// same comments apply to t-strings. /// same comments apply to t-strings.
/// ///
/// This is just a wrapper around [`FormatFString`] while considering a special /// This is just a wrapper around [`FormatFString`](crate::other::f_string::FormatFString) while considering a special
/// case when the f-string is at an assignment statement's value position. /// case when the f-string is at an assignment statement's value position.
/// This is necessary to prevent an instability where an f-string contains a /// This is necessary to prevent an instability where an f-string contains a
/// multiline expression and the f-string fits on the line, but only when it's /// multiline expression and the f-string fits on the line, but only when it's

View File

@ -177,7 +177,7 @@ enum WithItemsLayout<'a> {
/// ... /// ...
/// ``` /// ```
/// ///
/// In this case, use [`maybe_parenthesize_expression`] to format the context expression /// In this case, use [`maybe_parenthesize_expression`](crate::expression::maybe_parenthesize_expression) to format the context expression
/// to get the exact same formatting as when formatting an expression in any other clause header. /// to get the exact same formatting as when formatting an expression in any other clause header.
/// ///
/// Only used for Python 3.9+ /// Only used for Python 3.9+

View File

@ -783,7 +783,7 @@ enum CodeExampleKind<'src> {
/// ///
/// Documentation describing doctests and how they're recognized can be /// Documentation describing doctests and how they're recognized can be
/// found as part of the Python standard library: /// found as part of the Python standard library:
/// https://docs.python.org/3/library/doctest.html. /// <https://docs.python.org/3/library/doctest.html>.
/// ///
/// (You'll likely need to read the [regex matching] used internally by the /// (You'll likely need to read the [regex matching] used internally by the
/// doctest module to determine more precisely how it works.) /// doctest module to determine more precisely how it works.)

View File

@ -39,7 +39,7 @@ impl<'a, 'src> StringNormalizer<'a, 'src> {
/// it leads to more escaping. /// it leads to more escaping.
/// ///
/// Note: If you add more cases here where we return `QuoteStyle::Preserve`, /// Note: If you add more cases here where we return `QuoteStyle::Preserve`,
/// make sure to also add them to [`FormatImplicitConcatenatedStringFlat::new`]. /// make sure to also add them to [`FormatImplicitConcatenatedStringFlat::new`](crate::string::implicit::FormatImplicitConcatenatedStringFlat::new).
pub(super) fn preferred_quote_style(&self, string: StringLikePart) -> QuoteStyle { pub(super) fn preferred_quote_style(&self, string: StringLikePart) -> QuoteStyle {
let preferred_quote_style = self let preferred_quote_style = self
.preferred_quote_style .preferred_quote_style

View File

@ -9,7 +9,7 @@ use crate::prelude::*;
#[derive(Default)] #[derive(Default)]
pub struct FormatTypeParams; pub struct FormatTypeParams;
/// Formats a sequence of [`TypeParam`] nodes. /// Formats a sequence of [`TypeParam`](ruff_python_ast::TypeParam) nodes.
impl FormatNodeRule<TypeParams> for FormatTypeParams { impl FormatNodeRule<TypeParams> for FormatTypeParams {
fn fmt_fields(&self, item: &TypeParams, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &TypeParams, f: &mut PyFormatter) -> FormatResult<()> {
// A dangling comment indicates a comment on the same line as the opening bracket, e.g.: // A dangling comment indicates a comment on the same line as the opening bracket, e.g.:

View File

@ -679,7 +679,7 @@ impl Indentation {
/// Returns `true` for a space or tab character. /// Returns `true` for a space or tab character.
/// ///
/// This is different than [`is_python_whitespace`] in that it returns `false` for a form feed character. /// This is different than [`is_python_whitespace`](ruff_python_trivia::is_python_whitespace) in that it returns `false` for a form feed character.
/// Form feed characters are excluded because they should be preserved in the suppressed output. /// Form feed characters are excluded because they should be preserved in the suppressed output.
const fn is_indent_whitespace(c: char) -> bool { const fn is_indent_whitespace(c: char) -> bool {
matches!(c, ' ' | '\t') matches!(c, ' ' | '\t')