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

prettierIgnore key in package.json? #3460

Open
cinnamonKale opened this issue Dec 12, 2017 · 62 comments
Open

prettierIgnore key in package.json? #3460

cinnamonKale opened this issue Dec 12, 2017 · 62 comments
Labels
area:cli Issues with Prettier's Command Line Interface area:ignore .prettierignore file, --ignore-path CLI option, /* prettier-ignore */ comments and so on status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@cinnamonKale
Copy link

ESlint currently allows ignore options to be set in package.json under the eslintIgnore key: https://eslint.org/docs/user-guide/configuring#using-eslintignore-in-packagejson

I noticed there's no mention of a prettierIgnore option in the docs (https://prettier.io/docs/en/ignore.html). I also tried adding a similar key for prettier like this, which did nothing:

"prettierIgnore": ["build"],

At this point I'm pretty sure this isn't possible currently, but I wanted to make sure. Are there plans to add this in or is this intentionally left out?

@azz azz added area:cli Issues with Prettier's Command Line Interface type:enhancement A potential new feature to be added, or an improvement to how we print something labels Dec 12, 2017
@azz
Copy link
Member

azz commented Dec 12, 2017

It's not currently implemented. We don't currently look at the package.json at all. We use cosmiconfig for configuration which is separate to the ignore file handling.

@lipis
Copy link
Member

lipis commented Dec 12, 2017

@azz that is not true. You can add the "prettier" key in the package.json with all the options there.

@duailibe
Copy link
Member

@lipis Yeah that’s the “we use cosmicconfig” part, but we don’t look the package.json for ignore.. those are two completely separate flows

@lipis
Copy link
Member

lipis commented Dec 12, 2017

@duailibe I see :)

@duailibe duailibe added the help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! label Dec 12, 2017
@azz
Copy link
Member

azz commented Dec 12, 2017

What's the incentive for putting this in package.json anyway?

@duailibe duailibe added status:needs discussion Issues needing discussion and a decision to be made before action can be taken and removed help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! labels Dec 12, 2017
@cinnamonKale
Copy link
Author

@azz the only reason I can think of is keeping the config format options as close to ESlint as possible because many people use it alongside ESlint and would expect the options to be the same. I could be wrong but not allowing prettierIgnore is the only difference from where you can add ESlint settings.

Maybe more people prefer using files to package.json keys (.eslintrc, .eslintignore, .prettierrc, .prettierignore) but it seems incomplete that the only thing missing is allowing prettierIgnore in package.json

@azz
Copy link
Member

azz commented Dec 14, 2017

I don't find "because ESLint does it this way" a particularly compelling reason. I think people like to put all kinds of things in their package.json files that don't really belong, and this seems like one of those things.

@cinnamonKale
Copy link
Author

@azz you're right that's not a compelling reason, but assuming that it shouldn't belong in package.json is a pretty sweeping dismissal of another dev's potential needs. By that reasoning using package.json shouldn't be an option for "prettier" either. And seeing as this is the only config missing in package.json it seems more like an accident than an informed decision.

If you don't want to do it, that's fine, I won't lose sleep over an extra file. But don't attribute it to wanting to keep package.json clean

fwiw, standard also allows exclusions in package.json, though it's a different format: https://standardjs.com/index.html#how-do-i-ignore-files

@hawkrives
Copy link
Contributor

hawkrives commented Jan 19, 2018

I was looking through the documentation for how to add the ignore list to my package.json config a few days ago, actually.

My reasoning is that I don't like adding new files to my top-level folder, and while I can get around that with the "prettier" package.json key, I still have to create a .prettierignore.

Idk. Not a huge deal, but a minor annoyance for me.

@olsonpm
Copy link

olsonpm commented Jan 31, 2018

yeah I thought the community was moving toward project configurations inside package.json because the dot files at the project directory were getting out of hand. I don't remember reading any functional constraints, more a community wide preference. But I've seen it plenty other places than just eslint take adoption.

