From 43fe330e0faf027d6849e0c00c64562ac73a5dd5 Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Tue, 22 Sep 2026 14:53:19 -0400 Subject: [PATCH] Update default rules Summary -- This makes a few modifications to our default rule set for v0.17. As the snapshots show, these had already been incorporated into our preview defaults via rule recategorization. This just ports them back to the stable default rules. This closes #27197, which brought the problems with the DTZ rules to our attention. F406 being a syntax error was raised in [this comment]. [this comment]: https://github.com/astral-sh/ruff/issues/27199#issuecomment-5093309966 Test Plan -- Updated snapshots --- crates/ruff/tests/cli/lint.rs | 8 +------- ..._show_settings__display_default_settings.snap | 16 ++-------------- crates/ruff_linter/src/settings/mod.rs | 16 +--------------- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/crates/ruff/tests/cli/lint.rs b/crates/ruff/tests/cli/lint.rs index fcef87d7b0c27f..02d1dbeebcadbf 100644 --- a/crates/ruff/tests/cli/lint.rs +++ b/crates/ruff/tests/cli/lint.rs @@ -5084,16 +5084,9 @@ fn default_rules() -> Result<()> { unnecessary-map (C417), unnecessary-literal-within-dict-call (C418), unnecessary-comprehension-in-call (C419), - call-datetime-without-tzinfo (DTZ001), call-datetime-today (DTZ002), call-datetime-utcnow (DTZ003), call-datetime-utcfromtimestamp (DTZ004), - call-datetime-now-without-tzinfo (DTZ005), - call-datetime-fromtimestamp (DTZ006), - call-datetime-strptime-without-zone (DTZ007), - call-date-today (DTZ011), - call-date-fromtimestamp (DTZ012), - datetime-min-max (DTZ901), debugger (T100), shebang-not-executable (EXE001), shebang-missing-executable-file (EXE002), @@ -5216,6 +5209,7 @@ fn default_rules() -> Result<()> { unused-import (F401), import-shadowed-by-loop-var (F402), late-future-import (F404), + undefined-local-with-nested-import-star-usage (F406), future-feature-not-defined (F407), percent-format-invalid-format (F501), percent-format-expected-mapping (F502), diff --git a/crates/ruff/tests/cli/snapshots/cli__show_settings__display_default_settings.snap b/crates/ruff/tests/cli/snapshots/cli__show_settings__display_default_settings.snap index 999be28ab2f36a..3f6a81bdebbbf1 100644 --- a/crates/ruff/tests/cli/snapshots/cli__show_settings__display_default_settings.snap +++ b/crates/ruff/tests/cli/snapshots/cli__show_settings__display_default_settings.snap @@ -139,16 +139,9 @@ linter.rules.enabled = [ unnecessary-map (C417), unnecessary-literal-within-dict-call (C418), unnecessary-comprehension-in-call (C419), - call-datetime-without-tzinfo (DTZ001), call-datetime-today (DTZ002), call-datetime-utcnow (DTZ003), call-datetime-utcfromtimestamp (DTZ004), - call-datetime-now-without-tzinfo (DTZ005), - call-datetime-fromtimestamp (DTZ006), - call-datetime-strptime-without-zone (DTZ007), - call-date-today (DTZ011), - call-date-fromtimestamp (DTZ012), - datetime-min-max (DTZ901), debugger (T100), shebang-not-executable (EXE001), shebang-missing-executable-file (EXE002), @@ -271,6 +264,7 @@ linter.rules.enabled = [ unused-import (F401), import-shadowed-by-loop-var (F402), late-future-import (F404), + undefined-local-with-nested-import-star-usage (F406), future-feature-not-defined (F407), percent-format-invalid-format (F501), percent-format-expected-mapping (F502), @@ -554,16 +548,9 @@ linter.rules.should_fix = [ unnecessary-map (C417), unnecessary-literal-within-dict-call (C418), unnecessary-comprehension-in-call (C419), - call-datetime-without-tzinfo (DTZ001), call-datetime-today (DTZ002), call-datetime-utcnow (DTZ003), call-datetime-utcfromtimestamp (DTZ004), - call-datetime-now-without-tzinfo (DTZ005), - call-datetime-fromtimestamp (DTZ006), - call-datetime-strptime-without-zone (DTZ007), - call-date-today (DTZ011), - call-date-fromtimestamp (DTZ012), - datetime-min-max (DTZ901), debugger (T100), shebang-not-executable (EXE001), shebang-missing-executable-file (EXE002), @@ -686,6 +673,7 @@ linter.rules.should_fix = [ unused-import (F401), import-shadowed-by-loop-var (F402), late-future-import (F404), + undefined-local-with-nested-import-star-usage (F406), future-feature-not-defined (F407), percent-format-invalid-format (F501), percent-format-expected-mapping (F502), diff --git a/crates/ruff_linter/src/settings/mod.rs b/crates/ruff_linter/src/settings/mod.rs index 042512d323f53b..7ed61e4fd27393 100644 --- a/crates/ruff_linter/src/settings/mod.rs +++ b/crates/ruff_linter/src/settings/mod.rs @@ -413,16 +413,9 @@ pub const DEFAULT_SELECTORS: &[RuleSelector] = &[ RuleSelector::rule(Rule::UnnecessaryLiteralWithinDictCall), // C418 RuleSelector::rule(Rule::UnnecessaryComprehensionInCall), // C419 RuleSelector::rule(Rule::EmptyDocstring), // D419 - RuleSelector::rule(Rule::CallDatetimeWithoutTzinfo), // DTZ001 RuleSelector::rule(Rule::CallDatetimeToday), // DTZ002 RuleSelector::rule(Rule::CallDatetimeUtcnow), // DTZ003 RuleSelector::rule(Rule::CallDatetimeUtcfromtimestamp), // DTZ004 - RuleSelector::rule(Rule::CallDatetimeNowWithoutTzinfo), // DTZ005 - RuleSelector::rule(Rule::CallDatetimeFromtimestamp), // DTZ006 - RuleSelector::rule(Rule::CallDatetimeStrptimeWithoutZone), // DTZ007 - RuleSelector::rule(Rule::CallDateToday), // DTZ011 - RuleSelector::rule(Rule::CallDateFromtimestamp), // DTZ012 - RuleSelector::rule(Rule::DatetimeMinMax), // DTZ901 RuleSelector::rule(Rule::BareExcept), // E722 RuleSelector::rule(Rule::IOError), // E902 RuleSelector::rule(Rule::ShebangNotExecutable), // EXE001 @@ -432,6 +425,7 @@ pub const DEFAULT_SELECTORS: &[RuleSelector] = &[ RuleSelector::rule(Rule::UnusedImport), // F401 RuleSelector::rule(Rule::ImportShadowedByLoopVar), // F402 RuleSelector::rule(Rule::LateFutureImport), // F404 + RuleSelector::rule(Rule::UndefinedLocalWithNestedImportStarUsage), // F406 RuleSelector::rule(Rule::FutureFeatureNotDefined), // F407 RuleSelector::rule(Rule::PercentFormatInvalidFormat), // F501 RuleSelector::rule(Rule::PercentFormatExpectedMapping), // F502 @@ -1013,7 +1007,6 @@ mod tests { pandas-use-of-dot-read-table (PD012), pandas-use-of-pd-merge (PD015), escape-sequence-in-docstring (D301), - undefined-local-with-nested-import-star-usage (F406), missing-maxsplit-arg (PLC0207), unnecessary-dunder-call (PLC2801), duplicate-bases (PLE0241), @@ -1070,13 +1063,6 @@ mod tests { Removed in preview: [ exec-builtin (S102), - call-datetime-without-tzinfo (DTZ001), - call-datetime-now-without-tzinfo (DTZ005), - call-datetime-fromtimestamp (DTZ006), - call-datetime-strptime-without-zone (DTZ007), - call-date-today (DTZ011), - call-date-fromtimestamp (DTZ012), - datetime-min-max (DTZ901), ] "); }