diff --git a/Cargo.toml b/Cargo.toml index 12ba78a1b7729..9b356fc885307 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" [workspace.package] edition = "2021" -rust-version = "1.83" +rust-version = "1.84" homepage = "https://docs.astral.sh/ruff" documentation = "https://docs.astral.sh/ruff" repository = "https://github.com/astral-sh/ruff" @@ -209,6 +209,7 @@ must_use_candidate = "allow" similar_names = "allow" single_match_else = "allow" too_many_lines = "allow" +needless_continue = "allow" # An explicit continue can be more readable, especially if the alternative is an empty block. # Without the hashes we run into a `rustfmt` bug in some snapshot tests, see #13250 needless_raw_string_hashes = "allow" # Disallowed restriction lints @@ -227,6 +228,10 @@ redundant_clone = "warn" debug_assert_with_mut_call = "warn" unused_peekable = "warn" +# Has false positives +# https://github.com/rust-lang/rust-clippy/issues/14275 +doc_overindented_list_items = "allow" + # Diagnostics are not actionable: Enable once https://github.com/rust-lang/rust-clippy/issues/13774 is resolved. large_stack_arrays = "allow" diff --git a/crates/red_knot_project/src/db.rs b/crates/red_knot_project/src/db.rs index 8f2b336b3fcd0..64a1aa59407e3 100644 --- a/crates/red_knot_project/src/db.rs +++ b/crates/red_knot_project/src/db.rs @@ -159,7 +159,7 @@ impl salsa::Database for ProjectDatabase { } let event = event(); - if matches!(event.kind, salsa::EventKind::WillCheckCancellation { .. }) { + if matches!(event.kind, salsa::EventKind::WillCheckCancellation) { return; } diff --git a/crates/red_knot_project/src/db/changes.rs b/crates/red_knot_project/src/db/changes.rs index 66b6552da1e6f..4ba90af10fce6 100644 --- a/crates/red_knot_project/src/db/changes.rs +++ b/crates/red_knot_project/src/db/changes.rs @@ -187,7 +187,7 @@ impl ProjectDatabase { let program = Program::get(self); if let Err(error) = program.update_from_settings(self, program_settings) { tracing::error!("Failed to update the program settings, keeping the old program settings: {error}"); - }; + } if metadata.root() == project.root(self) { tracing::debug!("Reloading project after structural change"); diff --git a/crates/red_knot_python_semantic/src/module_resolver/typeshed.rs b/crates/red_knot_python_semantic/src/module_resolver/typeshed.rs index de46fa93f04bd..8a3fe2e645690 100644 --- a/crates/red_knot_python_semantic/src/module_resolver/typeshed.rs +++ b/crates/red_knot_python_semantic/src/module_resolver/typeshed.rs @@ -322,6 +322,7 @@ fn python_version_from_versions_file_string( #[cfg(test)] mod tests { + use std::fmt::Write as _; use std::num::{IntErrorKind, NonZeroU16}; use std::path::Path; @@ -333,8 +334,7 @@ mod tests { const TYPESHED_STDLIB_DIR: &str = "stdlib"; - #[allow(unsafe_code)] - const ONE: Option = Some(unsafe { NonZeroU16::new_unchecked(1) }); + const ONE: Option = Some(NonZeroU16::new(1).unwrap()); impl TypeshedVersions { #[must_use] @@ -571,7 +571,7 @@ foo: 3.8- # trailing comment let mut massive_versions_file = String::new(); for i in 0..too_many { - massive_versions_file.push_str(&format!("x{i}: 3.8-\n")); + let _ = writeln!(&mut massive_versions_file, "x{i}: 3.8-"); } assert_eq!( diff --git a/crates/red_knot_python_semantic/src/semantic_index/builder.rs b/crates/red_knot_python_semantic/src/semantic_index/builder.rs index 6dbf25cbec5f9..451da69668d52 100644 --- a/crates/red_knot_python_semantic/src/semantic_index/builder.rs +++ b/crates/red_knot_python_semantic/src/semantic_index/builder.rs @@ -1448,7 +1448,7 @@ where self.visit_expr(subject); if cases.is_empty() { return; - }; + } let after_subject = self.flow_snapshot(); let mut vis_constraints = vec![]; diff --git a/crates/red_knot_python_semantic/src/suppression.rs b/crates/red_knot_python_semantic/src/suppression.rs index 3a76a0b7c456f..e3ac813226d46 100644 --- a/crates/red_knot_python_semantic/src/suppression.rs +++ b/crates/red_knot_python_semantic/src/suppression.rs @@ -145,7 +145,7 @@ pub(crate) fn check_suppressions(db: &dyn Db, file: File, diagnostics: &mut Type fn check_unknown_rule(context: &mut CheckSuppressionsContext) { if context.is_lint_disabled(&UNKNOWN_RULE) { return; - }; + } for unknown in &context.suppressions.unknown { match &unknown.reason { @@ -174,7 +174,7 @@ fn check_unknown_rule(context: &mut CheckSuppressionsContext) { format_args!("Unknown rule `{prefixed}`. Did you mean `{suggestion}`?"), ); } - }; + } } } @@ -267,7 +267,7 @@ fn check_unused_suppressions(context: &mut CheckSuppressionsContext) { suppression.range, format_args!("Unused `{kind}` without a code", kind = suppression.kind), ), - }; + } } } diff --git a/crates/red_knot_python_semantic/src/symbol.rs b/crates/red_knot_python_semantic/src/symbol.rs index e7fc55e7a5ea8..e6a8fd39914e0 100644 --- a/crates/red_knot_python_semantic/src/symbol.rs +++ b/crates/red_knot_python_semantic/src/symbol.rs @@ -657,7 +657,7 @@ fn symbol_from_bindings_impl<'db>( binding, visibility_constraint, narrowing_constraint: _, - }) if binding.map_or(true, is_non_exported) => { + }) if binding.is_none_or(is_non_exported) => { visibility_constraints.evaluate(db, predicates, *visibility_constraint) } _ => Truthiness::AlwaysFalse, @@ -794,7 +794,7 @@ fn symbol_from_declarations_impl<'db>( Some(DeclarationWithConstraint { declaration, visibility_constraint, - }) if declaration.map_or(true, is_non_exported) => { + }) if declaration.is_none_or(is_non_exported) => { visibility_constraints.evaluate(db, predicates, *visibility_constraint) } _ => Truthiness::AlwaysFalse, diff --git a/crates/red_knot_python_semantic/src/types/call/bind.rs b/crates/red_knot_python_semantic/src/types/call/bind.rs index 590b20f550f6d..8714e481208f8 100644 --- a/crates/red_knot_python_semantic/src/types/call/bind.rs +++ b/crates/red_knot_python_semantic/src/types/call/bind.rs @@ -502,13 +502,13 @@ impl<'db> Bindings<'db> { if let Some(len_ty) = first_arg.len(db) { overload.set_return_type(len_ty); } - }; + } } Some(KnownFunction::Repr) => { if let [Some(first_arg)] = overload.parameter_types() { overload.set_return_type(first_arg.repr(db)); - }; + } } Some(KnownFunction::Cast) => { diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 80f24dbcbee3d..0bc051b850e3a 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -985,7 +985,7 @@ impl<'db> TypeInferenceBuilder<'db> { Some(KnownClass::Float | KnownClass::Int | KnownClass::Bool) ) => {} _ => return false, - }; + } let (op, by_zero) = match op { ast::Operator::Div => ("divide", "by zero"), @@ -1036,7 +1036,7 @@ impl<'db> TypeInferenceBuilder<'db> { report_invalid_assignment(&self.context, node, declared_ty, bound_ty); // allow declarations to override inference in case of invalid assignment bound_ty = declared_ty; - }; + } self.types.bindings.insert(binding, bound_ty); } @@ -2216,7 +2216,7 @@ impl<'db> TypeInferenceBuilder<'db> { } } ast::Pattern::MatchStar(_) | ast::Pattern::MatchSingleton(_) => {} - }; + } } fn infer_assignment_statement(&mut self, assignment: &ast::StmtAssign) { @@ -3242,7 +3242,7 @@ impl<'db> TypeInferenceBuilder<'db> { &DeclaredAndInferredType::AreTheSame(ty), ); return; - }; + } // If the module doesn't bind the symbol, check if it's a submodule. This won't get // handled by the `Type::member` call because it relies on the semantic index's @@ -4044,7 +4044,7 @@ impl<'db> TypeInferenceBuilder<'db> { parameter_ty=parameter_ty.display(self.db()) ), ); - }; + } } } } @@ -4895,7 +4895,7 @@ impl<'db> TypeInferenceBuilder<'db> { if done { return Type::Never; - }; + } match (truthiness, op) { (Truthiness::AlwaysTrue, ast::BoolOp::And) => Type::Never, @@ -5815,7 +5815,7 @@ impl<'db> TypeInferenceBuilder<'db> { Err(CallDunderError::MethodNotAvailable) => { // try `__class_getitem__` } - }; + } // Otherwise, if the value is itself a class and defines `__class_getitem__`, // return its return type. diff --git a/crates/red_knot_python_semantic/src/types/slots.rs b/crates/red_knot_python_semantic/src/types/slots.rs index 8dfa9d419815e..b0afda81baca6 100644 --- a/crates/red_knot_python_semantic/src/types/slots.rs +++ b/crates/red_knot_python_semantic/src/types/slots.rs @@ -30,7 +30,7 @@ impl SlotsKind { if matches!(bound, Boundness::PossiblyUnbound) { return Self::Dynamic; - }; + } match slots_ty { // __slots__ = ("a", "b") @@ -98,6 +98,6 @@ pub(super) fn check_class_slots(context: &InferContext, class: Class, node: &ast if let Some(index) = first_with_solid_base { let base_node = &node.bases()[index]; report_base_with_incompatible_slots(context, base_node); - }; + } } } diff --git a/crates/red_knot_python_semantic/src/types/unpacker.rs b/crates/red_knot_python_semantic/src/types/unpacker.rs index b32218de4538f..2f50536f0e0e2 100644 --- a/crates/red_knot_python_semantic/src/types/unpacker.rs +++ b/crates/red_knot_python_semantic/src/types/unpacker.rs @@ -116,8 +116,10 @@ impl<'db> Unpacker<'db> { // it's worth it. TupleType::from_elements( self.db(), - std::iter::repeat(Type::LiteralString) - .take(string_literal_ty.python_len(self.db())), + std::iter::repeat_n( + Type::LiteralString, + string_literal_ty.python_len(self.db()), + ), ) } _ => ty, diff --git a/crates/red_knot_test/src/assertion.rs b/crates/red_knot_test/src/assertion.rs index 8c4f3fbfea1d9..d88c7d2b27c78 100644 --- a/crates/red_knot_test/src/assertion.rs +++ b/crates/red_knot_test/src/assertion.rs @@ -131,7 +131,7 @@ impl<'a> Iterator for AssertionWithRangeIterator<'a> { let comment = &self.file_assertions.source[inner_next]; if let Some(assertion) = UnparsedAssertion::from_comment(comment) { return Some(AssertionWithRange(assertion, inner_next)); - }; + } } } } diff --git a/crates/red_knot_test/src/lib.rs b/crates/red_knot_test/src/lib.rs index 4123fc2cb7033..d7b475575af4e 100644 --- a/crates/red_knot_test/src/lib.rs +++ b/crates/red_knot_test/src/lib.rs @@ -265,13 +265,13 @@ fn run_test( match info.location { Some(location) => messages.push(format!("panicked at {location}")), None => messages.push("panicked at unknown location".to_string()), - }; + } match info.payload { Some(payload) => messages.push(payload), // Mimic the default panic hook's rendering of the panic payload if it's // not a string. None => messages.push("Box".to_string()), - }; + } if let Some(backtrace) = info.backtrace { if std::env::var("RUST_BACKTRACE").is_ok() { messages.extend(backtrace.to_string().split('\n').map(String::from)); diff --git a/crates/red_knot_test/src/parser.rs b/crates/red_knot_test/src/parser.rs index 2a25efc48c7ff..5eb3b003a120b 100644 --- a/crates/red_knot_test/src/parser.rs +++ b/crates/red_knot_test/src/parser.rs @@ -673,7 +673,7 @@ impl<'s> Parser<'s> { "Test `{test_name}` has duplicate files named `{}`.", path.as_str(), ); - }; + } if has_explicit_file_paths { bail!("Merged snippets in test `{test_name}` are not allowed in the presence of other files."); diff --git a/crates/ruff/src/args.rs b/crates/ruff/src/args.rs index a1fe96e1624e9..fa4655de57a42 100644 --- a/crates/ruff/src/args.rs +++ b/crates/ruff/src/args.rs @@ -1,5 +1,5 @@ use std::cmp::Ordering; -use std::fmt::Formatter; +use std::fmt::{Formatter, Write as _}; use std::ops::Deref; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -974,12 +974,13 @@ A `--config` flag must either be a path to a `.toml` configuration file .is_some_and(|ext| ext.eq_ignore_ascii_case("toml")) { if !value.contains('=') { - tip.push_str(&format!( + let _ = write!( + &mut tip, " It looks like you were trying to pass a path to a configuration file. The path `{value}` does not point to a configuration file" - )); + ); } } else if let Some((key, value)) = value.split_once('=') { let key = key.trim_ascii(); @@ -993,7 +994,8 @@ The path `{value}` does not point to a configuration file" .map(|(name, _)| format!("- `{key}.{name}`")) .join("\n"); - tip.push_str(&format!( + let _ = write!( + &mut tip, " `{key}` is a table of configuration options. @@ -1002,13 +1004,14 @@ Did you want to override one of the table's subkeys? Possible choices: {prefixed_subfields}" - )); + ); } _ => { - tip.push_str(&format!( + let _ = write!( + &mut tip, "\n\n{}:\n\n{underlying_error}", config_parse_error.description() - )); + ); } } } diff --git a/crates/ruff/src/commands/rule.rs b/crates/ruff/src/commands/rule.rs index 0b0c1ca840788..fd2e682b0fbdd 100644 --- a/crates/ruff/src/commands/rule.rs +++ b/crates/ruff/src/commands/rule.rs @@ -1,3 +1,4 @@ +use std::fmt::Write as _; use std::io::{self, BufWriter, Write}; use anyhow::Result; @@ -43,12 +44,16 @@ impl<'a> Explanation<'a> { fn format_rule_text(rule: Rule) -> String { let mut output = String::new(); - output.push_str(&format!("# {} ({})", rule.as_ref(), rule.noqa_code())); + let _ = write!(&mut output, "# {} ({})", rule.as_ref(), rule.noqa_code()); output.push('\n'); output.push('\n'); let (linter, _) = Linter::parse_code(&rule.noqa_code().to_string()).unwrap(); - output.push_str(&format!("Derived from the **{}** linter.", linter.name())); + let _ = write!( + &mut output, + "Derived from the **{}** linter.", + linter.name() + ); output.push('\n'); output.push('\n'); @@ -76,7 +81,7 @@ fn format_rule_text(rule: Rule) -> String { output.push_str("Message formats:"); for format in rule.message_formats() { output.push('\n'); - output.push_str(&format!("* {format}")); + let _ = write!(&mut output, "* {format}"); } } output @@ -92,7 +97,7 @@ pub(crate) fn rule(rule: Rule, format: HelpFormat) -> Result<()> { HelpFormat::Json => { serde_json::to_writer_pretty(stdout, &Explanation::from_rule(&rule))?; } - }; + } Ok(()) } diff --git a/crates/ruff/src/commands/version.rs b/crates/ruff/src/commands/version.rs index 729d0f15d5e9e..3361071206843 100644 --- a/crates/ruff/src/commands/version.rs +++ b/crates/ruff/src/commands/version.rs @@ -16,6 +16,6 @@ pub(crate) fn version(output_format: HelpFormat) -> Result<()> { HelpFormat::Json => { serde_json::to_writer_pretty(stdout, &version_info)?; } - }; + } Ok(()) } diff --git a/crates/ruff/src/main.rs b/crates/ruff/src/main.rs index 2271cca49b617..b33260bf36042 100644 --- a/crates/ruff/src/main.rs +++ b/crates/ruff/src/main.rs @@ -31,7 +31,7 @@ pub fn main() -> ExitCode { // support FORCE_COLOR env var if let Some(force_color) = std::env::var_os("FORCE_COLOR") { - if force_color.len() > 0 { + if !force_color.is_empty() { colored::control::set_override(true); } } diff --git a/crates/ruff_annotate_snippets/src/renderer/display_list.rs b/crates/ruff_annotate_snippets/src/renderer/display_list.rs index b3aee72f2ca39..48269294f1cfe 100644 --- a/crates/ruff_annotate_snippets/src/renderer/display_list.rs +++ b/crates/ruff_annotate_snippets/src/renderer/display_list.rs @@ -315,7 +315,7 @@ impl DisplaySet<'_> { None => { buffer.putc(line_offset, lineno_width + 1, '|', *lineno_color); } - }; + } } if let DisplaySourceLine::Content { text, .. } = line { // The width of the line number, a space, pipe, and a space @@ -1753,7 +1753,7 @@ fn format_inline_marks( DisplayMarkType::AnnotationThrough(depth) => { buf.putc(line, 3 + lineno_width + depth, '|', *annotation_style); } - }; + } } Ok(()) } diff --git a/crates/ruff_dev/src/generate_docs.rs b/crates/ruff_dev/src/generate_docs.rs index c86814031c1d1..362ea4411f502 100644 --- a/crates/ruff_dev/src/generate_docs.rs +++ b/crates/ruff_dev/src/generate_docs.rs @@ -2,6 +2,7 @@ #![allow(clippy::print_stdout, clippy::print_stderr)] use std::collections::HashSet; +use std::fmt::Write as _; use std::fs; use std::path::PathBuf; @@ -29,8 +30,7 @@ pub(crate) fn main(args: &Args) -> Result<()> { if let Some(explanation) = rule.explanation() { let mut output = String::new(); - output.push_str(&format!("# {} ({})", rule.as_ref(), rule.noqa_code())); - output.push('\n'); + let _ = writeln!(&mut output, "# {} ({})", rule.as_ref(), rule.noqa_code()); let (linter, _) = Linter::parse_code(&rule.noqa_code().to_string()).unwrap(); if linter.url().is_some() { @@ -49,11 +49,12 @@ pub(crate) fn main(args: &Args) -> Result<()> { common_prefix.to_lowercase() ); - output.push_str(&format!( + let _ = write!( + output, "Derived from the **[{}](../rules.md#{})** linter.", linter.name(), - anchor - )); + anchor, + ); output.push('\n'); output.push('\n'); } @@ -155,8 +156,8 @@ fn process_documentation(documentation: &str, out: &mut String, rule_name: &str) } let anchor = option.replace('.', "_"); - out.push_str(&format!("- [`{option}`][{option}]\n")); - after.push_str(&format!("[{option}]: ../settings.md#{anchor}\n")); + let _ = writeln!(out, "- [`{option}`][{option}]"); + let _ = writeln!(&mut after, "[{option}]: ../settings.md#{anchor}"); referenced_options.insert(option); continue; @@ -171,7 +172,7 @@ fn process_documentation(documentation: &str, out: &mut String, rule_name: &str) if let Some(OptionEntry::Field(field)) = Options::metadata().find(option) { if referenced_options.insert(option) { let anchor = option.replace('.', "_"); - after.push_str(&format!("[{option}]: ../settings.md#{anchor}\n")); + let _ = writeln!(&mut after, "[{option}]: ../settings.md#{anchor}"); } if field.deprecated.is_some() { eprintln!("Rule {rule_name} references deprecated option {option}."); diff --git a/crates/ruff_dev/src/generate_options.rs b/crates/ruff_dev/src/generate_options.rs index 652cc4d2ee756..7c187878b85bc 100644 --- a/crates/ruff_dev/src/generate_options.rs +++ b/crates/ruff_dev/src/generate_options.rs @@ -98,17 +98,16 @@ fn emit_field(output: &mut String, name: &str, field: &OptionField, parents: &[S let parents_anchor = parents.iter().filter_map(|parent| parent.name()).join("_"); if parents_anchor.is_empty() { - output.push_str(&format!( - "{header_level} [`{name}`](#{name}) {{: #{name} }}\n" - )); + let _ = writeln!(output, "{header_level} [`{name}`](#{name}) {{: #{name} }}"); } else { - output.push_str(&format!( - "{header_level} [`{name}`](#{parents_anchor}_{name}) {{: #{parents_anchor}_{name} }}\n" - )); + let _ = + writeln!(output, + "{header_level} [`{name}`](#{parents_anchor}_{name}) {{: #{parents_anchor}_{name} }}" + ); // the anchor used to just be the name, but now it's the group name // for backwards compatibility, we need to keep the old anchor - output.push_str(&format!("\n")); + let _ = writeln!(output, ""); } output.push('\n'); @@ -132,9 +131,9 @@ fn emit_field(output: &mut String, name: &str, field: &OptionField, parents: &[S output.push_str(field.doc); output.push_str("\n\n"); - output.push_str(&format!("**Default value**: `{}`\n", field.default)); + let _ = writeln!(output, "**Default value**: `{}`", field.default); output.push('\n'); - output.push_str(&format!("**Type**: `{}`\n", field.value_type)); + let _ = writeln!(output, "**Type**: `{}`", field.value_type); output.push('\n'); output.push_str("**Example usage**:\n\n"); output.push_str(&format_tab( diff --git a/crates/ruff_dev/src/generate_rules_table.rs b/crates/ruff_dev/src/generate_rules_table.rs index 9923ed1a848a0..35723bae076bf 100644 --- a/crates/ruff_dev/src/generate_rules_table.rs +++ b/crates/ruff_dev/src/generate_rules_table.rs @@ -5,6 +5,7 @@ use itertools::Itertools; use ruff_linter::codes::RuleGroup; use std::borrow::Cow; +use std::fmt::Write; use strum::IntoEnumIterator; use ruff_diagnostics::FixAvailability; @@ -78,7 +79,8 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator, } #[allow(clippy::or_fun_call)] - table_out.push_str(&format!( + let _ = write!( + table_out, "| {ss}{0}{1}{se} {{ #{0}{1} }} | {ss}{2}{se} | {ss}{3}{se} | {ss}{4}{se} |", linter.common_prefix(), linter.code_for_rule(rule).unwrap(), @@ -88,7 +90,7 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator, .unwrap_or(format_args!("{rule_name}")), message, tokens, - )); + ); table_out.push('\n'); } table_out.push('\n'); @@ -101,29 +103,30 @@ pub(crate) fn generate() -> String { table_out.push_str("### Legend"); table_out.push('\n'); - table_out.push_str(&format!( + let _ = write!( + &mut table_out, "{SPACER}{STABLE_SYMBOL}{SPACER} The rule is stable." - )); + ); table_out.push_str("
"); - table_out.push_str(&format!( + let _ = write!(&mut table_out, "{SPACER}{PREVIEW_SYMBOL}{SPACER} The rule is unstable and is in [\"preview\"](faq.md#what-is-preview)." - )); + ); table_out.push_str("
"); - table_out.push_str(&format!( + let _ = write!(&mut table_out, "{SPACER}{WARNING_SYMBOL}{SPACER} The rule has been deprecated and will be removed in a future release." - )); + ); table_out.push_str("
"); - table_out.push_str(&format!( + let _ = write!(&mut table_out, "{SPACER}{REMOVED_SYMBOL}{SPACER} The rule has been removed only the documentation is available." - )); + ); table_out.push_str("
"); - table_out.push_str(&format!( + let _ = write!(&mut table_out, "{SPACER}{FIX_SYMBOL}{SPACER} The rule is automatically fixable by the `--fix` command-line option." - )); + ); table_out.push_str("
"); table_out.push('\n'); @@ -137,7 +140,7 @@ pub(crate) fn generate() -> String { .join(", "), prefix => prefix.to_string(), }; - table_out.push_str(&format!("### {} ({codes_csv})", linter.name())); + let _ = write!(&mut table_out, "### {} ({codes_csv})", linter.name()); table_out.push('\n'); table_out.push('\n'); @@ -147,7 +150,8 @@ pub(crate) fn generate() -> String { .split('/') .next() .unwrap(); - table_out.push_str(&format!( + let _ = write!( + table_out, "For more, see [{}]({}) on {}.", linter.name(), url, @@ -160,17 +164,18 @@ pub(crate) fn generate() -> String { linter.name() ), } - )); + ); table_out.push('\n'); table_out.push('\n'); } if Options::metadata().has(&format!("lint.{}", linter.name())) { - table_out.push_str(&format!( + let _ = write!( + table_out, "For related settings, see [{}](settings.md#lint{}).", linter.name(), linter.name(), - )); + ); table_out.push('\n'); table_out.push('\n'); } @@ -200,10 +205,10 @@ pub(crate) fn generate() -> String { let UpstreamCategoryAndPrefix { category, prefix } = opt.unwrap(); match codes_csv.as_str() { "PL" => { - table_out.push_str(&format!("#### {category} ({codes_csv}{prefix})")); + let _ = write!(table_out, "#### {category} ({codes_csv}{prefix})"); } _ => { - table_out.push_str(&format!("#### {category} ({prefix})")); + let _ = write!(table_out, "#### {category} ({prefix})"); } } } diff --git a/crates/ruff_formatter/src/format_element/document.rs b/crates/ruff_formatter/src/format_element/document.rs index cbdea125fdfc6..8236d92ee0ead 100644 --- a/crates/ruff_formatter/src/format_element/document.rs +++ b/crates/ruff_formatter/src/format_element/document.rs @@ -610,7 +610,7 @@ impl Format> for &[FormatElement] { } } - StartEntry | StartBestFittingEntry { .. } => { + StartEntry | StartBestFittingEntry => { // handled after the match for all start tags } EndEntry | EndBestFittingEntry => write!(f, [ContentArrayEnd])?, @@ -630,7 +630,7 @@ impl Format> for &[FormatElement] { | EndVerbatim => { write!(f, [ContentArrayEnd, token(")")])?; } - }; + } if tag.is_start() { write!(f, [ContentArrayStart])?; diff --git a/crates/ruff_formatter/src/format_element/tag.rs b/crates/ruff_formatter/src/format_element/tag.rs index 853008e516be6..bb3b7854641f9 100644 --- a/crates/ruff_formatter/src/format_element/tag.rs +++ b/crates/ruff_formatter/src/format_element/tag.rs @@ -144,7 +144,7 @@ impl Tag { StartVerbatim(_) | EndVerbatim => TagKind::Verbatim, StartLabelled(_) | EndLabelled => TagKind::Labelled, StartFitsExpanded { .. } | EndFitsExpanded => TagKind::FitsExpanded, - StartBestFittingEntry { .. } | EndBestFittingEntry => TagKind::BestFittingEntry, + StartBestFittingEntry | EndBestFittingEntry => TagKind::BestFittingEntry, StartBestFitParenthesize { .. } | EndBestFitParenthesize => { TagKind::BestFitParenthesize } diff --git a/crates/ruff_formatter/src/lib.rs b/crates/ruff_formatter/src/lib.rs index 337200cc0aaa8..f27ee19bec64a 100644 --- a/crates/ruff_formatter/src/lib.rs +++ b/crates/ruff_formatter/src/lib.rs @@ -7,10 +7,10 @@ //! //! * [`Format`]: Implemented by objects that can be formatted. //! * [`FormatRule`]: Rule that knows how to format an object of another type. Useful in the situation where -//! it's necessary to implement [Format] on an object from another crate. This module defines the -//! [`FormatRefWithRule`] and [`FormatOwnedWithRule`] structs to pass an item with its corresponding rule. +//! it's necessary to implement [Format] on an object from another crate. This module defines the +//! [`FormatRefWithRule`] and [`FormatOwnedWithRule`] structs to pass an item with its corresponding rule. //! * [`FormatWithRule`] implemented by objects that know how to format another type. Useful for implementing -//! some reusable formatting logic inside of this module if the type itself doesn't implement [Format] +//! some reusable formatting logic inside of this module if the type itself doesn't implement [Format] //! //! ## Formatting Macros //! diff --git a/crates/ruff_formatter/src/printer/mod.rs b/crates/ruff_formatter/src/printer/mod.rs index 4b7f7db9989b4..efdef79be46fc 100644 --- a/crates/ruff_formatter/src/printer/mod.rs +++ b/crates/ruff_formatter/src/printer/mod.rs @@ -362,9 +362,7 @@ impl<'a> Printer<'a> { stack.push(TagKind::FitsExpanded, args); } - FormatElement::Tag( - tag @ (StartLabelled(_) | StartEntry | StartBestFittingEntry { .. }), - ) => { + FormatElement::Tag(tag @ (StartLabelled(_) | StartEntry | StartBestFittingEntry)) => { stack.push(tag.kind(), args); } @@ -386,7 +384,7 @@ impl<'a> Printer<'a> { ) => { stack.pop(tag.kind())?; } - }; + } Ok(()) } @@ -1416,7 +1414,7 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> { | StartVerbatim(_) | StartLabelled(_) | StartEntry - | StartBestFittingEntry { .. }), + | StartBestFittingEntry), ) => { self.stack.push(tag.kind(), args); } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 7ccea7e5a5730..0dedf39da7354 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -1749,5 +1749,5 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { } } _ => {} - }; + } } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs index e378e070d6afb..744bb7c11d107 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs @@ -645,7 +645,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { } } if let Some(asname) = &alias.asname { - let name = alias.name.split('.').last().unwrap(); + let name = alias.name.split('.').next_back().unwrap(); if checker.enabled(Rule::ConstantImportedAsNonConstant) { if let Some(diagnostic) = pep8_naming::rules::constant_imported_as_non_constant( diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index fde85aa737db6..cd20506aa0225 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -1164,7 +1164,7 @@ impl<'a> Visitor<'a> for Checker<'a> { } } _ => visitor::walk_stmt(self, stmt), - }; + } if self.semantic().at_top_level() || self.semantic().current_scope().kind.is_class() { match stmt { @@ -1726,7 +1726,7 @@ impl<'a> Visitor<'a> for Checker<'a> { self.semantic.pop_scope(); } _ => {} - }; + } // Step 4: Analysis match expr { diff --git a/crates/ruff_linter/src/directives.rs b/crates/ruff_linter/src/directives.rs index b6e8752764465..71278963e9b69 100644 --- a/crates/ruff_linter/src/directives.rs +++ b/crates/ruff_linter/src/directives.rs @@ -320,7 +320,7 @@ impl<'a> TodoDirective<'a> { subset = &comment[relative_offset.to_usize()..]; } else { break; - }; + } } None diff --git a/crates/ruff_linter/src/fix/edits.rs b/crates/ruff_linter/src/fix/edits.rs index 991d3210a3a9a..3d9f08d35bd41 100644 --- a/crates/ruff_linter/src/fix/edits.rs +++ b/crates/ruff_linter/src/fix/edits.rs @@ -288,7 +288,7 @@ pub(crate) fn add_parameter(parameter: &str, parameters: &Parameters, source: &s .args .iter() .filter(|arg| arg.default.is_none()) - .last() + .next_back() { // Case 1: at least one regular parameter, so append after the last one. Edit::insertion(format!(", {parameter}"), last.end()) diff --git a/crates/ruff_linter/src/message/text.rs b/crates/ruff_linter/src/message/text.rs index db50e3d958454..914f12a075268 100644 --- a/crates/ruff_linter/src/message/text.rs +++ b/crates/ruff_linter/src/message/text.rs @@ -162,7 +162,7 @@ impl Display for RuleCodeAndBody<'_> { ); } } - }; + } if let Some(rule) = self.message.rule() { write!( diff --git a/crates/ruff_linter/src/noqa.rs b/crates/ruff_linter/src/noqa.rs index 8c7b34c625d9d..fc00468992a58 100644 --- a/crates/ruff_linter/src/noqa.rs +++ b/crates/ruff_linter/src/noqa.rs @@ -291,7 +291,7 @@ impl<'a> FileNoqaDirectives<'a> { warn!("Invalid `# ruff: noqa` directive at {path_display}:{line}: {err}"); } Ok(None) => {} - }; + } } Self(lines) } @@ -990,7 +990,7 @@ fn generate_noqa_edit<'a>( codes = Some(existing_codes); } Some(Directive::All(_)) => return None, - }; + } Some(NoqaEdit { edit_range, diff --git a/crates/ruff_linter/src/rule_selector.rs b/crates/ruff_linter/src/rule_selector.rs index 2ee25df5d0f0c..b433cad267bf4 100644 --- a/crates/ruff_linter/src/rule_selector.rs +++ b/crates/ruff_linter/src/rule_selector.rs @@ -216,8 +216,7 @@ impl RuleSelector { } // Deprecated rules are excluded in preview mode and with 'All' option unless explicitly selected RuleGroup::Deprecated => { - (!preview_enabled || self.is_exact()) - && !matches!(self, RuleSelector::All { .. }) + (!preview_enabled || self.is_exact()) && !matches!(self, RuleSelector::All) } // Removed rules are included if explicitly selected but will error downstream RuleGroup::Removed => self.is_exact(), diff --git a/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs b/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs index 991573d228078..3aaed2875160b 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs @@ -91,7 +91,7 @@ pub(crate) fn airflow_3_removal_expr(checker: &Checker, expr: &Expr) { ) => { if let Some(qualified_name) = checker.semantic().resolve_qualified_name(func) { check_call_arguments(checker, &qualified_name, arguments); - }; + } check_method(checker, call_expr); check_context_key_usage_in_call(checker, call_expr); } @@ -256,7 +256,7 @@ fn check_call_arguments(checker: &Checker, qualified_name: &QualifiedName, argum } } } - }; + } } /// Check whether a removed Airflow class attribute (include property) is called. @@ -930,7 +930,7 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) { let replacement_edit = Edit::range_replacement(binding, range); Ok(Fix::safe_edits(import_edit, [replacement_edit])) }); - }; + } checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs b/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs index d3034ecd10c96..e8dc02b490b6c 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs @@ -72,7 +72,7 @@ pub(crate) fn cancel_scope_no_checkpoint( None } }) - .last() + .next_back() else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs b/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs index 1665c9c41c74a..58d421316d317 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs @@ -78,7 +78,7 @@ pub(crate) fn sync_call(checker: &Checker, call: &ExprCall) { .is_some_and(Expr::is_await_expr) { return; - }; + } let mut diagnostic = Diagnostic::new(TrioSyncCall { method_name }, call.range); if checker.semantic().in_async_context() { diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs index f79868f0326be..486428d1ef1c2 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs @@ -70,5 +70,5 @@ pub(crate) fn hardcoded_bind_all_interfaces(checker: &Checker, string: StringLik } } StringLike::Bytes(_) => (), - }; + } } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs index 82108586fd5eb..deb208863d6a7 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs @@ -599,7 +599,7 @@ pub(crate) fn suspicious_imports(checker: &Checker, stmt: &Stmt) { } } _ => panic!("Expected Stmt::Import | Stmt::ImportFrom"), - }; + } } fn check_and_push_diagnostic(checker: &Checker, diagnostic_kind: DiagnosticKind, range: TextRange) { diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs index a69bc70209e59..37c67831ca4c2 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs @@ -97,7 +97,7 @@ pub(crate) fn assert_raises_exception(checker: &Checker, items: &[WithItem]) { && arguments.find_keyword("match").is_none()) { continue; - }; + } checker.report_diagnostic(Diagnostic::new( AssertRaisesException { exception }, diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs index 5d7f64a386b8a..90bed89adb98d 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs @@ -74,7 +74,7 @@ pub(crate) fn duplicate_value(checker: &Checker, set: &ast::ExprSet) { checker.report_diagnostic(diagnostic); } - }; + } } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs index d9ca9ae9e0b36..a828364f9c104 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs @@ -1,3 +1,5 @@ +use std::fmt::Write; + use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_docstring_stmt; @@ -160,14 +162,15 @@ fn move_initialization( // Add an `if`, to set the argument to its original value if still `None`. let mut content = String::new(); - content.push_str(&format!("if {} is None:", parameter.name())); + let _ = write!(&mut content, "if {} is None:", parameter.name()); content.push_str(stylist.line_ending().as_str()); content.push_str(stylist.indentation()); - content.push_str(&format!( + let _ = write!( + &mut content, "{} = {}", parameter.name(), generator.expr(default) - )); + ); content.push_str(stylist.line_ending().as_str()); // Determine the indentation depth of the function body. @@ -204,7 +207,7 @@ fn move_initialization( } } else { break; - }; + } } let initialization_edit = Edit::insertion(content, pos); diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs index 2c7fa1358959f..70c66f7a1699e 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs @@ -61,5 +61,5 @@ pub(crate) fn unintentional_type_annotation( } } _ => {} - }; + } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs index a30cb83b1f00a..62231f7e39529 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs @@ -426,7 +426,7 @@ pub(crate) fn fix_unnecessary_call_around_sorted( tree = Expression::Call(Box::new((*inner_call).clone())); if inner_needs_parens { tree = tree.with_parens(LeftParen::default(), RightParen::default()); - }; + } } else { // If the `reverse` argument is used... let args = if inner_call.args.iter().any(|arg| { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs index 77a1d98070390..a91c38f8c474c 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs @@ -79,7 +79,7 @@ pub(crate) fn unnecessary_subscript_reversal(checker: &Checker, call: &ast::Expr }; if *val != 1 { return; - }; + } let Some(function_name) = checker.semantic().resolve_builtin_symbol(&call.func) else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs index 708cb4a575f33..d4ef7a1203669 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs @@ -132,7 +132,7 @@ pub(crate) fn call_datetime_strptime_without_zone(checker: &Checker, call: &ast: } _ => {} } - }; + } let semantic = checker.semantic(); if let Some(antipattern) = find_antipattern( diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs b/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs index 0d4c62a5d4da3..3343dcd15af0b 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs @@ -95,7 +95,7 @@ pub(crate) fn all_with_model_form(checker: &Checker, class_def: &ast::StmtClassD } } _ => (), - }; + } } } } diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs index 9ebdc87538e8b..200a093265540 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs @@ -54,7 +54,7 @@ impl Violation for PrintfInGetTextFuncCall { pub(crate) fn printf_in_gettext_func_call(checker: &Checker, args: &[Expr]) { if let Some(first) = args.first() { if let Expr::BinOp(ast::ExprBinOp { - op: Operator::Mod { .. }, + op: Operator::Mod, left, .. }) = &first diff --git a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs index 8cbbcc18bf180..20d2e23e076df 100644 --- a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs +++ b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs @@ -160,7 +160,7 @@ pub(crate) fn implicit( } diagnostics.push(diagnostic); - }; + } } } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs index 8c2dc82b577ca..f95bf277885e4 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs @@ -63,12 +63,12 @@ pub(crate) fn unnecessary_range_start(checker: &Checker, call: &ast::ExprCall) { }; if *value != 0 { return; - }; + } // Verify that the call is to the `range` builtin. if !checker.semantic().match_builtin_expr(&call.func, "range") { return; - }; + } let mut diagnostic = Diagnostic::new(UnnecessaryRangeStart, start.range()); diagnostic.try_set_fix(|| { diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs index 809cc13ac76da..f10947217063f 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs @@ -209,7 +209,7 @@ pub(crate) fn bad_generator_return_type(function_def: &ast::StmtFunctionDef, che _ => return, } } - }; + } let mut diagnostic = Diagnostic::new( GeneratorReturnFromIterMethod { return_type: member.to_iter(), diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs index 10a6da538b0b0..81066c0027343 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs @@ -149,6 +149,6 @@ pub(crate) fn bad_version_info_comparison(checker: &Checker, test: &Expr, has_el } else { if checker.enabled(Rule::BadVersionInfoComparison) { checker.report_diagnostic(Diagnostic::new(BadVersionInfoComparison, test.range())); - }; + } } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs index c3190e0fb1242..fe968f534c3fe 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs @@ -107,7 +107,7 @@ pub(crate) fn duplicate_literal_member<'a>(checker: &Checker, expr: &'a Expr) { for diagnostic in &mut diagnostics { diagnostic.set_fix(fix.clone()); } - }; + } checker.report_diagnostics(diagnostics); } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs index f35b378916f83..397326755ef6a 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs @@ -47,7 +47,7 @@ pub(crate) fn from_future_import(checker: &Checker, target: &StmtImportFrom) { if module_name != "__future__" { return; - }; + } if names.iter().all(|alias| &*alias.name != "annotations") { return; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs index 6f3e1d6dbf3e2..96fb143c21752 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs @@ -73,7 +73,7 @@ pub(crate) fn prefix_type_params(checker: &Checker, value: &Expr, targets: &[Exp if id.starts_with('_') { return; } - }; + } let Expr::Call(ast::ExprCall { func, .. }) = value else { return; diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs index f655665060634..4b3f038f3e8c9 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs @@ -646,7 +646,7 @@ impl<'a> Visitor<'a> for SkipFunctionsVisitor<'a> { .is_some_and(|name| matches!(name.segments(), ["request", "addfinalizer"])) { self.addfinalizer_call = Some(expr); - }; + } visitor::walk_expr(self, expr); } _ => {} diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/imports.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/imports.rs index a77816d8477b0..830dd882bd937 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/imports.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/imports.rs @@ -59,7 +59,7 @@ pub(crate) fn import_from( // If level is not zero or module is none, return if level != 0 { return None; - }; + } if let Some(module) = module { if is_pytest_or_subpackage(module) { @@ -68,7 +68,7 @@ pub(crate) fn import_from( import_from.range(), )); } - }; + } None } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs index 44e54842cc57b..534f851bdd36f 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -458,7 +458,7 @@ fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr checker.report_diagnostic(diagnostic); } } - }; + } } Expr::List(ast::ExprList { elts, .. }) => { if elts.len() == 1 { @@ -505,7 +505,7 @@ fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr checker.report_diagnostic(diagnostic); } } - }; + } } _ => {} } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs index 568238894b65d..9f054ef51e004 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -195,7 +195,7 @@ pub(crate) fn if_expr_with_true_false( ), expr.range(), ))); - }; + } checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs index 94c851f58a0b1..45e163fb285ca 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs @@ -295,6 +295,6 @@ pub(crate) fn double_negation(checker: &Checker, expr: &Expr, op: UnaryOp, opera checker.generator().expr(&node1.into()), expr.range(), ))); - }; + } checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs index 9775e441482db..144bb43d4c8c6 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs @@ -114,7 +114,7 @@ pub(crate) fn if_else_block_instead_of_dict_lookup(checker: &Checker, stmt_if: & contains_effect(value, |id| checker.semantic().has_builtin_binding(id)) }) { return; - }; + } } // `elif` Some(Expr::Compare(ast::ExprCompare { @@ -140,7 +140,7 @@ pub(crate) fn if_else_block_instead_of_dict_lookup(checker: &Checker, stmt_if: & contains_effect(value, |id| checker.semantic().has_builtin_binding(id)) }) { return; - }; + } // The `expr` was checked to be a literal above, so this is safe. literals.insert(literal_expr.into()); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs index f1dc612919c22..6639392f19a4a 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs @@ -71,7 +71,7 @@ pub(crate) fn zip_dict_keys_and_values(checker: &Checker, expr: &ast::ExprCall) arg: Some(name), .. }] if name.as_str() == "strict" => {} _ => return, - }; + } let [arg1, arg2] = &args[..] else { return; }; diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs index edd1ccbb96641..011678ee112a7 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs @@ -128,7 +128,7 @@ pub(crate) fn banned_relative_import( fix_banned_relative_import(stmt, level, module, module_path, checker.generator()) { diagnostic.set_fix(fix); - }; + } Some(diagnostic) } else { None diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs b/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs index 40e24076632fe..259342e2b9a48 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs @@ -216,7 +216,7 @@ pub(crate) fn is_singledispatch_implementation( if attribute.attr.as_str() != "register" { return false; - }; + } let Some(id) = semantic.lookup_attribute(attribute.value.as_ref()) else { return false; diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs index 49244ba24065d..e8ab662f15451 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs @@ -74,7 +74,7 @@ pub(crate) fn os_sep_split(checker: &Checker, call: &ast::ExprCall) { if attr.as_str() != "split" { return; - }; + } // Match `.split(os.sep)` or `.split(sep=os.sep)`, but avoid cases in which a `maxsplit` is // specified. diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs index 9efa42132b9b4..5f9c89bbb6240 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs @@ -110,7 +110,7 @@ pub(crate) fn path_constructor_current_directory(checker: &Checker, call: &ExprC let edit = remove_argument(arg, arguments, Parentheses::Preserve, checker.source())?; Ok(Fix::applicable_edit(edit, applicability(call.range()))) }), - }; + } checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs index 1750f41de82e0..7d44916c89007 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs @@ -178,7 +178,7 @@ fn is_file_descriptor(expr: &Expr, semantic: &SemanticModel) -> bool { }) ) { return true; - }; + } let Some(name) = expr.as_name_expr() else { return false; diff --git a/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs b/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs index 64ad9889383a3..5fca95a4f7700 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs @@ -706,7 +706,7 @@ pub(crate) fn numpy_2_0_deprecation(checker: &Checker, expr: &Expr) { Edit::range_replacement(python_expr.to_string(), expr.range()), )), Details::Manual { guideline: _ } => {} - }; + } checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs index 93d44372c5b6b..396f50fdd3eb9 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs @@ -307,7 +307,7 @@ pub(crate) fn compound_statements( match_ = Some(token.range()); } _ => {} - }; + } } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs index a3e16837e2d7d..03b8e16c4dab7 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs @@ -175,7 +175,7 @@ pub(crate) fn missing_whitespace_around_operator( TokenKind::Lpar | TokenKind::Lambda => parens += 1, TokenKind::Rpar => parens = parens.saturating_sub(1), _ => {} - }; + } let needs_space = if kind == TokenKind::Equal && (parens > 0 || fstrings > 0 || definition_state.in_type_params()) diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/too_many_newlines_at_end_of_file.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/too_many_newlines_at_end_of_file.rs index d05d340e087a8..fb7ad77c476c3 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/too_many_newlines_at_end_of_file.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/too_many_newlines_at_end_of_file.rs @@ -68,7 +68,7 @@ pub(crate) fn too_many_newlines_at_end_of_file( diagnostics.extend(notebook_newline_diagnostics(tokens_iter, cell_offsets)); } else if let Some(diagnostic) = newline_diagnostic(&mut tokens_iter, false) { diagnostics.push(diagnostic); - }; + } } /// Collects trailing newline diagnostics for each cell @@ -127,7 +127,7 @@ fn newline_diagnostic<'a>( if num_trailing_newlines == 0 || num_trailing_newlines == 1 { return None; - }; + } let (start, end) = (match (newline_range_start, newline_range_end) { (Some(s), Some(e)) => Some((s, e)), diff --git a/crates/ruff_linter/src/rules/pydocstyle/helpers.rs b/crates/ruff_linter/src/rules/pydocstyle/helpers.rs index 405be36dc5291..93b47cfdad13f 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/helpers.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/helpers.rs @@ -119,7 +119,7 @@ pub(crate) fn get_section_contexts<'a>( Ordering::Greater => return google_sections, Ordering::Less => return numpy_sections, Ordering::Equal => {} - }; + } // 0 sections of either convention? Default to numpy if google_sections.len() == 0 { diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs index e58c8bea68e06..d9368797647ac 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs @@ -115,6 +115,6 @@ pub(crate) fn ends_with_period(checker: &Checker, docstring: &Docstring) { ))); } checker.report_diagnostic(diagnostic); - }; + } } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs index de70eb4bf5b96..b34f3c99feab1 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs @@ -114,6 +114,6 @@ pub(crate) fn ends_with_punctuation(checker: &Checker, docstring: &Docstring) { ))); } checker.report_diagnostic(diagnostic); - }; + } } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs index 03040e8686da1..f5f1829ea7bf9 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs @@ -146,7 +146,7 @@ pub(crate) fn multi_line_summary_start(checker: &Checker, docstring: &Docstring) .is_none() { return; - }; + } let mut content_lines = UniversalNewlineIterator::with_offset(docstring.contents(), docstring.start()); @@ -201,7 +201,7 @@ pub(crate) fn multi_line_summary_start(checker: &Checker, docstring: &Docstring) indentation.push_str(checker.stylist().indentation()); fixable = true; } - }; + } } if fixable { diff --git a/crates/ruff_linter/src/rules/pyflakes/cformat.rs b/crates/ruff_linter/src/rules/pyflakes/cformat.rs index 9fccc4788484a..311241b0ac53c 100644 --- a/crates/ruff_linter/src/rules/pyflakes/cformat.rs +++ b/crates/ruff_linter/src/rules/pyflakes/cformat.rs @@ -36,7 +36,7 @@ impl From<&CFormatString> for CFormatSummary { None => { num_positional += 1; } - }; + } if min_field_width == &Some(CFormatQuantity::FromValuesTuple) { num_positional += 1; starred = true; diff --git a/crates/ruff_linter/src/rules/pyflakes/format.rs b/crates/ruff_linter/src/rules/pyflakes/format.rs index f53d7acfa1b66..e19f58f627924 100644 --- a/crates/ruff_linter/src/rules/pyflakes/format.rs +++ b/crates/ruff_linter/src/rules/pyflakes/format.rs @@ -55,7 +55,7 @@ impl TryFrom<&str> for FormatSummary { FieldType::Auto => autos.push(autos.len()), FieldType::Index(i) => indices.push(i), FieldType::Keyword(k) => keywords.push(Name::from(k)), - }; + } let nested = FormatString::from_str(format_spec)?; for nested_part in nested.format_parts { @@ -67,7 +67,7 @@ impl TryFrom<&str> for FormatSummary { FieldType::Auto => autos.push(autos.len()), FieldType::Index(i) => indices.push(i), FieldType::Keyword(k) => keywords.push(Name::from(k)), - }; + } has_nested_parts = true; } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs index 9cf65152fc934..51b7ca0b7f481 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs @@ -80,7 +80,7 @@ pub(crate) fn bad_staticmethod_argument(checker: &Checker, scope: &Scope) { FunctionType::Function | FunctionType::Method | FunctionType::ClassMethod => { return; } - }; + } let Some(ParameterWithDefault { parameter: self_or_cls, diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs index 614aac6a126fe..8a3ee38847330 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs @@ -108,6 +108,6 @@ pub(crate) fn percent(checker: &Checker, expr: &Expr, format_string: &ExprString expr.range(), )); } - }; + } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs index f7bea6d481c5b..70e22b2e61bd4 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs @@ -230,7 +230,7 @@ pub(crate) fn bad_string_format_type( // Parse the format string (e.g. `"%s"`) into a list of `PercentFormat`. if let Ok(format_string) = CFormatString::from_str(string) { format_strings.push(format_string); - }; + } } // Parse the parameters. diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs index 63bc90ac70e8b..c42f7b8c5da95 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs @@ -72,6 +72,6 @@ pub(crate) fn comparison_of_constant( ); checker.report_diagnostic(diagnostic); - }; + } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs b/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs index d7c1af53b913f..f19d7e7eb71de 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs @@ -72,7 +72,7 @@ pub(crate) fn dict_iter_missing_items(checker: &Checker, target: &Expr, iter: &E if tuple.len() != 2 { return; - }; + } let Expr::Name(name) = iter else { return; diff --git a/crates/ruff_linter/src/rules/pylint/rules/logging.rs b/crates/ruff_linter/src/rules/pylint/rules/logging.rs index ad731e93f2cd6..359b0de4ec7df 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/logging.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/logging.rs @@ -105,7 +105,7 @@ pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { Expr::Attribute(ast::ExprAttribute { attr, .. }) => { if LoggingLevel::from_attribute(attr).is_none() { return; - }; + } if !logging::is_logger_candidate( &call.func, checker.semantic(), @@ -126,10 +126,10 @@ pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { }; if LoggingLevel::from_attribute(attribute).is_none() { return; - }; + } } _ => return, - }; + } let Some(Expr::StringLiteral(ast::ExprStringLiteral { value, .. })) = call.arguments.find_positional(0) diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs index a3b91e07cdaf1..8f6cd66d2041e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs @@ -135,16 +135,16 @@ fn get_undecorated_methods(checker: &Checker, class_stmt: &Stmt, method_type: &M if target_name == *id { explicit_decorator_calls.insert(id.clone(), stmt); } - }; + } } } } - }; + } } if explicit_decorator_calls.is_empty() { return; - }; + } for stmt in &class_def.body { if let Stmt::FunctionDef(ast::StmtFunctionDef { @@ -196,7 +196,7 @@ fn get_undecorated_methods(checker: &Checker, class_stmt: &Stmt, method_type: &M None => { continue; } - }; - }; + } + } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs index 2f18de205430b..d9e7647e30201 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs @@ -103,8 +103,8 @@ pub(crate) fn self_or_cls_assignment(checker: &Checker, target: &Expr) { ); let method_type = match (function_type, self_or_cls.name().as_str()) { - (FunctionType::Method { .. }, "self") => MethodType::Instance, - (FunctionType::ClassMethod { .. }, "cls") => MethodType::Class, + (FunctionType::Method, "self") => MethodType::Instance, + (FunctionType::ClassMethod, "cls") => MethodType::Class, (FunctionType::NewMethod, "cls") => MethodType::New, _ => return, }; diff --git a/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs b/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs index 1e33a383f93b4..7aeb5bbff898e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs @@ -101,9 +101,9 @@ pub(crate) fn super_without_brackets(checker: &Checker, func: &Expr) { ); if !matches!( classification, - function_type::FunctionType::Method { .. } - | function_type::FunctionType::ClassMethod { .. } - | function_type::FunctionType::StaticMethod { .. } + function_type::FunctionType::Method + | function_type::FunctionType::ClassMethod + | function_type::FunctionType::StaticMethod ) { return; } diff --git a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs index 49f788a800648..be59c46c5b771 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs @@ -79,7 +79,7 @@ pub(crate) fn sys_exit_alias(checker: &Checker, call: &ExprCall) { if call.arguments.len() > 1 || has_star_kwargs { checker.report_diagnostic(diagnostic); return; - }; + } diagnostic.try_set_fix(|| { let (import_edit, binding) = checker.importer().get_or_import_symbol( @@ -94,7 +94,7 @@ pub(crate) fn sys_exit_alias(checker: &Checker, call: &ExprCall) { checker.source()[kwarg.value.range()].to_string(), kwarg.range, )); - }; + } Ok(Fix::unsafe_edits(import_edit, edits)) }); checker.report_diagnostic(diagnostic); diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs index a144b81098908..3c87cf02df4b2 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs @@ -54,6 +54,6 @@ pub(crate) fn too_many_locals(checker: &Checker, scope: &Scope) { }, func.identifier(), )); - }; + } } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs index bb4775908c043..28163c94fc367 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs @@ -208,7 +208,7 @@ pub(crate) fn unnecessary_dunder_call(checker: &Checker, call: &ast::ExprCall) { fixed, call.range(), ))); - }; + } checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs index 513f391f53382..0143a026f58e6 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs @@ -85,7 +85,7 @@ pub(crate) fn useless_return( .is_none_or(|expr| expr.is_none_literal_expr()) { return; - }; + } // Finally: verify that there are no _other_ return statements in the function. let mut visitor = ReturnStatementVisitor::default(); diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs index e032bb6516814..001c0407ee473 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs @@ -527,6 +527,6 @@ pub(crate) fn f_strings(checker: &Checker, call: &ast::ExprCall, summary: &Forma call.range(), ))); } - }; + } checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs index 205b0219ca26f..986ce240c6205 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -1,4 +1,5 @@ use std::borrow::Cow; +use std::fmt::Write; use std::str::FromStr; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; @@ -501,7 +502,7 @@ pub(crate) fn printf_string_formatting( } // Add the `.format` call. - contents.push_str(&format!(".format{params_string}")); + let _ = write!(&mut contents, ".format{params_string}"); let mut diagnostic = Diagnostic::new(PrintfStringFormatting, bin_op.range()); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs index 3d7db1bdbd480..05216a7107582 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs @@ -124,7 +124,7 @@ pub(crate) fn replace_str_enum(checker: &Checker, class_def: &ast::StmtClassDef) // If the class does not inherit both `str` and `enum.Enum`, exit early. if !inherits_str || !inherits_enum { return; - }; + } let mut diagnostic = Diagnostic::new( ReplaceStrEnum { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs index 505ed8ffa522d..438e5055d8c3f 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs @@ -1,3 +1,5 @@ +use std::fmt::Write as _; + use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; @@ -129,10 +131,11 @@ fn replace_with_bytes_literal(locator: &Locator, call: &ast::ExprCall, tokens: & TokenKind::String => { replacement.push_str(locator.slice(TextRange::new(prev, token.start()))); let string = locator.slice(token); - replacement.push_str(&format!( + let _ = write!( + &mut replacement, "b{}", &string.trim_start_matches('u').trim_start_matches('U') - )); + ); } _ => { replacement.push_str(locator.slice(TextRange::new(prev, token.end()))); diff --git a/crates/ruff_linter/src/rules/refurb/helpers.rs b/crates/ruff_linter/src/rules/refurb/helpers.rs index d3a96b908f63f..54ca98a586e2f 100644 --- a/crates/ruff_linter/src/rules/refurb/helpers.rs +++ b/crates/ruff_linter/src/rules/refurb/helpers.rs @@ -283,7 +283,7 @@ fn match_open_keywords( // All other keywords cannot be directly forwarded. _ => return None, - }; + } } Some((result, mode)) } diff --git a/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs b/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs index a5b99e89ff826..863ea3cdd4c08 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs @@ -74,7 +74,7 @@ pub(crate) fn bit_count(checker: &Checker, call: &ExprCall) { if !call.arguments.keywords.is_empty() { return; - }; + } let [arg] = &*call.arguments.args else { return; }; @@ -100,7 +100,7 @@ pub(crate) fn bit_count(checker: &Checker, call: &ExprCall) { if !arguments.keywords.is_empty() { return; - }; + } let [arg] = &*arguments.args else { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs index 55c1c3e93eb7c..446ec88a2543a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs @@ -102,7 +102,7 @@ pub(crate) fn check_and_remove_from_set(checker: &Checker, if_stmt: &ast::StmtIf .is_some_and(|binding| is_set(binding, checker.semantic())) { return; - }; + } let mut diagnostic = Diagnostic::new( CheckAndRemoveFromSet { diff --git a/crates/ruff_linter/src/rules/refurb/rules/fromisoformat_replace_z.rs b/crates/ruff_linter/src/rules/refurb/rules/fromisoformat_replace_z.rs index b89dcb7c6c7e2..f5b5e6e790e5b 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/fromisoformat_replace_z.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/fromisoformat_replace_z.rs @@ -160,7 +160,7 @@ impl<'a> ReplaceTimeZone<'a> { if !arguments.keywords.is_empty() { return None; - }; + } let ExprAttribute { value, attr, .. } = call.func.as_attribute_expr()?; diff --git a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs index c3995008c728c..b6dcaec72dfdf 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs @@ -182,7 +182,7 @@ fn extract_name_from_sliced_reversed(expr: &Expr) -> Option<&ExprName> { .is_none_or(|value| value != 1) { return None; - }; + } value.as_name_expr() } diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs index ba771643a50a1..d7d327a561185 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs @@ -273,7 +273,7 @@ fn itemgetter_op(expr: &ExprSubscript, params: &Parameters, locator: &Locator) - // The argument to the lambda must match the subscripted value, as in: `lambda x: x[1]`. if !is_same_expression(arg, &expr.value) { return None; - }; + } // The subscripted expression can't contain references to the argument, as in: `lambda x: x[x]`. if any_over_expr(expr.slice.as_ref(), &|expr| is_same_expression(arg, expr)) { diff --git a/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs b/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs index 1314978dc55b5..14de99b09be6c 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs @@ -184,7 +184,7 @@ fn affix_removal_data_stmt(if_stmt: &ast::StmtIf) -> Option { // ``` if !elif_else_clauses.is_empty() { return None; - }; + } // Cannot safely transform, e.g., // ```python @@ -265,7 +265,7 @@ fn affix_removal_data<'a>( }) { return None; - }; + } let compr_test_expr = ast::comparable::ComparableExpr::from( &test.as_call_expr()?.func.as_attribute_expr()?.value, diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs index 0d07fae3ce9a6..02f0de2c32fd5 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs @@ -109,10 +109,10 @@ pub(crate) fn unnecessary_from_float(checker: &Checker, call: &ExprCall) { 'short_circuit: { if !matches!(constructor, Constructor::Decimal) { break 'short_circuit; - }; + } if !(method_name == MethodName::FromFloat) { break 'short_circuit; - }; + } let Some(value) = (match method_name { MethodName::FromFloat => call.arguments.find_argument_value("f", 0), @@ -131,9 +131,9 @@ pub(crate) fn unnecessary_from_float(checker: &Checker, call: &ExprCall) { }; // Must have exactly one argument, which is a string literal. - if arguments.keywords.len() != 0 { + if !arguments.keywords.is_empty() { break 'short_circuit; - }; + } let [float] = arguments.args.as_ref() else { break 'short_circuit; }; @@ -150,7 +150,7 @@ pub(crate) fn unnecessary_from_float(checker: &Checker, call: &ExprCall) { // Must be a call to the `float` builtin. if !semantic.match_builtin_expr(func, "float") { break 'short_circuit; - }; + } let replacement = checker.locator().slice(float).to_string(); diagnostic.set_fix(Fix::safe_edits( diff --git a/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs b/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs index 02ca50dd3ee64..1b9a92801992a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs @@ -96,7 +96,7 @@ pub(crate) fn verbose_decimal_constructor(checker: &Checker, call: &ast::ExprCal // Early return if we now have an empty string // or a very long string: - if (rest.len() > PYTHONINTMAXSTRDIGITS) || (rest.len() == 0) { + if (rest.len() > PYTHONINTMAXSTRDIGITS) || (rest.is_empty()) { return; } @@ -106,7 +106,7 @@ pub(crate) fn verbose_decimal_constructor(checker: &Checker, call: &ast::ExprCal // Verify that the rest of the string is a valid integer. if !rest.bytes().all(|c| c.is_ascii_digit()) { return; - }; + } // If all the characters are zeros, then the value is zero. let rest = match (unary, rest.is_empty()) { @@ -140,12 +140,12 @@ pub(crate) fn verbose_decimal_constructor(checker: &Checker, call: &ast::ExprCal // Must be a call to the `float` builtin. if !checker.semantic().match_builtin_expr(func, "float") { return; - }; + } // Must have exactly one argument, which is a string literal. - if arguments.keywords.len() != 0 { + if !arguments.keywords.is_empty() { return; - }; + } let [float] = arguments.args.as_ref() else { return; }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/implicit_classvar_in_dataclass.rs b/crates/ruff_linter/src/rules/ruff/rules/implicit_classvar_in_dataclass.rs index 545ecf7e3998a..722086e96e399 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/implicit_classvar_in_dataclass.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/implicit_classvar_in_dataclass.rs @@ -71,7 +71,7 @@ pub(crate) fn implicit_class_var_in_dataclass(checker: &mut Checker, class_def: if !matches!(dataclass_kind, Some((DataclassKind::Stdlib, _))) { return; - }; + } for statement in &class_def.body { let Stmt::Assign(StmtAssign { targets, .. }) = statement else { diff --git a/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs b/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs index d4223508b41ff..3942fa6c5edf1 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs @@ -82,7 +82,7 @@ fn map_call_with_two_arguments<'a>( if !semantic.match_builtin_expr(func, "map") { return None; - }; + } Some((first, second)) } diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs index 341af13c67304..9cb5dba688e44 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs @@ -70,7 +70,7 @@ pub(crate) fn mutable_dataclass_default(checker: &Checker, class_def: &ast::Stmt if dataclass_kind(class_def, semantic).is_none() { return; - }; + } for statement in &class_def.body { let Stmt::AnnAssign(ast::StmtAnnAssign { diff --git a/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs b/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs index 76c58dec4797e..1aef814d3a9a0 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs @@ -93,6 +93,6 @@ pub(crate) fn parenthesize_chained_logical_operators(checker: &Checker, expr: &a } } _ => continue, - }; + } } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs index 105da2ac7fe95..53d4bf44cecd5 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs @@ -85,7 +85,7 @@ pub(crate) fn quadratic_list_summation(checker: &Checker, call: &ast::ExprCall) if !start_is_empty_list(arguments, semantic) { return; - }; + } let mut diagnostic = Diagnostic::new(QuadraticListSummation, *range); diagnostic.try_set_fix(|| convert_to_reduce(iterable, call, checker)); diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs index 4b89da7bc28a5..948e211190a67 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs @@ -84,7 +84,7 @@ pub(crate) fn unnecessary_nested_literal<'a>(checker: &Checker, literal_expr: &' // If the parent is not equal to the `literal_expr` then we know we are traversing recursively. if !AnyNodeRef::ptr_eq(parent.into(), literal_expr.into()) { is_nested = true; - }; + } }, checker.semantic(), literal_expr, @@ -133,7 +133,7 @@ pub(crate) fn unnecessary_nested_literal<'a>(checker: &Checker, literal_expr: &' }, ); diagnostic.set_fix(fix); - }; + } checker.report_diagnostic(diagnostic); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs index 89b08df619386..6edf01cc1ba7c 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_round.rs @@ -89,7 +89,7 @@ pub(crate) fn unnecessary_round(checker: &Checker, call: &ExprCall) { if checker.comment_ranges().intersects(call.range()) { applicability = Applicability::Unsafe; - }; + } let edit = unwrap_round_call(call, rounded, checker.semantic(), checker.locator()); let fix = Fix::applicable_edit(edit, applicability); diff --git a/crates/ruff_linter/src/rules/tryceratops/helpers.rs b/crates/ruff_linter/src/rules/tryceratops/helpers.rs index f38ca0b16c50e..da30bfe23c25d 100644 --- a/crates/ruff_linter/src/rules/tryceratops/helpers.rs +++ b/crates/ruff_linter/src/rules/tryceratops/helpers.rs @@ -31,7 +31,7 @@ impl<'b> Visitor<'b> for LoggerCandidateVisitor<'_, 'b> { { if let Some(logging_level) = LoggingLevel::from_attribute(attr) { self.calls.push((call, logging_level)); - }; + } } } Expr::Name(_) => { diff --git a/crates/ruff_macros/src/derive_message_formats.rs b/crates/ruff_macros/src/derive_message_formats.rs index 10571efb02d9b..3ee3826edf809 100644 --- a/crates/ruff_macros/src/derive_message_formats.rs +++ b/crates/ruff_macros/src/derive_message_formats.rs @@ -44,8 +44,8 @@ fn parse_expr(expr: &Expr, strings: &mut TokenStream) -> Result<(), TokenStream> return Err( quote_spanned!(expr.span() => compile_error!("prefer `String::to_string` over `format!` without arguments")), ); - }; - }; + } + } strings.extend(quote! {#first_token,}); Ok(()) } diff --git a/crates/ruff_notebook/src/notebook.rs b/crates/ruff_notebook/src/notebook.rs index 80018a3daa888..3c2855f6ffb29 100644 --- a/crates/ruff_notebook/src/notebook.rs +++ b/crates/ruff_notebook/src/notebook.rs @@ -5,10 +5,10 @@ use serde_json::error::Category; use std::cmp::Ordering; use std::collections::HashSet; use std::fs::File; +use std::io; use std::io::{BufReader, Cursor, Read, Seek, SeekFrom, Write}; use std::path::Path; use std::sync::OnceLock; -use std::{io, iter}; use thiserror::Error; use ruff_diagnostics::{SourceMap, SourceMarker}; @@ -340,9 +340,10 @@ impl Notebook { } } }; - row_to_cell.extend( - iter::repeat(OneIndexed::from_zero_indexed(cell_index as usize)).take(line_count), - ); + row_to_cell.extend(std::iter::repeat_n( + OneIndexed::from_zero_indexed(cell_index as usize), + line_count, + )); row_to_row_in_cell.extend((0..line_count).map(OneIndexed::from_zero_indexed)); } diff --git a/crates/ruff_python_ast/src/identifier.rs b/crates/ruff_python_ast/src/identifier.rs index 566b9c79251be..8a4478c1f274a 100644 --- a/crates/ruff_python_ast/src/identifier.rs +++ b/crates/ruff_python_ast/src/identifier.rs @@ -207,7 +207,7 @@ impl<'a> IdentifierTokenizer<'a> { _ => { // Nothing to do. } - }; + } } None diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index 0b0acd6c36cf9..128d3164f18d3 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -322,10 +322,10 @@ impl ast::StmtRaise { if let Some(expr) = exc { visitor.visit_expr(expr); - }; + } if let Some(expr) = cause { visitor.visit_expr(expr); - }; + } } } diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 40631fc8f967b..0146903c6c9bb 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -1522,7 +1522,7 @@ impl BytesLiteralFlags { self.0 .set(BytesLiteralFlagsInner::R_PREFIX_LOWER, !uppercase_r); } - }; + } self } @@ -1749,7 +1749,7 @@ impl AnyStringFlags { match quotes { Quote::Double => self.0 |= AnyStringFlagsInner::DOUBLE, Quote::Single => self.0 -= AnyStringFlagsInner::DOUBLE, - }; + } self } diff --git a/crates/ruff_python_ast/src/visitor.rs b/crates/ruff_python_ast/src/visitor.rs index 0f16af535461c..6d9bb92cef968 100644 --- a/crates/ruff_python_ast/src/visitor.rs +++ b/crates/ruff_python_ast/src/visitor.rs @@ -276,10 +276,10 @@ pub fn walk_stmt<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, stmt: &'a Stmt) { }) => { if let Some(expr) = exc { visitor.visit_expr(expr); - }; + } if let Some(expr) = cause { visitor.visit_expr(expr); - }; + } } Stmt::Try(ast::StmtTry { body, diff --git a/crates/ruff_python_ast/src/visitor/transformer.rs b/crates/ruff_python_ast/src/visitor/transformer.rs index bc48c1bd95f70..dad507c53e34f 100644 --- a/crates/ruff_python_ast/src/visitor/transformer.rs +++ b/crates/ruff_python_ast/src/visitor/transformer.rs @@ -263,10 +263,10 @@ pub fn walk_stmt(visitor: &V, stmt: &mut Stmt) { }) => { if let Some(expr) = exc { visitor.visit_expr(expr); - }; + } if let Some(expr) = cause { visitor.visit_expr(expr); - }; + } } Stmt::Try(ast::StmtTry { body, diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index 6df104a02f0b0..11217c7ff3528 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -1170,7 +1170,7 @@ impl<'a> Generator<'a> { } else { self.unparse_expr(value, precedence::MAX); self.p("."); - }; + } self.p_id(attr); } Expr::Subscript(ast::ExprSubscript { value, slice, .. }) => { diff --git a/crates/ruff_python_formatter/src/builders.rs b/crates/ruff_python_formatter/src/builders.rs index 8c50d70c22cb9..86cabaea091e2 100644 --- a/crates/ruff_python_formatter/src/builders.rs +++ b/crates/ruff_python_formatter/src/builders.rs @@ -42,7 +42,7 @@ impl<'ast> Format> for ParenthesizeIfExpands<'_, 'ast> { soft_block_indent(&Arguments::from(&self.inner)).fmt(f)?; } else { Arguments::from(&self.inner).fmt(f)?; - }; + } if_group_breaks(&token(")")).fmt(f) }))] diff --git a/crates/ruff_python_formatter/src/comments/placement.rs b/crates/ruff_python_formatter/src/comments/placement.rs index cf5316af5be77..db58d1402c0ee 100644 --- a/crates/ruff_python_formatter/src/comments/placement.rs +++ b/crates/ruff_python_formatter/src/comments/placement.rs @@ -273,7 +273,7 @@ fn handle_enclosed_comment<'a>( .any(|token| token.kind() == SimpleTokenKind::LBracket) { return CommentPlacement::Default(comment); - }; + } // If there are no additional tokens between the open parenthesis and the comment, then // it should be attached as a dangling comment on the brackets, rather than a leading @@ -1393,7 +1393,7 @@ fn handle_attribute_comment<'a>( { if comment.start() < right_paren.start() { return CommentPlacement::trailing(attribute.value.as_ref(), comment); - }; + } } // If the comment precedes the `.`, treat it as trailing _if_ it's on the same line as the @@ -1648,7 +1648,7 @@ fn handle_pattern_match_mapping_comment<'a>( // like `rest` above, isn't a node.) if comment.following_node().is_some() { return CommentPlacement::Default(comment); - }; + } // If there's no rest pattern, no need to do anything special. let Some(rest) = pattern.rest.as_ref() else { diff --git a/crates/ruff_python_formatter/src/comments/visitor.rs b/crates/ruff_python_formatter/src/comments/visitor.rs index d0f146a3f725b..b9670a3ee829a 100644 --- a/crates/ruff_python_formatter/src/comments/visitor.rs +++ b/crates/ruff_python_formatter/src/comments/visitor.rs @@ -363,7 +363,7 @@ pub(super) enum CommentPlacement<'a> { /// Makes the comment a... /// /// * [trailing comment] of the [`preceding_node`] if both the [`following_node`] and [`preceding_node`] are not [None] - /// and the comment and [`preceding_node`] are only separated by a space (there's no token between the comment and [`preceding_node`]). + /// and the comment and [`preceding_node`] are only separated by a space (there's no token between the comment and [`preceding_node`]). /// * [leading comment] of the [`following_node`] if the [`following_node`] is not [None] /// * [trailing comment] of the [`preceding_node`] if the [`preceding_node`] is not [None] /// * [dangling comment] of the [`enclosing_node`]. diff --git a/crates/ruff_python_formatter/src/expression/mod.rs b/crates/ruff_python_formatter/src/expression/mod.rs index 97182fc44401a..d1a1777362f29 100644 --- a/crates/ruff_python_formatter/src/expression/mod.rs +++ b/crates/ruff_python_formatter/src/expression/mod.rs @@ -518,8 +518,8 @@ impl<'ast> IntoFormat> for Expr { /// /// We prefer parentheses at least in the following cases: /// * The expression contains more than one unparenthesized expression with the same precedence. For example, -/// the expression `a * b * c` contains two multiply operations. We prefer parentheses in that case. -/// `(a * b) * c` or `a * b + c` are okay, because the subexpression is parenthesized, or the expression uses operands with a lower precedence +/// the expression `a * b * c` contains two multiply operations. We prefer parentheses in that case. +/// `(a * b) * c` or `a * b + c` are okay, because the subexpression is parenthesized, or the expression uses operands with a lower precedence /// * The expression contains at least one parenthesized sub expression (optimization to avoid unnecessary work) /// /// This mimics Black's [`_maybe_split_omitting_optional_parens`](https://github.com/psf/black/blob/d1248ca9beaf0ba526d265f4108836d89cf551b7/src/black/linegen.py#L746-L820) @@ -787,7 +787,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> { | Expr::IpyEscapeCommand(_) => { return; } - }; + } walk_expr(self, expr); } diff --git a/crates/ruff_python_formatter/src/string/docstring.rs b/crates/ruff_python_formatter/src/string/docstring.rs index ef6aaa190242f..2bdd99936a1b5 100644 --- a/crates/ruff_python_formatter/src/string/docstring.rs +++ b/crates/ruff_python_formatter/src/string/docstring.rs @@ -459,7 +459,7 @@ impl<'src> DocstringLinePrinter<'_, '_, '_, 'src> { Indentation::from_str(trim_end).columns() - self.stripped_indentation.columns(); let in_docstring_indent = " ".repeat(indent_len) + trim_end.trim_start(); text(&in_docstring_indent).fmt(self.f)?; - }; + } // We handled the case that the closing quotes are on their own line // above (the last line is empty except for whitespace). If they are on diff --git a/crates/ruff_python_formatter/src/string/normalize.rs b/crates/ruff_python_formatter/src/string/normalize.rs index 0c3e0cb6f3975..7ebc3929053dd 100644 --- a/crates/ruff_python_formatter/src/string/normalize.rs +++ b/crates/ruff_python_formatter/src/string/normalize.rs @@ -679,7 +679,7 @@ pub(crate) fn normalize_string( output.push_str(&input[last_index..escape_start_offset]); output.push_str(normalised); last_index = escape_start_offset + normalised.len(); - }; + } // Move the `chars` iterator passed the escape sequence. // Simply reassigning `chars` doesn't work because the indices` would diff --git a/crates/ruff_python_formatter/src/verbatim.rs b/crates/ruff_python_formatter/src/verbatim.rs index 6aac70efeac07..2f60a7abc81b5 100644 --- a/crates/ruff_python_formatter/src/verbatim.rs +++ b/crates/ruff_python_formatter/src/verbatim.rs @@ -478,7 +478,7 @@ enum SuppressionComments<'a> { /// Any following `fmt: off` comment if any. /// * `None`: The suppression ends here (for good) /// * `Some`: A `fmt: off`..`fmt: on` .. `fmt: off` sequence. The suppression continues after - /// the `fmt: off` comment. + /// the `fmt: off` comment. format_off_comment: Option<&'a SourceComment>, }, diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index f03630a92435b..4b529855aad96 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -290,7 +290,7 @@ impl<'src> Lexer<'src> { LexicalErrorType::IndentationError, self.token_range(), ))); - }; + } // The lexer might've eaten some whitespaces to calculate the `indentation`. For // example: @@ -1071,7 +1071,7 @@ impl<'src> Lexer<'src> { if first_digit_or_dot != '.' { number.push(first_digit_or_dot); self.radix_run(&mut number, Radix::Decimal); - }; + } let is_float = if first_digit_or_dot == '.' || self.cursor.eat_char('.') { number.push('.'); diff --git a/crates/ruff_python_parser/src/parser/expression.rs b/crates/ruff_python_parser/src/parser/expression.rs index bbb26751a6b5a..3ccfb9935123a 100644 --- a/crates/ruff_python_parser/src/parser/expression.rs +++ b/crates/ruff_python_parser/src/parser/expression.rs @@ -891,7 +891,7 @@ impl<'src> Parser<'src> { elt.range(), ); } - }; + } ast::ExprSubscript { value: Box::new(value), @@ -1462,7 +1462,7 @@ impl<'src> Parser<'src> { UnsupportedSyntaxErrorKind::Pep701FString(FStringKind::NestedQuote), TextRange::at(expr.range.start() + quote_position, quote_len), ); - }; + } } self.check_fstring_comments(range); @@ -2114,7 +2114,7 @@ impl<'src> Parser<'src> { self.expect(TokenKind::For); } else { self.bump(TokenKind::For); - }; + } let mut target = self.parse_expression_list(ExpressionContext::starred_conditional().with_in_excluded()); diff --git a/crates/ruff_python_parser/src/parser/statement.rs b/crates/ruff_python_parser/src/parser/statement.rs index 46016e6aabffe..a0fb724a034f5 100644 --- a/crates/ruff_python_parser/src/parser/statement.rs +++ b/crates/ruff_python_parser/src/parser/statement.rs @@ -1,5 +1,5 @@ use compact_str::CompactString; -use std::fmt::Display; +use std::fmt::{Display, Write}; use rustc_hash::{FxBuildHasher, FxHashSet}; @@ -1028,7 +1028,7 @@ impl<'src> Parser<'src> { .. }) = &**slice { - buffer.push_str(&format!("{integer}")); + let _ = write!(buffer, "{integer}"); } else { parser.add_error( ParseErrorType::OtherError( diff --git a/crates/ruff_python_parser/src/semantic_errors.rs b/crates/ruff_python_parser/src/semantic_errors.rs index 4aa7fbeff36c6..fba092d52c78d 100644 --- a/crates/ruff_python_parser/src/semantic_errors.rs +++ b/crates/ruff_python_parser/src/semantic_errors.rs @@ -449,7 +449,7 @@ impl SemanticSyntaxChecker { } } _ => {} - }; + } } // PLE0118 @@ -781,7 +781,7 @@ impl Visitor<'_> for ReboundComprehensionVisitor<'_> { }) { self.rebound_variables.push(*range); } - }; + } } walk_expr(self, expr); } diff --git a/crates/ruff_python_resolver/src/native_module.rs b/crates/ruff_python_resolver/src/native_module.rs index fe4f41276aa23..6cb0b97efce65 100644 --- a/crates/ruff_python_resolver/src/native_module.rs +++ b/crates/ruff_python_resolver/src/native_module.rs @@ -31,7 +31,7 @@ pub(crate) fn is_native_module_file_name(module_name: &str, file_name: &Path) -> .is_some_and(is_native_module_file_extension) { return false; - }; + } // The file must represent the module name. native_module_name(file_name) == Some(module_name) diff --git a/crates/ruff_python_semantic/src/analyze/function_type.rs b/crates/ruff_python_semantic/src/analyze/function_type.rs index 49dd3d089d3b3..be9cac6c60c13 100644 --- a/crates/ruff_python_semantic/src/analyze/function_type.rs +++ b/crates/ruff_python_semantic/src/analyze/function_type.rs @@ -27,7 +27,7 @@ pub fn classify( ) -> FunctionType { if !parent_scope.kind.is_class() { return FunctionType::Function; - }; + } if decorator_list .iter() .any(|decorator| is_static_method(decorator, semantic, staticmethod_decorators)) diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index 2c2be80283cb0..9b1f1c43f9a58 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -1231,7 +1231,7 @@ fn match_target<'a>(binding: &Binding, targets: &[Expr], values: &'a [Expr]) -> } } _ => (), - }; + } } Expr::Name(name) => { if name.range() == binding.range() { diff --git a/crates/ruff_server/src/server/api/requests/hover.rs b/crates/ruff_server/src/server/api/requests/hover.rs index 04aeaa53f0a97..02e698ccd4466 100644 --- a/crates/ruff_server/src/server/api/requests/hover.rs +++ b/crates/ruff_server/src/server/api/requests/hover.rs @@ -6,6 +6,7 @@ use regex::Regex; use ruff_diagnostics::FixAvailability; use ruff_linter::registry::{Linter, Rule, RuleNamespace}; use ruff_source_file::OneIndexed; +use std::fmt::Write; pub(crate) struct Hover; @@ -84,12 +85,16 @@ pub(crate) fn hover( fn format_rule_text(rule: Rule) -> String { let mut output = String::new(); - output.push_str(&format!("# {} ({})", rule.as_ref(), rule.noqa_code())); + let _ = write!(&mut output, "# {} ({})", rule.as_ref(), rule.noqa_code()); output.push('\n'); output.push('\n'); let (linter, _) = Linter::parse_code(&rule.noqa_code().to_string()).unwrap(); - output.push_str(&format!("Derived from the **{}** linter.", linter.name())); + let _ = write!( + &mut output, + "Derived from the **{}** linter.", + linter.name() + ); output.push('\n'); output.push('\n'); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c5794a6b87c9a..e7f22fb8ba993 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.85" +channel = "1.86"