How to use the prettier.getSupportInfo 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 flow-typed / flow-typed / definitions / npm / prettier_v1.x.x / flow_v0.56.x-v0.83.x / test_prettier_v1.x.x.js View on Github external
(syncConfig.printWidth: void | number);
}
// $ExpectError (Does not return promise)
(syncConfig: Promise);

// $ExpectError (Options should have proper types)
prettier.resolveConfig.sync("/path", { useCache: "true" });
prettier.resolveConfig.sync("/path", { useCache: true });

// $ExpectError (Must use correct name)
prettier.clearConfigCash();
prettier.clearConfigCache();

// $ExpectError (Version should be a string)
prettier.getSupportInfo(0.1);
prettier.getSupportInfo("0.1");

prettier.format(code, {
  parser() {
    // $ExpectError (Custom parser should return an ast)
    return null;
  }
});

prettier.format(code, {
  parser(text, { babylon }) {
    const ast = babylon(text);
    return ast;
  }
});

/**
github flow-typed / flow-typed / definitions / npm / prettier_v1.x.x / flow_v0.56.x-v0.83.x / test_prettier_v1.x.x.js View on Github external
if (syncConfig != null) {
  (syncConfig.printWidth: void | number);
}
// $ExpectError (Does not return promise)
(syncConfig: Promise);

// $ExpectError (Options should have proper types)
prettier.resolveConfig.sync("/path", { useCache: "true" });
prettier.resolveConfig.sync("/path", { useCache: true });

// $ExpectError (Must use correct name)
prettier.clearConfigCash();
prettier.clearConfigCache();

// $ExpectError (Version should be a string)
prettier.getSupportInfo(0.1);
prettier.getSupportInfo("0.1");

prettier.format(code, {
  parser() {
    // $ExpectError (Custom parser should return an ast)
    return null;
  }
});

prettier.format(code, {
  parser(text, { babylon }) {
    const ast = babylon(text);
    return ast;
  }
});
github meteorlxy / eslint-plugin-prettier-vue / lib / rules / prettier / create.js View on Github external
// If we can't infer the parser from from the filename, either
        // because no filename was provided or because there is no parser
        // found for the filename, use javascript.
        // This is added to the options first, so that
        // prettierRcOptions and eslintPrettierOptions can still override
        // the parser.

        // `parserBlockList` should contain the list of prettier parser
        // names for file types where:
        // * Prettier supports parsing the file type
        // * There is an ESLint processor that extracts JavaScript snippets
        //   from the file type.
        const initialOptions = {}
        const parserBlockList = [null, 'graphql', 'markdown', 'html']
        if (parserBlockList.includes(inferredParser)) {
          const supportBabelParser = prettier
            .getSupportInfo()
            .languages.some(language => language.parsers.includes('babel'))

          initialOptions.parser = supportBabelParser ? 'babel' : 'babylon'
        }

        // Run prettier on this file
        prettierDifferences({
          context,
          source,
          options: Object.assign({}, initialOptions, prettierOptions),
        })
      }
    },
  }
github flow-typed / flow-typed / definitions / npm / prettier_v1.x.x / flow_v0.56.x-v0.83.x / test_prettier_v1.x.x.js View on Github external
(result: string);

result = prettier.check(code);
(result: boolean);

result = prettier.formatWithCursor(code, { cursorOffset: 1 });
(result.formatted: string);
(result.cursorOffset: number);

result = prettier.resolveConfig("/");
(result.then: Function);

result = prettier.clearConfigCache();
(result: void);

result = prettier.getSupportInfo("1.0");
(result.languages: Array<*>);
(result.options: Array<*>);
github jsxstyle / jsxstyle / packages / jsxstyle-prettier-parser / src / utils.ts View on Github external
export const inferParser = (
  filepath: string,
  plugins?: Array
): string | null => {
  const extension = path.extname(filepath);
  const filename = path.basename(filepath).toLowerCase();

  console.log('plugins!', plugins);

  const targetLanguage = prettier.getSupportInfo().languages.find(language => {
    const resultLanguage =
      language.since !== null &&
      ((language.extensions && language.extensions.indexOf(extension) > -1) ||
        (language.filenames &&
          language.filenames.find(name => name.toLowerCase() === filename)));

    return !!resultLanguage;
  });

  if (!targetLanguage) {
    return null;
  }

  return targetLanguage.parsers[0];
};
github azz / pretty-quick / src / isSupportedExtension.js View on Github external
import { extname } from 'path';
import { getSupportInfo } from 'prettier';

const extensions = getSupportInfo().languages.reduce(
  (prev, language) => prev.concat(language.extensions || []),
  []
);

export default file => extensions.includes(extname(file));
github walrusjs / walrus / packages / walrus-plugin-prettier / src / is-supported-extension.ts View on Github external
import { extname } from 'path';
import { getSupportInfo } from 'prettier';

const extensions = getSupportInfo().languages.reduce(
  (prev, language) => prev.concat(language.extensions || []),
  []
);

export default (file) => extensions.includes(extname(file));
github Siteimprove / alfa / build / tasks / prettier / transform.js View on Github external
const { notify } = require("wsk");
const { format, check, getSupportInfo } = require("prettier");
const { read, write } = require("../../utils/file");
const { extension } = require("../../utils/path");

const extensions = getSupportInfo().languages.reduce(
  (extensions, language) => extensions.concat(language.extensions || []),
  []
);

function isSupported(path) {
  return extensions.includes(extension(path));
}

async function onEvent(event, path, options = {}) {
  try {
    const source = await read(path);
    const options = { filepath: path };

    if (isSupported(path)) {
      await write(path, format(source, options));
github hawkins / prettier-webpack-plugin / index.js View on Github external
const prettier = require("prettier");
const fs = require("fs");
const path = require("path");

const DEFAULT_EXTENSIONS = prettier.getSupportInfo
  ? prettier
      .getSupportInfo()
      .languages.map(l => l.extensions)
      .reduce((accumulator, currentValue) => accumulator.concat(currentValue))
  : [
      ".css",
      ".graphql",
      ".js",
      ".json",
      ".jsx",
      ".less",
      ".sass",
      ".scss",
      ".ts",
      ".tsx",
      ".vue",
      ".yaml",