mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
Join implicit concatenated strings when they fit on a line (#13663)
This commit is contained in:
parent
e402e27a09
commit
73ee72b665
50 changed files with 3907 additions and 363 deletions
|
@ -431,6 +431,41 @@ impl<'a> Comments<'a> {
|
|||
pub(crate) fn debug(&'a self, source_code: SourceCode<'a>) -> DebugComments<'a> {
|
||||
DebugComments::new(&self.data.comments, source_code)
|
||||
}
|
||||
|
||||
/// Returns true if the node itself or any of its descendants have comments.
|
||||
pub(crate) fn contains_comments(&self, node: AnyNodeRef) -> bool {
|
||||
use ruff_python_ast::visitor::source_order::{SourceOrderVisitor, TraversalSignal};
|
||||
|
||||
struct Visitor<'a> {
|
||||
comments: &'a Comments<'a>,
|
||||
has_comment: bool,
|
||||
}
|
||||
|
||||
impl<'a> SourceOrderVisitor<'a> for Visitor<'a> {
|
||||
fn enter_node(&mut self, node: AnyNodeRef<'a>) -> TraversalSignal {
|
||||
if self.has_comment {
|
||||
TraversalSignal::Skip
|
||||
} else if self.comments.has(node) {
|
||||
self.has_comment = true;
|
||||
TraversalSignal::Skip
|
||||
} else {
|
||||
TraversalSignal::Traverse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.has(node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let mut visitor = Visitor {
|
||||
comments: self,
|
||||
has_comment: false,
|
||||
};
|
||||
node.visit_preorder(&mut visitor);
|
||||
|
||||
visitor.has_comment
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) type LeadingDanglingTrailingComments<'a> = LeadingDanglingTrailing<'a, SourceComment>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue