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

config option to ignore paths #4708

Open
tvald opened this issue Jun 17, 2018 · 19 comments
Open

config option to ignore paths #4708

tvald opened this issue Jun 17, 2018 · 19 comments
Labels
area:api Issues with Prettier's Application Programming Interface area:cli Issues with Prettier's Command Line Interface area:ignore .prettierignore file, --ignore-path CLI option, /* prettier-ignore */ comments and so on type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@tvald
Copy link

tvald commented Jun 17, 2018

It's desirable to place rules for ignoring/excluding paths in .prettierrc rather than in .prettierignore, so that configuration for Prettier is self-contained within a single file.

(Of secondary concern, the prettier-vscode extension should soon support configuring the location of .prettierrc, but not .prettierignore. In general, more configuration files are just harder to deal with.)

For prior art, consider TypeScript's exclude configuration option:

// tsconfig.json
{
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}
@ikatyang
Copy link
Member

Related: #3460, #2691, and #3764.

@alexander-akait alexander-akait added area:api Issues with Prettier's Application Programming Interface type:enhancement A potential new feature to be added, or an improvement to how we print something labels Aug 7, 2019
@thorn0 thorn0 added the area:ignore .prettierignore file, --ignore-path CLI option, /* prettier-ignore */ comments and so on label Apr 30, 2020
@thorn0 thorn0 added the area:cli Issues with Prettier's Command Line Interface label Feb 13, 2021
@saadq
Copy link

saadq commented Mar 31, 2021

May be worth mentioning that one of the benefits for allowing this is to improve the usage of shareable Prettier configs. My team has a shareable Prettier config that we're using across our packages, but we still need to create separate .prettierignore files that list out all our globs in each one. Allowing this to be store inside the shareable config would be great.

@charles-allen
Copy link

charles-allen commented Jun 5, 2021

When running Prettier in a directory, I believe it will look for .prettierrc in ancestor directories, but it will not do the same for .prettierignore. As a result, I'm currently duplicating ignores (to support executing prettier module-by-module).

I believe, in addition to merging rc & ignore, this issue would also allow me to eliminate duplicate ignores by centralizing them under one .prettierrc (TL;DR: I could delete all the files below with comments; .eslintrc shown for comparison).

.eslintrc.js
.prettierrc.js
.prettierignore           # separate file
admin/.prettierignore     # duplicate
common/.prettierignore    # duplicate
docs/.prettierignore      # duplicate
functions/prettierignore  # duplicate
hosting/.prettierignore   # duplicate

@ssbarnea
Copy link

ssbarnea commented Feb 5, 2022

At this moment, for practical reasons, .prettierignore is a symlink to .gitignore but that prevents us from adding other exclude for files that are tracked in git but for which we do not want to use prettier.

The current options make it very hard to use prettier or to adopt prettier on bigger codebases as reformatting cannot happen over the night, it can easily take many months, especially if you happen to have at least one developer in the team that dislikes formatters. They will do their best to fight every related change.

@eddiemonge
Copy link

Is this a feature someone can work on or does the team not want this option?

@TomSssM
Copy link

TomSssM commented Mar 31, 2022

Yeah, would really appreciate this feature, having to duplicate .prettierignore for each leave package in a monorepo is inconvenient

@ssbarnea
Copy link

The worst part is that the prettierignore would always have to extend the already existing gitignore file.

If we would use gitignore implicitly and add extra ignores from config file, we could avoid having two files for prettier at repository root.

ewels added a commit to ewels/nf-core-tools that referenced this issue Apr 1, 2022
Direct copy of .gitignore.

Hopefully can get rid of this file again one day, see prettier/prettier#4708
@dawsbot
Copy link

dawsbot commented May 6, 2022

Everyone loves this request. I'd be happy to implement this if the core team can agree it'll get merged @prettier 🙏

I need fewer files at the root of the project.

@kevinwolfcr
Copy link

@prettier is there a way we can see this implemented? It is not a breaking change, and it will make a lot of people life's easier by allowing them to share their ignored paths, and easily picked by other tools (IDE extensions, other libraries relying on prettier, etc).

