Avoid attempting to fix PT018 in multi-statement lines (#6829)

## Summary

These fixes will _always_ fail, so we should avoid trying to construct
them in the first place.

Closes https://github.com/astral-sh/ruff/issues/6812.
This commit is contained in:
Charlie Marsh 2023-08-23 19:09:34 -04:00 committed by GitHub
parent 9b6e008cf1
commit 847432cacf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 109 additions and 52 deletions

View file

@ -4,7 +4,7 @@ use ruff_text_size::{TextRange, TextSize};
/// Extract the leading indentation from a line.
pub fn indentation_at_offset<'a>(offset: TextSize, locator: &'a Locator) -> Option<&'a str> {
let line_start = locator.line_start(offset);
let indentation = &locator.contents()[TextRange::new(line_start, offset)];
let indentation = locator.slice(TextRange::new(line_start, offset));
if indentation.chars().all(is_python_whitespace) {
Some(indentation)
@ -16,14 +16,14 @@ pub fn indentation_at_offset<'a>(offset: TextSize, locator: &'a Locator) -> Opti
/// Return `true` if the node starting the given [`TextSize`] has leading content.
pub fn has_leading_content(offset: TextSize, locator: &Locator) -> bool {
let line_start = locator.line_start(offset);
let leading = &locator.contents()[TextRange::new(line_start, offset)];
let leading = locator.slice(TextRange::new(line_start, offset));
leading.chars().any(|char| !is_python_whitespace(char))
}
/// Return `true` if the node ending at the given [`TextSize`] has trailing content.
pub fn has_trailing_content(offset: TextSize, locator: &Locator) -> bool {
let line_end = locator.line_end(offset);
let trailing = &locator.contents()[TextRange::new(offset, line_end)];
let trailing = locator.slice(TextRange::new(offset, line_end));
for char in trailing.chars() {
if char == '#' {