Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(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;
}
});
/**
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;
}
});
// 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),
})
}
},
}
(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<*>);
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];
};
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));
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));
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));
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",