@tjx666
Copy link

tjx666 commented Jan 30, 2023

  • In order to ignore one file, I need to add a file .prettierignore. This is too heavy.
  • This also make it hard to share ignore config.

@andreavaccari
Copy link

I found two alternative workarounds until this feature is implemented.

Opt 1: Exclude files using Prettier's requirePragma:

  • Symlink .prettierignore to .gitignore to ignore all gitignored files:
ln .gitignore .prettierignore
  • Edit .prettierrc.cjs and include an override that requires pragmas:
overrides: [
  {
    files: [
      "package-lock.json",
    ],
    options: { requirePragma: true },
  },
],

In this example, package-lock.json is tracked by git but ignored by prettier.

Caveats:

  • It is possible to ignore directories with this approach, but prettier will still iterate over each file to check if the pragma is present. This is why it is still helpful to symlink the gitignore file to properly skip large directories like node_modules.
  • It looks like some file types (e.g. .svelte) are still formatted even without a pragma. If you choose to use this approach, make sure to test that the files you intend to ignore are actually skipped with prettier --check.

Opt 2: Run prettier with eslint using with eslint-plugins-prettier

  • Edit .eslintrc to use the prettier plugin and ignore the appropriate files:
extends: ["plugin:prettier/recommended"],
ignorePatterns: [
  require("parse-gitignore").parse(".gitignore").patterns,
  "package-lock.json"
],

Running prettier via eslint is however discouraged in the docs.


Neither workaround is desirable, and I hope a config option is provided soon.

@treshugart
Copy link

My use case involves both prettier and pretty-quick. While it's not too bad to run --workspaces with prettier in CI, for DX it's preferable not to run pretty-quick with --workspaces due to the start up time for each workspace. Doing this once at the root is preferable.

However, if you run pretty-quick at the root, Prettier respects the root .prettierignore but not the closest .prettierignore to the files being formatted in each workspace (in conflict with the behavior of both .gitignore and Prettier's configuration file). I've seen this create significant confusion among monorepo developers and it would be fantastic if we could get a feature that both respects proximity as well as extensibility.

@srMarquinho
Copy link

This is particularly interesting to us as we have a centralised .prettierrc. This way we don't have copy/maintain .prettierignore across projects.

@dawsbot
Copy link

dawsbot commented Apr 5, 2023

Someone should take this on. It seems like a lot of people want this (including us)

I won't have any power to merge or push this along, but it's certainly something many want with no visible downsides when executed properly using standard conventions the way other tools do this.

@gyhyfj
Copy link

gyhyfj commented Apr 6, 2023

I really want this because prettier config files can be extended but single ignore file cannot be extend

@srMarquinho
Copy link

Worth noting that this issue is about 5 years old.

@eddiemonge
Copy link

Worth noting that this issue is about 5 years old.

5 years of a want is a long time. That should have no bearing on prioritizing though. The @prettier team has not yet said whether they would even consider this, thus discouraging people from even wanting to try to implement it

@rotu
Copy link
Contributor

rotu commented Apr 30, 2023

A possible fix is to add a new parser type that ignores files.

Then ignoring files could be done like, e.g.:

{
"overrides": [
  { "files": ["dist/**/*.js"], "options": { "parser": "ignore" } }
]
}

@regnaio
Copy link

regnaio commented Oct 22, 2023

@fisker Any chance this can be considered?

I'm looking to remove all .___ignore files

For example, I can remove ESLint's .eslintignore and ignore files using ignorePatterns: [...] in .eslintrc.js. I'm hoping to remove .prettierignore and ignore files using a config option in .prettierrc.js

If everything can be moved into a JS config file, it works better with projects with nested directories. And it eliminates the need for a .prettierignore file in every single directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Issues with Prettier's Application Programming Interface area:cli Issues with Prettier's Command Line Interface area:ignore .prettierignore file, --ignore-path CLI option, /* prettier-ignore */ comments and so on type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

No branches or pull requests