From b40cd1fabc220c719f28ba0d07dae8a260a92dbb Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Mon, 30 Jan 2023 03:13:42 +0100 Subject: [PATCH] debug assert for fix usage (#2335) --- src/fix.rs | 4 ++++ src/rules/flake8_pytest_style/rules/fixture.rs | 7 ++----- src/rules/flake8_pytest_style/rules/marks.rs | 7 ++----- src/rules/pyupgrade/fixes.rs | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/fix.rs b/src/fix.rs index 7827bddc92..1f4a8273a5 100644 --- a/src/fix.rs +++ b/src/fix.rs @@ -36,6 +36,8 @@ impl Fix { } pub fn replacement(content: String, start: Location, end: Location) -> Self { + debug_assert!(!content.is_empty(), "Prefer `Fix::deletion`"); + Self { content, location: start, @@ -44,6 +46,8 @@ impl Fix { } pub fn insertion(content: String, at: Location) -> Self { + debug_assert!(!content.is_empty(), "Insert content is empty"); + Self { content, location: at, diff --git a/src/rules/flake8_pytest_style/rules/fixture.rs b/src/rules/flake8_pytest_style/rules/fixture.rs index c398c22da4..698099e38c 100644 --- a/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/src/rules/flake8_pytest_style/rules/fixture.rs @@ -109,11 +109,8 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E && args.is_empty() && keywords.is_empty() { - let fix = Fix::replacement( - String::new(), - func.end_location.unwrap(), - decorator.end_location.unwrap(), - ); + let fix = + Fix::deletion(func.end_location.unwrap(), decorator.end_location.unwrap()); pytest_fixture_parentheses(checker, decorator, fix, "", "()"); } diff --git a/src/rules/flake8_pytest_style/rules/marks.rs b/src/rules/flake8_pytest_style/rules/marks.rs index 9810e4f360..11873f3a40 100644 --- a/src/rules/flake8_pytest_style/rules/marks.rs +++ b/src/rules/flake8_pytest_style/rules/marks.rs @@ -40,11 +40,8 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Expr) { && args.is_empty() && keywords.is_empty() { - let fix = Fix::replacement( - String::new(), - func.end_location.unwrap(), - decorator.end_location.unwrap(), - ); + let fix = + Fix::deletion(func.end_location.unwrap(), decorator.end_location.unwrap()); pytest_mark_parentheses(checker, decorator, fix, "", "()"); } } diff --git a/src/rules/pyupgrade/fixes.rs b/src/rules/pyupgrade/fixes.rs index c32580709c..be3c478d1a 100644 --- a/src/rules/pyupgrade/fixes.rs +++ b/src/rules/pyupgrade/fixes.rs @@ -79,7 +79,7 @@ pub fn remove_class_def_base( } match (fix_start, fix_end) { - (Some(start), Some(end)) => Some(Fix::replacement(String::new(), start, end)), + (Some(start), Some(end)) => Some(Fix::deletion(start, end)), _ => None, } } else { @@ -98,7 +98,7 @@ pub fn remove_class_def_base( } match (fix_start, fix_end) { - (Some(start), Some(end)) => Some(Fix::replacement(String::new(), start, end)), + (Some(start), Some(end)) => Some(Fix::deletion(start, end)), _ => None, } }