Refactor and rename skip_trailing_trivia (#6312)

Based on feedback here:
https://github.com/astral-sh/ruff/pull/6274#discussion_r1282747964.
This commit is contained in:
Charlie Marsh 2023-08-04 09:30:53 -04:00 committed by GitHub
parent 38a96c88c1
commit 1e3fe67ca5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 42 deletions

View file

@ -1,7 +1,7 @@
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions};
use ruff_python_ast::helpers::is_compound_statement;
use ruff_python_ast::{self as ast, Constant, Expr, Ranged, Stmt, Suite};
use ruff_python_trivia::{lines_after, lines_before, skip_trailing_trivia};
use ruff_python_trivia::{lines_after_ignoring_trivia, lines_before};
use crate::context::{NodeLevel, WithNodeLevel};
use crate::prelude::*;
@ -180,8 +180,7 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
// it then counts the lines between the statement and the trailing comment, which is
// always 0. This is why it skips any trailing trivia (trivia that's on the same line)
// and counts the lines after.
let after_trailing_trivia = skip_trailing_trivia(offset, source);
lines_after(after_trailing_trivia, source)
lines_after_ignoring_trivia(offset, source)
};
match node_level {