Skip to content

Commit

Permalink
clean up to fix nightly clippy warnings and dedents (#3057)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Feb 20, 2023
1 parent 3ad257c commit 35606d7
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 211 deletions.
9 changes: 5 additions & 4 deletions crates/ruff/src/ast/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,14 @@ pub fn locate_cmpops(contents: &str) -> Vec<LocatedCmpop> {
ops.push(LocatedCmpop::new(start, end, Cmpop::In));
}
Tok::Is => {
if let Some((_, _, end)) =
let op = if let Some((_, _, end)) =
tok_iter.next_if(|(_, tok, _)| matches!(tok, Tok::Not))
{
ops.push(LocatedCmpop::new(start, end, Cmpop::IsNot));
LocatedCmpop::new(start, end, Cmpop::IsNot)
} else {
ops.push(LocatedCmpop::new(start, end, Cmpop::Is));
}
LocatedCmpop::new(start, end, Cmpop::Is)
};
ops.push(op);
}
Tok::NotEqual => {
ops.push(LocatedCmpop::new(start, end, Cmpop::NotEq));
Expand Down
346 changes: 175 additions & 171 deletions crates/ruff/src/checkers/ast.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/ruff/src/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fn push_codes<I: Display>(str: &mut String, codes: impl Iterator<Item = I>) {
if !first {
str.push_str(", ");
}
let _ = write!(str, "{}", code);
let _ = write!(str, "{code}");
first = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
//! method()
//! ```

use std::iter;

use ruff_macros::{define_violation, derive_message_formats};
use rustc_hash::FxHashMap;
use rustpython_parser::ast::{Expr, ExprKind, Stmt};
Expand Down Expand Up @@ -174,27 +172,19 @@ pub fn unused_loop_control_variable(
if matches!(certainty, Certainty::Certain) && checker.patch(diagnostic.kind.rule()) {
// Find the `BindingKind::LoopVar` corresponding to the name.
let scope = checker.current_scope();
if let Some(binding) = iter::once(scope.bindings.get(name))
.flatten()
.chain(
iter::once(scope.rebounds.get(name))
.flatten()
.into_iter()
.flatten(),
)
let binding = scope
.bindings
.get(name)
.into_iter()
.chain(scope.rebounds.get(name).into_iter().flatten())
.find_map(|index| {
let binding = &checker.bindings[*index];
if let Some(source) = &binding.source {
if source == &RefEquality(stmt) {
Some(binding)
} else {
None
}
} else {
None
}
})
{
binding
.source
.as_ref()
.and_then(|source| (source == &RefEquality(stmt)).then_some(binding))
});
if let Some(binding) = binding {
if matches!(binding.kind, BindingKind::LoopVar) {
if !binding.used() {
diagnostic.amend(Fix::replacement(
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl ConfigProcessor for &Overrides {
.ignore
.iter()
.cloned()
.chain(self.extend_ignore.iter().cloned().into_iter())
.chain(self.extend_ignore.iter().cloned())
.flatten()
.collect(),
extend_select: self.extend_select.clone().unwrap_or_default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ fn print_fixed<T: Write>(stdout: &mut T, fixed: &FxHashMap<String, FixTable>) ->
);

let s = if total == 1 { "" } else { "s" };
let label = format!("Fixed {total} error{s}:", total = total, s = s);
let label = format!("Fixed {total} error{s}:");
writeln!(stdout, "{}", label.bold().green())?;

for (filename, table) in fixed
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_dev/src/generate_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ruff::settings::options::Options;
use ruff::settings::options_base::{ConfigurationOptions, OptionEntry, OptionField};

fn emit_field(output: &mut String, name: &str, field: &OptionField, group_name: Option<&str>) {
output.push_str(&format!("#### [`{0}`](#{0})\n", name));
output.push_str(&format!("#### [`{name}`](#{name})\n"));
output.push('\n');
output.push_str(field.doc);
output.push_str("\n\n");
Expand Down Expand Up @@ -40,7 +40,7 @@ pub fn generate() -> String {
// Generate all the sub-groups.
for (group_name, entry) in &sorted_options {
let OptionEntry::Group(fields) = entry else { continue; };
output.push_str(&format!("### `{}`\n", group_name));
output.push_str(&format!("### `{group_name}`\n"));
output.push('\n');
for (name, entry) in fields.iter().sorted_by_key(|(name, _)| name) {
let OptionEntry::Field(field) = entry else { continue; };
Expand Down
14 changes: 4 additions & 10 deletions crates/ruff_python_formatter/src/newlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,10 @@ impl<'a> Visitor<'a> for NewlineNormalizer {
let required_newlines = match self.trailer {
Trailer::FunctionDef | Trailer::ClassDef => self.depth.max_newlines(),
Trailer::Docstring if matches!(self.scope, Scope::Class) => 1,
Trailer::Import => {
if matches!(
stmt.node,
StmtKind::Import { .. } | StmtKind::ImportFrom { .. }
) {
0
} else {
1
}
}
Trailer::Import => usize::from(!matches!(
stmt.node,
StmtKind::Import { .. } | StmtKind::ImportFrom { .. }
)),
_ => 0,
};
let present_newlines = stmt
Expand Down

0 comments on commit 35606d7

Please sign in to comment.