Skip to content

Add global docstring-convention setting#26441

Open
hhubert14 wants to merge 4 commits into
astral-sh:mainfrom
hhubert14:fix-issue-9043
Open

Add global docstring-convention setting#26441
hhubert14 wants to merge 4 commits into
astral-sh:mainfrom
hhubert14:fix-issue-9043

Conversation

@hhubert14

Copy link
Copy Markdown

Closes #9043

Summary

The problem right now is there are multiple places to set the docstring convention (lint.pydocstyle.convention and potentially others), making it inconsistent. I added a global docstring-convention under [tool.ruff] which serves as the default. If a local lint.pydocstyle.convention is set, it takes precedence over the global one. In the future, the local lint.pydocstyle.convention setting could be deprecated in favor of this global one.

Example of the new setting in action:

[tool.ruff]
docstring-convention = "google"

Changes

  • crates/ruff_workspace/src/options.rs: Added docstring_convention field
  • crates/ruff_workspace/src/configuration.rs: Configured pydocstyle to default to global convention and added two tests. One checks that the global docstring convention applies if no local convention is set and the other checks that the local docstring convention overrides the global convention if it is set.

Test Plan

  • Two new unit tests added covering global-only and local-overrides-global behavior
  • cargo dev generate-all regenerated JSON schema and docs
  • cargo clippy --workspace --all-targets --all-features -- -D warnings passes
  • RUFF_UPDATE_SCHEMA=1 cargo test passes
  • uvx prek run -a passes
  • cargo test -p ruff_workspace passes

Copilot AI review requested due to automatic review settings June 28, 2026 18:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new top-level Ruff configuration option, docstring-convention, to provide a single global default docstring convention that tools inspecting docstrings can share. The setting is wired such that lint.pydocstyle.convention continues to take precedence when explicitly set, aligning with the goal of unifying convention configuration while preserving existing per-tool overrides.

Changes:

  • Introduced a new global docstring-convention option in Ruff’s options model and JSON schema.
  • Applied the global convention as the default for pydocstyle when no local lint.pydocstyle.convention is provided.
  • Added unit tests to validate global-only behavior and local-overrides-global precedence.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
ruff.schema.json Adds the docstring-convention property (including precedence documentation) to the generated JSON schema.
crates/ruff_workspace/src/options.rs Adds docstring_convention: Option<Convention> as a top-level [tool.ruff] option with metadata for schema/docs generation.
crates/ruff_workspace/src/configuration.rs Wires the global option into settings resolution (defaulting pydocstyle convention) and adds tests for precedence behavior.
Comments suppressed due to low confidence (1)

crates/ruff_workspace/src/configuration.rs:248

  • The global convention fallback works, but pydocstyle.convention = pydocstyle.convention.or(Some(global_convention)) is a bit unidiomatic and eagerly constructs an Option. You can simplify and make the intent clearer by using get_or_insert_default and get_or_insert to only set the convention when it’s currently unset.
                .line_length
                .map_or(format_defaults.line_width, |length| {
                    ruff_formatter::LineWidth::from(NonZeroU16::from(length))
                }),

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make docstring convention a global setting

2 participants