-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
What it does
Suggest replacing string.split("\n")
, string.split('\n')
, and string.split("\r\n")
with string.lines()
.
Note that clippy throws a single_char_split
warning for string.split("\n")
which should be updated to this.
Lint Name
non_portable_line_iteration
Category
suspicious, style
Advantage
Makes string line iteration portable across Unix and Windows.
Drawbacks
If you need to differentiate between platform specific newlines this will be a false positive.
Also, if the string has a final terminating newline, the result of a .split
will differ from .lines
.
This could be avoiding by having the lint only trigger on .trim().split(sep)
.
Example
for line in string.split("\n") { ... }
// or
for line in string.split("\r\n") { ... }
// or
for line in string.split('\n') { ... }
Could be written as:
for line in string.lines() { ... }
smoelius, xFrednet, matthiaskrgr, TennyZhuang, yonip23 and 7 more
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy