(node: CstNode)
| 2524 | } |
| 2525 | |
| 2526 | fn remove_comma_separated(node: CstNode) { |
| 2527 | fn check_next_node_same_line(trailing_comma: &CstToken) -> bool { |
| 2528 | for sibling in trailing_comma.next_siblings() { |
| 2529 | match sibling { |
| 2530 | CstNode::Container(_) => return true, |
| 2531 | CstNode::Leaf(n) => match n { |
| 2532 | CstLeafNode::BooleanLit(_) |
| 2533 | | CstLeafNode::NullKeyword(_) |
| 2534 | | CstLeafNode::NumberLit(_) |
| 2535 | | CstLeafNode::StringLit(_) |
| 2536 | | CstLeafNode::WordLit(_) |
| 2537 | | CstLeafNode::Token(_) => return true, |
| 2538 | CstLeafNode::Whitespace(_) | CstLeafNode::Comment(_) => { |
| 2539 | // keep going |
| 2540 | } |
| 2541 | CstLeafNode::Newline(_) => return false, |
| 2542 | }, |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | true |
| 2547 | } |
| 2548 | |
| 2549 | let parent = node.parent(); |
| 2550 | let trailing_comma = node.trailing_comma(); |
| 2551 | let is_in_array_or_obj = parent |
| 2552 | .as_ref() |
| 2553 | .map(|p| matches!(p, CstContainerNode::Array(_) | CstContainerNode::Object(_))) |
| 2554 | .unwrap_or(false); |
| 2555 | let remove_up_to_next_line = trailing_comma |
| 2556 | .as_ref() |
| 2557 | .map(|c| !check_next_node_same_line(c)) |
| 2558 | .unwrap_or(true); |
| 2559 | |
| 2560 | for previous in node.previous_siblings() { |
| 2561 | if previous.is_trivia() && !previous.is_newline() { |
| 2562 | previous.remove_raw(); |
| 2563 | } else { |
| 2564 | break; |
| 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | let mut found_newline = false; |
| 2569 | |
| 2570 | // remove up to the trailing comma |
| 2571 | if trailing_comma.is_some() { |
| 2572 | let mut next_siblings = node.next_siblings(); |
| 2573 | for next in next_siblings.by_ref() { |
| 2574 | let is_comma = next.is_comma(); |
| 2575 | if next.is_newline() { |
| 2576 | found_newline = true; |
| 2577 | } |
| 2578 | next.remove_raw(); |
| 2579 | if is_comma { |
| 2580 | break; |
| 2581 | } |
| 2582 | } |
| 2583 | } else if is_in_array_or_obj && let Some(previous_comma) = node.previous_siblings().find(|n| n.is_comma()) { |
no test coverage detected
searching dependent graphs…