in src/models/matches.rs [263:300]
fn _is_comment_safe_to_delete(
&mut self, comment: &Node, deleted_node: &Node, piranha_arguments: &PiranhaArguments,
trailing: bool,
) -> bool {
// Check if the comment is a comment in the language
if !self.is_comment(comment.kind().to_string(), piranha_arguments) {
return false;
}
// If trailing, check if the comment is on the same line as the deleted node
// i.e. where the deleted node ends or starts
let is_on_same_line = comment.range().start_point.row == deleted_node.range().end_point.row
|| comment.range().start_point.row == deleted_node.range().start_point.row;
// If trailing, return if the comment is on the same line as the deleted node
if trailing {
return is_on_same_line;
}
// If not trailing, return if the comment is on the same line as the deleted node
if is_on_same_line {
return true;
}
// Check if the previous node does not overlap with the comment
if let Some(previous_node) = comment.prev_sibling() {
if self.overlaps(comment, &previous_node) {
return false;
}
}
// Check if there exists no node between the comment and the deleted node
if let Some(next_node) = comment.next_sibling() {
if next_node.start_byte() < deleted_node.start_byte() {
let (start_range, _) = self.get_first_and_last_associated_ranges();
if next_node.start_byte() < start_range.start_byte {
return false;
}
}
}
true
}