You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!
Editor plugins don't always have ways to pass configuration to the process they call.
For example, in order to set the vim plugin neoformat to tell prettier to use single quotes, I've had to fork the plugin.
Other vim plugins for linting, for example, aren't an issue because we have eslintrc.
I appreciate the complexity involved in having a prettierrc file (the spelling alone is awkward!) and I agree with the spirit of not adding too many options, but is there a way to set a global configuration that prettier could always use?
Reacted by Esa-Matti Suuronen, ingf, Evan Davis, Adam Pietrasiak, Tomáš Vojtěch, Austin, Simon Thörnqvist, Matt, Jon Crenshaw, Manuel Bieh and 25 more
Reacted by Adam Pietrasiak, Thomas Deinhamer and Austin Shoecraft
Reacted by Jacob Parker, ingf, Adam Pietrasiak, Manuel Bieh, Thomas Deinhamer, Sebastian Busch, majnu-campact and Jahlela Hasle
That's a good use case, thanks. It sucks to have to fork it. We're not going to have an rc file, but would it work for you we if supported environment variables? So you could do PRETTIER_WIDTH=80 prettier? It's not ideal, but I'm happy to make this work as much as we can as long as we only have 3-5 options and avoid configuration files.
I did think ENV variables would be a good option after posting this. I think that would work really well, especially if there's only a couple of options!
ENV variables sometimes can cause great source of pain. I think it's just better to avoid them. So having editor plugins support configuration is the best in my opinion.
I would really love to use this if I can get prettier to output code that will pass my large corporate eslint rules. Right now, it looks like the two issues I have are spaces between array braces [] and contents [ 1, 2, 3 ] is output but my lint hook requires [1, 2, 3] and no semicolon ending the last line of code, so I get }) instead of });
@vramana Explain more about the pain? I don't think it would be pain for us to support, but might be a pain for users to use. They can deal with the pain if they are using tools that can't properly pass arguments in.
@brookswift You are in luck. There is already an option for bracket spacing (pass --bracket-spacing=false in CLI or bracketSpacing: false or API). As for semicolons, see #12. We will not directly support lack of semicolons, but I'm working on an idea to integrate eslint and use that pass to remove them.
@jlongster , sorry, I wasn't clear about the 2nd issue. After I run prettier, I lose the semicolon on my last line of code. That's the issue I was running into. I need every statement to end with a semicolon, including the last one. Maybe that's actually a bug then? I can type up an example case for you if so. If I can get your tool to pass our eslint requirements, I might be able to integrate it into our build process and save our hundreds of developers the daily headache of trying to fix lint issues.
@brookswift Oh, even better. Yes, if there should be a semicolon, we should output it. I suspect it's more with the type of syntax that's on that line. Please file a new issue!
@jlongster ENV variable is a pain to use unlike a file configuration.
Consider a project :
which can be run on windows, mac and linux ;
which is edited on vscode, vim, textmate, notepad (etc) according developper flavour
Consider you have several project on your laptop, and each one with a different configuration (because of different team)
A prettierrc, tracked in the version control (like git) is the nice way to share the configuration :
a new developper have it when he checkout it
it's version controlled, with all benefit (history, PR review ...)
ENV variable need a configuration for each team's developper. It a big break to adopt it in a project.
Reacted by Rob Wise, Aaron Boyd, James Hegedus, ingf, Kevin Renskers, Tomáš Vojtěch, Jon Crenshaw, Vlad Frolov, Sebastien Barre, Marco Arduini and 14 more
letpkgString;try{pkgString=fs.readFileSync("./package.json","utf8");}catch(e){// Ignore no package.json found.}letpkg;if(pkgString){try{pkg=JSON.parse(pkgString);}catch(e){console.error(e);}}constglobalOptions=(pkg&&pkg.prettierConfig)||{};
Reacted by Gabe, Rob Caldecott, Caleb Meredith, Ben McCormick, Joni Korpi, Christopher Chedeau, Samir Talwar, Gustav Nikolaj, Austin, Dara Hak and 16 more
Reacted by Tomáš Vojtěch, Jon Crenshaw, Kutsan Kaplan, Joe Stanton and Roberto SLopez
If somebody wants global configuration now, you can run prettier via eslint using the brilliant eslint-plugin-prettier plugin. prettier some-file.js --write then basically becomes eslint some-file.js --fix. (You get ignore file support, too, via .eslintignore.)
Does prettier want to support a user working across projects that use different prettier rules? I don't think env vars are a good solution for that use case.
With emacs, I'll sometimes start a single process and open files from multiple projects. If those projects want a different prettier rule, and I'm configuring with env vars, I'd be forced to launch multiple instances of emacs. Not the end of the world, but it would be the only reason I'd have to do that.
I should have been more clear. If the only thing you want is "global" configuration, environment variables seem like a very good solution. The argument for a .prettierrc is that you want more flexibility than that.
I think there are at least three use cases touched on in this issue thread:
"Globally" configure prettier so that whenever I start my editor/IDE it always has the same config.
Specify prettier configuration when I start my editor/IDE, so that I can have multiple instances of my IDE running with different configs.
Run a single instance of my IDE/editor that will determine prettier config based on the file (or project) that is currently loaded.
(and then there is also the desire for a solution that works on any platform, but i'll leave that aside...)
The title of this thread makes it sound like the goal is #1.
I hope that doesn't all just sound like a bunch of words. It seems like it would useful to be clear about what the actual goal is. A .prettierrc does seem like a good solution if we're after more flexibility like what is suggested by #3.
@aaronyo yeah, this is about global config. I mentioned over here that it would be nice if we had a solution that worked both globally and locally per project. My proposal (and that of others), is to use the standard config file approach (.prettierrc/prettier.opts/.prettier.config/etc). Here is what I think would be ideal:
By default, prettier does its thing (default behavior)
If you have a prettier.opts (or whatever we end up calling this file) in your $HOME, we use that
If one exists in a project, that is preferred (completely overrides that in $HOME)
To me this covers all use cases I can think of. Editors just need to call prettier when files are changed and prettier figures it out (editor integration then becomes "dumb").
Reacted by Matija Marohnić, Harald Ringvold and Joseph Wolfe
Good news, node 8 will ship with support for trailing commas in function calls and declarations. So we'll be able to use --trailing-comma=all everywhere :) nodejs/node#10117 (comment)
Reacted by Slađan Ristić, Josh Buchea and BrunoLM
Reacted by David Nunez
Reacted by Brian Ng, Aaron McAdam, Joseph Frazier and BrunoLM
locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!
Activity
[-]Is there a way to set global configuration[/-][+]Is there a way to set global configuration?[/+]jlongster commentedon Jan 11, 2017
That's a good use case, thanks. It sucks to have to fork it. We're not going to have an rc file, but would it work for you we if supported environment variables? So you could do
PRETTIER_WIDTH=80 prettier? It's not ideal, but I'm happy to make this work as much as we can as long as we only have 3-5 options and avoid configuration files.aaronmcadam commentedon Jan 11, 2017
Hey @jlongster, thanks for getting back to me!
I did think ENV variables would be a good option after posting this. I think that would work really well, especially if there's only a couple of options!
cedricpinson commentedon Jan 12, 2017
That would be great I have the same problem with emacs
vramana commentedon Jan 12, 2017
ENV variables sometimes can cause great source of pain. I think it's just better to avoid them. So having editor plugins support configuration is the best in my opinion.
brookswift commentedon Jan 13, 2017
I would really love to use this if I can get prettier to output code that will pass my large corporate eslint rules. Right now, it looks like the two issues I have are spaces between array braces [] and contents
[ 1, 2, 3 ]is output but my lint hook requires[1, 2, 3]and no semicolon ending the last line of code, so I get})instead of});jlongster commentedon Jan 13, 2017
@vramana Explain more about the pain? I don't think it would be pain for us to support, but might be a pain for users to use. They can deal with the pain if they are using tools that can't properly pass arguments in.
@brookswift You are in luck. There is already an option for bracket spacing (pass
--bracket-spacing=falsein CLI orbracketSpacing: falseor API). As for semicolons, see #12. We will not directly support lack of semicolons, but I'm working on an idea to integrate eslint and use that pass to remove them.brookswift commentedon Jan 13, 2017
@jlongster , sorry, I wasn't clear about the 2nd issue. After I run prettier, I lose the semicolon on my last line of code. That's the issue I was running into. I need every statement to end with a semicolon, including the last one. Maybe that's actually a bug then? I can type up an example case for you if so. If I can get your tool to pass our eslint requirements, I might be able to integrate it into our build process and save our hundreds of developers the daily headache of trying to fix lint issues.
jlongster commentedon Jan 13, 2017
@brookswift Oh, even better. Yes, if there should be a semicolon, we should output it. I suspect it's more with the type of syntax that's on that line. Please file a new issue!
evanliomain commentedon Jan 14, 2017
@jlongster ENV variable is a pain to use unlike a file configuration.
Consider a project :
Consider you have several project on your laptop, and each one with a different configuration (because of different team)
A prettierrc, tracked in the version control (like git) is the nice way to share the configuration :
ENV variable need a configuration for each team's developper. It a big break to adopt it in a project.
lydell commentedon Jan 26, 2017
What about being able to specify options in package.json?
{ "name": "some-package", "prettierConfig": { "printWidth": 71, "tabWidth": 4, "singleQuote": true, "trailingComma": true, "bracketSpacing": false, "parser": "flow" }, "dependencies": { "prettier": "0.11.0" } }It's easy to read the closest package.json with read-pkg-up;
Or simply always from
./package.json:lydell commentedon Jan 26, 2017
If somebody wants global configuration now, you can run prettier via eslint using the brilliant eslint-plugin-prettier plugin.
prettier some-file.js --writethen basically becomeseslint some-file.js --fix. (You get ignore file support, too, via.eslintignore.)aaronyo commentedon Feb 13, 2017
Does prettier want to support a user working across projects that use different prettier rules? I don't think env vars are a good solution for that use case.
With emacs, I'll sometimes start a single process and open files from multiple projects. If those projects want a different prettier rule, and I'm configuring with env vars, I'd be forced to launch multiple instances of emacs. Not the end of the world, but it would be the only reason I'd have to do that.
esamattis commentedon Feb 15, 2017
I also needed project specific config files for prettier. As a workaround I ended up creating this wrapper:
https://gist.github.com/epeli/7e9511cbd2ec806c5f8a6f96428352c2
Just put it to PATH and use
prettier-configinstead ofprettierand it will read cli options from the project's.prettieroptsfile.The file just contains the cli options you want to have. ex.
It will look for the
.prettieroptsfile like eslint: From the current directory and any parent directory. It will use the first one found.For Vim the Gist also contains a neoformat config for it.
8 remaining items
aaronmcadam commentedon Apr 17, 2017
other rc file implementations will look for rc files in $HOME and in the local project directory
danawoodman commentedon Apr 17, 2017
Yes a
.prettierrc(or my preference,prettier.opts) should work just fine globally. It prefers the local version over the global, if present.aaronyo commentedon Apr 17, 2017
@aaronmcadam @danawoodman
I should have been more clear. If the only thing you want is "global" configuration, environment variables seem like a very good solution. The argument for a .prettierrc is that you want more flexibility than that.
I think there are at least three use cases touched on in this issue thread:
(and then there is also the desire for a solution that works on any platform, but i'll leave that aside...)
The title of this thread makes it sound like the goal is
#1.I hope that doesn't all just sound like a bunch of words. It seems like it would useful to be clear about what the actual goal is. A .prettierrc does seem like a good solution if we're after more flexibility like what is suggested by
#3.danawoodman commentedon Apr 17, 2017
@aaronyo yeah, this is about global config. I mentioned over here that it would be nice if we had a solution that worked both globally and locally per project. My proposal (and that of others), is to use the standard config file approach (
.prettierrc/prettier.opts/.prettier.config/etc). Here is what I think would be ideal:prettier.opts(or whatever we end up calling this file) in your$HOME, we use that$HOME)To me this covers all use cases I can think of. Editors just need to call
prettierwhen files are changed and prettier figures it out (editor integration then becomes "dumb").Fix the rules used when working with the pre-commit hook
vjeux commentedon May 10, 2017
Good news, node 8 will ship with support for trailing commas in function calls and declarations. So we'll be able to use
--trailing-comma=alleverywhere :) nodejs/node#10117 (comment)azz commentedon May 11, 2017
@vjeux Except in prettier where node 4 is supported? 😉
danawoodman commentedon May 11, 2017
How is this relevant to global cofig?
thasmo commentedon Jun 15, 2017
I'd love to see support for a stored configuration and I'm suggesting https://github.com/davidtheclark/cosmiconfig so people have the choice. Thanks a lot!
rattrayalex commentedon Jul 14, 2017
Fixed in #2434 with cosmiconfig