How to use the prettier.doc.builders function in prettier

To help you get started, we’ve selected a few prettier examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onflow / cadence / tools / prettier-plugin-cadence / src / utils.ts View on Github external
import { doc } from "prettier"
const { line, group, softline } = doc.builders

export function splitByLength(input: string, size: number): string[] {
	const result = input.split(" ").reduce(
		(acc: any, word: string): any => {
			const newSlice =
				acc.slice !== "" ? [acc.slice, word].join(" ") : `/// ${word}`
			if (newSlice.length < size) {
				acc.slice = newSlice
			} else {
				acc.arr.push(acc.slice)
				acc.slice = ""
			}
			return acc
		},
		{
			slice: "",
github prettier / plugin-swift / src / printer / chain.js View on Github external
"use strict";

const util = require("prettier/src/common/util");
const comments = require("prettier/src/main/comments");
const doc = require("prettier").doc;
const {
  indent,
  hardline,
  group,
  breakParent,
  join,
  conditionalGroup
} = doc.builders;
const { willBreak } = doc.utils;

const { concat } = require("./builders");

// We detect calls on member expressions specially to format a
// common pattern better. The pattern we are looking for is this:
//
// arr
//   .map(x => x + 1)
//   .filter(x => x > 10)
//   .some(x => x % 2)
//
// The way it is structured in the AST is via a nested sequence of
// MemberAccessExpr and FunctionCallExpr. We need to traverse the AST
// and make groups out of it to print it in the desired way.
function printMemberChain(path, options, print) {
github UnwrittenFun / prettier-plugin-svelte / src / print / index.ts View on Github external
import { extractAttributes } from '../lib/extractAttributes';
import { getText } from '../lib/getText';
import { parseSortOrder, SortOrderPart } from '../options';
import { hasSnippedContent, unsnipContent } from '../lib/snipTagContent';
const {
    concat,
    join,
    line,
    group,
    indent,
    dedent,
    softline,
    hardline,
    fill,
    breakParent,
} = doc.builders;

export type PrintFn = (path: FastPath) => Doc;

declare module 'prettier' {
    export namespace doc {
        namespace builders {
            interface Line {
                keepIfLonely?: boolean;
            }
        }
    }
}

// @see http://xahlee.info/js/html5_non-closing_tag.html
const SELF_CLOSING_TAGS = [
    'area',
github prettier / plugin-swift / src / printer / generic.js View on Github external
"use strict";

const assert = require("assert");

const { mapDoc } = require("prettier/src/common/util");
const comments = require("prettier/src/main/comments");

const doc = require("prettier").doc;
const docBuilders = doc.builders;

const { printToken } = require("./tokens");
const { verbatimPrint } = require("./verbatim");
const chain = require("./chain");
const isMemberish = chain.isMemberish;
const printMemberChain = chain.printMemberChain;

const identity = o => o;

const {
  align,
  indent,
  line,
  hardline,
  softline,
  group,
github prettier / plugin-swift / src / printer / builders.js View on Github external
"use strict";

const doc = require("prettier").doc;
const docBuilders = doc.builders;

const { join, hardline, softline, line } = docBuilders;

function smartJoin(separator, parts) {
  const result = [];
  let lastPart;

  parts.filter(x => x).forEach((part, index) => {
    const firstPart = part.parts ? part.parts[0] : part;
    if (
      index > 0 &&
      firstPart !== ":" &&
      firstPart !== "..." &&
      firstPart !== ")" &&
      firstPart !== "<" &&
      lastPart !== "("
github onflow / cadence / tools / prettier-plugin-cadence / src / utils.ts View on Github external
function concat(parts: any[]) {
	parts = parts.filter(x => x);

	switch (parts.length) {
		case 0:
			return "";
		case 1:
			return parts[0];
		default:
			return doc.builders.concat(parts);
	}
}