* Add option to require @prettier or @format pragma Fixes #2397. Inspired by `eslint-plugin-prettier` and the discussion in #2397, this implements requiring a special comment pragma to be present in a file's first comment in order to be formatted. This will help large codebases gradually transition to prettier over time without tons of churn or large code reviews. I implemented this as a standard prettier "option", not just a typical `argv` flag, as it is relevant in both the cli and the api. This way it can be provided programmatically, on the command line, or standardized in a prettierrc file so like the style options, every user can use this setting consistently and only apply prettier to relevant files, no mattier their editor integration. This requires the pragma begin with `@` (in fact it's inserted if the user doesn't provide it). Currently the usage implies it must be "prettier" or "format", but it can technically be any value other than "none", which is similar to the `trailingCommas` option. cc @vjeux * Don't quote anything in runPrettier; this is usually handled by a shell * Make --require-pragma a boolean option * Use jest-docblock to find pragmas without parsing the ast * Clarify docs * includes -> indexOf * Move test out of integration
60 lines
608 B
Plaintext
60 lines
608 B
Plaintext
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
exports[`module-with-pragma.js 1`] = `
|
|
/**
|
|
* @flow
|
|
* @format
|
|
*/
|
|
|
|
function foo(bar)
|
|
|
|
|
|
{
|
|
|
|
return bar +
|
|
3 +
|
|
4;
|
|
}
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/**
|
|
* @flow
|
|
* @format
|
|
*/
|
|
|
|
function foo(bar) {
|
|
return bar + 3 + 4;
|
|
}
|
|
|
|
`;
|
|
|
|
exports[`module-without-pragma.js 1`] = `
|
|
/**
|
|
* @flow
|
|
*/
|
|
|
|
function foo(bar)
|
|
|
|
|
|
{
|
|
|
|
return bar +
|
|
3 +
|
|
4;
|
|
}
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/**
|
|
* @flow
|
|
*/
|
|
|
|
function foo(bar)
|
|
|
|
|
|
{
|
|
|
|
return bar +
|
|
3 +
|
|
4;
|
|
}
|
|
|
|
`;
|