Fix SIM905 handling for raw strings with newlines and quotes

Refactors the logic in split_static_string.rs to correctly handle raw string literals containing newlines and embedded quotes, ensuring the appropriate quote style and flags are used to avoid syntax errors. Updates test fixtures and snapshots to reflect the improved handling and corrects misplaced test cases.
This commit is contained in:
Dan 2025-10-23 23:50:14 -04:00
parent e58c51fb34
commit 64ae3d75ee
4 changed files with 452 additions and 457 deletions

View File

@ -131,13 +131,6 @@ print(" x ".rsplit(sep=None, maxsplit=0))
print(" x ".rsplit(maxsplit=0)) print(" x ".rsplit(maxsplit=0))
print(" x ".rsplit(sep=None, maxsplit=0)) print(" x ".rsplit(sep=None, maxsplit=0))
# https://github.com/astral-sh/ruff/issues/19610
r"1" "\n".split("1") # [r"", "\n"]
r"" "\"".split("1") # ['"']
r"1" """
""".split("1") # [r"", "\n"]
r"\n" "\n'\"".split("1") # ["\\n\n'\""]
# https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
r"""simple@example.com r"""simple@example.com
very.common@example.com very.common@example.com
@ -177,3 +170,10 @@ print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
# leading/trailing whitespace should not count towards maxsplit # leading/trailing whitespace should not count towards maxsplit
" a b c d ".split(maxsplit=2) # ["a", "b", "c d "] " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
" a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
# https://github.com/astral-sh/ruff/issues/19610
r"1" "\n".split("1") # [r"", "\n"]
r"" "\"".split("1") # ['"']
r"1" """
""".split("1") # [r"", "\n"]
r"\n" "\n'\"".split("1") # ["\\n\n'\""]

View File

