.prettierignore ignore everything except specific folder

See original GitHub issue

.prettierignore file:

# Ignore everything:
*

# Except myapp folder:
!myapp/

When running prettier from console - works great, changes in myapp folder are formatted by prettier and changes in other folders are ignored (I am using commit hook with husky and lint-staged configured exactly like in prettier docs).

When I run “Format document” from vscode on file inside myapp folder, it is not working. After removing .prettierignore file, “Format document” works great.

I think prettier-vscode is ignoring everything without exceptions when I use such prettierignore file?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
tlaregcommented, Sep 5, 2018

ok, maybe this is my fault, works ok with:

# Ignore everything:
/*

# Except myapp:
!/myapp
1reaction
michael13491commented, Jul 24, 2019

I have a similar problem to this, except my project is a monorepo. The solution that tlareg has does not seem to work for me.

Project structure:

root/
  .git
  other-app/
  web-app/
    package.json
    .prettierignore

I want to specify prettierignore so that only web-app dir files get formatted on save.

.prettierignore file:

# Ignore everything:
/*

# Except web-app:
!/web-app

When I run “Format document” from vscode on file inside web-app folder, it is not working. After removing .prettierignore file, “Format document” works great.

However, with pretty-quick pre-commit hook, the staged files inside web-app will be formatted. So it seems the prettierignore syntax is problematic only on prettier-vscode?

Update The above .prettierignore will work with prettier-vscode if I open the project from root, but does not work if it is opened from web-app directory

Update again Fixed this myself. Resolved by moving .prettierignore to root, and add files to ignore. In web-app, create a workspace setting to include prettier.ignorePath

Final result. Project structure:

root/
  .git
  .prettierignore
  other-app/
  web-app/
    package.json

.prettierignore file:

# Ignore everything:
/*

# Except web-app:
!/**/web-app

vscode settings.json in web-app dir includes

"editor.formatOnSave": true,
"prettier.ignorePath": "../.prettierignore"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignoring Code - Prettier
Use .prettierignore to ignore (i.e. not reformat) certain files and folders completely. Use “prettier-ignore” comments to ignore parts of files.
Read more >
How to Ignore all folders with folder pattern using prettier
You can add .next or /.next to the .prettierignore file. -- ignore-path is the path to a file containing patterns that describe files...
Read more >
prettier ignore folders | The search engine you control.
To exclude files from formatting, create a .prettierignore file in the root of ... .prettierignore ignore everything except specific folder #578 - GitHub....
Read more >
prettier/prettier ignore Code Example - Code Grepper
All Languages >> Html >> prettier/prettier ignore. Grepper Logo Small. “prettier/prettier ignore” Code Answer's. how to ignore prettier.
Read more >
Ignoring Code - ESLint - Pluggable JavaScript Linter
If the path to lint is a glob pattern or directory path and contains a dot-folder, all dot-files and dot-folders are linted. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found