const formatFile = async (inputFilePath, outputFilePath) => { const fileContent = await readFile(inputFilePath); const prettierConfig = await prettier.resolveConfig(inputFilePath); const writtenFilePath = await writeFile( outputFilePath, prettier.format(fileContent, {...prettierConfig, filepath: inputFilePath}), ); return writtenFilePath; }
task.plugin('prettier', {}, function * (file, opts) { const out = format(file.data.toString(), opts); file.data = Buffer.from(out); });
const check = async () => { console.log(chalk.reset('Validating source file formatting...')); try { const sourceFilePaths = await getSourceFilePaths(); await Promise.all( sourceFilePaths.map(async filePath => { const fileContent = await readFile(filePath); const prettierConfig = await prettier.resolveConfig(filePath); const isCompliant = prettier.check(fileContent, {...prettierConfig, filepath: filePath}); if (!isCompliant) { throw filePath; } }), ); console.log(chalk.green('Finished validating file formatting.')); } catch (error) { console.log(chalk.red('Unformatted file found:\n'), chalk.reset(error)); process.exit(1); } }
files.forEach(file => { const { content, check, path } = file if (check) { print(chalk.grey(`INFO: lint ${path}`)) return } print(`INFO: lint ${path}`) const validContent = prettier.format(content, { filepath: path }) fs.writeFileSync(path, validContent, { flag: 'w' }) })
files.forEach(file => { const { path, content } = file process.stdout.write('\b'.repeat(10000)) process.stdout.write(chalk.grey(`INFO: check ${path}`)) const valid = prettier.check(content, { filepath: path }) file.check = valid if (!valid && !program.lint) { print(chalk.red(`ERROR: ${path} lint check fails`)) process.exit(1) } })
function cleanHtml(html) { return prettier.format(html, { parser: 'html' }); }
fn() { return payloads.map(({ payload, options }) => prettier.format(payload, options) ); }
const PackagedExternalFile = ({ obj, packagedArguments }) => { const { isTypescript } = packagedArguments; const dialect = isTypescript ? 'typescript' : 'javascript'; const wrappedObj = wrapSafely(obj); const code = { typescript: `export default ${wrappedObj}`, javascript: `module.exports = ${wrappedObj}`, }[dialect]; return prettier.format(code, { singleQuote: true, parser: 'babel', }); }
function cleanHtml(html) { return prettier.format(html, { parser: 'html' }); }
function cleanHtml(html) { return prettier.format(html, { parser: 'html' }); }
function cleanHtml(html) { return prettier.format(html, { parser: 'html' }); }
function cleanHtml(html) { return prettier.format(html, { parser: 'html' }); }
function cleanHtml(html) { return prettier.format(html, { parser: 'html' }); }
function cleanHtml(html) { return prettier.format(html, { parser: 'html' }); }
function cleanHtml(html) { return prettier.format(html, { parser: 'html' }); }