mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-16 01:25:22 +00:00
--show-settings
displays active settings in a far more readable format (#9464)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Fixes #8334. `Display` has been implemented for `ruff_workspace::Settings`, which gives a much nicer and more readable output to `--show-settings`. Internally, a `display_settings` utility macro has been implemented to reduce the boilerplate of the display code. ### Work to be done - [x] A lot of formatting for `Vec<_>` and `HashSet<_>` types have been stubbed out, using `Debug` as a fallback. There should be a way to add generic formatting support for these types as a modifier in `display_settings`. - [x] Several complex types were also stubbed out and need proper `Display` implementations rather than falling back on `Debug`. - [x] An open question needs to be answered: how important is it that the output be valid TOML? Some types in settings, such as a hash-map from a glob pattern to a multi-variant enum, will be hard to rework into valid _and_ readable TOML. - [x] Tests need to be implemented. ## Test Plan Tests consist of a snapshot test for the default `--show-settings` output and a doctest for `display_settings!`.
This commit is contained in:
parent
fee64b52ba
commit
7504bf347b
39 changed files with 1455 additions and 43 deletions
|
@ -2,6 +2,7 @@ use ruff_formatter::printer::{LineEnding, PrinterOptions, SourceMapGeneration};
|
|||
use ruff_formatter::{FormatOptions, IndentStyle, IndentWidth, LineWidth};
|
||||
use ruff_macros::CacheKey;
|
||||
use ruff_python_ast::PySourceType;
|
||||
use std::fmt;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
@ -241,6 +242,16 @@ pub enum QuoteStyle {
|
|||
Preserve,
|
||||
}
|
||||
|
||||
impl fmt::Display for QuoteStyle {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Single => write!(f, "single"),
|
||||
Self::Double => write!(f, "double"),
|
||||
Self::Preserve => write!(f, "preserve"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for QuoteStyle {
|
||||
type Err = &'static str;
|
||||
|
||||
|
@ -277,6 +288,15 @@ impl MagicTrailingComma {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MagicTrailingComma {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Respect => write!(f, "respect"),
|
||||
Self::Ignore => write!(f, "ignore"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for MagicTrailingComma {
|
||||
type Err = &'static str;
|
||||
|
||||
|
@ -306,6 +326,15 @@ impl PreviewMode {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PreviewMode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Disabled => write!(f, "disabled"),
|
||||
Self::Enabled => write!(f, "enabled"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default, CacheKey)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
|
||||
|
@ -323,6 +352,15 @@ impl DocstringCode {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DocstringCode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Disabled => write!(f, "disabled"),
|
||||
Self::Enabled => write!(f, "enabled"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Eq, PartialEq, CacheKey)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
|
||||
|
@ -338,8 +376,8 @@ pub enum DocstringCodeLineWidth {
|
|||
Dynamic,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for DocstringCodeLineWidth {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl fmt::Debug for DocstringCodeLineWidth {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
DocstringCodeLineWidth::Fixed(v) => v.value().fmt(f),
|
||||
DocstringCodeLineWidth::Dynamic => "dynamic".fmt(f),
|
||||
|
@ -347,6 +385,15 @@ impl std::fmt::Debug for DocstringCodeLineWidth {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DocstringCodeLineWidth {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Fixed(width) => width.fmt(f),
|
||||
Self::Dynamic => write!(f, "dynamic"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Responsible for deserializing the `DocstringCodeLineWidth::Dynamic`
|
||||
/// variant.
|
||||
fn deserialize_docstring_code_line_width_dynamic<'de, D>(d: D) -> Result<(), D::Error>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue