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 there a way to set global configuration? #98
Comments
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 |
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! |
That would be great I have the same problem with emacs |
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 |
@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 |
@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 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. |
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; const readPkgUp = require("read-pkg-up");
let pkg;
try {
pkg = readPkgUp.sync({normalize: false}).pkg;
} catch (e) {
console.error(e);
}
const globalOptions = (pkg && pkg.prettierConfig) || {}; Or simply always from let pkgString;
try {
pkgString = fs.readFileSync("./package.json", "utf8");
} catch (e) {
// Ignore no package.json found.
}
let pkg;
if (pkgString) {
try {
pkg = JSON.parse(pkgString);
} catch (e) {
console.error(e);
}
}
const globalOptions = (pkg && pkg.prettierConfig) || {}; |
If somebody wants global configuration now, you can run prettier via eslint using the brilliant eslint-plugin-prettier plugin. |
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 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 The file just contains the cli options you want to have. ex.
It will look for the For Vim the Gist also contains a neoformat config for it. |
Please not environment variables: they cause headaches between Windows/Macs. A package.json section would be perfect. I'm desperate to get prettier adopted here and per-project configuration would definitely make that easier. |
I'd be fan of |
Jumping between multiple projects and not having an easy way to define my pretter settings per project is quite a pain! I would love to have something along the lines of |
I think looking into both For example - in a huge webpack project I have 3 js files in scripts folder which get executed by node. For those 3 files I need Another situation when configuration file outside of |
I mentioned a similar approach to @epeli over here. It seems like since prettier's goal is to keep config simple, using a simple I think having out of the box support for this would be huge for adoption of prettier since it would mean just needing to install a plugin for your editor or running |
I've implemented what I think is a simple approach to getting a |
Here's my workaround: If you install prettier local to your project rather than globally (which is highly recommend for any team projects) then you've probably already got your IDE finding the project-local prettier executable. You've done the hard part. Now just create an executable in your project, say (If you're using emacs, you can modify this stack stackexchange answer to find a locally installed prettier. Just replace "node_modules" and the executable location with "bin/prettier".) |
I just realized I'm talking about local config rather than global. This issue thread is dealing with both (.prettierrc is not a global config solution). If global config is desired, it's a much easier problem and should probably be separated from the challenge of local config. |
other rc file implementations will look for rc files in $HOME and in the local project directory |
Yes a |
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 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 |
@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 (
To me this covers all use cases I can think of. Editors just need to call |
The real issue is: prettier/prettier#98
Good news, node 8 will ship with support for trailing commas in function calls and declarations. So we'll be able to use |
@vjeux Except in prettier where node 4 is supported? 😉 |
How is this relevant to global cofig? |
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! |
Fixed in #2434 with cosmiconfig |
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 thatprettier
could always use?The text was updated successfully, but these errors were encountered: