Add global docstring-convention setting#26441
Open
hhubert14 wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
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-conventionoption in Ruff’s options model and JSON schema. - Applied the global convention as the default for pydocstyle when no local
lint.pydocstyle.conventionis 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 anOption. You can simplify and make the intent clearer by usingget_or_insert_defaultandget_or_insertto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9043
Summary
The problem right now is there are multiple places to set the docstring convention (
lint.pydocstyle.conventionand potentially others), making it inconsistent. I added a globaldocstring-conventionunder[tool.ruff]which serves as the default. If a locallint.pydocstyle.conventionis set, it takes precedence over the global one. In the future, the locallint.pydocstyle.conventionsetting could be deprecated in favor of this global one.Example of the new setting in action:
Changes
crates/ruff_workspace/src/options.rs: Addeddocstring_conventionfieldcrates/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
cargo dev generate-allregenerated JSON schema and docscargo clippy --workspace --all-targets --all-features -- -D warningspassesRUFF_UPDATE_SCHEMA=1 cargo testpassesuvx prek run -apassescargo test -p ruff_workspacepasses