Respect #(deprecated) attribute in configuration options (#8035)

This commit is contained in:
Micha Reiser 2023-10-19 10:07:36 +09:00 committed by GitHub
parent 2e225d7538
commit a85ed309ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 272 additions and 65 deletions

View file

@ -567,6 +567,22 @@ pub struct LintConfiguration {
impl LintConfiguration {
fn from_options(options: LintOptions, project_root: &Path) -> Result<Self> {
#[allow(deprecated)]
let ignore = options
.common
.ignore
.into_iter()
.flatten()
.chain(options.common.extend_ignore.into_iter().flatten())
.collect();
#[allow(deprecated)]
let unfixable = options
.common
.unfixable
.into_iter()
.flatten()
.chain(options.common.extend_unfixable.into_iter().flatten())
.collect();
Ok(LintConfiguration {
exclude: options.exclude.map(|paths| {
paths
@ -581,22 +597,10 @@ impl LintConfiguration {
rule_selections: vec![RuleSelection {
select: options.common.select,
ignore: options
.common
.ignore
.into_iter()
.flatten()
.chain(options.common.extend_ignore.into_iter().flatten())
.collect(),
ignore,
extend_select: options.common.extend_select.unwrap_or_default(),
fixable: options.common.fixable,
unfixable: options
.common
.unfixable
.into_iter()
.flatten()
.chain(options.common.extend_unfixable.into_iter().flatten())
.collect(),
unfixable,
extend_fixable: options.common.extend_fixable.unwrap_or_default(),
}],
extend_safe_fixes: options.common.extend_safe_fixes.unwrap_or_default(),

View file

@ -471,9 +471,6 @@ pub struct LintCommonOptions {
/// A list of rule codes or prefixes to ignore, in addition to those
/// specified by `ignore`.
///
/// This option has been **deprecated** in favor of `ignore`
/// since its usage is now interchangeable with `ignore`.
#[option(
default = "[]",
value_type = "list[RuleSelector]",
@ -482,7 +479,9 @@ pub struct LintCommonOptions {
extend-ignore = ["F841"]
"#
)]
#[cfg_attr(feature = "schemars", schemars(skip))]
#[deprecated(
note = "The `extend-ignore` option is now interchangeable with `ignore`. Please update your configuration to use the `ignore` option instead."
)]
pub extend_ignore: Option<Vec<RuleSelector>>,
/// A list of rule codes or prefixes to enable, in addition to those
@ -511,10 +510,9 @@ pub struct LintCommonOptions {
/// A list of rule codes or prefixes to consider non-auto-fixable, in addition to those
/// specified by `unfixable`.
///
/// This option has been **deprecated** in favor of `unfixable` since its usage is now
/// interchangeable with `unfixable`.
#[cfg_attr(feature = "schemars", schemars(skip))]
#[deprecated(
note = "The `extend-unfixable` option is now interchangeable with `unfixable`. Please update your configuration to use the `unfixable` option instead."
)]
pub extend_unfixable: Option<Vec<RuleSelector>>,
/// A list of rule codes that are unsupported by Ruff, but should be

View file

@ -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)
}
}