Remove trailing punctuation from error messages (#983)

This commit is contained in:
Charlie Marsh 2022-12-01 12:25:37 -05:00 committed by GitHub
parent 6fe478cb43
commit 9e5df82578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 65 additions and 74 deletions

View file

@ -46,7 +46,7 @@ fn main() -> Result<()> {
// Extract the Flake8 section. // Extract the Flake8 section.
let flake8 = config let flake8 = config
.get("flake8") .get("flake8")
.expect("Unable to find flake8 section in INI file."); .expect("Unable to find flake8 section in INI file");
// Create the pyproject.toml. // Create the pyproject.toml.
let pyproject = converter::convert(flake8, cli.plugin)?; let pyproject = converter::convert(flake8, cli.plugin)?;

View file

@ -73,13 +73,13 @@ pub fn main(cli: &Cli) -> Result<()> {
// Extract the prefix. // Extract the prefix.
let index = existing let index = existing
.find(BEGIN_PRAGMA) .find(BEGIN_PRAGMA)
.expect("Unable to find begin pragma."); .expect("Unable to find begin pragma");
let prefix = &existing[..index + BEGIN_PRAGMA.len()]; let prefix = &existing[..index + BEGIN_PRAGMA.len()];
// Extract the suffix. // Extract the suffix.
let index = existing let index = existing
.find(END_PRAGMA) .find(END_PRAGMA)
.expect("Unable to find end pragma."); .expect("Unable to find end pragma");
let suffix = &existing[index..]; let suffix = &existing[index..];
// Write the prefix, new contents, and suffix. // Write the prefix, new contents, and suffix.

View file

@ -21,7 +21,7 @@ fn is_lone_child(child: &Stmt, parent: &Stmt, deleted: &[&Stmt]) -> Result<bool>
if body.iter().contains(child) { if body.iter().contains(child) {
Ok(has_single_child(body, deleted)) Ok(has_single_child(body, deleted))
} else { } else {
Err(anyhow::anyhow!("Unable to find child in parent body.")) Err(anyhow::anyhow!("Unable to find child in parent body"))
} }
} }
StmtKind::For { body, orelse, .. } StmtKind::For { body, orelse, .. }
@ -33,7 +33,7 @@ fn is_lone_child(child: &Stmt, parent: &Stmt, deleted: &[&Stmt]) -> Result<bool>
} else if orelse.iter().contains(child) { } else if orelse.iter().contains(child) {
Ok(has_single_child(orelse, deleted)) Ok(has_single_child(orelse, deleted))
} else { } else {
Err(anyhow::anyhow!("Unable to find child in parent body.")) Err(anyhow::anyhow!("Unable to find child in parent body"))
} }
} }
StmtKind::Try { StmtKind::Try {
@ -59,10 +59,10 @@ fn is_lone_child(child: &Stmt, parent: &Stmt, deleted: &[&Stmt]) -> Result<bool>
}) { }) {
Ok(has_single_child(body, deleted)) Ok(has_single_child(body, deleted))
} else { } else {
Err(anyhow::anyhow!("Unable to find child in parent body.")) Err(anyhow::anyhow!("Unable to find child in parent body"))
} }
} }
_ => Err(anyhow::anyhow!("Unable to find child in parent body.")), _ => Err(anyhow::anyhow!("Unable to find child in parent body")),
} }
} }

View file

