Closed blablatdinov closed 1 year ago
Thank you for opening this! Unfortunately, .split("\n")
is not the same as .splitlines()
, so we can't safely replace all split
calls with splitlines
.
Take the following for instance:
>>> data = "hello\r\nworld\r\n"
>>> data.split("\n")
['hello\r', 'world\r', '']
>>> data.splitlines()
['hello', 'world']
splitlines()
differs in a few ways, primarily in that it splits on all newline-like white space characters (not just newline), and by default, splitlines()
doesn't include empty lines in the output. See the docs for a more detailed explanation of the splitlines()
function.
Overview
Refurb can detect
.split('\n')
methods and suggest replacing them with.splitlines()
Proposal
We can create a new check for the search
str.split
method with'\n'
argument usage