Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have Format On Save recognize .prettierignore within workspace/project subfolders #3465

Open
cwhitemaddox opened this issue Jul 10, 2024 · 6 comments
Labels

Comments

@cwhitemaddox
Copy link

cwhitemaddox commented Jul 10, 2024

Right now, with the prettier-vscode extension installed, the extension will recognize a .prettierignore file that is on the root of the vscode workspace/project, but it will not recognize any .prettierignore files that are within folders in that vscode workspace.

It would be helpful to have the prettier-vscode extension recognize and honor the .prettierignore files that are within folders in a vscode workspace. This is especially helpful in a monorepo context, where different folders of the monorepo can have different package.jsons and different .prettierignore files.

If, for example, you have a folder structure in a workspace like so:

codebase-1/
  package.json
  .prettierignore
  src/
    first-script.ts
    first-file-to-ignore.ts
codebase-2/
  package.json
  .prettierignore
  src/
    second-script.ts
    second-file-to-ignore.ts

And the contents of codebase-1/.prettierignore are:

src/first-file-to-ignore.ts

With the vscode workspace opened on code structure above, opening codebase-1/src/first-file-to-ignore.ts and saving the file (with Format On Save enabled), prettier-vscode will format the file and disregard codebase-1/.prettierignore.


Edits:

  • 2025-02-21: I confirmed on my setup re: the comment below that this issue appears to only affect .prettierignore files and not .prettierrc files in subfolders. Updated the copy above to reflect that.
@MrHaila
Copy link

MrHaila commented Sep 7, 2024

To add to the issue, this also affects .prettierignore files. The current workaround is to duplicate the ignore file contents from subfolders into the repo root.

@edwinbradford
Copy link

I can also verify this behaviour with .prettierignore files in my setup as reported in this StackOverflow post. Reading the documentation I expected to be able to create a .prettierignore file in my project but it was being ignored and like the other reports it has to be in the workspace root which in a multiroot workspace is the parent of all projects.

@edwinbradford
Copy link

After some further tests it seems .prettierrc.json is recognised in any directory and does not have to be in the root directory of the project, however .prettierignore still has to be in the root directory to work at all. The workaround I've found is to create a prettierrc.json in any folder I want to ignore with a single { "requirePragma": true } rule inside.

Copy link

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

@github-actions github-actions bot added the Stale label Feb 11, 2025
@dev-nicolaos
Copy link

Bump, although this issue should be renamed to be ignore file specific

@cwhitemaddox cwhitemaddox changed the title Ability to use/configure Format On Save to work with prettier configs within folders Have Format On Save recognize .prettierignore within workspace/project subfolders Feb 21, 2025
@cwhitemaddox
Copy link
Author

I just updated this issue's title and the copy of my original post to reflect the scope only being .prettierignore files. I found the same with my setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
@MrHaila @edwinbradford @dev-nicolaos @cwhitemaddox and others