From 8b8fd411e2c12d8be1e47eed77b937f108b8fc45 Mon Sep 17 00:00:00 2001 From: Zanie Date: Wed, 30 Aug 2023 22:00:00 -0500 Subject: [PATCH] Rename a bunch of "nursery" references to "preview" --- crates/ruff/src/codes.rs | 90 ++++++++++----------- crates/ruff/src/rule_selector.rs | 6 +- crates/ruff_cli/src/commands/rule.rs | 11 ++- crates/ruff_dev/src/generate_docs.rs | 7 +- crates/ruff_dev/src/generate_rules_table.rs | 12 +-- crates/ruff_macros/src/map_codes.rs | 12 +-- crates/ruff_macros/src/rule_code_prefix.rs | 8 +- docs/faq.md | 21 +++-- 8 files changed, 85 insertions(+), 82 deletions(-) diff --git a/crates/ruff/src/codes.rs b/crates/ruff/src/codes.rs index 67eb3887db..5828bee708 100644 --- a/crates/ruff/src/codes.rs +++ b/crates/ruff/src/codes.rs @@ -51,8 +51,8 @@ impl PartialEq<&str> for NoqaCode { pub enum RuleGroup { /// The rule has not been assigned to any specific group. Unspecified, - /// The rule is still under development, and must be enabled explicitly. - Nursery, + /// The rule is unstable, and must be enabled explicitly or by enabling preview. + Preview, } #[ruff_macros::map_codes] @@ -64,39 +64,39 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { Some(match (linter, code) { // pycodestyle errors (Pycodestyle, "E101") => (RuleGroup::Unspecified, rules::pycodestyle::rules::MixedSpacesAndTabs), - (Pycodestyle, "E111") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::IndentationWithInvalidMultiple), - (Pycodestyle, "E112") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoIndentedBlock), - (Pycodestyle, "E113") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::UnexpectedIndentation), - (Pycodestyle, "E114") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::IndentationWithInvalidMultipleComment), - (Pycodestyle, "E115") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoIndentedBlockComment), - (Pycodestyle, "E116") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::UnexpectedIndentationComment), - (Pycodestyle, "E117") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::OverIndented), - (Pycodestyle, "E201") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceAfterOpenBracket), - (Pycodestyle, "E202") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeCloseBracket), - (Pycodestyle, "E203") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceBeforePunctuation), - (Pycodestyle, "E211") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeParameters), - (Pycodestyle, "E221") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesBeforeOperator), - (Pycodestyle, "E222") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterOperator), - (Pycodestyle, "E223") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabBeforeOperator), - (Pycodestyle, "E224") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabAfterOperator), - (Pycodestyle, "E225") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundOperator), - (Pycodestyle, "E226") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundArithmeticOperator), - (Pycodestyle, "E227") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundBitwiseOrShiftOperator), - (Pycodestyle, "E228") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundModuloOperator), - (Pycodestyle, "E231") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespace), - (Pycodestyle, "E241") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterComma), - (Pycodestyle, "E242") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabAfterComma), - (Pycodestyle, "E251") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::UnexpectedSpacesAroundKeywordParameterEquals), - (Pycodestyle, "E252") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundParameterEquals), - (Pycodestyle, "E261") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TooFewSpacesBeforeInlineComment), - (Pycodestyle, "E262") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoSpaceAfterInlineComment), - (Pycodestyle, "E265") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoSpaceAfterBlockComment), - (Pycodestyle, "E266") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleLeadingHashesForBlockComment), - (Pycodestyle, "E271") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterKeyword), - (Pycodestyle, "E272") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesBeforeKeyword), - (Pycodestyle, "E273") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabAfterKeyword), - (Pycodestyle, "E274") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabBeforeKeyword), - (Pycodestyle, "E275") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAfterKeyword), + (Pycodestyle, "E111") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::IndentationWithInvalidMultiple), + (Pycodestyle, "E112") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::NoIndentedBlock), + (Pycodestyle, "E113") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::UnexpectedIndentation), + (Pycodestyle, "E114") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::IndentationWithInvalidMultipleComment), + (Pycodestyle, "E115") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::NoIndentedBlockComment), + (Pycodestyle, "E116") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::UnexpectedIndentationComment), + (Pycodestyle, "E117") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::OverIndented), + (Pycodestyle, "E201") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::WhitespaceAfterOpenBracket), + (Pycodestyle, "E202") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeCloseBracket), + (Pycodestyle, "E203") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::WhitespaceBeforePunctuation), + (Pycodestyle, "E211") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeParameters), + (Pycodestyle, "E221") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesBeforeOperator), + (Pycodestyle, "E222") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterOperator), + (Pycodestyle, "E223") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabBeforeOperator), + (Pycodestyle, "E224") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabAfterOperator), + (Pycodestyle, "E225") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundOperator), + (Pycodestyle, "E226") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundArithmeticOperator), + (Pycodestyle, "E227") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundBitwiseOrShiftOperator), + (Pycodestyle, "E228") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundModuloOperator), + (Pycodestyle, "E231") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespace), + (Pycodestyle, "E241") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterComma), + (Pycodestyle, "E242") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabAfterComma), + (Pycodestyle, "E251") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::UnexpectedSpacesAroundKeywordParameterEquals), + (Pycodestyle, "E252") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundParameterEquals), + (Pycodestyle, "E261") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TooFewSpacesBeforeInlineComment), + (Pycodestyle, "E262") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::NoSpaceAfterInlineComment), + (Pycodestyle, "E265") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::NoSpaceAfterBlockComment), + (Pycodestyle, "E266") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleLeadingHashesForBlockComment), + (Pycodestyle, "E271") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterKeyword), + (Pycodestyle, "E272") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesBeforeKeyword), + (Pycodestyle, "E273") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabAfterKeyword), + (Pycodestyle, "E274") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabBeforeKeyword), + (Pycodestyle, "E275") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAfterKeyword), (Pycodestyle, "E401") => (RuleGroup::Unspecified, rules::pycodestyle::rules::MultipleImportsOnOneLine), (Pycodestyle, "E402") => (RuleGroup::Unspecified, rules::pycodestyle::rules::ModuleImportNotAtTopOfFile), (Pycodestyle, "E501") => (RuleGroup::Unspecified, rules::pycodestyle::rules::LineTooLong), @@ -176,7 +176,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "C0205") => (RuleGroup::Unspecified, rules::pylint::rules::SingleStringSlots), (Pylint, "C0208") => (RuleGroup::Unspecified, rules::pylint::rules::IterationOverSet), (Pylint, "C0414") => (RuleGroup::Unspecified, rules::pylint::rules::UselessImportAlias), - (Pylint, "C1901") => (RuleGroup::Nursery, rules::pylint::rules::CompareToEmptyString), + (Pylint, "C1901") => (RuleGroup::Preview, rules::pylint::rules::CompareToEmptyString), (Pylint, "C3002") => (RuleGroup::Unspecified, rules::pylint::rules::UnnecessaryDirectLambdaCall), (Pylint, "E0100") => (RuleGroup::Unspecified, rules::pylint::rules::YieldInInit), (Pylint, "E0101") => (RuleGroup::Unspecified, rules::pylint::rules::ReturnInInit), @@ -216,7 +216,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "R1722") => (RuleGroup::Unspecified, rules::pylint::rules::SysExitAlias), (Pylint, "R2004") => (RuleGroup::Unspecified, rules::pylint::rules::MagicValueComparison), (Pylint, "R5501") => (RuleGroup::Unspecified, rules::pylint::rules::CollapsibleElseIf), - (Pylint, "R6301") => (RuleGroup::Nursery, rules::pylint::rules::NoSelfUse), + (Pylint, "R6301") => (RuleGroup::Preview, rules::pylint::rules::NoSelfUse), (Pylint, "W0120") => (RuleGroup::Unspecified, rules::pylint::rules::UselessElseOnLoop), (Pylint, "W0127") => (RuleGroup::Unspecified, rules::pylint::rules::SelfAssigningVariable), (Pylint, "W0129") => (RuleGroup::Unspecified, rules::pylint::rules::AssertOnStringLiteral), @@ -228,9 +228,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "W1508") => (RuleGroup::Unspecified, rules::pylint::rules::InvalidEnvvarDefault), (Pylint, "W1509") => (RuleGroup::Unspecified, rules::pylint::rules::SubprocessPopenPreexecFn), (Pylint, "W1510") => (RuleGroup::Unspecified, rules::pylint::rules::SubprocessRunWithoutCheck), - (Pylint, "W1641") => (RuleGroup::Nursery, rules::pylint::rules::EqWithoutHash), + (Pylint, "W1641") => (RuleGroup::Preview, rules::pylint::rules::EqWithoutHash), (Pylint, "W2901") => (RuleGroup::Unspecified, rules::pylint::rules::RedefinedLoopName), - (Pylint, "W3201") => (RuleGroup::Nursery, rules::pylint::rules::BadDunderMethodName), + (Pylint, "W3201") => (RuleGroup::Preview, rules::pylint::rules::BadDunderMethodName), (Pylint, "W3301") => (RuleGroup::Unspecified, rules::pylint::rules::NestedMinMax), // flake8-async @@ -403,7 +403,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8Simplify, "910") => (RuleGroup::Unspecified, rules::flake8_simplify::rules::DictGetWithNoneDefault), // flake8-copyright - (Flake8Copyright, "001") => (RuleGroup::Nursery, rules::flake8_copyright::rules::MissingCopyrightNotice), + (Flake8Copyright, "001") => (RuleGroup::Preview, rules::flake8_copyright::rules::MissingCopyrightNotice), // pyupgrade (Pyupgrade, "001") => (RuleGroup::Unspecified, rules::pyupgrade::rules::UselessMetaclassType), @@ -815,10 +815,10 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Ruff, "012") => (RuleGroup::Unspecified, rules::ruff::rules::MutableClassDefault), (Ruff, "013") => (RuleGroup::Unspecified, rules::ruff::rules::ImplicitOptional), #[cfg(feature = "unreachable-code")] // When removing this feature gate, also update rules_selector.rs - (Ruff, "014") => (RuleGroup::Nursery, rules::ruff::rules::UnreachableCode), + (Ruff, "014") => (RuleGroup::Preview, rules::ruff::rules::UnreachableCode), (Ruff, "015") => (RuleGroup::Unspecified, rules::ruff::rules::UnnecessaryIterableAllocationForFirstElement), (Ruff, "016") => (RuleGroup::Unspecified, rules::ruff::rules::InvalidIndexType), - (Ruff, "017") => (RuleGroup::Nursery, rules::ruff::rules::QuadraticListSummation), + (Ruff, "017") => (RuleGroup::Preview, rules::ruff::rules::QuadraticListSummation), (Ruff, "100") => (RuleGroup::Unspecified, rules::ruff::rules::UnusedNOQA), (Ruff, "200") => (RuleGroup::Unspecified, rules::ruff::rules::InvalidPyprojectToml), @@ -866,9 +866,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8Slots, "002") => (RuleGroup::Unspecified, rules::flake8_slots::rules::NoSlotsInNamedtupleSubclass), // refurb - (Refurb, "113") => (RuleGroup::Nursery, rules::refurb::rules::RepeatedAppend), - (Refurb, "131") => (RuleGroup::Nursery, rules::refurb::rules::DeleteFullSlice), - (Refurb, "132") => (RuleGroup::Nursery, rules::refurb::rules::CheckAndRemoveFromSet), + (Refurb, "113") => (RuleGroup::Preview, rules::refurb::rules::RepeatedAppend), + (Refurb, "131") => (RuleGroup::Preview, rules::refurb::rules::DeleteFullSlice), + (Refurb, "132") => (RuleGroup::Preview, rules::refurb::rules::CheckAndRemoveFromSet), _ => return None, }) diff --git a/crates/ruff/src/rule_selector.rs b/crates/ruff/src/rule_selector.rs index a20213b10d..367bc334d8 100644 --- a/crates/ruff/src/rule_selector.rs +++ b/crates/ruff/src/rule_selector.rs @@ -14,7 +14,7 @@ use crate::rule_redirects::get_redirect; pub enum RuleSelector { /// Select all stable rules. All, - /// Select all nursery rules. + /// Legacy category to select all preview rules, previously known as the nursery Nursery, /// Legacy category to select both the `mccabe` and `flake8-comprehensions` linters /// via a single selector. @@ -151,10 +151,10 @@ impl IntoIterator for &RuleSelector { fn into_iter(self) -> Self::IntoIter { match self { RuleSelector::All => { - RuleSelectorIter::All(Rule::iter().filter(|rule| !rule.is_nursery())) + RuleSelectorIter::All(Rule::iter().filter(|rule| !rule.is_preview())) } RuleSelector::Nursery => { - RuleSelectorIter::Nursery(Rule::iter().filter(Rule::is_nursery)) + RuleSelectorIter::Nursery(Rule::iter().filter(Rule::is_preview)) } RuleSelector::C => RuleSelectorIter::Chain( Linter::Flake8Comprehensions diff --git a/crates/ruff_cli/src/commands/rule.rs b/crates/ruff_cli/src/commands/rule.rs index a16ec4622b..bcc20003fd 100644 --- a/crates/ruff_cli/src/commands/rule.rs +++ b/crates/ruff_cli/src/commands/rule.rs @@ -19,7 +19,7 @@ struct Explanation<'a> { message_formats: &'a [&'a str], autofix: String, explanation: Option<&'a str>, - nursery: bool, + preview: bool, } impl<'a> Explanation<'a> { @@ -35,7 +35,7 @@ impl<'a> Explanation<'a> { message_formats: rule.message_formats(), autofix, explanation: rule.explanation(), - nursery: rule.is_nursery(), + preview: rule.is_preview(), } } } @@ -58,11 +58,10 @@ fn format_rule_text(rule: Rule) -> String { output.push('\n'); } - if rule.is_nursery() { + if rule.is_preview() { output.push_str(&format!( - r#"This rule is part of the **nursery**, a collection of newer lints that are -still under development. As such, it must be enabled by explicitly selecting -{}."#, + r#"This rule is in preview and is not stable. It may be enabled by explicitly selecting {}" +" or providing the `--preview` flag."#, rule.noqa_code() )); output.push('\n'); diff --git a/crates/ruff_dev/src/generate_docs.rs b/crates/ruff_dev/src/generate_docs.rs index 108a02c264..3652fb2b2c 100644 --- a/crates/ruff_dev/src/generate_docs.rs +++ b/crates/ruff_dev/src/generate_docs.rs @@ -43,11 +43,10 @@ pub(crate) fn main(args: &Args) -> Result<()> { output.push('\n'); } - if rule.is_nursery() { + if rule.is_preview() { output.push_str(&format!( - r#"This rule is part of the **nursery**, a collection of newer lints that are -still under development. As such, it must be enabled by explicitly selecting -{}."#, + r#"This rule is in preview and is not stable. It may be enabled by explicitly selecting {}" +" or providing the `--preview` flag."#, rule.noqa_code() )); output.push('\n'); diff --git a/crates/ruff_dev/src/generate_rules_table.rs b/crates/ruff_dev/src/generate_rules_table.rs index 44389ec89b..20c1cf9dd3 100644 --- a/crates/ruff_dev/src/generate_rules_table.rs +++ b/crates/ruff_dev/src/generate_rules_table.rs @@ -11,7 +11,7 @@ use ruff_diagnostics::AutofixKind; use ruff_workspace::options::Options; const FIX_SYMBOL: &str = "🛠"; -const NURSERY_SYMBOL: &str = "🌅"; +const PREVIEW_SYMBOL: &str = "🌅"; fn generate_table(table_out: &mut String, rules: impl IntoIterator, linter: &Linter) { table_out.push_str("| Code | Name | Message | |"); @@ -25,12 +25,12 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator, } AutofixKind::None => format!("{FIX_SYMBOL}"), }; - let nursery_token = if rule.is_nursery() { - format!("{NURSERY_SYMBOL}") + let preview_token = if rule.is_preview() { + format!("{PREVIEW_SYMBOL}") } else { - format!("{NURSERY_SYMBOL}") + format!("{PREVIEW_SYMBOL}") }; - let status_token = format!("{fix_token} {nursery_token}"); + let status_token = format!("{fix_token} {preview_token}"); let rule_name = rule.as_ref(); @@ -61,7 +61,7 @@ pub(crate) fn generate() -> String { table_out.push('\n'); table_out.push_str(&format!( - "The {NURSERY_SYMBOL} emoji indicates that a rule is part of the [\"nursery\"](../faq/#what-is-the-nursery)." + "The {PREVIEW_SYMBOL} emoji indicates that a rule is part of the [\"nursery\"](../faq/#what-is-the-nursery)." )); table_out.push('\n'); table_out.push('\n'); diff --git a/crates/ruff_macros/src/map_codes.rs b/crates/ruff_macros/src/map_codes.rs index eeee0d7ac9..bb100c28ee 100644 --- a/crates/ruff_macros/src/map_codes.rs +++ b/crates/ruff_macros/src/map_codes.rs @@ -8,7 +8,7 @@ use syn::{ Ident, ItemFn, LitStr, Pat, Path, Stmt, Token, }; -use crate::rule_code_prefix::{get_prefix_ident, if_all_same, is_nursery}; +use crate::rule_code_prefix::{get_prefix_ident, if_all_same, is_preview}; /// A rule entry in the big match statement such a /// `(Pycodestyle, "E112") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoIndentedBlock),` @@ -199,7 +199,7 @@ fn rules_by_prefix( // Nursery rules have to be explicitly selected, so we ignore them when looking at // prefix-level selectors (e.g., `--select SIM10`), but add the rule itself under // its fully-qualified code (e.g., `--select SIM101`). - if is_nursery(&rule.group) { + if is_preview(&rule.group) { rules_by_prefix.insert(code.clone(), vec![(rule.path.clone(), rule.attrs.clone())]); continue; } @@ -211,7 +211,7 @@ fn rules_by_prefix( .filter_map(|(code, rule)| { // Nursery rules have to be explicitly selected, so we ignore them when // looking at prefixes. - if is_nursery(&rule.group) { + if is_preview(&rule.group) { return None; } @@ -311,8 +311,8 @@ See also https://github.com/astral-sh/ruff/issues/2186. } } - pub fn is_nursery(&self) -> bool { - matches!(self.group(), RuleGroup::Nursery) + pub fn is_preview(&self) -> bool { + matches!(self.group(), RuleGroup::Preview) } } @@ -336,7 +336,7 @@ fn generate_iter_impl( let mut linter_rules_match_arms = quote!(); let mut linter_all_rules_match_arms = quote!(); for (linter, map) in linter_to_rules { - let rule_paths = map.values().filter(|rule| !is_nursery(&rule.group)).map( + let rule_paths = map.values().filter(|rule| !is_preview(&rule.group)).map( |Rule { attrs, path, .. }| { let rule_name = path.segments.last().unwrap(); quote!(#(#attrs)* Rule::#rule_name) diff --git a/crates/ruff_macros/src/rule_code_prefix.rs b/crates/ruff_macros/src/rule_code_prefix.rs index 29379b2cb3..57ccd24f5a 100644 --- a/crates/ruff_macros/src/rule_code_prefix.rs +++ b/crates/ruff_macros/src/rule_code_prefix.rs @@ -15,7 +15,7 @@ pub(crate) fn expand<'a>( for (variant, group, attr) in variants { let code_str = variant.to_string(); // Nursery rules have to be explicitly selected, so we ignore them when looking at prefixes. - if is_nursery(group) { + if is_preview(group) { prefix_to_codes .entry(code_str.clone()) .or_default() @@ -126,13 +126,13 @@ pub(crate) fn get_prefix_ident(prefix: &str) -> Ident { Ident::new(&prefix, Span::call_site()) } -/// Returns true if the given group is the "nursery" group. -pub(crate) fn is_nursery(group: &Path) -> bool { +/// Returns true if the given group is the "preview" group. +pub(crate) fn is_preview(group: &Path) -> bool { let group = group .segments .iter() .map(|segment| segment.ident.to_string()) .collect::>() .join("::"); - group == "RuleGroup::Nursery" + group == "RuleGroup::Preview" } diff --git a/docs/faq.md b/docs/faq.md index 5394e6e184..e6ba725186 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -382,13 +382,13 @@ matter how they're provided, which avoids accidental incompatibilities and simpl By default, no `convention` is set, and so the enabled rules are determined by the `select` setting alone. -## What is the "nursery"? +## What is preview mode? -The "nursery" is a collection of newer rules that are considered experimental or unstable. +Preview mode enables a collection of newer rules and fixes that are considered experimental or unstable. -If a rule is marked as part of the "nursery", it can only be enabled via direct selection. For -example, consider a hypothetical rule, `HYP001`. If `HYP001` were included in the "nursery", it -could be enabled by adding the following to your `pyproject.toml`: +If a rule is marked as preview, it can only be enabled via direct selection or the `--preview` flag. For +example, consider a hypothetical rule, `HYP001`. If `HYP001` were in preview, it could be enabled by adding the +following to your `pyproject.toml`: ```toml [tool.ruff] @@ -409,10 +409,15 @@ Similarly, it would _not_ be enabled via the `ALL` selector: select = ["ALL"] ``` -(The "nursery" terminology comes from [Clippy](https://doc.rust-lang.org/nightly/clippy/), a similar -tool for linting Rust code.) +Unless you also enabled `preview`: -To see which rules are currently in the "nursery", visit the [rules reference](https://beta.ruff.rs/docs/rules/). +```toml +[tool.ruff] +select = ["ALL"] +preview = true +``` + +To see which rules are currently in preview, visit the [rules reference](https://beta.ruff.rs/docs/rules/). ## How can I tell what settings Ruff is using to check my code?