@nickmccurdy
Copy link
Member

Cosmic config supports this by default, so I see no reason to not support this in package.json (if it isn't supported already). This doesn't prevent you from using a separate file if you prefer, it's just another option. This is quickly becoming a de facto standard for JSON configuration in JS packages.

@duailibe
Copy link
Member

duailibe commented Mar 9, 2018

Just FYI (this is not a justification) we don't use cosmiconfig for ignore, only for the configuration stuff.

@nickmccurdy
Copy link
Member

Ah I wasn't aware, thanks. Would it be a good idea to use it for ignore or can there be only one config per project?

@suchipi
Copy link
Member

suchipi commented Mar 9, 2018

cosmiconfig is built for loading configurations from JSON or yaml, but prettierignore files are a list of file globs and negations, perhaps with comments. You could emulate that behavior with an array or list, but it'd be a little bit awkward and incongruent with eg gitignore files. Also, I think cosmiconfig would look for files named ".prettierignorerc". So it's not really the right tool for this job.

@nickmccurdy
Copy link
Member

eslintIgnore is fine in package.json. They use custom logic instead of cosmicconfig to implement it, but it doesn't look very complex. https://github.com/eslint/eslint/blob/master/lib/ignored-paths.js

@olsonpm
Copy link

olsonpm commented Jun 28, 2018

I think cosmiconfig would look for files named ".prettierignorerc". So it's not really the right tool for this job.

cosmiconfig can be configured to look for whatever file names you choose. You're right by default it includes *rc files.

@cenobitedk
Copy link

... project configurations inside package.json because the dot files at the project directory were getting out of hand.

Exactly. I'm working on writing a common ground (boilerplate) for a larger company and the more config I can combine in one place, the better. It will make it more flexible and more transportable.

This issue hasn't changed in a year, what's the status?

@jamonholmgren
Copy link

Updated link to ESLint implementation. It’s really simple, although they don’t use cosmiconfig for it.

https://github.com/eslint/eslint/blob/master/lib/cli-engine/ignored-paths.js

I’m tempted to make a PR; anyone else interested, though? I have plenty of other open source on my plate.

@VivekNayyar
Copy link

Interested in making a PR for the same. Do I need to worry about cosmicconfig or can we go how eslint is doing it?

@ark120202
Copy link
Contributor

ESLint is going to allow specifying ignore patterns in config (see eslint/eslint#12274), was it considered to do the same for Prettier? That way it would be possible to specify them everywhere it can be configured, including package.json

@kael-shipman
Copy link

I see this is tagged as "discussion needed", but it appears to have gone stale. Is there any way we can get to a definitive yes or no here? This seems to be an expected feature by a significant group of people, including myself, and the path to implementation, while perhaps not as straightforward as hoped, is certainly not treacherous or fraught.

My argument toward "yes" is simply that there is no semantic difference to the user between types of config. From a user perspective, config is config, and any options that appear in the help text (prettier -h) should be available in any config file, including package.json. While from a program perspective we seem to be drawing a difference between "environment" config (which files do we act on, etc.) and "functional" config (what do we do to those files), that difference is in no way pertinent to the end user, which is for whom we build our products, and revealing that difference is simply confusing.

One more thing to consider: Who does it harm to implement this? Will anyone (users, documenters or project contributors) say "oh my god, this was such a bad idea"? Probably not.... So if there's virtually no cost (after the cost of implementation) and there's significant gain, why not just do it?

@alexander-akait
Copy link
Member

I think we should use logic from eslint eslint/eslint#12274, allow to use ignorePatterns in configuration

@yangwao
Copy link

yangwao commented Jan 16, 2022

I came across this thread to see if it's possible to add to key .prettierIgnore to package.json as an extra file at top-level is a bit annoying to clear repository.

  "prettier": {
    "cli": {
      "ignore": [
        ".vscode/"
      ]
    }
  },
  "prettier": {
    "cli": {
      "ignorePath": [
        ".vscode/"
      ]
    }
  },

EDIT Probably this is way to go

To exclude files from formatting, create a .prettierignore file in the root of your project. .prettierignore uses gitignore syntax.

@mataha
Copy link

mataha commented May 13, 2022

I've opened a PR here - would appreciate some feedback.

@thilllon
Copy link

thilllon commented Oct 2, 2022

check

@kachkaev
Copy link
Member

kachkaev commented Nov 2, 2022

I agree with some folks here that we should go for ignorePatterns in Prettier config instead of adding more fields to package.json. Alignment with ESLint would be nice! Using ignorePatterns in config files improves compatibility with monorepos by making things more flexible than with a static .*ignore file or a JSON.

📖 Docs on ingorePatterns in ESLint config

I’ve asked @mataha if they want to continue with #12672. Either way, it'd be great to see ignorePatterns landed!

@sean-au
Copy link

sean-au commented Nov 2, 2022

Adding ignore patterns has also been requested many times here #13088

@kachkaev
Copy link
Member

kachkaev commented Nov 2, 2022

@sean-au, yep. I’ve merged #13088 into this discussion so that we can join forces 🙂 The idea of ignorePatterns in Prettier config has been mentioned here too.

@valtlai
Copy link

valtlai commented Nov 2, 2022

Alignment with ESLint would be nice!

In the new config file system (blog post), the key is called ignores, so I think that’s the name we should use.

@binaryben
Copy link

This is top result for me when searching how to add ignore patterns to package.json. Seems like a reasonable request, why still no action on it? Just the maintainers don't like it so we suck it up?

@Standard8
Copy link

@binaryben That is unfair and unnecessary. The maintainers might have various reasons that they haven't yet got to this, but we don't know what they are. Do we have to remind you this is open source and free?

No I'm not a maintainer, and yes I want something similar. Rather than complaining, I did something. My first attempt (linked literally just above your comment) had some reasonable concerns raised, and I've a second attempt under way, unfortunately, I too haven't had much time recently.

@binaryben
Copy link

@Standard8 I meant no offence or complaint, just an honest enquiry about the state of this issue and reasoning for wherever it is where it is. Thanks for pointing out the work you're doing. Most of what I had read was bikeshedding and I'll admit I didn't read past yangwao's comment so I did miss your PR.

@fisker
Copy link
Sponsor Member

fisker commented Mar 25, 2023

Hey, I'm a maintainer. Sorry for letting you down.

Personally I want to support this too. But it's not simple to support, for example we need know where is package.json, so we can know what are those patterns related to.

My plan is to add multiple ignore files support first, then treat package.json with ignorePatterns as an .ignore file. I didn't post this idea because I'm busy with other works, haven't get time to finish #14332.


Update: we also support external package name as prettierConfig, we'll need figure how should ignorePatterns work when using shared config package.

@Standard8
Copy link

Personally I want to support this too. But it's not simple to support, for example we need know where is package.json, so we can know what are those patterns related to.

My plan is to add multiple ignore files support first, then treat package.json with ignorePatterns as an .ignore file. I didn't post this idea because I'm busy with other works, haven't get time to finish #14332.

Do you mean using ignorePatterns within package.json or a list of ignore files which is what ESLint supports?

I'm curious about why we're heading towards package.json rather than the prettier configuration file? I would have thought it would be easier to work in the prettier configuration file and more flexible, and some of the comments above suggested it might be good to head in that direction as that would also match ESLint.

This was the approach I was heading towards as a follow-up to #14223 although I did come across a few complications with that.

I definitely don't want to derail your efforts though, I'm more checking what you're intended there, and seeing if I should continue my efforts or not (I'm thinking probably not). At the end of the day I'd love any sort of multi-file support, so anything is a bonus.

@PatrykMilewski
Copy link

I would love to see this feature, in my case we are having tons of config/ignore files in the root of repo, that's why I'm trying to limit them and hide all of that in package.json

@jregistr
Copy link

What's the incentive for putting this in package.json anyway?

For me, I just mainly wanna reduce the number of . files in my repo.

@wpyoga
Copy link

wpyoga commented Jun 18, 2023

I agree with @kachkaev , and I would also love to see support for ignorePatterns inside prettierrc, just like @ivodolenc mentioned in #12672 (comment) .

As an added benefit, with this feature, we can reuse all .gitignore files if we use a js-based prettierrc:

module.exports = {
  ignorePatterns: require('eslint-gitignore').readGitignoreFiles({ cwd: __dirname }),
  ...
};

Note: eslint-gitignore actually just reads all .gitignore files in the project directory, and generate an array of .gitignore entries. It doesn't do anything specific to ESLint. There is also parse-gitignore as an alternative.

On another note, should this feature request be tracked here, or in #4708 ? I feel that they overlap somewhat.

@davea38
Copy link

davea38 commented Jul 18, 2023

Just my two pence, but it would be great to cut down on the various ignore files and be able to maintain a single one (prettier / eslint etc) for auto formatting etc. Being as they all use the same format I don't see this should be doable.

Specifying the file path of the ignore file via package.json is a great idea +1 from me!

@nickmccurdy
Copy link
Member

Just my two pence, but it would be great to cut down on the various ignore files and be able to maintain a single one (prettier / eslint etc) for auto formatting etc.

You can pass --ignore-path to both Prettier and ESLint to set a single ignore file. If you use .gitignore, Prettier 3 will use it by default, too.

@davea38
Copy link

davea38 commented Jul 18, 2023

Just my two pence, but it would be great to cut down on the various ignore files and be able to maintain a single one (prettier / eslint etc) for auto formatting etc.

You can pass --ignore-path to both Prettier and ESLint to set a single ignore file. If you use .gitignore, Prettier 3 will use it by default, too.

Thank you for mentioning this as I didn't know that this was possible.
I'm currently using eslint-plugin-prettier - I presume to do this I need to add it as an option in the eslint rule. I'll give it a go and see what happens!

@nickmccurdy
Copy link
Member

nickmccurdy commented Jul 18, 2023

currently using eslint-plugin-prettier - I presume to do this I need to add it as an option in the eslint rule.

No, it should be using the same ignore list as ESLint. That being said, if you still have issues configuring it, I'd recommend installing eslint-config-prettier and extending from plugin:prettier/recommended (to continue using the plugin) or prettier (to use Prettier separately without conflicts, which I'd recommend for better DX).

