How to use the prettier.__debug 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 prettier-solidity / prettier-plugin-solidity / tests_config / run_spec.js View on Github external
function parse(string, opts) {
  return prettier.__debug.parse(string, opts, /* massage */ true).ast;
}
github prettier / plugin-ruby / test / js / setupTests.js View on Github external
const { spawn, spawnSync } = require("child_process");
const path = require("path");
const prettier = require("prettier");
const readline = require("readline");

// Set RUBY_VERSION so certain tests only run for certain versions
process.env.RUBY_VERSION = spawnSync("ruby", ["-e", "puts RUBY_VERSION"])
  .stdout.toString()
  .trim();

// eslint-disable-next-line no-underscore-dangle
const { formatAST } = prettier.__debug;

const parser = spawn("ruby", ["./test/js/parser.rb"]);
afterAll(() => parser.kill());

const rl = readline.createInterface({
  input: parser.stdout,
  output: parser.stdin
});

const checkFormat = (before, after, config) =>
  new Promise(resolve => {
    const opts = Object.assign({ parser: "ruby", plugins: ["."] }, config);

    rl.question(`${before}\n---\n`, response => {
      const { formatted } = formatAST(JSON.parse(response), opts);
github dangmai / prettier-plugin-apex / tests_config / run_spec.js View on Github external
function parse(string, opts) {
  // eslint-disable-next-line no-underscore-dangle
  return prettier.__debug.parse(
    string,
    {
      apexStandaloneParser: "built-in",
      apexStandalonePort: 2117,
      apexStandaloneHost: "localhost",
      ...opts,
    },
    /* massage */ true,
  ).ast;
}
github jsxstyle / jsxstyle / packages / jsxstyle-prettier-parser / src / babylonTraverse.ts View on Github external
!t.isStringLiteral(attr.value)
        ) {
          return;
        }

        if (!seenValues[attr.value.value]) {
          try {
            if (attr.value.value.includes(';')) {
              throw new Error('CSS values cannot contain semicolons');
            }

            // the minimal amount of CSS that the CSS parser can parse
            const wrapped = `__jsxstyle__:${attr.value.value};`;
            const cssAst = postcssParser.parsers.css.parse(wrapped, null, {});

            const value = prettier.__debug.formatAST(cssAst.nodes[0].value, {
              filepath: 'example.css',
              printWidth: 1000,
            });

            if (typeof value.formatted !== 'string') {
              throw new Error('formatted value is not a string!');
            }

            seenValues[attr.value.value] = value.formatted;
          } catch (e) {
            console.error(e);
            return;
          }
        }

        attr.value = t.stringLiteral(seenValues[attr.value.value]);
github prettier / plugin-python / tests_config / run_spec.js View on Github external
function parse(string, opts) {
  return stripExtraNonComparableKeys(prettier.__debug.parse(string, opts));
}
github trivago / prettier-plugin-twig-melody / tests_config / run_spec.js View on Github external
function parse(string, opts) {
    return stripLocation(prettier.__debug.parse(string, opts));
}