Skip to content

Commit

Permalink
Revert changes
Browse files Browse the repository at this point in the history
This makes the additional test
fail again.
  • Loading branch information
robincaloudis committed Mar 28, 2024
1 parent bb04cb1 commit 345e5a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
36 changes: 16 additions & 20 deletions crates/ruff_python_formatter/src/statement/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,22 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
.map_or(preceding.end(), |comment| comment.slice().end());

match node_level {
NodeLevel::TopLevel(_) => {
match lines_after_ignoring_end_of_line_trivia(end, source) {
0 | 1 => hard_line_break().fmt(f)?,
2 => empty_line().fmt(f)?,
_ => match source_type {
PySourceType::Stub => {
empty_line().fmt(f)?;
}
PySourceType::Python | PySourceType::Ipynb => {
write!(f, [empty_line(), empty_line()])?;
}
},
}
}
NodeLevel::CompoundStatement => {
match lines_after_ignoring_end_of_line_trivia(end, source) {
0 | 1 => hard_line_break().fmt(f)?,
_ => empty_line().fmt(f)?,
}
}
NodeLevel::TopLevel(_) => match lines_after(end, source) {
0 | 1 => hard_line_break().fmt(f)?,
2 => empty_line().fmt(f)?,
_ => match source_type {
PySourceType::Stub => {
empty_line().fmt(f)?;
}
PySourceType::Python | PySourceType::Ipynb => {
write!(f, [empty_line(), empty_line()])?;
}
},
},
NodeLevel::CompoundStatement => match lines_after(end, source) {
0 | 1 => hard_line_break().fmt(f)?,
_ => empty_line().fmt(f)?,
},
NodeLevel::Expression(_) | NodeLevel::ParenthesizedExpression => {
hard_line_break().fmt(f)?;
}
Expand Down
20 changes: 2 additions & 18 deletions crates/ruff_python_trivia/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ pub fn lines_after_ignoring_end_of_line_trivia(offset: TextSize, code: &str) ->
SimpleTokenizer::starts_at(offset, code)
.skip_while(|token| token.kind != SimpleTokenKind::Newline && token.kind.is_trivia())
.take_while(|token| {
token.kind == SimpleTokenKind::Newline
|| token.kind == SimpleTokenKind::Whitespace
|| token.kind == SimpleTokenKind::Semi
token.kind == SimpleTokenKind::Newline || token.kind == SimpleTokenKind::Whitespace
})
.filter(|token| token.kind == SimpleTokenKind::Newline)
.count() as u32
Expand Down Expand Up @@ -1035,10 +1033,7 @@ mod tests {
use ruff_python_parser::{Mode, Tok};
use ruff_text_size::{TextLen, TextRange, TextSize};

use crate::tokenizer::{
lines_after, lines_after_ignoring_end_of_line_trivia, lines_before, SimpleToken,
SimpleTokenizer,
};
use crate::tokenizer::{lines_after, lines_before, SimpleToken, SimpleTokenizer};
use crate::{BackwardsTokenizer, SimpleTokenKind};

struct TokenizationTestCase {
Expand Down Expand Up @@ -1451,15 +1446,4 @@ mod tests {
);
}
}

#[test]
fn lines_after_ignoring_end_of_line_trivia_multiline_string_semi_delimiter() {
assert_eq!(
lines_after_ignoring_end_of_line_trivia(
TextSize::new(19),
"a=\"\"\"hello world\"\"\";\n\n\nb = 10"
),
3
);
}
}

0 comments on commit 345e5a7

Please sign in to comment.