@kirkbushell
Copy link

I just stumbled upon this - honestly, I found it really odd that -some- configuration can go in package.json but not ignores. It's intuitive to put it there if that's where you want to put it.

The fact that prettier supports all these different areas only adds to confusion - took me about half an hour to get everything wired up correctly. Some areas suggest prettierrc, others the json file, others in different files together.

@nickmccurdy
Copy link
Member

I think it's a bit easier to set up Prettier 3 now with .gitignore, but I'm still in favor of adding prettierIgnore explicitly for consistency.

@jasongitmail
Copy link

The best location would be within Prettier config, rather than scattered into more files like package.json. Removing the need for .prettierignore, and eventually deprecating it, would help reduce JS config file pollution/fatigue too.

Better DX to just have one way and one config file:

One way to define configs - we didn’t want folks to have multiple ways to do the same thing any longer. There should be one way to define configs for any given project. ESLint

@Standard8
Copy link

Although there's a risk of splitting the discussion, I've just filed #15481 asking for supporting the configuration in the same way as ESLint (i.e. via ignorePatterns in the configuration file).

Whilst I respect the desire to have all the configuration in one file, as per the reasons I mention there, package.json does not have sufficient capability for anything other than a small project. Hence this would be insufficient for my needs, and so I'm splitting that request out to make it clear what is really needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:cli Issues with Prettier's Command Line Interface area:ignore .prettierignore file, --ignore-path CLI option, /* prettier-ignore */ comments and so on status:needs discussion Issues needing discussion and a decision to be made before action can be taken 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