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 {
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,

View File

@ -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, "", "()");
}

View File

@ -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, "", "()");
}
}

View File

@ -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,
}
}