Avoid trimming escaped whitespace in D210 (#3635)
This commit is contained in:
@@ -62,6 +62,11 @@ pub(crate) fn should_ignore_definition(
|
||||
false
|
||||
}
|
||||
|
||||
/// Return true if a line ends with an odd number of backslashes (i.e., ends with an escape).
|
||||
pub(crate) fn ends_with_backslash(line: &str) -> bool {
|
||||
line.chars().rev().take_while(|c| *c == '\\').count() % 2 == 1
|
||||
}
|
||||
|
||||
/// Check if a docstring should be ignored.
|
||||
pub(crate) fn should_ignore_docstring(contents: &str) -> bool {
|
||||
// Avoid analyzing docstrings that contain implicit string concatenations.
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::checkers::ast::Checker;
|
||||
use crate::docstrings::definition::Docstring;
|
||||
use crate::message::Location;
|
||||
use crate::registry::AsRule;
|
||||
use crate::rules::pydocstyle::helpers::ends_with_backslash;
|
||||
|
||||
#[violation]
|
||||
pub struct SurroundingWhitespace;
|
||||
@@ -46,6 +47,7 @@ pub fn no_surrounding_whitespace(checker: &mut Checker, docstring: &Docstring) {
|
||||
// characters, avoid applying the fix.
|
||||
if !trimmed.ends_with(pattern.chars().last().unwrap())
|
||||
&& !trimmed.starts_with(pattern.chars().last().unwrap())
|
||||
&& !ends_with_backslash(trimmed)
|
||||
{
|
||||
diagnostic.amend(Fix::replacement(
|
||||
trimmed.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user