Fixes#2820. While that issue is about `@media (--fooBar)` in
particular, this commit changes to never lowercase stuff starting with
`--` in general, as it seems like those `--customStuff` things can pop
up kind of anywhere.
* 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
- Move the very important options --write and --list-different to the
top, in the new Output category. It could be argued that --help and
--version also belong there, but I don't think they deserve such a
prominent position, so they are left in the Other category.
--find-config-path could also be considered an Output option, but I
think it fits better in the Config category.
- Now that there's an Output category, should there also be an Input
category? I thought about that, but the only candidates for such a
category are --stdin and --stdin-filepath and I don't think they are
important enough to have their own category, so they stay in Other.
- Move --cursor-offset, --range-end and --range-start to a new Editor
category, since they are mainly for editor integrations.
- Document how Prettier deals with input and output by default.
- Move Format options first, since they feel the most important.
- Move --find-config-path to the Config category.
- Merge Command into Other. It wasn't clear what "Command" options are,
and the Other category isn't too long anyway.
- Move --range-end and --range-start into Other. The aren't Format
options.