Skip to content

How do I use the CLI to fix all files? #6280

@octogonz

Description

@octogonz

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/**/*.json

But 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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:awaiting responseIssues that require answers to questions from maintainers before action can be taken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions