Ignore commonly generated folders

See original GitHub issue

At the moment, Prettier ignores node_modules/. In my experience, folders coverage and dist are commonly used to contain generated artifacts and could be ignored accordingly, as a sensible default.

If someone really needs to include those, adding !coverage/ and/or !dist/ in .prettierignore should re-include them.

Thoughts? 😃

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:14
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

43reactions
BuckyMalercommented, Sep 6, 2019

I think all entries in .gitignore should be ignored by Prettier without the need to specify --ignore-path .gitignore. The .gitignore should be a constant with the option to additionally use a .prettierignore. I think this is sensible because I cannot think of a reason as to why a file that is not version controlled would need to be formatted. With this, many projects may not even need to add a .prettierignore. A .prettierignore is particularly useful for ignoring files that are version controlled because that cannot be done with a .gitignore.

6reactions
alexilyaevcommented, May 14, 2020

I think it’s safe to say that eventually Prettier will face the same requests from the community as ESLint did. So I suggest following ESLint’s ignore features: https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories

Specifically:

  • Supporting –ignore-pattern CLI command (can be used multiple times) to add custom ignore patterns on top of the ones from --ignore-path.
    • This is useful for running Prettier without needing to add config files.
    • e.g. npx prettier --ignore-pattern ... would be really nice.
    • But this is not comfortable when you have many patterns you want to ignore, and would require extra integration from IDE’s (otherwise ā€œFormat On Saveā€ could format a file we want to ignore).
    • Another interesting use case: Un-ignore a pattern, thus force formatting files that are usually ignored (e.g. ā€œFormat this file with Prettierā€ command in IDE’s doesn’t work without it if the file is ignored elsewhere).
  • Supporting ignorePatterns property in Prettier configurations.
    • In ESLint, this one took several years of discussions and tickets from the community until they were finally convinced to add it.
    • This essentially solves most custom ignore use cases, as Prettier already uses the config no matter how you run it. So IDE support is out-of-the-box.
  • /* prettier-disable */ block comment at the top of the file (Disabling Rules with Inline Comments)
  • Worth mentioning they also have –no-ignore

An alternative would be to always include .prettierignore and let --ignore-path merge on top of that. Or support several --ignore-path commands. But that would be confusing IMO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

.gitignore File – How to Ignore Files and Folders in Git
A . gitignore file is a plain text file that contains a list of all the specified files and folders from the project...
Read more >
Ignoring Files and Directories in Git (.gitignore) - Linuxize
Ignored files are usually platform-specific files or automatically created files from the build systems. Some common examples include:.
Read more >
gitignore - ignore generated files in a folder, but not the folder
I have a gulp task that pipes assets into a directory. I would like to include the directory in my project, but exclude...
Read more >
Ignoring files, folders, or code - Semgrep
Exclude specific files, folders or parts of code from results of Semgrep scans in your repository or working directory. Semgrep does not generate...
Read more >
.gitignore file - ignoring files in Git | Atlassian Git Tutorial
Git sees every file in your working copy as one of three things: ... Ignored files are usually build artifacts and machine generated...
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