Rename a bunch of "nursery" references to "preview"

This commit is contained in:
Zanie 2023-08-30 22:00:00 -05:00
parent 96a9717c1a
commit 8b8fd411e2
8 changed files with 85 additions and 82 deletions

View File

@ -51,8 +51,8 @@ impl PartialEq<&str> for NoqaCode {
pub enum RuleGroup { pub enum RuleGroup {
/// The rule has not been assigned to any specific group. /// The rule has not been assigned to any specific group.
Unspecified, Unspecified,
/// The rule is still under development, and must be enabled explicitly. /// The rule is unstable, and must be enabled explicitly or by enabling preview.
Nursery, Preview,
} }
#[ruff_macros::map_codes] #[ruff_macros::map_codes]
@ -64,39 +64,39 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
Some(match (linter, code) { Some(match (linter, code) {
// pycodestyle errors // pycodestyle errors
(Pycodestyle, "E101") => (RuleGroup::Unspecified, rules::pycodestyle::rules::MixedSpacesAndTabs), (Pycodestyle, "E101") => (RuleGroup::Unspecified, rules::pycodestyle::rules::MixedSpacesAndTabs),
(Pycodestyle, "E111") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::IndentationWithInvalidMultiple), (Pycodestyle, "E111") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::IndentationWithInvalidMultiple),
(Pycodestyle, "E112") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoIndentedBlock), (Pycodestyle, "E112") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::NoIndentedBlock),
(Pycodestyle, "E113") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::UnexpectedIndentation), (Pycodestyle, "E113") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::UnexpectedIndentation),
(Pycodestyle, "E114") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::IndentationWithInvalidMultipleComment), (Pycodestyle, "E114") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::IndentationWithInvalidMultipleComment),
(Pycodestyle, "E115") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoIndentedBlockComment), (Pycodestyle, "E115") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::NoIndentedBlockComment),
(Pycodestyle, "E116") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::UnexpectedIndentationComment), (Pycodestyle, "E116") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::UnexpectedIndentationComment),
(Pycodestyle, "E117") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::OverIndented), (Pycodestyle, "E117") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::OverIndented),
(Pycodestyle, "E201") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceAfterOpenBracket), (Pycodestyle, "E201") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::WhitespaceAfterOpenBracket),
(Pycodestyle, "E202") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeCloseBracket), (Pycodestyle, "E202") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeCloseBracket),
(Pycodestyle, "E203") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceBeforePunctuation), (Pycodestyle, "E203") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::WhitespaceBeforePunctuation),
(Pycodestyle, "E211") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeParameters), (Pycodestyle, "E211") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeParameters),
(Pycodestyle, "E221") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesBeforeOperator), (Pycodestyle, "E221") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesBeforeOperator),
(Pycodestyle, "E222") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterOperator), (Pycodestyle, "E222") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterOperator),
(Pycodestyle, "E223") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabBeforeOperator), (Pycodestyle, "E223") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabBeforeOperator),
(Pycodestyle, "E224") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabAfterOperator), (Pycodestyle, "E224") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabAfterOperator),
(Pycodestyle, "E225") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundOperator), (Pycodestyle, "E225") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundOperator),
(Pycodestyle, "E226") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundArithmeticOperator), (Pycodestyle, "E226") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundArithmeticOperator),
(Pycodestyle, "E227") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundBitwiseOrShiftOperator), (Pycodestyle, "E227") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundBitwiseOrShiftOperator),
(Pycodestyle, "E228") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundModuloOperator), (Pycodestyle, "E228") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundModuloOperator),
(Pycodestyle, "E231") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespace), (Pycodestyle, "E231") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespace),
(Pycodestyle, "E241") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterComma), (Pycodestyle, "E241") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterComma),
(Pycodestyle, "E242") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabAfterComma), (Pycodestyle, "E242") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabAfterComma),
(Pycodestyle, "E251") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::UnexpectedSpacesAroundKeywordParameterEquals), (Pycodestyle, "E251") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::UnexpectedSpacesAroundKeywordParameterEquals),
(Pycodestyle, "E252") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundParameterEquals), (Pycodestyle, "E252") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAroundParameterEquals),
(Pycodestyle, "E261") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TooFewSpacesBeforeInlineComment), (Pycodestyle, "E261") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TooFewSpacesBeforeInlineComment),
(Pycodestyle, "E262") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoSpaceAfterInlineComment), (Pycodestyle, "E262") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::NoSpaceAfterInlineComment),
(Pycodestyle, "E265") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoSpaceAfterBlockComment), (Pycodestyle, "E265") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::NoSpaceAfterBlockComment),
(Pycodestyle, "E266") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleLeadingHashesForBlockComment), (Pycodestyle, "E266") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleLeadingHashesForBlockComment),
(Pycodestyle, "E271") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterKeyword), (Pycodestyle, "E271") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesAfterKeyword),
(Pycodestyle, "E272") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MultipleSpacesBeforeKeyword), (Pycodestyle, "E272") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MultipleSpacesBeforeKeyword),
(Pycodestyle, "E273") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabAfterKeyword), (Pycodestyle, "E273") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabAfterKeyword),
(Pycodestyle, "E274") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::TabBeforeKeyword), (Pycodestyle, "E274") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::TabBeforeKeyword),
(Pycodestyle, "E275") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAfterKeyword), (Pycodestyle, "E275") => (RuleGroup::Preview, rules::pycodestyle::rules::logical_lines::MissingWhitespaceAfterKeyword),
(Pycodestyle, "E401") => (RuleGroup::Unspecified, rules::pycodestyle::rules::MultipleImportsOnOneLine), (Pycodestyle, "E401") => (RuleGroup::Unspecified, rules::pycodestyle::rules::MultipleImportsOnOneLine),
(Pycodestyle, "E402") => (RuleGroup::Unspecified, rules::pycodestyle::rules::ModuleImportNotAtTopOfFile), (Pycodestyle, "E402") => (RuleGroup::Unspecified, rules::pycodestyle::rules::ModuleImportNotAtTopOfFile),
(Pycodestyle, "E501") => (RuleGroup::Unspecified, rules::pycodestyle::rules::LineTooLong), (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, "C0205") => (RuleGroup::Unspecified, rules::pylint::rules::SingleStringSlots),
(Pylint, "C0208") => (RuleGroup::Unspecified, rules::pylint::rules::IterationOverSet), (Pylint, "C0208") => (RuleGroup::Unspecified, rules::pylint::rules::IterationOverSet),
(Pylint, "C0414") => (RuleGroup::Unspecified, rules::pylint::rules::UselessImportAlias), (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, "C3002") => (RuleGroup::Unspecified, rules::pylint::rules::UnnecessaryDirectLambdaCall),
(Pylint, "E0100") => (RuleGroup::Unspecified, rules::pylint::rules::YieldInInit), (Pylint, "E0100") => (RuleGroup::Unspecified, rules::pylint::rules::YieldInInit),
(Pylint, "E0101") => (RuleGroup::Unspecified, rules::pylint::rules::ReturnInInit), (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, "R1722") => (RuleGroup::Unspecified, rules::pylint::rules::SysExitAlias),
(Pylint, "R2004") => (RuleGroup::Unspecified, rules::pylint::rules::MagicValueComparison), (Pylint, "R2004") => (RuleGroup::Unspecified, rules::pylint::rules::MagicValueComparison),
(Pylint, "R5501") => (RuleGroup::Unspecified, rules::pylint::rules::CollapsibleElseIf), (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, "W0120") => (RuleGroup::Unspecified, rules::pylint::rules::UselessElseOnLoop),
(Pylint, "W0127") => (RuleGroup::Unspecified, rules::pylint::rules::SelfAssigningVariable), (Pylint, "W0127") => (RuleGroup::Unspecified, rules::pylint::rules::SelfAssigningVariable),
(Pylint, "W0129") => (RuleGroup::Unspecified, rules::pylint::rules::AssertOnStringLiteral), (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, "W1508") => (RuleGroup::Unspecified, rules::pylint::rules::InvalidEnvvarDefault),
(Pylint, "W1509") => (RuleGroup::Unspecified, rules::pylint::rules::SubprocessPopenPreexecFn), (Pylint, "W1509") => (RuleGroup::Unspecified, rules::pylint::rules::SubprocessPopenPreexecFn),
(Pylint, "W1510") => (RuleGroup::Unspecified, rules::pylint::rules::SubprocessRunWithoutCheck), (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, "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), (Pylint, "W3301") => (RuleGroup::Unspecified, rules::pylint::rules::NestedMinMax),
// flake8-async // 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), (Flake8Simplify, "910") => (RuleGroup::Unspecified, rules::flake8_simplify::rules::DictGetWithNoneDefault),
// flake8-copyright // flake8-copyright
(Flake8Copyright, "001") => (RuleGroup::Nursery, rules::flake8_copyright::rules::MissingCopyrightNotice), (Flake8Copyright, "001") => (RuleGroup::Preview, rules::flake8_copyright::rules::MissingCopyrightNotice),
// pyupgrade // pyupgrade
(Pyupgrade, "001") => (RuleGroup::Unspecified, rules::pyupgrade::rules::UselessMetaclassType), (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, "012") => (RuleGroup::Unspecified, rules::ruff::rules::MutableClassDefault),
(Ruff, "013") => (RuleGroup::Unspecified, rules::ruff::rules::ImplicitOptional), (Ruff, "013") => (RuleGroup::Unspecified, rules::ruff::rules::ImplicitOptional),
#[cfg(feature = "unreachable-code")] // When removing this feature gate, also update rules_selector.rs #[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, "015") => (RuleGroup::Unspecified, rules::ruff::rules::UnnecessaryIterableAllocationForFirstElement),
(Ruff, "016") => (RuleGroup::Unspecified, rules::ruff::rules::InvalidIndexType), (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, "100") => (RuleGroup::Unspecified, rules::ruff::rules::UnusedNOQA),
(Ruff, "200") => (RuleGroup::Unspecified, rules::ruff::rules::InvalidPyprojectToml), (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), (Flake8Slots, "002") => (RuleGroup::Unspecified, rules::flake8_slots::rules::NoSlotsInNamedtupleSubclass),
// refurb // refurb
(Refurb, "113") => (RuleGroup::Nursery, rules::refurb::rules::RepeatedAppend), (Refurb, "113") => (RuleGroup::Preview, rules::refurb::rules::RepeatedAppend),
(Refurb, "131") => (RuleGroup::Nursery, rules::refurb::rules::DeleteFullSlice), (Refurb, "131") => (RuleGroup::Preview, rules::refurb::rules::DeleteFullSlice),
(Refurb, "132") => (RuleGroup::Nursery, rules::refurb::rules::CheckAndRemoveFromSet), (Refurb, "132") => (RuleGroup::Preview, rules::refurb::rules::CheckAndRemoveFromSet),
_ => return None, _ => return None,
}) })

