Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do multiline string test for W293 too #10049

Merged
merged 1 commit into from Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,3 +14,6 @@ class Chassis(RobotModuleTemplate):
" \
\

'''blank line with whitespace

inside a multiline string'''
Expand Up @@ -86,30 +86,33 @@ pub(crate) fn trailing_whitespace(
.sum();
if whitespace_len > TextSize::from(0) {
let range = TextRange::new(line.end() - whitespace_len, line.end());

// Removing trailing whitespace is not safe inside multiline strings.
let applicability = if indexer.multiline_ranges().contains_range(range) {
Applicability::Unsafe
} else {
Applicability::Safe
};
if range == line.range() {
if settings.rules.enabled(Rule::BlankLineWithWhitespace) {
let mut diagnostic = Diagnostic::new(BlankLineWithWhitespace, range);
// Remove any preceding continuations, to avoid introducing a potential
// syntax error.
diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(TextRange::new(
indexer
.preceded_by_continuations(line.start(), locator)
.unwrap_or(range.start()),
range.end(),
))));
diagnostic.set_fix(Fix::applicable_edit(
Edit::range_deletion(TextRange::new(
indexer
.preceded_by_continuations(line.start(), locator)
.unwrap_or(range.start()),
range.end(),
)),
applicability,
));
return Some(diagnostic);
}
} else if settings.rules.enabled(Rule::TrailingWhitespace) {
let mut diagnostic = Diagnostic::new(TrailingWhitespace, range);
diagnostic.set_fix(Fix::applicable_edit(
Edit::range_deletion(range),
// Removing trailing whitespace is not safe inside multiline strings.
if indexer.multiline_ranges().contains_range(range) {
Applicability::Unsafe
} else {
Applicability::Safe
},
applicability,
));
return Some(diagnostic);
}
Expand Down
Expand Up @@ -11,7 +11,7 @@ W293.py:4:1: W293 [*] Blank line contains whitespace
|
= help: Remove whitespace from blank line

Safe fix
Unsafe fix
1 1 | # See: https://github.com/astral-sh/ruff/issues/9323
2 2 | class Chassis(RobotModuleTemplate):
3 3 | """底盘信息推送控制
Expand Down Expand Up @@ -48,6 +48,7 @@ W293.py:16:1: W293 [*] Blank line contains whitespace
15 | \
16 |
| ^^^^ W293
17 | '''blank line with whitespace
|
= help: Remove whitespace from blank line

Expand All @@ -59,5 +60,25 @@ W293.py:16:1: W293 [*] Blank line contains whitespace
15 |- \
16 |-
14 |+ "
17 15 | '''blank line with whitespace
18 16 |
19 17 | inside a multiline string'''

W293.py:18:1: W293 [*] Blank line contains whitespace
|
17 | '''blank line with whitespace
18 |
| ^ W293
19 | inside a multiline string'''
|
= help: Remove whitespace from blank line

ℹ Unsafe fix
15 15 | \
16 16 |
17 17 | '''blank line with whitespace
18 |-
18 |+
19 19 | inside a multiline string'''