UNPKG

prettier-plugin-awk

Version:

[![tests](https://github.com/Beaglefoot/prettier-plugin-awk/actions/workflows/tests.yml/badge.svg)](https://github.com/Beaglefoot/prettier-plugin-awk/actions/workflows/tests.yml) [![npm](https://img.shields.io/npm/v/prettier-plugin-awk)](https://www.npmjs

35 lines (28 loc) 962 B
import { doc, Printer } from 'prettier' import { SyntaxNode } from 'tree-sitter' import { doesCommentBelongToNode } from './utils' import { separatedNodes } from './wrappers' const { hardline, indent, group, line } = doc.builders export const formatBlock: Printer<SyntaxNode>['print'] = (path, _options, print) => { const node = path.getValue() const statementsCount = node.children.filter((node) => node.isNamed).length if (statementsCount === 0) return ['{}'] if ( statementsCount === 1 && !separatedNodes.has(node.firstNamedChild!.type) && node.descendantsOfType('comment').length === 0 ) { return group(['{', indent([line, path.call(print, 'firstNamedChild')]), line, '}']) } return [ '{', indent( node.namedChildren.flatMap((n, i) => { if (doesCommentBelongToNode(n)) return [' ', n.text] return [hardline, path.call(print, 'namedChildren', i)] }), ), hardline, '}', ] }