View File

@ -14,7 +14,7 @@ use crate::rule_redirects::get_redirect;
pub enum RuleSelector { pub enum RuleSelector {
/// Select all stable rules. /// Select all stable rules.
All, All,
/// Select all nursery rules. /// Legacy category to select all preview rules, previously known as the nursery
Nursery, Nursery,
/// Legacy category to select both the `mccabe` and `flake8-comprehensions` linters /// Legacy category to select both the `mccabe` and `flake8-comprehensions` linters
/// via a single selector. /// via a single selector.
@ -151,10 +151,10 @@ impl IntoIterator for &RuleSelector {
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
match self { match self {
RuleSelector::All => { RuleSelector::All => {
RuleSelectorIter::All(Rule::iter().filter(|rule| !rule.is_nursery())) RuleSelectorIter::All(Rule::iter().filter(|rule| !rule.is_preview()))
} }
RuleSelector::Nursery => { RuleSelector::Nursery => {
RuleSelectorIter::Nursery(Rule::iter().filter(Rule::is_nursery)) RuleSelectorIter::Nursery(Rule::iter().filter(Rule::is_preview))
} }
RuleSelector::C => RuleSelectorIter::Chain( RuleSelector::C => RuleSelectorIter::Chain(
Linter::Flake8Comprehensions Linter::Flake8Comprehensions

View File

@ -19,7 +19,7 @@ struct Explanation<'a> {
message_formats: &'a [&'a str], message_formats: &'a [&'a str],
autofix: String, autofix: String,
explanation: Option<&'a str>, explanation: Option<&'a str>,
nursery: bool, preview: bool,
} }
impl<'a> Explanation<'a> { impl<'a> Explanation<'a> {
@ -35,7 +35,7 @@ impl<'a> Explanation<'a> {
message_formats: rule.message_formats(), message_formats: rule.message_formats(),
autofix, autofix,
explanation: rule.explanation(), 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'); output.push('\n');
} }
if rule.is_nursery() { if rule.is_preview() {
output.push_str(&format!( output.push_str(&format!(
r#"This rule is part of the **nursery**, a collection of newer lints that are r#"This rule is in preview and is not stable. It may be enabled by explicitly selecting {}"
still under development. As such, it must be enabled by explicitly selecting " or providing the `--preview` flag."#,
{}."#,
rule.noqa_code() rule.noqa_code()
)); ));
output.push('\n'); output.push('\n');

View File

@ -43,11 +43,10 @@ pub(crate) fn main(args: &Args) -> Result<()> {
output.push('\n'); output.push('\n');
} }
if rule.is_nursery() { if rule.is_preview() {
output.push_str(&format!( output.push_str(&format!(
r#"This rule is part of the **nursery**, a collection of newer lints that are r#"This rule is in preview and is not stable. It may be enabled by explicitly selecting {}"
still under development. As such, it must be enabled by explicitly selecting " or providing the `--preview` flag."#,
{}."#,
rule.noqa_code() rule.noqa_code()
)); ));
output.push('\n'); output.push('\n');

View File

@ -11,7 +11,7 @@ use ruff_diagnostics::AutofixKind;
use ruff_workspace::options::Options; use ruff_workspace::options::Options;
const FIX_SYMBOL: &str = "🛠"; const FIX_SYMBOL: &str = "🛠";
const NURSERY_SYMBOL: &str = "🌅"; const PREVIEW_SYMBOL: &str = "🌅";
fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>, linter: &Linter) { fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>, linter: &Linter) {
table_out.push_str("| Code | Name | Message | |"); table_out.push_str("| Code | Name | Message | |");
@ -25,12 +25,12 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>,
} }
AutofixKind::None => format!("<span style='opacity: 0.1'>{FIX_SYMBOL}</span>"), AutofixKind::None => format!("<span style='opacity: 0.1'>{FIX_SYMBOL}</span>"),
}; };
let nursery_token = if rule.is_nursery() { let preview_token = if rule.is_preview() {
format!("<span style='opacity: 1'>{NURSERY_SYMBOL}</span>") format!("<span style='opacity: 1'>{PREVIEW_SYMBOL}</span>")
} else { } else {
format!("<span style='opacity: 0.1'>{NURSERY_SYMBOL}</span>") format!("<span style='opacity: 0.1'>{PREVIEW_SYMBOL}</span>")
}; };
let status_token = format!("{fix_token} {nursery_token}"); let status_token = format!("{fix_token} {preview_token}");
let rule_name = rule.as_ref(); let rule_name = rule.as_ref();
@ -61,7 +61,7 @@ pub(crate) fn generate() -> String {
table_out.push('\n'); table_out.push('\n');
table_out.push_str(&format!( 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');
table_out.push('\n'); table_out.push('\n');

View File

@ -8,7 +8,7 @@ use syn::{
Ident, ItemFn, LitStr, Pat, Path, Stmt, Token, 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 /// A rule entry in the big match statement such a
/// `(Pycodestyle, "E112") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::NoIndentedBlock),` /// `(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 // 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 // prefix-level selectors (e.g., `--select SIM10`), but add the rule itself under
// its fully-qualified code (e.g., `--select SIM101`). // 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())]); rules_by_prefix.insert(code.clone(), vec![(rule.path.clone(), rule.attrs.clone())]);
continue; continue;
} }
@ -211,7 +211,7 @@ fn rules_by_prefix(
.filter_map(|(code, rule)| { .filter_map(|(code, rule)| {
// Nursery rules have to be explicitly selected, so we ignore them when // Nursery rules have to be explicitly selected, so we ignore them when
// looking at prefixes. // looking at prefixes.
if is_nursery(&rule.group) { if is_preview(&rule.group) {
return None; return None;
} }
@ -311,8 +311,8 @@ See also https://github.com/astral-sh/ruff/issues/2186.
} }
} }
pub fn is_nursery(&self) -> bool { pub fn is_preview(&self) -> bool {
matches!(self.group(), RuleGroup::Nursery) matches!(self.group(), RuleGroup::Preview)
} }
} }
@ -336,7 +336,7 @@ fn generate_iter_impl(
let mut linter_rules_match_arms = quote!(); let mut linter_rules_match_arms = quote!();
let mut linter_all_rules_match_arms = quote!(); let mut linter_all_rules_match_arms = quote!();
for (linter, map) in linter_to_rules { 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, .. }| { |Rule { attrs, path, .. }| {
let rule_name = path.segments.last().unwrap(); let rule_name = path.segments.last().unwrap();
quote!(#(#attrs)* Rule::#rule_name) quote!(#(#attrs)* Rule::#rule_name)

View File

@ -15,7 +15,7 @@ pub(crate) fn expand<'a>(
for (variant, group, attr) in variants { for (variant, group, attr) in variants {
let code_str = variant.to_string(); let code_str = variant.to_string();
// Nursery rules have to be explicitly selected, so we ignore them when looking at prefixes. // 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 prefix_to_codes
.entry(code_str.clone()) .entry(code_str.clone())
.or_default() .or_default()
@ -126,13 +126,13 @@ pub(crate) fn get_prefix_ident(prefix: &str) -> Ident {
Ident::new(&prefix, Span::call_site()) Ident::new(&prefix, Span::call_site())
} }
/// Returns true if the given group is the "nursery" group. /// Returns true if the given group is the "preview" group.
pub(crate) fn is_nursery(group: &Path) -> bool { pub(crate) fn is_preview(group: &Path) -> bool {
let group = group let group = group
.segments .segments
.iter() .iter()
.map(|segment| segment.ident.to_string()) .map(|segment| segment.ident.to_string())
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("::"); .join("::");
group == "RuleGroup::Nursery" group == "RuleGroup::Preview"
} }

View File

@ -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 By default, no `convention` is set, and so the enabled rules are determined by the `select` setting
alone. 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 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 included in the "nursery", it example, consider a hypothetical rule, `HYP001`. If `HYP001` were in preview, it could be enabled by adding the
could be enabled by adding the following to your `pyproject.toml`: following to your `pyproject.toml`:
```toml ```toml
[tool.ruff] [tool.ruff]
@ -409,10 +409,15 @@ Similarly, it would _not_ be enabled via the `ALL` selector:
select = ["ALL"] select = ["ALL"]
``` ```
(The "nursery" terminology comes from [Clippy](https://doc.rust-lang.org/nightly/clippy/), a similar Unless you also enabled `preview`:
tool for linting Rust code.)
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? ## How can I tell what settings Ruff is using to check my code?