ruff/crates/ruff_python_formatter/src
Charlie Marsh c2750a59ab
Implement an iterator for universal newlines (#3454)
# Summary

We need to support CR line endings (as opposed to LF and CRLF line endings, which are already supported). They're rare, but they do appear in Python code, and we tend to panic on any file that uses them.

Our `Locator` abstraction now supports CR line endings. However, Rust's `str#lines` implementation does _not_.

This PR adds a `UniversalNewlineIterator` implementation that respects all of CR, LF, and CRLF line endings, and plugs it into most of the `.lines()` call sites.

As an alternative design, it could be nice if we could leverage `Locator` for this. We've already computed all of the line endings, so we could probably iterate much more efficiently?

# Test Plan

Largely relying on automated testing, however, also ran over some known failure cases, like #3404.
2023-03-13 00:01:29 -04:00
..
cst Implement an iterator for universal newlines (#3454) 2023-03-13 00:01:29 -04:00
format Remove copied core modules from ruff_python_formatter (#3371) 2023-03-08 19:03:40 +00:00
snapshots Introduce dedicated CST tokens for other operator kinds (#3267) 2023-02-27 23:54:57 -05:00
attachment.rs Remove core module from ruff_python_formatter (#3373) 2023-03-08 19:11:39 +00:00
cli.rs Add initial formatter implementation (#2883) 2023-02-15 04:06:35 +00:00
context.rs Remove copied core modules from ruff_python_formatter (#3371) 2023-03-08 19:03:40 +00:00
lib.rs Remove core module from ruff_python_formatter (#3373) 2023-03-08 19:11:39 +00:00
main.rs Add builders for common comment rendering (#3232) 2023-02-26 04:16:24 +00:00
newlines.rs Remove core module from ruff_python_formatter (#3373) 2023-03-08 19:11:39 +00:00
parentheses.rs Remove core module from ruff_python_formatter (#3373) 2023-03-08 19:11:39 +00:00
shared_traits.rs Remove unused AsFormat trait for Option<T> (#3041) 2023-02-19 20:19:35 +00:00
trivia.rs Remove copied core modules from ruff_python_formatter (#3371) 2023-03-08 19:03:40 +00:00