mirror of https://github.com/astral-sh/ruff
debug assert for fix usage (#2335)
This commit is contained in:
parent
64fb0bd2cc
commit
b40cd1fabc
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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, "", "()");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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, "", "()");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue