src/main/comments.js/printTrailingComment
function printTrailingComment(path, options) {
  const comment = path.getValue();
  const printed = printComment(path, options);

  const { printer, originalText, locStart } = options;
  const isBlock = printer.isBlockComment && printer.isBlockComment(comment);

  if (hasNewline(originalText, locStart(comment), { backwards: true })) {
    // This allows comments at the end of nested structures:
    // {
    //   x: 1,
    //   y: 2
    //   // A comment
    // }
    // Those kinds of comments are almost always leading comments, but
    // here it doesn't go "outside" the block and turns it into a
    // trailing comment for `2`. We can simulate the above by checking
    // if this a comment on its own line; normal trailing comments are
    // always at the end of another expression.

    const isLineBeforeEmpty = isPreviousLineEmpty(
      originalText,
      comment,
      locStart
    );

    return lineSuffix([hardline, isLineBeforeEmpty ? hardline : "", printed]);
  }

  let parts = [" ", printed];

  // Trailing block comments never need a newline
  if (!isBlock) {
    parts = [lineSuffix(parts), breakParent];
  }

  return parts;
}