-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
How do I use the CLI to fix all files? #6280
Description
I apologize if this is a stupid question.
We have a large monorepo containing lots of projects. We need to specify the exact set of paths to be processed by Prettier. It's not okay for Prettier to go trawling through random folders, rewriting files with no idea whether they are inputs or outputs.
The .prettierignore config file seems like the right way to do this. Well, actually we want to specify what DOES get processed, rather than what doesn't. But I can solve that by inverting the logic, something like this:
/.prettierignore
# Exclude everything by default
/**/*
# But don't exclude folders (i.e. only exclude files)
!/**/*/
# Exclude node_modules folders at every level
node_modules/
# Also exclude the common folder at the top level
/common/
# Include specific file extensions if they appear in a project folder,
# which is always two levels deep
!/*/*/src/**/*.ts
!/*/*/src/**/*.tsx
!/*/*/src/**/*.js
!/*/*/config/**/*.jsonBut now, how do I get Prettier to rewrite these files? The CLI docs show an example like this:
prettier --single-quote --trailing-comma es5 --write "{app,__{tests,mocks}__}/**/*.js"
The "{app,__{tests,mocks}__}/**/*.js" glob is redundant, because my .prettierignore file is already communicating this information.
If I try prettier --check "*" or prettier --check NOTHING then Prettier seems to completely ignore the .prettierignore file.
The option --config-precedence=file-override looks like a solution. It supposedly makes the config file take precedence over the CLI.
But when I try prettier --check --config-precedence=file-override NOTHING, it fails with this error:
[error] No matching files. Patterns tried: NOTHING !**/node_modules/** !./node_modules/** !**/.{git,svn,hg}/** !./.{git,svn,hg}/**
What am I doing wrong here? This seems like the most basic first step for adopting Prettier...