@ -135,27 +135,27 @@ fn replace_flags(elt: &str, flags: StringLiteralFlags) -> StringLiteralFlags {
// 'single'quoted // 'single'quoted
// """.split() # -> [r"itemA",r"'single'quoted'"] // """.split() # -> [r"itemA",r"'single'quoted'"]
// ``` // ```
if !flags.prefix().is_raw() { if !flags.prefix().is_raw() {
return flags.with_triple_quotes(ruff_python_ast::str::TripleQuotes::No);
}
if elt.contains('\n') || elt.contains('\r') {
return StringLiteralFlags::empty()
.with_triple_quotes(ruff_python_ast::str::TripleQuotes::No);
}
if elt.contains(flags.quote_style().as_char()) {
if elt.contains(flags.quote_style().opposite().as_char()) {
return StringLiteralFlags::empty()
.with_triple_quotes(ruff_python_ast::str::TripleQuotes::No);
}
return flags
.with_quote_style(flags.quote_style().opposite())
.with_triple_quotes(ruff_python_ast::str::TripleQuotes::No);
}
flags.with_triple_quotes(ruff_python_ast::str::TripleQuotes::No) flags.with_triple_quotes(ruff_python_ast::str::TripleQuotes::No)
} else if elt.contains(['\n', '\r']) {
// If the element contains newlines or carriage returns, we need to use
// default flags (no raw prefix) to avoid syntax errors
StringLiteralFlags::empty()
} else if elt.contains(flags.quote_style().as_char()) {
// If we have a raw string containing a quotation mark of the same style,
// then we have to swap the style of quotation marks used
if elt.contains(flags.quote_style().opposite().as_char()) {
// If both types of quotes are used in the raw string, then
// we are forced to use default flags to avoid syntax errors
StringLiteralFlags::empty()
} else {
flags
.with_quote_style(flags.quote_style().opposite())
.with_triple_quotes(ruff_python_ast::str::TripleQuotes::No)
}
} else {
flags.with_triple_quotes(ruff_python_ast::str::TripleQuotes::No)
}
} }
fn construct_replacement(elts: &[&str], flags: StringLiteralFlags) -> Expr { fn construct_replacement(elts: &[&str], flags: StringLiteralFlags) -> Expr {

View File

@ -1307,7 +1307,7 @@ help: Replace with list literal
131 |+print([" x"]) 131 |+print([" x"])
132 132 | print(" x ".rsplit(sep=None, maxsplit=0)) 132 132 | print(" x ".rsplit(sep=None, maxsplit=0))
133 133 | 133 133 |
134 134 | # https://github.com/astral-sh/ruff/issues/19610 134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:132:7 --> SIM905.py:132:7
@ -1317,7 +1317,7 @@ SIM905 [*] Consider using a list literal instead of `str.split`
132 | print(" x ".rsplit(sep=None, maxsplit=0)) 132 | print(" x ".rsplit(sep=None, maxsplit=0))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133 | 133 |
134 | # https://github.com/astral-sh/ruff/issues/19610 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
| |
help: Replace with list literal help: Replace with list literal
@ -1328,266 +1328,261 @@ help: Replace with list literal
132 |-print(" x ".rsplit(sep=None, maxsplit=0)) 132 |-print(" x ".rsplit(sep=None, maxsplit=0))
132 |+print([" x"]) 132 |+print([" x"])
133 133 | 133 133 |
134 134 | # https://github.com/astral-sh/ruff/issues/19610 134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
135 135 | r"1" "\n".split("1") # [r"", "\n"] 135 135 | r"""simple@example.com
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:135:1 --> SIM905.py:135:1
| |
134 | # https://github.com/astral-sh/ruff/issues/19610 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
135 | r"1" "\n".split("1") # [r"", "\n"] 135 | / r"""simple@example.com
| ^^^^^^^^^^^^^^^^^^^^ 136 | | very.common@example.com
136 | r"" "\"".split("1") # ['"'] 137 | | FirstName.LastName@EasierReading.org
137 | r"1" """ 138 | | x@example.com
139 | | long.email-address-with-hyphens@and.subdomains.example.com
140 | | user.name+tag+sorting@example.com
141 | | name/surname@example.com
142 | | xample@s.example
143 | | " "@example.org
144 | | "john..doe"@example.org
145 | | mailhost!username@example.org
146 | | "very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
147 | | user%example.com@example.org
148 | | user-@example.org
149 | | I❤CHOCOLATE@example.com
150 | | this\ still\"not\\allowed@example.com
151 | | stellyamburrr985@example.com
152 | | Abc.123@example.com
153 | | user+mailbox/department=shipping@example.com
154 | | !#$%&'*+-/=?^_`.{|}~@example.com
155 | | "Abc@def"@example.com
156 | | "Fred\ Bloggs"@example.com
157 | | "Joe.\\Blow"@example.com""".split("\n")
| |_______________________________________^
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
132 132 | print(" x ".rsplit(sep=None, maxsplit=0)) 132 132 | print(" x ".rsplit(sep=None, maxsplit=0))
133 133 | 133 133 |
134 134 | # https://github.com/astral-sh/ruff/issues/19610 134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
135 |-r"1" "\n".split("1") # [r"", "\n"] 135 |-r"""simple@example.com
135 |+[r"", '\n'] # [r"", "\n"] 136 |-very.common@example.com
136 136 | r"" "\"".split("1") # ['"'] 137 |-FirstName.LastName@EasierReading.org
137 137 | r"1" """ 138 |-x@example.com
138 138 | """.split("1") # [r"", "\n"] 139 |-long.email-address-with-hyphens@and.subdomains.example.com
140 |-user.name+tag+sorting@example.com
141 |-name/surname@example.com
142 |-xample@s.example
143 |-" "@example.org
144 |-"john..doe"@example.org
145 |-mailhost!username@example.org
146 |-"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
147 |-user%example.com@example.org
148 |-user-@example.org
149 |-I❤CHOCOLATE@example.com
150 |-this\ still\"not\\allowed@example.com
151 |-stellyamburrr985@example.com
152 |-Abc.123@example.com
153 |-user+mailbox/department=shipping@example.com
154 |-!#$%&'*+-/=?^_`.{|}~@example.com
155 |-"Abc@def"@example.com
156 |-"Fred\ Bloggs"@example.com
157 |-"Joe.\\Blow"@example.com""".split("\n")
135 |+[r"simple@example.com", r"very.common@example.com", r"FirstName.LastName@EasierReading.org", r"x@example.com", r"long.email-address-with-hyphens@and.subdomains.example.com", r"user.name+tag+sorting@example.com", r"name/surname@example.com", r"xample@s.example", r'" "@example.org', r'"john..doe"@example.org', r"mailhost!username@example.org", r'"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com', r"user%example.com@example.org", r"user-@example.org", r"I❤CHOCOLATE@example.com", r'this\ still\"not\\allowed@example.com', r"stellyamburrr985@example.com", r"Abc.123@example.com", r"user+mailbox/department=shipping@example.com", r"!#$%&'*+-/=?^_`.{|}~@example.com", r'"Abc@def"@example.com', r'"Fred\ Bloggs"@example.com', r'"Joe.\\Blow"@example.com']
158 136 |
159 137 |
160 138 | r"""first
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:136:1 --> SIM905.py:160:1
| |
134 | # https://github.com/astral-sh/ruff/issues/19610 160 | / r"""first
135 | r"1" "\n".split("1") # [r"", "\n"] 161 | | 'no need' to escape
136 | r"" "\"".split("1") # ['"'] 162 | | "swap" quote style
| ^^^^^^^^^^^^^^^^^^^ 163 | | "use' ugly triple quotes""".split("\n")
137 | r"1" """
138 | """.split("1") # [r"", "\n"]
|
help: Replace with list literal
Safe fix
133 133 |
134 134 | # https://github.com/astral-sh/ruff/issues/19610
135 135 | r"1" "\n".split("1") # [r"", "\n"]
136 |-r"" "\"".split("1") # ['"']
136 |+[r'"'] # ['"']
137 137 | r"1" """
138 138 | """.split("1") # [r"", "\n"]
139 139 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:137:1
|
135 | r"1" "\n".split("1") # [r"", "\n"]
136 | r"" "\"".split("1") # ['"']
137 | / r"1" """
138 | | """.split("1") # [r"", "\n"]
| |______________^
139 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
|
help: Replace with list literal
Safe fix
134 134 | # https://github.com/astral-sh/ruff/issues/19610
135 135 | r"1" "\n".split("1") # [r"", "\n"]
136 136 | r"" "\"".split("1") # ['"']
137 |-r"1" """
138 |-""".split("1") # [r"", "\n"]
137 |+[r"", '\n'] # [r"", "\n"]
139 138 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
140 139 |
141 140 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:139:1
|
137 | r"1" """
138 | """.split("1") # [r"", "\n"]
139 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
| ^^^^^^^^^^^^^^^^^^^^^^^^
140 |
141 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
|
help: Replace with list literal
Safe fix
136 136 | r"" "\"".split("1") # ['"']
137 137 | r"1" """
138 138 | """.split("1") # [r"", "\n"]
139 |-r"\n" "\n'\"".split("1") # ["\\n\n'\""]
139 |+['\\n\n\'"'] # ["\\n\n'\""]
140 140 |
141 141 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
142 142 | r"""simple@example.com
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:142:1
|
141 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
142 | / r"""simple@example.com
143 | | very.common@example.com
144 | | FirstName.LastName@EasierReading.org
145 | | x@example.com
146 | | long.email-address-with-hyphens@and.subdomains.example.com
147 | | user.name+tag+sorting@example.com
148 | | name/surname@example.com
149 | | xample@s.example
150 | | " "@example.org
151 | | "john..doe"@example.org
152 | | mailhost!username@example.org
153 | | "very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
154 | | user%example.com@example.org
155 | | user-@example.org
156 | | I❤CHOCOLATE@example.com
157 | | this\ still\"not\\allowed@example.com
158 | | stellyamburrr985@example.com
159 | | Abc.123@example.com
160 | | user+mailbox/department=shipping@example.com
161 | | !#$%&'*+-/=?^_`.{|}~@example.com
162 | | "Abc@def"@example.com
163 | | "Fred\ Bloggs"@example.com
164 | | "Joe.\\Blow"@example.com""".split("\n")
| |_______________________________________^ | |_______________________________________^
164 |
165 | # https://github.com/astral-sh/ruff/issues/19845
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
139 139 | r"\n" "\n'\"".split("1") # ["\\n\n'\""] 157 157 | "Joe.\\Blow"@example.com""".split("\n")
140 140 | 158 158 |
141 141 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings 159 159 |
142 |-r"""simple@example.com 160 |-r"""first
143 |-very.common@example.com 161 |-'no need' to escape
144 |-FirstName.LastName@EasierReading.org 162 |-"swap" quote style
145 |-x@example.com 163 |-"use' ugly triple quotes""".split("\n")
146 |-long.email-address-with-hyphens@and.subdomains.example.com 160 |+[r"first", r"'no need' to escape", r'"swap" quote style', '"use\' ugly triple quotes']
147 |-user.name+tag+sorting@example.com 164 161 |
148 |-name/surname@example.com 165 162 | # https://github.com/astral-sh/ruff/issues/19845
149 |-xample@s.example 166 163 | print("S\x1cP\x1dL\x1eI\x1fT".split())
150 |-" "@example.org
151 |-"john..doe"@example.org
152 |-mailhost!username@example.org
153 |-"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
154 |-user%example.com@example.org
155 |-user-@example.org
156 |-I❤CHOCOLATE@example.com
157 |-this\ still\"not\\allowed@example.com
158 |-stellyamburrr985@example.com
159 |-Abc.123@example.com
160 |-user+mailbox/department=shipping@example.com
161 |-!#$%&'*+-/=?^_`.{|}~@example.com
162 |-"Abc@def"@example.com
163 |-"Fred\ Bloggs"@example.com
164 |-"Joe.\\Blow"@example.com""".split("\n")
142 |+[r"simple@example.com", r"very.common@example.com", r"FirstName.LastName@EasierReading.org", r"x@example.com", r"long.email-address-with-hyphens@and.subdomains.example.com", r"user.name+tag+sorting@example.com", r"name/surname@example.com", r"xample@s.example", r'" "@example.org', r'"john..doe"@example.org', r"mailhost!username@example.org", r'"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com', r"user%example.com@example.org", r"user-@example.org", r"I❤CHOCOLATE@example.com", r'this\ still\"not\\allowed@example.com', r"stellyamburrr985@example.com", r"Abc.123@example.com", r"user+mailbox/department=shipping@example.com", r"!#$%&'*+-/=?^_`.{|}~@example.com", r'"Abc@def"@example.com', r'"Fred\ Bloggs"@example.com', r'"Joe.\\Blow"@example.com']
165 143 |
166 144 |
167 145 | r"""first
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:167:1 --> SIM905.py:166:7
| |
167 | / r"""first 165 | # https://github.com/astral-sh/ruff/issues/19845
168 | | 'no need' to escape 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
169 | | "swap" quote style
170 | | "use' ugly triple quotes""".split("\n")
| |_______________________________________^
171 |
172 | # https://github.com/astral-sh/ruff/issues/19845
|
help: Replace with list literal
Safe fix
164 164 | "Joe.\\Blow"@example.com""".split("\n")
165 165 |
166 166 |
167 |-r"""first
168 |-'no need' to escape
169 |-"swap" quote style
170 |-"use' ugly triple quotes""".split("\n")
167 |+[r"first", r"'no need' to escape", r'"swap" quote style', '"use\' ugly triple quotes']
171 168 |
172 169 | # https://github.com/astral-sh/ruff/issues/19845
173 170 | print("S\x1cP\x1dL\x1eI\x1fT".split())
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:173:7
|
172 | # https://github.com/astral-sh/ruff/issues/19845
173 | print("S\x1cP\x1dL\x1eI\x1fT".split())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
170 170 | "use' ugly triple quotes""".split("\n") 163 163 | "use' ugly triple quotes""".split("\n")
171 171 | 164 164 |
172 172 | # https://github.com/astral-sh/ruff/issues/19845 165 165 | # https://github.com/astral-sh/ruff/issues/19845
173 |-print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 |-print("S\x1cP\x1dL\x1eI\x1fT".split())
173 |+print(["S", "P", "L", "I", "T"]) 166 |+print(["S", "P", "L", "I", "T"])
174 174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
175 175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
176 176 | 169 169 |
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:174:7 --> SIM905.py:167:7
| |
172 | # https://github.com/astral-sh/ruff/issues/19845 165 | # https://github.com/astral-sh/ruff/issues/19845
173 | print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
171 171 | 164 164 |
172 172 | # https://github.com/astral-sh/ruff/issues/19845 165 165 | # https://github.com/astral-sh/ruff/issues/19845
173 173 | print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
174 |-print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 |-print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
174 |+print([">"]) 167 |+print([">"])
175 175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
176 176 | 169 169 |
177 177 | # leading/trailing whitespace should not count towards maxsplit 170 170 | # leading/trailing whitespace should not count towards maxsplit
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:175:7 --> SIM905.py:168:7
| |
173 | print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176 | 169 |
177 | # leading/trailing whitespace should not count towards maxsplit 170 | # leading/trailing whitespace should not count towards maxsplit
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
172 172 | # https://github.com/astral-sh/ruff/issues/19845 165 165 | # https://github.com/astral-sh/ruff/issues/19845
173 173 | print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
174 174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
175 |-print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 |-print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
175 |+print(["<"]) 168 |+print(["<"])
176 176 | 169 169 |
177 177 | # leading/trailing whitespace should not count towards maxsplit 170 170 | # leading/trailing whitespace should not count towards maxsplit
178 178 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] 171 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
SIM905 Consider using a list literal instead of `str.split` SIM905 Consider using a list literal instead of `str.split`
--> SIM905.py:178:1 --> SIM905.py:171:1
| |
177 | # leading/trailing whitespace should not count towards maxsplit 170 | # leading/trailing whitespace should not count towards maxsplit
178 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] 172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
| |
help: Replace with list literal help: Replace with list literal
SIM905 Consider using a list literal instead of `str.split` SIM905 Consider using a list literal instead of `str.split`
--> SIM905.py:172:1
|
170 | # leading/trailing whitespace should not count towards maxsplit
171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173 |
174 | # https://github.com/astral-sh/ruff/issues/19610
|
help: Replace with list literal
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:175:1
|
174 | # https://github.com/astral-sh/ruff/issues/19610
175 | r"1" "\n".split("1") # [r"", "\n"]
| ^^^^^^^^^^^^^^^^^^^^
176 | r"" "\"".split("1") # ['"']
177 | r"1" """
|
help: Replace with list literal
Safe fix
172 172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
173 173 |
174 174 | # https://github.com/astral-sh/ruff/issues/19610
175 |-r"1" "\n".split("1") # [r"", "\n"]
175 |+[r"", '\n'] # [r"", "\n"]
176 176 | r"" "\"".split("1") # ['"']
177 177 | r"1" """
178 178 | """.split("1") # [r"", "\n"]
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:176:1
|
174 | # https://github.com/astral-sh/ruff/issues/19610
175 | r"1" "\n".split("1") # [r"", "\n"]
176 | r"" "\"".split("1") # ['"']
| ^^^^^^^^^^^^^^^^^^^
177 | r"1" """
178 | """.split("1") # [r"", "\n"]
|
help: Replace with list literal
Safe fix
173 173 |
174 174 | # https://github.com/astral-sh/ruff/issues/19610
175 175 | r"1" "\n".split("1") # [r"", "\n"]
176 |-r"" "\"".split("1") # ['"']
176 |+[r'"'] # ['"']
177 177 | r"1" """
178 178 | """.split("1") # [r"", "\n"]
179 179 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:177:1
|
175 | r"1" "\n".split("1") # [r"", "\n"]
176 | r"" "\"".split("1") # ['"']
177 | / r"1" """
178 | | """.split("1") # [r"", "\n"]
| |______________^
179 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
|
help: Replace with list literal
Safe fix
174 174 | # https://github.com/astral-sh/ruff/issues/19610
175 175 | r"1" "\n".split("1") # [r"", "\n"]
176 176 | r"" "\"".split("1") # ['"']
177 |-r"1" """
178 |-""".split("1") # [r"", "\n"]
177 |+[r"", '\n'] # [r"", "\n"]
179 178 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:179:1 --> SIM905.py:179:1
| |
177 | # leading/trailing whitespace should not count towards maxsplit 177 | r"1" """
178 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] 178 | """.split("1") # [r"", "\n"]
179 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] 179 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
| |
help: Replace with list literal help: Replace with list literal
Safe fix
176 176 | r"" "\"".split("1") # ['"']
177 177 | r"1" """
178 178 | """.split("1") # [r"", "\n"]
179 |-r"\n" "\n'\"".split("1") # ["\\n\n'\""]
179 |+['\\n\n\'"'] # ["\\n\n'\""]

View File

@ -1367,7 +1367,7 @@ help: Replace with list literal
131 |+print([" x"]) 131 |+print([" x"])
132 132 | print(" x ".rsplit(sep=None, maxsplit=0)) 132 132 | print(" x ".rsplit(sep=None, maxsplit=0))
133 133 | 133 133 |
134 134 | # https://github.com/astral-sh/ruff/issues/19610 134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:132:7 --> SIM905.py:132:7
@ -1377,7 +1377,7 @@ SIM905 [*] Consider using a list literal instead of `str.split`
132 | print(" x ".rsplit(sep=None, maxsplit=0)) 132 | print(" x ".rsplit(sep=None, maxsplit=0))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133 | 133 |
134 | # https://github.com/astral-sh/ruff/issues/19610 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
| |
help: Replace with list literal help: Replace with list literal
@ -1388,281 +1388,281 @@ help: Replace with list literal
132 |-print(" x ".rsplit(sep=None, maxsplit=0)) 132 |-print(" x ".rsplit(sep=None, maxsplit=0))
132 |+print([" x"]) 132 |+print([" x"])
133 133 | 133 133 |
134 134 | # https://github.com/astral-sh/ruff/issues/19610 134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
135 135 | r"1" "\n".split("1") # [r"", "\n"] 135 135 | r"""simple@example.com
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:135:1 --> SIM905.py:135:1
| |
134 | # https://github.com/astral-sh/ruff/issues/19610 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
135 | r"1" "\n".split("1") # [r"", "\n"] 135 | / r"""simple@example.com
| ^^^^^^^^^^^^^^^^^^^^ 136 | | very.common@example.com
136 | r"" "\"".split("1") # ['"'] 137 | | FirstName.LastName@EasierReading.org
137 | r"1" """ 138 | | x@example.com
139 | | long.email-address-with-hyphens@and.subdomains.example.com
140 | | user.name+tag+sorting@example.com
141 | | name/surname@example.com
142 | | xample@s.example
143 | | " "@example.org
144 | | "john..doe"@example.org
145 | | mailhost!username@example.org
146 | | "very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
147 | | user%example.com@example.org
148 | | user-@example.org
149 | | I❤CHOCOLATE@example.com
150 | | this\ still\"not\\allowed@example.com
151 | | stellyamburrr985@example.com
152 | | Abc.123@example.com
153 | | user+mailbox/department=shipping@example.com
154 | | !#$%&'*+-/=?^_`.{|}~@example.com
155 | | "Abc@def"@example.com
156 | | "Fred\ Bloggs"@example.com
157 | | "Joe.\\Blow"@example.com""".split("\n")
| |_______________________________________^
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
132 132 | print(" x ".rsplit(sep=None, maxsplit=0)) 132 132 | print(" x ".rsplit(sep=None, maxsplit=0))
133 133 | 133 133 |
134 134 | # https://github.com/astral-sh/ruff/issues/19610 134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
135 |-r"1" "\n".split("1") # [r"", "\n"] 135 |-r"""simple@example.com
135 |+[r"", '\n'] # [r"", "\n"] 136 |-very.common@example.com
136 136 | r"" "\"".split("1") # ['"'] 137 |-FirstName.LastName@EasierReading.org
137 137 | r"1" """ 138 |-x@example.com
138 138 | """.split("1") # [r"", "\n"] 139 |-long.email-address-with-hyphens@and.subdomains.example.com
140 |-user.name+tag+sorting@example.com
141 |-name/surname@example.com
142 |-xample@s.example
143 |-" "@example.org
144 |-"john..doe"@example.org
145 |-mailhost!username@example.org
146 |-"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
147 |-user%example.com@example.org
148 |-user-@example.org
149 |-I❤CHOCOLATE@example.com
150 |-this\ still\"not\\allowed@example.com
151 |-stellyamburrr985@example.com
152 |-Abc.123@example.com
153 |-user+mailbox/department=shipping@example.com
154 |-!#$%&'*+-/=?^_`.{|}~@example.com
155 |-"Abc@def"@example.com
156 |-"Fred\ Bloggs"@example.com
157 |-"Joe.\\Blow"@example.com""".split("\n")
135 |+[r"simple@example.com", r"very.common@example.com", r"FirstName.LastName@EasierReading.org", r"x@example.com", r"long.email-address-with-hyphens@and.subdomains.example.com", r"user.name+tag+sorting@example.com", r"name/surname@example.com", r"xample@s.example", r'" "@example.org', r'"john..doe"@example.org', r"mailhost!username@example.org", r'"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com', r"user%example.com@example.org", r"user-@example.org", r"I❤CHOCOLATE@example.com", r'this\ still\"not\\allowed@example.com', r"stellyamburrr985@example.com", r"Abc.123@example.com", r"user+mailbox/department=shipping@example.com", r"!#$%&'*+-/=?^_`.{|}~@example.com", r'"Abc@def"@example.com', r'"Fred\ Bloggs"@example.com', r'"Joe.\\Blow"@example.com']
158 136 |
159 137 |
160 138 | r"""first
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:136:1 --> SIM905.py:160:1
| |
134 | # https://github.com/astral-sh/ruff/issues/19610 160 | / r"""first
135 | r"1" "\n".split("1") # [r"", "\n"] 161 | | 'no need' to escape
136 | r"" "\"".split("1") # ['"'] 162 | | "swap" quote style
| ^^^^^^^^^^^^^^^^^^^ 163 | | "use' ugly triple quotes""".split("\n")
137 | r"1" """
138 | """.split("1") # [r"", "\n"]
|
help: Replace with list literal
Safe fix
133 133 |
134 134 | # https://github.com/astral-sh/ruff/issues/19610
135 135 | r"1" "\n".split("1") # [r"", "\n"]
136 |-r"" "\"".split("1") # ['"']
136 |+[r'"'] # ['"']
137 137 | r"1" """
138 138 | """.split("1") # [r"", "\n"]
139 139 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:137:1
|
135 | r"1" "\n".split("1") # [r"", "\n"]
136 | r"" "\"".split("1") # ['"']
137 | / r"1" """
138 | | """.split("1") # [r"", "\n"]
| |______________^
139 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
|
help: Replace with list literal
Safe fix
134 134 | # https://github.com/astral-sh/ruff/issues/19610
135 135 | r"1" "\n".split("1") # [r"", "\n"]
136 136 | r"" "\"".split("1") # ['"']
137 |-r"1" """
138 |-""".split("1") # [r"", "\n"]
137 |+[r"", '\n'] # [r"", "\n"]
139 138 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
140 139 |
141 140 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:139:1
|
137 | r"1" """
138 | """.split("1") # [r"", "\n"]
139 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
| ^^^^^^^^^^^^^^^^^^^^^^^^
140 |
141 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
|
help: Replace with list literal
Safe fix
136 136 | r"" "\"".split("1") # ['"']
137 137 | r"1" """
138 138 | """.split("1") # [r"", "\n"]
139 |-r"\n" "\n'\"".split("1") # ["\\n\n'\""]
139 |+['\\n\n\'"'] # ["\\n\n'\""]
140 140 |
141 141 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
142 142 | r"""simple@example.com
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:142:1
|
141 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings
142 | / r"""simple@example.com
143 | | very.common@example.com
144 | | FirstName.LastName@EasierReading.org
145 | | x@example.com
146 | | long.email-address-with-hyphens@and.subdomains.example.com
147 | | user.name+tag+sorting@example.com
148 | | name/surname@example.com
149 | | xample@s.example
150 | | " "@example.org
151 | | "john..doe"@example.org
152 | | mailhost!username@example.org
153 | | "very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
154 | | user%example.com@example.org
155 | | user-@example.org
156 | | I❤CHOCOLATE@example.com
157 | | this\ still\"not\\allowed@example.com
158 | | stellyamburrr985@example.com
159 | | Abc.123@example.com
160 | | user+mailbox/department=shipping@example.com
161 | | !#$%&'*+-/=?^_`.{|}~@example.com
162 | | "Abc@def"@example.com
163 | | "Fred\ Bloggs"@example.com
164 | | "Joe.\\Blow"@example.com""".split("\n")
| |_______________________________________^ | |_______________________________________^
164 |
165 | # https://github.com/astral-sh/ruff/issues/19845
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
139 139 | r"\n" "\n'\"".split("1") # ["\\n\n'\""] 157 157 | "Joe.\\Blow"@example.com""".split("\n")
140 140 | 158 158 |
141 141 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings 159 159 |
142 |-r"""simple@example.com 160 |-r"""first
143 |-very.common@example.com 161 |-'no need' to escape
144 |-FirstName.LastName@EasierReading.org 162 |-"swap" quote style
145 |-x@example.com 163 |-"use' ugly triple quotes""".split("\n")
146 |-long.email-address-with-hyphens@and.subdomains.example.com 160 |+[r"first", r"'no need' to escape", r'"swap" quote style', '"use\' ugly triple quotes']
147 |-user.name+tag+sorting@example.com 164 161 |
148 |-name/surname@example.com 165 162 | # https://github.com/astral-sh/ruff/issues/19845
149 |-xample@s.example 166 163 | print("S\x1cP\x1dL\x1eI\x1fT".split())
150 |-" "@example.org
151 |-"john..doe"@example.org
152 |-mailhost!username@example.org
153 |-"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
154 |-user%example.com@example.org
155 |-user-@example.org
156 |-I❤CHOCOLATE@example.com
157 |-this\ still\"not\\allowed@example.com
158 |-stellyamburrr985@example.com
159 |-Abc.123@example.com
160 |-user+mailbox/department=shipping@example.com
161 |-!#$%&'*+-/=?^_`.{|}~@example.com
162 |-"Abc@def"@example.com
163 |-"Fred\ Bloggs"@example.com
164 |-"Joe.\\Blow"@example.com""".split("\n")
142 |+[r"simple@example.com", r"very.common@example.com", r"FirstName.LastName@EasierReading.org", r"x@example.com", r"long.email-address-with-hyphens@and.subdomains.example.com", r"user.name+tag+sorting@example.com", r"name/surname@example.com", r"xample@s.example", r'" "@example.org', r'"john..doe"@example.org', r"mailhost!username@example.org", r'"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com', r"user%example.com@example.org", r"user-@example.org", r"I❤CHOCOLATE@example.com", r'this\ still\"not\\allowed@example.com', r"stellyamburrr985@example.com", r"Abc.123@example.com", r"user+mailbox/department=shipping@example.com", r"!#$%&'*+-/=?^_`.{|}~@example.com", r'"Abc@def"@example.com', r'"Fred\ Bloggs"@example.com', r'"Joe.\\Blow"@example.com']
165 143 |
166 144 |
167 145 | r"""first
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:167:1 --> SIM905.py:166:7
| |
167 | / r"""first 165 | # https://github.com/astral-sh/ruff/issues/19845
168 | | 'no need' to escape 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
169 | | "swap" quote style
170 | | "use' ugly triple quotes""".split("\n")
| |_______________________________________^
171 |
172 | # https://github.com/astral-sh/ruff/issues/19845
|
help: Replace with list literal
Safe fix
164 164 | "Joe.\\Blow"@example.com""".split("\n")
165 165 |
166 166 |
167 |-r"""first
168 |-'no need' to escape
169 |-"swap" quote style
170 |-"use' ugly triple quotes""".split("\n")
167 |+[r"first", r"'no need' to escape", r'"swap" quote style', '"use\' ugly triple quotes']
171 168 |
172 169 | # https://github.com/astral-sh/ruff/issues/19845
173 170 | print("S\x1cP\x1dL\x1eI\x1fT".split())
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:173:7
|
172 | # https://github.com/astral-sh/ruff/issues/19845
173 | print("S\x1cP\x1dL\x1eI\x1fT".split())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
170 170 | "use' ugly triple quotes""".split("\n") 163 163 | "use' ugly triple quotes""".split("\n")
171 171 | 164 164 |
172 172 | # https://github.com/astral-sh/ruff/issues/19845 165 165 | # https://github.com/astral-sh/ruff/issues/19845
173 |-print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 |-print("S\x1cP\x1dL\x1eI\x1fT".split())
173 |+print(["S", "P", "L", "I", "T"]) 166 |+print(["S", "P", "L", "I", "T"])
174 174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
175 175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
176 176 | 169 169 |
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:174:7 --> SIM905.py:167:7
| |
172 | # https://github.com/astral-sh/ruff/issues/19845 165 | # https://github.com/astral-sh/ruff/issues/19845
173 | print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
171 171 | 164 164 |
172 172 | # https://github.com/astral-sh/ruff/issues/19845 165 165 | # https://github.com/astral-sh/ruff/issues/19845
173 173 | print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
174 |-print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 |-print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
174 |+print([">"]) 167 |+print([">"])
175 175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
176 176 | 169 169 |
177 177 | # leading/trailing whitespace should not count towards maxsplit 170 170 | # leading/trailing whitespace should not count towards maxsplit
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:175:7 --> SIM905.py:168:7
| |
173 | print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176 | 169 |
177 | # leading/trailing whitespace should not count towards maxsplit 170 | # leading/trailing whitespace should not count towards maxsplit
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
172 172 | # https://github.com/astral-sh/ruff/issues/19845 165 165 | # https://github.com/astral-sh/ruff/issues/19845
173 173 | print("S\x1cP\x1dL\x1eI\x1fT".split()) 166 166 | print("S\x1cP\x1dL\x1eI\x1fT".split())
174 174 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
175 |-print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 |-print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
175 |+print(["<"]) 168 |+print(["<"])
176 176 | 169 169 |
177 177 | # leading/trailing whitespace should not count towards maxsplit 170 170 | # leading/trailing whitespace should not count towards maxsplit
178 178 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] 171 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:178:1 --> SIM905.py:171:1
| |
177 | # leading/trailing whitespace should not count towards maxsplit 170 | # leading/trailing whitespace should not count towards maxsplit
178 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] 172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
175 175 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
176 176 | 169 169 |
177 177 | # leading/trailing whitespace should not count towards maxsplit 170 170 | # leading/trailing whitespace should not count towards maxsplit
178 |-" a b c d ".split(maxsplit=2) # ["a", "b", "c d "] 171 |-" a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
178 |+["a", "b", "c d "] # ["a", "b", "c d "] 171 |+["a", "b", "c d "] # ["a", "b", "c d "]
179 179 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] 172 172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
173 173 |
174 174 | # https://github.com/astral-sh/ruff/issues/19610
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:172:1
|
170 | # leading/trailing whitespace should not count towards maxsplit
171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173 |
174 | # https://github.com/astral-sh/ruff/issues/19610
|
help: Replace with list literal
Safe fix
169 169 |
170 170 | # leading/trailing whitespace should not count towards maxsplit
171 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
172 |-" a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
172 |+[" a b", "c", "d"] # [" a b", "c", "d"]
173 173 |
174 174 | # https://github.com/astral-sh/ruff/issues/19610
175 175 | r"1" "\n".split("1") # [r"", "\n"]
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:175:1
|
174 | # https://github.com/astral-sh/ruff/issues/19610
175 | r"1" "\n".split("1") # [r"", "\n"]
| ^^^^^^^^^^^^^^^^^^^^
176 | r"" "\"".split("1") # ['"']
177 | r"1" """
|
help: Replace with list literal
Safe fix
172 172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
173 173 |
174 174 | # https://github.com/astral-sh/ruff/issues/19610
175 |-r"1" "\n".split("1") # [r"", "\n"]
175 |+[r"", '\n'] # [r"", "\n"]
176 176 | r"" "\"".split("1") # ['"']
177 177 | r"1" """
178 178 | """.split("1") # [r"", "\n"]
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:176:1
|
174 | # https://github.com/astral-sh/ruff/issues/19610
175 | r"1" "\n".split("1") # [r"", "\n"]
176 | r"" "\"".split("1") # ['"']
| ^^^^^^^^^^^^^^^^^^^
177 | r"1" """
178 | """.split("1") # [r"", "\n"]
|
help: Replace with list literal
Safe fix
173 173 |
174 174 | # https://github.com/astral-sh/ruff/issues/19610
175 175 | r"1" "\n".split("1") # [r"", "\n"]
176 |-r"" "\"".split("1") # ['"']
176 |+[r'"'] # ['"']
177 177 | r"1" """
178 178 | """.split("1") # [r"", "\n"]
179 179 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:177:1
|
175 | r"1" "\n".split("1") # [r"", "\n"]
176 | r"" "\"".split("1") # ['"']
177 | / r"1" """
178 | | """.split("1") # [r"", "\n"]
| |______________^
179 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
|
help: Replace with list literal
Safe fix
174 174 | # https://github.com/astral-sh/ruff/issues/19610
175 175 | r"1" "\n".split("1") # [r"", "\n"]
176 176 | r"" "\"".split("1") # ['"']
177 |-r"1" """
178 |-""".split("1") # [r"", "\n"]
177 |+[r"", '\n'] # [r"", "\n"]
179 178 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
SIM905 [*] Consider using a list literal instead of `str.split` SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:179:1 --> SIM905.py:179:1
| |
177 | # leading/trailing whitespace should not count towards maxsplit 177 | r"1" """
178 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] 178 | """.split("1") # [r"", "\n"]
179 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] 179 | r"\n" "\n'\"".split("1") # ["\\n\n'\""]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
| |
help: Replace with list literal help: Replace with list literal
Safe fix Safe fix
176 176 | 176 176 | r"" "\"".split("1") # ['"']
177 177 | # leading/trailing whitespace should not count towards maxsplit 177 177 | r"1" """
178 178 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] 178 178 | """.split("1") # [r"", "\n"]
179 |-" a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] 179 |-r"\n" "\n'\"".split("1") # ["\\n\n'\""]
179 |+[" a b", "c", "d"] # [" a b", "c", "d"] 179 |+['\\n\n\'"'] # ["\\n\n'\""]