mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
Respect #(deprecated)
attribute in configuration options (#8035)
This commit is contained in:
parent
2e225d7538
commit
a85ed309ea
9 changed files with 272 additions and 65 deletions
|
@ -100,6 +100,7 @@ impl OptionSet {
|
|||
/// default: "false",
|
||||
/// value_type: "bool",
|
||||
/// example: "",
|
||||
/// deprecated: None,
|
||||
/// });
|
||||
/// }
|
||||
/// }
|
||||
|
@ -121,6 +122,7 @@ impl OptionSet {
|
|||
/// default: "false",
|
||||
/// value_type: "bool",
|
||||
/// example: "",
|
||||
/// deprecated: None
|
||||
/// });
|
||||
///
|
||||
/// visit.record_set("format", Nested::metadata());
|
||||
|
@ -136,6 +138,7 @@ impl OptionSet {
|
|||
/// default: "false",
|
||||
/// value_type: "bool",
|
||||
/// example: "",
|
||||
/// deprecated: None
|
||||
/// });
|
||||
/// }
|
||||
/// }
|
||||
|
@ -166,6 +169,7 @@ impl OptionSet {
|
|||
/// default: "false",
|
||||
/// value_type: "bool",
|
||||
/// example: "",
|
||||
/// deprecated: None
|
||||
/// };
|
||||
///
|
||||
/// impl OptionsMetadata for WithOptions {
|
||||
|
@ -187,6 +191,7 @@ impl OptionSet {
|
|||
/// default: "false",
|
||||
/// value_type: "bool",
|
||||
/// example: "",
|
||||
/// deprecated: None
|
||||
/// };
|
||||
///
|
||||
/// struct Root;
|
||||
|
@ -198,6 +203,7 @@ impl OptionSet {
|
|||
/// default: "false",
|
||||
/// value_type: "bool",
|
||||
/// example: "",
|
||||
/// deprecated: None
|
||||
/// });
|
||||
///
|
||||
/// visit.record_set("format", Nested::metadata());
|
||||
|
@ -283,8 +289,16 @@ impl Visit for DisplayVisitor<'_, '_> {
|
|||
self.result = self.result.and_then(|_| writeln!(self.f, "{name}"));
|
||||
}
|
||||
|
||||
fn record_field(&mut self, name: &str, _: OptionField) {
|
||||
self.result = self.result.and_then(|_| writeln!(self.f, "{name}"));
|
||||
fn record_field(&mut self, name: &str, field: OptionField) {
|
||||
self.result = self.result.and_then(|_| {
|
||||
write!(self.f, "{name}")?;
|
||||
|
||||
if field.deprecated.is_some() {
|
||||
write!(self.f, " (deprecated)")?;
|
||||
}
|
||||
|
||||
writeln!(self.f)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,6 +322,13 @@ pub struct OptionField {
|
|||
pub default: &'static str,
|
||||
pub value_type: &'static str,
|
||||
pub example: &'static str,
|
||||
pub deprecated: Option<Deprecated>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Deprecated {
|
||||
pub since: Option<&'static str>,
|
||||
pub message: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl Display for OptionField {
|
||||
|
@ -316,6 +337,21 @@ impl Display for OptionField {
|
|||
writeln!(f)?;
|
||||
writeln!(f, "Default value: {}", self.default)?;
|
||||
writeln!(f, "Type: {}", self.value_type)?;
|
||||
|
||||
if let Some(deprecated) = &self.deprecated {
|
||||
write!(f, "Deprecated")?;
|
||||
|
||||
if let Some(since) = deprecated.since {
|
||||
write!(f, " (since {since})")?;
|
||||
}
|
||||
|
||||
if let Some(message) = deprecated.message {
|
||||
write!(f, ": {message}")?;
|
||||
}
|
||||
|
||||
writeln!(f)?;
|
||||
}
|
||||
|
||||
writeln!(f, "Example usage:\n```toml\n{}\n```", self.example)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue