All files / src/nodes print-comments.js

100% Statements 12/12
100% Branches 10/10
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28        55x   105x 5947x         860x 860x 730x   130x 5x   125x 125x           55x  
const {
  doc: {
    builders: { join, line }
  }
} = require('prettier');
 
const printComments = (node, path, options, filter = () => true) =>
  node.comments
    ? join(
        line,
        path
          .map((commentPath) => {
            const comment = commentPath.getValue();
            if (comment.trailing || comment.leading || comment.printed) {
              return null;
            }
            if (!filter(comment)) {
              return null;
            }
            comment.printed = true;
            return options.printer.printComment(commentPath);
          }, 'comments')
          .filter(Boolean)
      )
    : '';
 
module.exports = printComments;