debug assert for fix usage (#2335)

This commit is contained in:
Simon Brugman 2023-01-30 03:13:42 +01:00 committed by GitHub
parent 64fb0bd2cc
commit b40cd1fabc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 12 deletions

View File

@ -36,6 +36,8 @@ impl Fix {
} }
pub fn replacement(content: String, start: Location, end: Location) -> Self { pub fn replacement(content: String, start: Location, end: Location) -> Self {
debug_assert!(!content.is_empty(), "Prefer `Fix::deletion`");
Self { Self {
content, content,
location: start, location: start,
@ -44,6 +46,8 @@ impl Fix {
} }
pub fn insertion(content: String, at: Location) -> Self { pub fn insertion(content: String, at: Location) -> Self {
debug_assert!(!content.is_empty(), "Insert content is empty");
Self { Self {
content, content,
location: at, location: at,

View File

@ -109,11 +109,8 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
&& args.is_empty() && args.is_empty()
&& keywords.is_empty() && keywords.is_empty()
{ {
let fix = Fix::replacement( let fix =
String::new(), Fix::deletion(func.end_location.unwrap(), decorator.end_location.unwrap());
func.end_location.unwrap(),
decorator.end_location.unwrap(),
);
pytest_fixture_parentheses(checker, decorator, fix, "", "()"); pytest_fixture_parentheses(checker, decorator, fix, "", "()");
} }

View File

@ -40,11 +40,8 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Expr) {
&& args.is_empty() && args.is_empty()
&& keywords.is_empty() && keywords.is_empty()
{ {
let fix = Fix::replacement( let fix =
String::new(), Fix::deletion(func.end_location.unwrap(), decorator.end_location.unwrap());
func.end_location.unwrap(),
decorator.end_location.unwrap(),
);
pytest_mark_parentheses(checker, decorator, fix, "", "()"); pytest_mark_parentheses(checker, decorator, fix, "", "()");
} }
} }

View File

@ -79,7 +79,7 @@ pub fn remove_class_def_base(
} }
match (fix_start, fix_end) { 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, _ => None,
} }
} else { } else {
@ -98,7 +98,7 @@ pub fn remove_class_def_base(
} }
match (fix_start, fix_end) { 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, _ => None,
} }
} }