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

Is it possible to specify where your config file is? #246

Closed
javierguzman opened this issue Nov 14, 2019 · 5 comments
Closed

Is it possible to specify where your config file is? #246

javierguzman opened this issue Nov 14, 2019 · 5 comments

Comments

@javierguzman
Copy link

Hello all!

Is there a way to specify where your .prettierrc is placed? I have it inside a config folder rather than the root and it seems like is not found. Prettier plugin has now an option "configPath" to specify where the configuration is, so if I format the code using Prettier, the result is ok. However, I still have ESLint/Prettier complaining about using single quotes that has to be converted to double ones (I have single quotes to true) and so on. So it is like the config file is not found.

My idea is to use ESLint/Prettier with Airbnb.

Any idea how can this be resolved?

Thank you in advance and regards

@BPScott
Copy link
Member

BPScott commented Nov 18, 2019

Much like ESLint and .eslintrc Prettier resolves configuration for a given file by looking up the folder path to find a particular a .prettierrc (or the other config names) in parent folder paths, this allows you to have different configs for different folders. By violating prettier's expectations you'll have to pass a config override to everywhere you configure prettier - in this plugin, when you run prettier on the command line, when you run prettier from your editor - which will break you're ability to do per-folder overrides and sounds like you're inventing a lot of work for yourself just because you don't like having a single file in your root folder.

This feature is not available as it makes it easier for people to misconfigure prettier and will lead to surprising results.

Please just put your config in the root folder, or as a key in your package.json if the file annoys you that much.

@BPScott BPScott closed this as completed Nov 18, 2019
@javierguzman
Copy link
Author

Hello Ben!

Thanks for your response. Well from my point of view ESLint plugin and Prettier plugin already allow you to specify where your config file is, so just for the sake of coherence within the ecosystem would be good to get this here. I do not know the details of how this works but from my ignorant point of view seems a bit strict to not having this just because the user can misconfigure prettier easily.

Do not get me wrong, I just placed all my Prettier config within my eslint configuration, so it works and I can live without this, but I am just giving my feedback. Another guy from Reddit was parsing its config file and placing the content within its eslint config everytime eslint config was read by the plugin.

Anyway, thank you again Ben.

@BPScott
Copy link
Member

BPScott commented Nov 19, 2019

If you'd like to send a PR for this feature I would consider it. The best extension point is probably adding an option to the second options argument that gets passed to the rule (in the same object as usePrettierrc) see https://github.com/prettier/eslint-plugin-prettier#options

@alexkuc
Copy link

alexkuc commented Aug 11, 2020

I have come across this issue and noticed that if I specify prettier key in package.json with path to config, instead of actual config, it works. E.g.

{
  "prettier": "./configs/prettier.js"
}

The key part for me was to specify ./configs instead of configs. I am not sure if it is intended behaviour or not as prettier docs not mention this, at least not explictly (link to docs).

@BPScott
Copy link
Member

BPScott commented Aug 12, 2020

It mentions it in the docs as the Shared configurations section - you're still resolving a JS file, it's just a relative file instead of a package.

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

No branches or pull requests

3 participants