UNPKG

prettier-plugin-solidity

Version:

A Prettier Plugin for automatically formatting your Solidity code.

28 lines 1.07 kB
import { doc, util } from 'prettier'; import { printComment } from '../slang-comments/printer.js'; import { joinExisting } from '../slang-utils/join-existing.js'; import { locEnd } from '../slang-utils/loc.js'; const { hardline, line } = doc.builders; function isPrintable(comment) { return !comment.trailing && !comment.leading && !comment.printed; } export function printComments(path, options) { if (path.node.comments === undefined) return []; return joinExisting(line, path.map((commentPath, index, comments) => { const comment = commentPath.node; if (!isPrintable(comment)) { return ''; } comment.printed = true; const isLast = index === comments.length - 1 || comments.slice(index + 1).findIndex(isPrintable) === -1; return [ printComment(commentPath), !isLast && util.isNextLineEmpty(options.originalText, locEnd(comment)) ? hardline : '' ]; }, 'comments')); } //# sourceMappingURL=print-comments.js.map