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

RUF022, RUF023: Ensure closing parentheses for multiline sequences are always on their own line #9793

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,16 @@ fn multiline_string_sequence_postlude<'a>(
// ```
let newline_chars = ['\r', '\n'];
if !postlude.starts_with(newline_chars) {
return Cow::Borrowed(postlude);
// Special-case a few common situations so we can get formatting for the closing
// parenthesis that is similar to what the formatter would produce
return match postlude {
")" | "]" | "}" => Cow::Owned(format!("{newline}{leading_indent}{postlude}")),
",)" | ",]" | ",}" => {
let closing_paren = postlude.chars().last().unwrap();
Cow::Owned(format!(",{newline}{leading_indent}{closing_paren}"))
}
_ => Cow::Borrowed(postlude),
};
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
}
if TextSize::of(leading_indentation(
postlude.trim_start_matches(newline_chars),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,24 @@ RUF022.py:54:11: RUF022 [*] `__all__` is not sorted
76 70 | "SUNDAY",
77 71 | "THURSDAY",
78 72 | "TUESDAY",
73 |+ "WEDNESDAY",
79 |- "TextCalendar",
80 73 | "WEDNESDAY",
74 |+ "Calendar",
75 |+ "Day",
76 |+ "HTMLCalendar",
77 |+ "IllegalMonthError",
78 |+ "LocaleHTMLCalendar",
79 |+ "Month",
79 80 | "TextCalendar",
80 |- "WEDNESDAY",
80 |+ "TextCalendar",
81 81 | "calendar",
82 82 | "timegm",
83 83 | "weekday",
84 |- "weekheader"]
84 |+ "weekheader"
85 |+]
85 86 |
86 87 | ##########################################
87 88 | # Messier multiline __all__ definitions...

RUF022.py:91:11: RUF022 [*] `__all__` is not sorted
|
Expand Down Expand Up @@ -559,10 +565,11 @@ RUF022.py:110:11: RUF022 [*] `__all__` is not sorted
151 |+ "register_error",
152 |+ "replace_errors",
153 |+ "strict_errors",
154 |+ "xmlcharrefreplace_errors"]
124 155 |
125 156 | __all__: tuple[str, ...] = ( # a comment about the opening paren
126 157 | # multiline comment about "bbb" part 1
154 |+ "xmlcharrefreplace_errors"
155 |+]
124 156 |
125 157 | __all__: tuple[str, ...] = ( # a comment about the opening paren
126 158 | # multiline comment about "bbb" part 1

RUF022.py:125:28: RUF022 [*] `__all__` is not sorted
|
Expand Down Expand Up @@ -918,13 +925,13 @@ RUF022.py:225:11: RUF022 [*] `__all__` is not sorted
223 223 | ############################################################
224 224 |
225 225 | __all__ = (
226 |- "loads",
227 |- "dumps",)
226 |+ "dumps",
227 |+ "loads",)
228 228 |
229 229 | __all__ = [
230 230 | "loads",
226 227 | "loads",
227 |- "dumps",)
228 |+)
228 229 |
229 230 | __all__ = [
230 231 | "loads",

RUF022.py:229:11: RUF022 [*] `__all__` is not sorted
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,11 @@ RUF023.py:162:17: RUF023 [*] `BezierBuilder.__slots__` is not sorted
162 |+ __slots__ = (
163 |+ 'canvas',
164 |+ 'xp',
165 |+ 'yp',)
164 166 |
165 167 | class BezierBuilder2:
166 168 | __slots__ = {'xp', 'yp',
165 |+ 'yp',
166 |+ )
164 167 |
165 168 | class BezierBuilder2:
166 169 | __slots__ = {'xp', 'yp',

RUF023.py:166:17: RUF023 [*] `BezierBuilder2.__slots__` is not sorted
|
Expand Down
Loading