I'd like to propose a new option for prettier-vscode.
eslint-plugin-prettier supports a pragma comment. This comment tells eslint which files to apply prettier formatting rules to. This is a great affordance for incremental adoption in large codebases.
It would be great if format-on-save functionality could match this behaviour and respect a pragma comment.
Option would look something like:
// If set, prettier will only apply formatting rules to files with this pragma in the heading docblock.
"prettier.pragma": "@prettier",
IMO this is a good idea but not in this extension. It would be better in prettier itself.
Why only when formatOnSave?
formatOnSave is the most problematic experience, that's just where I'm coming from.
Prettier supports formatting of selections as well as entire files, which I'm surmising could make it awkward to support handling of a pragma comment.
That said, I'm happy with any solution that achieves this effect.
I have posted an issue against prettier, to continue this discussion: https://github.com/prettier/prettier/issues/2397
Closing it here as it is discussed in prettier.
Even if it is resolved in prettier itself, prettier-vscode will need to add support, I guess we can open a separate issue at such time?
If we need to.
Currently, I think prettier will simply return the original text if it encounters such a pragma. In that case, we won't need to do anything.
It sounds like it's most likely to be implemented as a command line flag, so it would just be a matter of supporting a new option and translating it to the command-line flag, I expect.
Thanks for coordinating on this. 馃憤
Seems my last comment was the opposite of what it should be.
We will certainly need to have an option to only run on pragma files. So yes an issue or a PR (referencing this) at that time would make sens.
Prettier now supports this. Can we reopen this issue, or create another?
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Prettier now supports this. Can we reopen this issue, or create another?