How to use the prettier/local.format 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 brodybits / prettierx / tests_integration / __tests__ / format.js View on Github external
test("html parser should handle CRLF correctly", () => {
  const input = "";
  expect(
    // use JSON.stringify to observe CRLF
    JSON.stringify(prettier.format(input, { parser: "html" }))
  ).toMatchSnapshot();
});
github brodybits / prettierx / tests_integration / __tests__ / format.js View on Github external
test("markdown parser should handle CRLF correctly", () => {
  const input = "```\r\n\r\n\r\n```";
  expect(
    // use JSON.stringify to observe CRLF
    JSON.stringify(prettier.format(input, { parser: "markdown" }))
  ).toMatchSnapshot();
});
github brodybits / prettierx / tests_integration / __tests__ / infer-parser.js View on Github external
test("prettier.format", () => {
    expect(prettier.format(" foo  (  )")).toEqual("foo();\n");
    expect(global.console.warn).toHaveBeenCalledTimes(1);
    expect(global.console.warn.mock.calls[0]).toMatchSnapshot();
  });
github brodybits / prettierx / tests_integration / __tests__ / parser-api.js View on Github external
test("allows usage of prettier's supported parsers", () => {
  const output = prettier.format("foo ( )", {
    parser(text, parsers) {
      expect(typeof parsers.babel).toEqual("function");
      expect(typeof parsers.babylon).toEqual("function");
      const ast = parsers.babel(text);
      ast.program.body[0].expression.callee.name = "bar";
      return ast;
    }
  });
  expect(output).toEqual("bar();\n");
});
github brodybits / prettierx / tests_integration / __tests__ / with-parser-inference.js View on Github external
test("json from .prettierrc", () => {
    expect(
      prettier.format("  {   }  ", { filepath: "x/y/.prettierrc" })
    ).toEqual("{}\n");
  });
github brodybits / prettierx / tests_integration / __tests__ / parser-api.js View on Github external
test("allows custom parser provided as object", () => {
  const output = prettier.format("1", {
    parser(text) {
      expect(text).toEqual("1");
      return {
        type: "Literal",
        value: 2,
        raw: "2"
      };
    }
  });
  expect(output).toEqual("2");
});
github brodybits / prettierx / tests_integration / __tests__ / with-parser-inference.js View on Github external
test("babel from Jakefile", () => {
    expect(
      prettier.format("let foo = ( x = 1 ) => x", { filepath: "x/y/Jakefile" })
    ).toEqual("let foo = (x = 1) => x;\n");
  });
});
github brodybits / prettierx / tests_integration / __tests__ / format.js View on Github external
expect(() =>
    prettier.format(input, { parser: "typescript" })
  ).toThrowErrorMatchingSnapshot();
github brodybits / prettierx / tests_integration / __tests__ / deprecated-parser.js View on Github external
expect(() => {
    prettier.format("hello_world( )", { parser: "babylon" });
    prettier.format("hello_world( )", { parser: "babylon" });
  }).not.toThrowError();
  expect(warnings).toMatchInlineSnapshot(`
github brodybits / prettierx / tests_integration / __tests__ / deprecated-parser.js View on Github external
expect(() =>
    prettier.format("body { color: #131313; }", { parser: "postcss" })
  ).not.toThrowError();