prettier: config file doesn't work at the way other libraries do
First, It’s very exciting that config file support is out.
However, after a few tries, I find its usage is a bit ambiguous.
For example, I define a .prettierrc
like the follow:
{
"printWidth": 120,
"tabWidth": 2,
"singleQuote": true,
"semi": false,
"trailingComma": "all",
"overrides": [
{
"files": "src/**/*.ts",
"options": {
"parser": "typescript",
"tabWidth": 4
}
},
{
"files": "./**/*.js",
"options": {
"parser": "babylon",
"singleQuote": false
}
},
{
"files": "src/**/*.{scss,css}",
"options": {
"parser": "postcss",
"singleQuote": false,
"semi": true
}
},
{
"files": "./**/*.json",
"options": {
"parser": "json"
}
},
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
]
}
Since I specify the files in overrides
, prettier should do the right job with prettier --write
or prettier --list-difference
.
However, prettier doesn’t work that way now. If I run the command above, prettier will only output the help message and exit. Apparently, prettier is waiting for source input. But it doesn’t make sense to specify input again.
There is a dirty workaround prettier --write ./**/**.{ts,js,json,scss,css}
. But it lose the ability to prettier various specify path.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 15
- Comments: 20 (10 by maintainers)
I would really like Prettier to just format all files in the cwd that it supports. Currently I have to construct a glob in every project, which is highly non-trivial when it comes to dotfiles like
.travis.yml
and other config files:@trevordmiller Prettier 2.0 is going to support
prettier --write .
, see https://github.com/prettier/prettier/pull/7660.It’s actually a separate issue.
@e-cloud is expressing that
prettier --write
should know where to look for files based on the configuration file, rather than passing a glob to the CLI.Now that we have
prettier --write .
, this can be considered resolved.As I told you here: https://github.com/prettier/prettier/issues/2506#issuecomment-325570177
Workaround:
prettier ./**/**.{ts,js,json,scss,css} --write
(move--write
last)Seems like the glob matching actually was fixed and the pattern
**/*.yml
now also matches.travis.yml
🎉+1 on this; whitelisting globs where prettier should run would be very helpful.