Skip to content

Commit

Permalink
[Ruff 0.5] Stabilise 11 FURB rules (#12043)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored and MichaReiser committed Jun 27, 2024
1 parent d13eb40 commit d72fb7e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
22 changes: 11 additions & 11 deletions crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,34 +1014,34 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
// refurb
(Refurb, "101") => (RuleGroup::Preview, rules::refurb::rules::ReadWholeFile),
(Refurb, "103") => (RuleGroup::Preview, rules::refurb::rules::WriteWholeFile),
(Refurb, "105") => (RuleGroup::Preview, rules::refurb::rules::PrintEmptyString),
(Refurb, "105") => (RuleGroup::Stable, rules::refurb::rules::PrintEmptyString),
(Refurb, "110") => (RuleGroup::Preview, rules::refurb::rules::IfExpInsteadOfOrOperator),
(Refurb, "113") => (RuleGroup::Preview, rules::refurb::rules::RepeatedAppend),
(Refurb, "116") => (RuleGroup::Preview, rules::refurb::rules::FStringNumberFormat),
(Refurb, "118") => (RuleGroup::Preview, rules::refurb::rules::ReimplementedOperator),
(Refurb, "129") => (RuleGroup::Preview, rules::refurb::rules::ReadlinesInFor),
(Refurb, "129") => (RuleGroup::Stable, rules::refurb::rules::ReadlinesInFor),
(Refurb, "131") => (RuleGroup::Preview, rules::refurb::rules::DeleteFullSlice),
(Refurb, "132") => (RuleGroup::Preview, rules::refurb::rules::CheckAndRemoveFromSet),
(Refurb, "136") => (RuleGroup::Preview, rules::refurb::rules::IfExprMinMax),
(Refurb, "136") => (RuleGroup::Stable, rules::refurb::rules::IfExprMinMax),
(Refurb, "140") => (RuleGroup::Preview, rules::refurb::rules::ReimplementedStarmap),
(Refurb, "142") => (RuleGroup::Preview, rules::refurb::rules::ForLoopSetMutations),
(Refurb, "145") => (RuleGroup::Preview, rules::refurb::rules::SliceCopy),
(Refurb, "148") => (RuleGroup::Preview, rules::refurb::rules::UnnecessaryEnumerate),
(Refurb, "152") => (RuleGroup::Preview, rules::refurb::rules::MathConstant),
(Refurb, "154") => (RuleGroup::Preview, rules::refurb::rules::RepeatedGlobal),
(Refurb, "157") => (RuleGroup::Preview, rules::refurb::rules::VerboseDecimalConstructor),
(Refurb, "161") => (RuleGroup::Preview, rules::refurb::rules::BitCount),
(Refurb, "163") => (RuleGroup::Preview, rules::refurb::rules::RedundantLogBase),
(Refurb, "161") => (RuleGroup::Stable, rules::refurb::rules::BitCount),
(Refurb, "163") => (RuleGroup::Stable, rules::refurb::rules::RedundantLogBase),
(Refurb, "164") => (RuleGroup::Preview, rules::refurb::rules::UnnecessaryFromFloat),
(Refurb, "166") => (RuleGroup::Preview, rules::refurb::rules::IntOnSlicedStr),
(Refurb, "167") => (RuleGroup::Preview, rules::refurb::rules::RegexFlagAlias),
(Refurb, "168") => (RuleGroup::Preview, rules::refurb::rules::IsinstanceTypeNone),
(Refurb, "169") => (RuleGroup::Preview, rules::refurb::rules::TypeNoneComparison),
(Refurb, "167") => (RuleGroup::Stable, rules::refurb::rules::RegexFlagAlias),
(Refurb, "168") => (RuleGroup::Stable, rules::refurb::rules::IsinstanceTypeNone),
(Refurb, "169") => (RuleGroup::Stable, rules::refurb::rules::TypeNoneComparison),
(Refurb, "171") => (RuleGroup::Preview, rules::refurb::rules::SingleItemMembershipTest),
(Refurb, "177") => (RuleGroup::Preview, rules::refurb::rules::ImplicitCwd),
(Refurb, "177") => (RuleGroup::Stable, rules::refurb::rules::ImplicitCwd),
(Refurb, "180") => (RuleGroup::Preview, rules::refurb::rules::MetaClassABCMeta),
(Refurb, "181") => (RuleGroup::Preview, rules::refurb::rules::HashlibDigestHex),
(Refurb, "187") => (RuleGroup::Preview, rules::refurb::rules::ListReverseCopy),
(Refurb, "181") => (RuleGroup::Stable, rules::refurb::rules::HashlibDigestHex),
(Refurb, "187") => (RuleGroup::Stable, rules::refurb::rules::ListReverseCopy),
(Refurb, "192") => (RuleGroup::Preview, rules::refurb::rules::SortedMinMax),

// flake8-logging
Expand Down
6 changes: 4 additions & 2 deletions crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ enum MinMax {
}

impl MinMax {
fn reverse(self) -> Self {
#[must_use]
const fn reverse(self) -> Self {
match self {
Self::Min => Self::Max,
Self::Max => Self::Min,
}
}

fn as_str(self) -> &'static str {
#[must_use]
const fn as_str(self) -> &'static str {
match self {
Self::Min => "min",
Self::Max => "max",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pub(crate) fn redundant_log_base(checker: &mut Checker, call: &ast::ExprCall) {
if !checker
.semantic()
.resolve_qualified_name(&call.func)
.as_ref()
.is_some_and(|qualified_name| matches!(qualified_name.segments(), ["math", "log"]))
{
return;
Expand All @@ -90,7 +89,6 @@ pub(crate) fn redundant_log_base(checker: &mut Checker, call: &ast::ExprCall) {
} else if checker
.semantic()
.resolve_qualified_name(base)
.as_ref()
.is_some_and(|qualified_name| matches!(qualified_name.segments(), ["math", "e"]))
{
Base::E
Expand Down
25 changes: 10 additions & 15 deletions crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ use crate::importer::ImportRequest;
///
#[violation]
pub struct RegexFlagAlias {
alias: &'static str,
full_name: &'static str,
flag: RegexFlag,
}

impl AlwaysFixableViolation for RegexFlagAlias {
#[derive_message_formats]
fn message(&self) -> String {
let RegexFlagAlias { alias, .. } = self;
format!("Use of regular expression alias `re.{alias}`")
let RegexFlagAlias { flag } = self;
format!("Use of regular expression alias `re.{}`", flag.alias())
}

fn fix_title(&self) -> String {
let RegexFlagAlias { full_name, .. } = self;
format!("Replace with `re.{full_name}`")
let RegexFlagAlias { flag } = self;
format!("Replace with `re.{}`", flag.full_name())
}
}

Expand Down Expand Up @@ -75,13 +74,7 @@ pub(crate) fn regex_flag_alias(checker: &mut Checker, expr: &Expr) {
return;
};

let mut diagnostic = Diagnostic::new(
RegexFlagAlias {
alias: flag.alias(),
full_name: flag.full_name(),
},
expr.range(),
);
let mut diagnostic = Diagnostic::new(RegexFlagAlias { flag }, expr.range());
diagnostic.try_set_fix(|| {
let (edit, binding) = checker.importer().get_or_import_symbol(
&ImportRequest::import("re", flag.full_name()),
Expand Down Expand Up @@ -109,7 +102,8 @@ enum RegexFlag {
}

impl RegexFlag {
fn alias(self) -> &'static str {
#[must_use]
const fn alias(self) -> &'static str {
match self {
Self::Ascii => "A",
Self::IgnoreCase => "I",
Expand All @@ -122,7 +116,8 @@ impl RegexFlag {
}
}

fn full_name(self) -> &'static str {
#[must_use]
const fn full_name(self) -> &'static str {
match self {
Self::Ascii => "ASCII",
Self::IgnoreCase => "IGNORECASE",
Expand Down
2 changes: 0 additions & 2 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,8 +1484,6 @@ mod tests {
use crate::options::PydocstyleOptions;

const PREVIEW_RULES: &[Rule] = &[
Rule::IsinstanceTypeNone,
Rule::IfExprMinMax,
Rule::ReimplementedStarmap,
Rule::SliceCopy,
Rule::TooManyPublicMethods,
Expand Down

0 comments on commit d72fb7e

Please sign in to comment.