mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 21:40:51 -05:00
Don't autofix D210 by introducing a syntax error (#1093)
This commit is contained in:
@@ -633,17 +633,25 @@ pub fn no_surrounding_whitespace(checker: &mut Checker, definition: &Definition)
|
||||
.chain(constants::SINGLE_QUOTE_PREFIXES)
|
||||
{
|
||||
if first_line.starts_with(pattern) {
|
||||
check.amend(Fix::replacement(
|
||||
trimmed.to_string(),
|
||||
Location::new(
|
||||
docstring.location.row(),
|
||||
docstring.location.column() + pattern.len(),
|
||||
),
|
||||
Location::new(
|
||||
docstring.location.row(),
|
||||
docstring.location.column() + pattern.len() + line.chars().count(),
|
||||
),
|
||||
));
|
||||
if let Some(quote) = pattern.chars().last() {
|
||||
// If removing whitespace would lead to an invalid string of quote
|
||||
// characters, avoid applying the fix.
|
||||
if !trimmed.ends_with(quote) {
|
||||
check.amend(Fix::replacement(
|
||||
trimmed.to_string(),
|
||||
Location::new(
|
||||
docstring.location.row(),
|
||||
docstring.location.column() + pattern.len(),
|
||||
),
|
||||
Location::new(
|
||||
docstring.location.row(),
|
||||
docstring.location.column()
|
||||
+ pattern.len()
|
||||
+ line.chars().count(),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +47,12 @@ expression: checks
|
||||
end_location:
|
||||
row: 299
|
||||
column: 36
|
||||
- kind: NoSurroundingWhitespace
|
||||
location:
|
||||
row: 581
|
||||
column: 4
|
||||
end_location:
|
||||
row: 581
|
||||
column: 51
|
||||
fix: ~
|
||||
|
||||
|
||||
@@ -106,4 +106,12 @@ expression: checks
|
||||
row: 520
|
||||
column: 32
|
||||
fix: ~
|
||||
- kind: EndsInPeriod
|
||||
location:
|
||||
row: 581
|
||||
column: 4
|
||||
end_location:
|
||||
row: 581
|
||||
column: 51
|
||||
fix: ~
|
||||
|
||||
|
||||
@@ -98,4 +98,12 @@ expression: checks
|
||||
row: 520
|
||||
column: 32
|
||||
fix: ~
|
||||
- kind: EndsInPunctuation
|
||||
location:
|
||||
row: 581
|
||||
column: 4
|
||||
end_location:
|
||||
row: 581
|
||||
column: 51
|
||||
fix: ~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user