@ -232,7 +232,7 @@ where
// Pre-visit. // Pre-visit.
match &stmt.node { match &stmt.node {
StmtKind::Global { names } => { StmtKind::Global { names } => {
let scope_index = *self.scope_stack.last().expect("No current scope found."); let scope_index = *self.scope_stack.last().expect("No current scope found");
if scope_index != GLOBAL_SCOPE_INDEX { if scope_index != GLOBAL_SCOPE_INDEX {
let scope = &mut self.scopes[scope_index]; let scope = &mut self.scopes[scope_index];
let usage = Some((scope.id, Range::from_located(stmt))); let usage = Some((scope.id, Range::from_located(stmt)));
@ -272,7 +272,7 @@ where
} }
} }
StmtKind::Nonlocal { names } => { StmtKind::Nonlocal { names } => {
let scope_index = *self.scope_stack.last().expect("No current scope found."); let scope_index = *self.scope_stack.last().expect("No current scope found");
if scope_index != GLOBAL_SCOPE_INDEX { if scope_index != GLOBAL_SCOPE_INDEX {
let scope = &mut self.scopes[scope_index]; let scope = &mut self.scopes[scope_index];
let usage = Some((scope.id, Range::from_located(stmt))); let usage = Some((scope.id, Range::from_located(stmt)));
@ -625,7 +625,7 @@ where
self.scopes[*(self self.scopes[*(self
.scope_stack .scope_stack
.last() .last()
.expect("No current scope found."))] .expect("No current scope found"))]
.id, .id,
Range::from_located(alias), Range::from_located(alias),
)) ))
@ -750,7 +750,7 @@ where
self.scopes[*(self self.scopes[*(self
.scope_stack .scope_stack
.last() .last()
.expect("No current scope found."))] .expect("No current scope found"))]
.id, .id,
Range::from_located(alias), Range::from_located(alias),
)), )),
@ -790,7 +790,7 @@ where
if self.settings.enabled.contains(&CheckCode::F406) { if self.settings.enabled.contains(&CheckCode::F406) {
let scope = &self.scopes let scope = &self.scopes
[*(self.scope_stack.last().expect("No current scope found."))]; [*(self.scope_stack.last().expect("No current scope found"))];
if !matches!(scope.kind, ScopeKind::Module) { if !matches!(scope.kind, ScopeKind::Module) {
self.add_check(Check::new( self.add_check(Check::new(
CheckKind::ImportStarNotPermitted(helpers::format_import_from( CheckKind::ImportStarNotPermitted(helpers::format_import_from(
@ -813,7 +813,7 @@ where
} }
let scope = &mut self.scopes let scope = &mut self.scopes
[*(self.scope_stack.last().expect("No current scope found."))]; [*(self.scope_stack.last().expect("No current scope found"))];
scope.import_starred = true; scope.import_starred = true;
} else { } else {
if let Some(asname) = &alias.node.asname { if let Some(asname) = &alias.node.asname {
@ -849,7 +849,7 @@ where
self.scopes[*(self self.scopes[*(self
.scope_stack .scope_stack
.last() .last()
.expect("No current scope found."))] .expect("No current scope found"))]
.id, .id,
range, range,
)) ))
@ -1657,7 +1657,7 @@ where
if let ExprKind::Name { id, ctx } = &func.node { if let ExprKind::Name { id, ctx } = &func.node {
if id == "locals" && matches!(ctx, ExprContext::Load) { if id == "locals" && matches!(ctx, ExprContext::Load) {
let scope = &mut self.scopes let scope = &mut self.scopes
[*(self.scope_stack.last().expect("No current scope found."))]; [*(self.scope_stack.last().expect("No current scope found"))];
if let ScopeKind::Function(inner) = &mut scope.kind { if let ScopeKind::Function(inner) = &mut scope.kind {
inner.uses_locals = true; inner.uses_locals = true;
} }
@ -2276,7 +2276,7 @@ where
if let Some(binding) = { if let Some(binding) = {
let scope = &mut self.scopes let scope = &mut self.scopes
[*(self.scope_stack.last().expect("No current scope found."))]; [*(self.scope_stack.last().expect("No current scope found"))];
&scope.values.remove(&name.as_str()) &scope.values.remove(&name.as_str())
} { } {
if binding.used.is_none() { if binding.used.is_none() {
@ -2291,7 +2291,7 @@ where
if let Some(binding) = definition { if let Some(binding) = definition {
let scope = &mut self.scopes let scope = &mut self.scopes
[*(self.scope_stack.last().expect("No current scope found."))]; [*(self.scope_stack.last().expect("No current scope found"))];
scope.values.insert(name, binding); scope.values.insert(name, binding);
} }
} }
@ -2433,7 +2433,7 @@ impl<'a> Checker<'a> {
fn pop_parent(&mut self) { fn pop_parent(&mut self) {
self.parent_stack self.parent_stack
.pop() .pop()
.expect("Attempted to pop without scope."); .expect("Attempted to pop without scope");
} }
fn push_scope(&mut self, scope: Scope<'a>) { fn push_scope(&mut self, scope: Scope<'a>) {
@ -2445,12 +2445,12 @@ impl<'a> Checker<'a> {
self.dead_scopes.push( self.dead_scopes.push(
self.scope_stack self.scope_stack
.pop() .pop()
.expect("Attempted to pop without scope."), .expect("Attempted to pop without scope"),
); );
} }
fn bind_builtins(&mut self) { fn bind_builtins(&mut self) {
let scope = &mut self.scopes[*(self.scope_stack.last().expect("No current scope found."))]; let scope = &mut self.scopes[*(self.scope_stack.last().expect("No current scope found"))];
for builtin in BUILTINS { for builtin in BUILTINS {
scope.values.insert( scope.values.insert(
@ -2475,7 +2475,7 @@ impl<'a> Checker<'a> {
} }
pub fn current_scope(&self) -> &Scope { pub fn current_scope(&self) -> &Scope {
&self.scopes[*(self.scope_stack.last().expect("No current scope found."))] &self.scopes[*(self.scope_stack.last().expect("No current scope found"))]
} }
pub fn current_scopes(&self) -> impl Iterator<Item = &Scope> { pub fn current_scopes(&self) -> impl Iterator<Item = &Scope> {
@ -2483,12 +2483,12 @@ impl<'a> Checker<'a> {
} }
pub fn current_parent(&self) -> &'a Stmt { pub fn current_parent(&self) -> &'a Stmt {
self.parents[*(self.parent_stack.last().expect("No parent found."))] self.parents[*(self.parent_stack.last().expect("No parent found"))]
} }
pub fn binding_context(&self) -> BindingContext { pub fn binding_context(&self) -> BindingContext {
let mut rev = self.parent_stack.iter().rev().fuse(); let mut rev = self.parent_stack.iter().rev().fuse();
let defined_by = *rev.next().expect("Expected to bind within a statement."); let defined_by = *rev.next().expect("Expected to bind within a statement");
let defined_in = rev.next().copied(); let defined_in = rev.next().copied();
BindingContext { BindingContext {
defined_by, defined_by,
@ -2536,7 +2536,7 @@ impl<'a> Checker<'a> {
}, },
}; };
let scope = &mut self.scopes[*(self.scope_stack.last().expect("No current scope found."))]; let scope = &mut self.scopes[*(self.scope_stack.last().expect("No current scope found"))];
scope.values.insert(name, binding); scope.values.insert(name, binding);
} }
@ -2743,7 +2743,7 @@ impl<'a> Checker<'a> {
} }
let scope = let scope =
&mut self.scopes[*(self.scope_stack.last().expect("No current scope found."))]; &mut self.scopes[*(self.scope_stack.last().expect("No current scope found"))];
if scope.values.remove(&id.as_str()).is_none() if scope.values.remove(&id.as_str()).is_none()
&& self.settings.enabled.contains(&CheckCode::F821) && self.settings.enabled.contains(&CheckCode::F821)
{ {
@ -2839,7 +2839,7 @@ impl<'a> Checker<'a> {
} }
self.deferred_assignments self.deferred_assignments
.push(*self.scope_stack.last().expect("No current scope found.")); .push(*self.scope_stack.last().expect("No current scope found"));
self.pop_scope(); self.pop_scope();
} }
@ -2857,7 +2857,7 @@ impl<'a> Checker<'a> {
} }
self.deferred_assignments self.deferred_assignments
.push(*self.scope_stack.last().expect("No current scope found.")); .push(*self.scope_stack.last().expect("No current scope found"));
self.pop_scope(); self.pop_scope();
} }

View file

@ -4,7 +4,7 @@ use libcst_native::{Expr, Module, SmallStatement, Statement};
pub fn match_module(module_text: &str) -> Result<Module> { pub fn match_module(module_text: &str) -> Result<Module> {
match libcst_native::parse_module(module_text, None) { match libcst_native::parse_module(module_text, None) {
Ok(module) => Ok(module), Ok(module) => Ok(module),
Err(_) => Err(anyhow::anyhow!("Failed to extract CST from source.")), Err(_) => Err(anyhow::anyhow!("Failed to extract CST from source")),
} }
} }
@ -13,9 +13,9 @@ pub fn match_expr<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut Expr<'b>
if let Some(SmallStatement::Expr(expr)) = expr.body.first_mut() { if let Some(SmallStatement::Expr(expr)) = expr.body.first_mut() {
Ok(expr) Ok(expr)
} else { } else {
Err(anyhow::anyhow!("Expected node to be: SmallStatement::Expr")) Err(anyhow::anyhow!("Expected SmallStatement::Expr"))
} }
} else { } else {
Err(anyhow::anyhow!("Expected node to be: Statement::Simple")) Err(anyhow::anyhow!("Expected Statement::Simple"))
} }
} }

View file

@ -45,9 +45,7 @@ fn match_tuple_range<T>(located: &Located<T>, locator: &SourceCodeLocator) -> Re
end_location, end_location,
}) })
} else { } else {
Err(anyhow::anyhow!( Err(anyhow::anyhow!("Unable to find left and right parentheses"))
"Unable to find left and right parentheses."
))
} }
} }

View file

@ -15,7 +15,7 @@ fn match_call<'a, 'b>(expr: &'a mut Expr<'b>) -> Result<&'a mut Call<'b>> {
if let Expression::Call(call) = &mut expr.value { if let Expression::Call(call) = &mut expr.value {
Ok(call) Ok(call)
} else { } else {
Err(anyhow::anyhow!("Expected node to be: Expression::Call")) Err(anyhow::anyhow!("Expected Expression::Call"))
} }
} }
@ -23,7 +23,7 @@ fn match_arg<'a, 'b>(call: &'a Call<'b>) -> Result<&'a Arg<'b>> {
if let Some(arg) = call.args.first() { if let Some(arg) = call.args.first() {
Ok(arg) Ok(arg)
} else { } else {
Err(anyhow::anyhow!("Expected node to be: Arg")) Err(anyhow::anyhow!("Expected Arg"))
} }
} }
@ -41,7 +41,7 @@ pub fn fix_unnecessary_generator_list(
let Expression::GeneratorExp(generator_exp) = &arg.value else { let Expression::GeneratorExp(generator_exp) = &arg.value else {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: Expression::GeneratorExp" "Expected Expression::GeneratorExp"
)); ));
}; };
@ -82,7 +82,7 @@ pub fn fix_unnecessary_generator_set(
let Expression::GeneratorExp(generator_exp) = &arg.value else { let Expression::GeneratorExp(generator_exp) = &arg.value else {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: Expression::GeneratorExp" "Expected Expression::GeneratorExp"
)); ));
}; };
@ -124,11 +124,11 @@ pub fn fix_unnecessary_generator_dict(
// Extract the (k, v) from `(k, v) for ...`. // Extract the (k, v) from `(k, v) for ...`.
let Expression::GeneratorExp(generator_exp) = &arg.value else { let Expression::GeneratorExp(generator_exp) = &arg.value else {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: Expression::GeneratorExp" "Expected Expression::GeneratorExp"
)); ));
}; };
let Expression::Tuple(tuple) = &generator_exp.elt.as_ref() else { let Expression::Tuple(tuple) = &generator_exp.elt.as_ref() else {
return Err(anyhow::anyhow!("Expected node to be: Expression::Tuple")); return Err(anyhow::anyhow!("Expected Expression::Tuple"));
}; };
let Some(Element::Simple { value: key, .. }) = &tuple.elements.get(0) else { let Some(Element::Simple { value: key, .. }) = &tuple.elements.get(0) else {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
@ -181,7 +181,7 @@ pub fn fix_unnecessary_list_comprehension_set(
let arg = match_arg(call)?; let arg = match_arg(call)?;
let Expression::ListComp(list_comp) = &arg.value else { let Expression::ListComp(list_comp) = &arg.value else {
return Err(anyhow::anyhow!("Expected node to be: Expression::ListComp")); return Err(anyhow::anyhow!("Expected Expression::ListComp"));
}; };
body.value = Expression::SetComp(Box::new(SetComp { body.value = Expression::SetComp(Box::new(SetComp {
@ -220,11 +220,11 @@ pub fn fix_unnecessary_list_comprehension_dict(
let arg = match_arg(call)?; let arg = match_arg(call)?;
let Expression::ListComp(list_comp) = &arg.value else { let Expression::ListComp(list_comp) = &arg.value else {
return Err(anyhow::anyhow!("Expected node to be: Expression::ListComp")); return Err(anyhow::anyhow!("Expected Expression::ListComp"));
}; };
let Expression::Tuple(tuple) = &*list_comp.elt else { let Expression::Tuple(tuple) = &*list_comp.elt else {
return Err(anyhow::anyhow!("Expected node to be: Expression::Tuple")); return Err(anyhow::anyhow!("Expected Expression::Tuple"));
}; };
let [Element::Simple { let [Element::Simple {
@ -275,7 +275,7 @@ pub fn fix_unnecessary_literal_set(
Expression::List(inner) => &inner.elements, Expression::List(inner) => &inner.elements,
_ => { _ => {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: Expression::Tuple | Expression::List" "Expected Expression::Tuple | Expression::List"
)) ))
} }
}; };
@ -323,7 +323,7 @@ pub fn fix_unnecessary_literal_dict(
Expression::List(inner) => &inner.elements, Expression::List(inner) => &inner.elements,
_ => { _ => {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: Expression::Tuple | Expression::List" "Expected Expression::Tuple | Expression::List"
)) ))
} }
}; };
@ -389,7 +389,7 @@ pub fn fix_unnecessary_collection_call(
let mut body = match_expr(&mut tree)?; let mut body = match_expr(&mut tree)?;
let call = match_call(body)?; let call = match_call(body)?;
let Expression::Name(name) = &call.func.as_ref() else { let Expression::Name(name) = &call.func.as_ref() else {
return Err(anyhow::anyhow!("Expected node to be: Expression::Name")); return Err(anyhow::anyhow!("Expected Expression::Name"));
}; };
// Arena allocator used to create formatted strings of sufficient lifetime, // Arena allocator used to create formatted strings of sufficient lifetime,
@ -520,7 +520,7 @@ pub fn fix_unnecessary_literal_within_tuple_call(
), ),
_ => { _ => {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: Expression::Tuple | Expression::List" "Expected Expression::Tuple | Expression::List"
)) ))
} }
}; };
@ -576,7 +576,7 @@ pub fn fix_unnecessary_literal_within_list_call(
), ),
_ => { _ => {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: Expression::Tuple | Expression::List" "Expected Expression::Tuple | Expression::List"
)) ))
} }
}; };
@ -643,7 +643,7 @@ pub fn fix_unnecessary_call_around_sorted(
if let Expression::Call(call) = &arg.value { if let Expression::Call(call) = &arg.value {
call call
} else { } else {
return Err(anyhow::anyhow!("Expected node to be: Expression::Call ")); return Err(anyhow::anyhow!("Expected Expression::Call "));
} }
} }
_ => { _ => {
@ -769,7 +769,7 @@ pub fn fix_unnecessary_comprehension(
} }
_ => { _ => {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: Expression::ListComp | Expression:SetComp" "Expected Expression::ListComp | Expression:SetComp"
)) ))
} }
} }

View file

@ -97,7 +97,7 @@ fn extract_quote(text: &str) -> &str {
} }
} }
panic!("Unable to find quotation mark for String token.") panic!("Unable to find quotation mark for String token")
} }
/// W605 /// W605

View file

@ -900,7 +900,7 @@ fn blanks_and_section_underline(
) { ) {
let docstring = definition let docstring = definition
.docstring .docstring
.expect("Sections are only available for docstrings."); .expect("Sections are only available for docstrings");
let mut blank_lines_after_header = 0; let mut blank_lines_after_header = 0;
for line in context.following_lines { for line in context.following_lines {
@ -1157,7 +1157,7 @@ fn common_section(
) { ) {
let docstring = definition let docstring = definition
.docstring .docstring
.expect("Sections are only available for docstrings."); .expect("Sections are only available for docstrings");
if checker.settings.enabled.contains(&CheckCode::D405) { if checker.settings.enabled.contains(&CheckCode::D405) {
if !style if !style
@ -1439,7 +1439,7 @@ fn numpy_section(checker: &mut Checker, definition: &Definition, context: &Secti
if !suffix.is_empty() { if !suffix.is_empty() {
let docstring = definition let docstring = definition
.docstring .docstring
.expect("Sections are only available for docstrings."); .expect("Sections are only available for docstrings");
let mut check = Check::new( let mut check = Check::new(
CheckKind::NewLineAfterSectionName(context.section_name.to_string()), CheckKind::NewLineAfterSectionName(context.section_name.to_string()),
Range::from_located(docstring), Range::from_located(docstring),
@ -1488,7 +1488,7 @@ fn google_section(checker: &mut Checker, definition: &Definition, context: &Sect
if suffix != ":" { if suffix != ":" {
let docstring = definition let docstring = definition
.docstring .docstring
.expect("Sections are only available for docstrings."); .expect("Sections are only available for docstrings");
let mut check = Check::new( let mut check = Check::new(
CheckKind::SectionNameEndsInColon(context.section_name.to_string()), CheckKind::SectionNameEndsInColon(context.section_name.to_string()),
Range::from_located(docstring), Range::from_located(docstring),

View file

@ -371,7 +371,7 @@ pub fn if_tuple(test: &Expr, location: Range) -> Option<Check> {
/// F821 /// F821
pub fn undefined_local(scopes: &[&Scope], name: &str) -> Option<Check> { pub fn undefined_local(scopes: &[&Scope], name: &str) -> Option<Check> {
let current = &scopes.last().expect("No current scope found."); let current = &scopes.last().expect("No current scope found");
if matches!(current.kind, ScopeKind::Function(_)) && !current.values.contains_key(name) { if matches!(current.kind, ScopeKind::Function(_)) && !current.values.contains_key(name) {
for scope in scopes.iter().rev().skip(1) { for scope in scopes.iter().rev().skip(1) {
if matches!(scope.kind, ScopeKind::Function(_) | ScopeKind::Module) { if matches!(scope.kind, ScopeKind::Function(_) | ScopeKind::Module) {

View file

@ -23,7 +23,7 @@ pub fn remove_unused_imports(
let mut tree = match_module(&module_text)?; let mut tree = match_module(&module_text)?;
let Some(Statement::Simple(body)) = tree.body.first_mut() else { let Some(Statement::Simple(body)) = tree.body.first_mut() else {
return Err(anyhow::anyhow!("Expected node to be: Statement::Simple")); return Err(anyhow::anyhow!("Expected Statement::Simple"));
}; };
let (aliases, import_module) = match body.body.first_mut() { let (aliases, import_module) = match body.body.first_mut() {
@ -32,11 +32,11 @@ pub fn remove_unused_imports(
if let ImportNames::Aliases(names) = &mut import_body.names { if let ImportNames::Aliases(names) = &mut import_body.names {
Ok((names, import_body.module.as_ref())) Ok((names, import_body.module.as_ref()))
} else { } else {
Err(anyhow::anyhow!("Expected node to be: Aliases")) Err(anyhow::anyhow!("Expected Aliases"))
} }
} }
_ => Err(anyhow::anyhow!( _ => Err(anyhow::anyhow!(
"Expected node to be: SmallStatement::ImportFrom or SmallStatement::Import" "Expected SmallStatement::ImportFrom or SmallStatement::Import"
)), )),
}?; }?;
@ -83,9 +83,7 @@ fn match_comparison<'a, 'b>(expr: &'a mut Expr<'b>) -> Result<&'a mut Comparison
if let Expression::Comparison(comparison) = &mut expr.value { if let Expression::Comparison(comparison) = &mut expr.value {
Ok(comparison) Ok(comparison)
} else { } else {
Err(anyhow::anyhow!( Err(anyhow::anyhow!("Expected Expression::Comparison"))
"Expected node to be: Expression::Comparison"
))
} }
} }
@ -117,7 +115,7 @@ pub fn fix_invalid_literal_comparison(locator: &SourceCodeLocator, location: Ran
whitespace_after: a.clone(), whitespace_after: a.clone(),
}), }),
op => Err(anyhow::anyhow!( op => Err(anyhow::anyhow!(
"Unexpected operator: {:?}. Expected Is or IsNot.", "Unexpected operator: {:?} (expected CompOp::Is or CompOp::IsNot)",
op op
)), )),
}?; }?;

View file

@ -148,16 +148,16 @@ pub fn remove_unnecessary_future_import(
let mut tree = match_module(&module_text)?; let mut tree = match_module(&module_text)?;
let Some(Statement::Simple(body)) = tree.body.first_mut() else { let Some(Statement::Simple(body)) = tree.body.first_mut() else {
return Err(anyhow::anyhow!("Expected node to be: Statement::Simple")); return Err(anyhow::anyhow!("Expected Statement::Simple"));
}; };
let Some(SmallStatement::ImportFrom(body)) = body.body.first_mut() else { let Some(SmallStatement::ImportFrom(body)) = body.body.first_mut() else {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Expected node to be: SmallStatement::ImportFrom" "Expected SmallStatement::ImportFrom"
)); ));
}; };
let ImportNames::Aliases(aliases) = &mut body.names else { let ImportNames::Aliases(aliases) = &mut body.names else {
return Err(anyhow::anyhow!("Expected node to be: Aliases")); return Err(anyhow::anyhow!("Expected Aliases"));
}; };
// Preserve the trailing comma (or not) from the last entry. // Preserve the trailing comma (or not) from the last entry.

View file

@ -141,7 +141,7 @@ fn create_remove_param_fix(
match (fix_start, fix_end) { match (fix_start, fix_end) {
(Some(start), Some(end)) => Ok(Fix::deletion(start, end)), (Some(start), Some(end)) => Ok(Fix::deletion(start, end)),
_ => Err(anyhow::anyhow!( _ => Err(anyhow::anyhow!(
"Failed to locate start and end parentheses." "Failed to locate start and end parentheses"
)), )),
} }
} }

View file

@ -358,19 +358,14 @@ other-attribute = 1
fn find_and_parse_pyproject_toml() -> Result<()> { fn find_and_parse_pyproject_toml() -> Result<()> {
let cwd = current_dir()?; let cwd = current_dir()?;
let project_root = let project_root =
find_project_root(&[PathBuf::from("resources/test/fixtures/__init__.py")]) find_project_root(&[PathBuf::from("resources/test/fixtures/__init__.py")]).unwrap();
.expect("Unable to find project root.");
assert_eq!(project_root, cwd.join("resources/test/fixtures")); assert_eq!(project_root, cwd.join("resources/test/fixtures"));
let path = let path = find_pyproject_toml(Some(&project_root)).unwrap();
find_pyproject_toml(Some(&project_root)).expect("Unable to find pyproject.toml.");
assert_eq!(path, cwd.join("resources/test/fixtures/pyproject.toml")); assert_eq!(path, cwd.join("resources/test/fixtures/pyproject.toml"));
let pyproject = parse_pyproject_toml(&path)?; let pyproject = parse_pyproject_toml(&path)?;
let config = pyproject let config = pyproject.tool.and_then(|tool| tool.ruff).unwrap();
.tool
.and_then(|tool| tool.ruff)
.expect("Unable to find tool.ruff.");
assert_eq!( assert_eq!(
config, config,
Options { Options {