mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:35 +00:00
Fix 'MarkVerbatimCommentsAsFormattedVisitor' is unused warning in release builds (#11304)
This commit is contained in:
parent
1bb61bab67
commit
868bbd4de6
1 changed files with 14 additions and 13 deletions
|
@ -96,7 +96,6 @@ pub(crate) use format::{
|
||||||
leading_alternate_branch_comments, leading_comments, leading_node_comments, trailing_comments,
|
leading_alternate_branch_comments, leading_comments, leading_node_comments, trailing_comments,
|
||||||
};
|
};
|
||||||
use ruff_formatter::{SourceCode, SourceCodeSlice};
|
use ruff_formatter::{SourceCode, SourceCodeSlice};
|
||||||
use ruff_python_ast::visitor::preorder::{PreorderVisitor, TraversalSignal};
|
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_trivia::{CommentLinePosition, CommentRanges, SuppressionKind};
|
use ruff_python_trivia::{CommentLinePosition, CommentRanges, SuppressionKind};
|
||||||
use ruff_source_file::Locator;
|
use ruff_source_file::Locator;
|
||||||
|
@ -407,6 +406,20 @@ impl<'a> Comments<'a> {
|
||||||
/// normally if `node` is the first or last node of a suppression range.
|
/// normally if `node` is the first or last node of a suppression range.
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
pub(crate) fn mark_verbatim_node_comments_formatted(&self, node: AnyNodeRef) {
|
pub(crate) fn mark_verbatim_node_comments_formatted(&self, node: AnyNodeRef) {
|
||||||
|
use ruff_python_ast::visitor::preorder::{PreorderVisitor, TraversalSignal};
|
||||||
|
|
||||||
|
struct MarkVerbatimCommentsAsFormattedVisitor<'a>(&'a Comments<'a>);
|
||||||
|
|
||||||
|
impl<'a> PreorderVisitor<'a> for MarkVerbatimCommentsAsFormattedVisitor<'a> {
|
||||||
|
fn enter_node(&mut self, node: AnyNodeRef<'a>) -> TraversalSignal {
|
||||||
|
for comment in self.0.leading_dangling_trailing(node) {
|
||||||
|
comment.mark_formatted();
|
||||||
|
}
|
||||||
|
|
||||||
|
TraversalSignal::Traverse
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for dangling in self.dangling(node) {
|
for dangling in self.dangling(node) {
|
||||||
dangling.mark_formatted();
|
dangling.mark_formatted();
|
||||||
}
|
}
|
||||||
|
@ -452,18 +465,6 @@ struct CommentsData<'a> {
|
||||||
comment_ranges: &'a CommentRanges,
|
comment_ranges: &'a CommentRanges,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MarkVerbatimCommentsAsFormattedVisitor<'a>(&'a Comments<'a>);
|
|
||||||
|
|
||||||
impl<'a> PreorderVisitor<'a> for MarkVerbatimCommentsAsFormattedVisitor<'a> {
|
|
||||||
fn enter_node(&mut self, node: AnyNodeRef<'a>) -> TraversalSignal {
|
|
||||||
for comment in self.0.leading_dangling_trailing(node) {
|
|
||||||
comment.mark_formatted();
|
|
||||||
}
|
|
||||||
|
|
||||||
TraversalSignal::Traverse
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn has_skip_comment(trailing_comments: &[SourceComment], source: &str) -> bool {
|
pub(crate) fn has_skip_comment(trailing_comments: &[SourceComment], source: &str) -> bool {
|
||||||
trailing_comments.iter().any(|comment| {
|
trailing_comments.iter().any(|comment| {
|
||||||
comment.line_position().is_end_of_line()
|
comment.line_position().is_end_of_line()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue