How to use the prettier.getFileInfo 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 usehenri / henri / packages / core / src / utils.js View on Github external
async function parseSyntax(resolve, file, data, onSuccess, inst = undefined) {
  if (typeof inst === 'undefined') {
    if (typeof henri === 'undefined') {
      throw new Error('henri is not defined...');
    }
    inst = henri;
  }

  try {
    const fileInfo = await prettier.getFileInfo(file);

    if (fileInfo) {
      prettier.format(data.toString(), { parser: fileInfo.inferredParser });
    }

    inst.status.set('locked', false);
    typeof onSuccess === 'function' && onSuccess();

    return resolve(true);
  } catch (error) {
    const { line, column } = _.has(error, 'loc.start')
      ? error.loc.start
      : { column: 0, line: 0 };

    inst.pen.error('server', `while parsing ${file}:${line}:${column}`);
    // eslint-disable-line no-console
github prettier / plugin-ruby / test / js / setupTests.js View on Github external
toInferRubyParser(filename) {
    const filepath = path.join(__dirname, filename);
    const plugin = path.join(__dirname, "..", "..", "src", "ruby");

    return prettier
      .getFileInfo(filepath, { plugins: [plugin] })
      .then(({ inferredParser }) => ({
        pass: inferredParser === "ruby",
        message: () => `
          Expected prettier to infer the ruby parser for ${filename},
          but got ${inferredParser} instead
        `
      }));
  }
});
github kuhami / react-ant / scripts / lint-prettier.js View on Github external
files.forEach(file => {
  Promise.all([
    prettier.resolveConfig(file, {
      config: prettierConfigPath,
    }),
    prettier.getFileInfo(file),
  ])
    .then(resolves => {
      const [options, fileInfo] = resolves;
      if (fileInfo.ignored) {
        return;
      }
      const input = fs.readFileSync(file, 'utf8');
      const withParserOptions = {
        ...options,
        parser: fileInfo.inferredParser,
      };
      const isPrettier = prettier.check(input, withParserOptions);
      if (!isPrettier) {
        console.log(
          `\x1b[31m ${file} is no prettier, please use npm run prettier and git add !\x1b[0m`
        );
github buildbuddy-io / buildbuddy / tools / prettier / common.ts View on Github external
export async function getFilePathsToFormat() {
  const paths = [];
  for (const path of getModifiedFilePaths()) {
    if (!FORMATTED_EXTENSIONS_REGEX.test(path)) continue;

    const info = await prettier.getFileInfo(`${getWorkspacePath()}/${path}`, { ignorePath: getPrettierignorePath() });
    if (info.ignored) continue;

    paths.push(path);
  }
  return paths;
}
github ant-design / ant-design-pro-layout / scripts / lint-prettier.js View on Github external
files.forEach(file => {
  Promise.all([
    prettier.resolveConfig(file, {
      config: prettierConfigPath,
    }),
    prettier.getFileInfo(file),
  ])
    .then(resolves => {
      const [options, fileInfo] = resolves;
      if (fileInfo.ignored) {
        return;
      }
      const input = fs.readFileSync(file, 'utf8');
      const withParserOptions = {
        ...options,
        parser: fileInfo.inferredParser,
      };
      const output = prettier.format(input, withParserOptions);
      if (output !== input) {
        fs.writeFileSync(file, output, 'utf8');
        console.log(chalk.green(`${file} is prettier`));
      }
github sphinx-quant / sphinx-quant / frontend / scripts / lint-prettier.js View on Github external
files.forEach(file => {
  Promise.all([
    prettier.resolveConfig(file, {
      config: prettierConfigPath,
    }),
    prettier.getFileInfo(file),
  ])
    .then(resolves => {
      const [options, fileInfo] = resolves;
      if (fileInfo.ignored) {
        return;
      }
      const input = fs.readFileSync(file, 'utf8');
      const withParserOptions = {
        ...options,
        parser: fileInfo.inferredParser,
      };
      const output = prettier.format(input, withParserOptions);
      if (output !== input) {
        fs.writeFileSync(file, output, 'utf8');
        console.log(chalk.green(`${file} is prettier`));
      }
github gitlabhq / gitlabhq / scripts / frontend / prettier.js View on Github external
const checkFileWithPrettierConfig = filePath =>
  prettier
    .getFileInfo(filePath, { ignorePath: '.prettierignore' })
    .then(({ ignored, inferredParser }) => {
      if (ignored || !inferredParser) {
        ignoredCount += 1;
        return;
      }
      return prettier.resolveConfig(filePath).then(fileOptions => {
        const options = { ...fileOptions, parser: inferredParser };
        return checkFileWithOptions(filePath, options);
      });
    });