Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--show-settings displays active settings in a far more readable format #9464

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
651c1aa
First-pass implementation of `Display` for `ruff_workspace::Settings`
snowsignal Jan 11, 2024
1341d50
Use `Display::fmt` directly instead of `write!(f, {}, ...)`
snowsignal Jan 11, 2024
415104e
Make `namespace` an optional parameter for `display_settings` and rem…
snowsignal Jan 11, 2024
afe986c
Eliminate unnessecary allocations in the `Display` implementations of…
snowsignal Jan 11, 2024
16dbd8f
Remove unnessecary allocation from `impl Display for KnownModules` an…
snowsignal Jan 11, 2024
e7a6aab
Implement `array` and `optional` formatting options for `display_sett…
snowsignal Jan 11, 2024
eb9c1fb
Add `quoted` formatter to `display_settings` and document the `displa…
snowsignal Jan 11, 2024
0ce38bc
Properly implement `Display` for `PerFileIgnores`
snowsignal Jan 11, 2024
2856361
Merge branch 'main' of github.com:astral-sh/ruff into jane/settings/d…
snowsignal Jan 11, 2024
14221b6
Set up a snapshot test for the default output of `--show-settings`
snowsignal Jan 11, 2024
84a1a2c
Remove extraneous newline from stdout for `--show-settings`
snowsignal Jan 11, 2024
14a8a6e
Cleanup snapshot tests
snowsignal Jan 11, 2024
8c82e87
Add top-level comment to `Settings` display
snowsignal Jan 12, 2024
5793b60
Make `resolve_per_file_ignores` into an associated function
snowsignal Jan 12, 2024
142883c
Space out comment headers for settings display
snowsignal Jan 12, 2024
b3e3c39
Add Linter Plugins heading to settings display
snowsignal Jan 12, 2024
27007a1
Use 'none' instead of 'nil' when displaying None values in settings
snowsignal Jan 12, 2024
ba3e00b
Explain the order of matchers in `PerFileIgnores`
snowsignal Jan 12, 2024
a24a50a
Merge branch 'main' of github.com:astral-sh/ruff into jane/settings/d…
snowsignal Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/commands/show_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn show_settings(
if let Some(settings_path) = pyproject_config.path.as_ref() {
writeln!(writer, "Settings path: {settings_path:?}")?;
}
writeln!(writer, "{settings:#?}")?;
writeln!(writer, "{settings}")?;

Ok(())
}
13 changes: 13 additions & 0 deletions crates/ruff_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod source_code;
use crate::formatter::Formatter;
use crate::group_id::UniqueGroupIdBuilder;
use crate::prelude::TagKind;
use std::fmt;
use std::fmt::{Debug, Display};
use std::marker::PhantomData;
use std::num::{NonZeroU16, NonZeroU8, TryFromIntError};
Expand Down Expand Up @@ -113,6 +114,12 @@ impl Default for IndentWidth {
}
}

impl fmt::Display for IndentWidth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
std::write!(f, "{}", self.0)
snowsignal marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl TryFrom<u8> for IndentWidth {
type Error = TryFromIntError;

Expand Down Expand Up @@ -146,6 +153,12 @@ impl Default for LineWidth {
}
}

impl Display for LineWidth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
std::write!(f, "{}", self.0)
}
}

impl TryFrom<u16> for LineWidth {
type Error = TryFromIntError;

Expand Down
13 changes: 13 additions & 0 deletions crates/ruff_linter/src/line_width.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::error::Error;
use std::fmt;
use std::hash::Hasher;
use std::num::{NonZeroU16, NonZeroU8, ParseIntError};
use std::str::FromStr;
Expand Down Expand Up @@ -39,6 +40,12 @@ impl Default for LineLength {
}
}

impl fmt::Display for LineLength {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

impl CacheKey for LineLength {
fn cache_key(&self, state: &mut CacheKeyHasher) {
state.write_u16(self.0.get());
Expand Down Expand Up @@ -248,6 +255,12 @@ impl Default for IndentWidth {
}
}

impl fmt::Display for IndentWidth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

impl From<NonZeroU8> for IndentWidth {
fn from(tab_size: NonZeroU8) -> Self {
Self(tab_size)
Expand Down
19 changes: 18 additions & 1 deletion crates/ruff_linter/src/registry/rule_set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::registry::Rule;
use itertools::Itertools;
use ruff_macros::CacheKey;
use std::fmt::{Debug, Formatter};
use std::fmt::{Debug, Display, Formatter};
use std::iter::FusedIterator;

const RULESET_SIZE: usize = 13;
Expand Down Expand Up @@ -269,6 +270,22 @@ impl Debug for RuleSet {
}
}

impl Display for RuleSet {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.is_empty() {
write!(f, "[]")
} else {
write!(
f,
"[\n\t{}\n]",
self.iter()
.map(|rule| format!("\"{rule:?}\""))
snowsignal marked this conversation as resolved.
Show resolved Hide resolved
.join(",\n\t")
)
}
}
snowsignal marked this conversation as resolved.
Show resolved Hide resolved
}

impl FromIterator<Rule> for RuleSet {
fn from_iter<T: IntoIterator<Item = Rule>>(iter: T) -> Self {
let mut set = RuleSet::empty();
Expand Down
19 changes: 19 additions & 0 deletions crates/ruff_linter/src/rules/flake8_annotations/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Settings for the `flake-annotations` plugin.

use crate::display_settings;
use ruff_macros::CacheKey;
use std::fmt::{Display, Formatter};

#[derive(Debug, Default, CacheKey)]
#[allow(clippy::struct_excessive_bools)]
Expand All @@ -11,3 +13,20 @@ pub struct Settings {
pub allow_star_arg_any: bool,
pub ignore_fully_untyped: bool,
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_annotations.",
fields = [
self.mypy_init_return,
self.suppress_dummy_args,
self.suppress_none_returning,
self.allow_star_arg_any,
self.ignore_fully_untyped
]
}
Ok(())
}
}
16 changes: 16 additions & 0 deletions crates/ruff_linter/src/rules/flake8_bandit/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Settings for the `flake8-bandit` plugin.

use crate::display_settings;
use ruff_macros::CacheKey;
use std::fmt::{Display, Formatter};

pub fn default_tmp_dirs() -> Vec<String> {
["/tmp", "/var/tmp", "/dev/shm"]
Expand All @@ -22,3 +24,17 @@ impl Default for Settings {
}
}
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_bandit.",
fields = [
self.hardcoded_tmp_directory | debug,
self.check_typed_exception
]
}
Ok(())
}
}
15 changes: 15 additions & 0 deletions crates/ruff_linter/src/rules/flake8_bugbear/settings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
//! Settings for the `flake8-bugbear` plugin.

use crate::display_settings;
use ruff_macros::CacheKey;
use std::fmt::{Display, Formatter};

#[derive(Debug, Default, CacheKey)]
pub struct Settings {
pub extend_immutable_calls: Vec<String>,
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_bugbear.",
fields = [
self.extend_immutable_calls | debug
]
}
Ok(())
}
}
15 changes: 15 additions & 0 deletions crates/ruff_linter/src/rules/flake8_builtins/settings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
//! Settings for the `flake8-builtins` plugin.

use crate::display_settings;
use ruff_macros::CacheKey;
use std::fmt::{Display, Formatter};

#[derive(Debug, Default, CacheKey)]
pub struct Settings {
pub builtins_ignorelist: Vec<String>,
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_builtins.",
fields = [
self.builtins_ignorelist | debug
]
}
Ok(())
}
}
15 changes: 15 additions & 0 deletions crates/ruff_linter/src/rules/flake8_comprehensions/settings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
//! Settings for the `flake8-comprehensions` plugin.

use crate::display_settings;
use ruff_macros::CacheKey;
use std::fmt::{Display, Formatter};

#[derive(Debug, Default, CacheKey)]
pub struct Settings {
pub allow_dict_calls_with_keyword_arguments: bool,
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_comprehensions.",
fields = [
self.allow_dict_calls_with_keyword_arguments
]
}
Ok(())
}
}
18 changes: 18 additions & 0 deletions crates/ruff_linter/src/rules/flake8_copyright/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

use once_cell::sync::Lazy;
use regex::Regex;
use std::fmt::{Display, Formatter};

use crate::display_settings;
use ruff_macros::CacheKey;

#[derive(Debug, CacheKey)]
Expand All @@ -24,3 +26,19 @@ impl Default for Settings {
}
}
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_copyright",
fields = [
self.notice_rgx,
// TODO(jane): remove debug
self.author | debug,
snowsignal marked this conversation as resolved.
Show resolved Hide resolved
self.min_file_size,
]
}
Ok(())
}
}
15 changes: 15 additions & 0 deletions crates/ruff_linter/src/rules/flake8_errmsg/settings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
//! Settings for the `flake8-errmsg` plugin.

use crate::display_settings;
use ruff_macros::CacheKey;
use std::fmt::{Display, Formatter};

#[derive(Debug, Default, CacheKey)]
pub struct Settings {
pub max_string_length: usize,
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_errmsg.",
fields = [
self.max_string_length
]
}
Ok(())
}
}
15 changes: 15 additions & 0 deletions crates/ruff_linter/src/rules/flake8_gettext/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::display_settings;
use ruff_macros::CacheKey;
use std::fmt::{Display, Formatter};

#[derive(Debug, CacheKey)]
pub struct Settings {
Expand All @@ -20,3 +22,16 @@ impl Default for Settings {
}
}
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_gettext.",
fields = [
self.functions_names | debug
]
}
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Settings for the `flake8-implicit-str-concat` plugin.

use crate::display_settings;
use ruff_macros::CacheKey;
use std::fmt::{Display, Formatter};

#[derive(Debug, CacheKey)]
pub struct Settings {
Expand All @@ -14,3 +16,16 @@ impl Default for Settings {
}
}
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_implicit_str_concat.",
fields = [
self.allow_multiline
]
}
Ok(())
}
}
17 changes: 17 additions & 0 deletions crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Settings for import conventions.

use rustc_hash::{FxHashMap, FxHashSet};
use std::fmt::{Display, Formatter};

use crate::display_settings;
use ruff_macros::CacheKey;

const CONVENTIONAL_ALIASES: &[(&str, &str)] = &[
Expand Down Expand Up @@ -44,3 +46,18 @@ impl Default for Settings {
}
}
}

impl Display for Settings {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
display_settings! {
formatter = f,
namespace = "linter.flake8_import_conventions",
snowsignal marked this conversation as resolved.
Show resolved Hide resolved
fields = [
self.aliases | debug,
self.banned_aliases | debug,
self.banned_from | debug,
]
}
Ok(())
}
}
Loading
Loading