Skip to content

Configuration file support #62

Closed

Description

@janicduplessis

I think it would be valuable to support for some type of file that contains prettier's config so that projects can check it in source control.

I can see 2 cases where this would be useful.

  • Allow tools to know that the project is using prettier. I'd like to enable thing like format on save but I don't want to reformat everyfile I touch on a project that doesn't use prettier.
  • Allow per project config to avoid the need to change options when changing projects or to have to create custom formating scripts.

Could be it's own file (something like .editorconfig) or maybe part of package.json.

Activity

  1. jlongster commented on Jan 11, 2017

    @jlongster
    Member

    We aim to be zero-config. For now at least, I am against this. The few existing config options only exist to help applying to existing projects, and should only be used if you really need to. We will see what happens over time, but for now I'll point you to #40

  2. janicduplessis commented on Jan 11, 2017

    @janicduplessis
    ContributorAuthor

    I like the idea of having no or very few config, but would also like a way to tell tools that a project uses prettier (see my first point). I feel like this is needed if we want to adopt auto formatting progressively for JS. We cannot do like Reason or Go did because these languages had something like this from the start so every project uses them and there is no need to tell tools if auto formatting should be used.

  3. ForbesLindesay commented on Jan 13, 2017

    @ForbesLindesay

    I would very much like this tool to be configureable. In particular, I use trailing commas in files that are compiled via babel, but it's not an option (in function calls) for files that are not compiled.

    I do think it should work, and do something people are mostly happy with, without a config. It seems to mostly do that, which is great.

    I also think we need to make sure that if you're using something like create-react-app, it just works out of the box.

    Would you consider a pull request that added support for a .prettier config file, defaulting to the current behaviour in it's absence?

  4. vramana commented on Jan 13, 2017

    @vramana

    @ForbesLindesay @jlongster has said in another thread the he may consider allowing an option to configure function trailing commas.

    Have you seen this https://github.com/kentcdodds/prettier-eslint?

  5. ForbesLindesay commented on Jan 13, 2017

    @ForbesLindesay

    @vramana I'm not asking for more configuration options. I'm happy to just enable/disable trailing commas across the board.

    What I want is a file to store settings in so I can use the atom plugin/cli without issues even on projects that do not use the defaults for every config option.

  6. jlongster commented on Jan 13, 2017

    @jlongster
    Member

    Would you consider a pull request that added support for a .prettier config file, defaulting to the current behaviour in it's absence?

    Not at this point in the project. I'd really like to avoid it, as explained below. Never say never, but this project is only a few days old, and my preference is to evolve slowly. If we can solve problems a different way that don't require an additional piece of infrastructure, everybody wins.

    There are already so many project-level configs. While we are sorting things out, an atom plugin itself could read from a .prettier file and the community can try it out without us supporting it natively yet.

    What I want is a file to store settings in so I can use the atom plugin/cli without issues even on projects that do not use the defaults for every config option.

    Here's the real reason I don't think we need it: you shouldn't have to worry about what settings the project has. One of the hidden benefits with this kind of printer is that we're closer to the ideal where text is stored in a generic format and you can view it however you like. Another project has different settings than you? Who cares! Just open a file and format it according to your preferred settings. When you go to make a commit, the project should have a way to auto-format the changes files back to its own preferred settings (we'll work on this toolchain soon).

    I think the JS ecosystem could hugely benefit from this given that it's probably the most diverse group of opinions because it's so large. It's a chance to end the endless debates because it doesn't matter what's committed anymore: you can reformat and read code in your preferred settings, and reformat it back before committing. Worst case if some unformatted code gets through, the CLI will fail when it checks to make sure everything is formatted in the "formal" way.

  7. jlongster commented on Jan 13, 2017

    @jlongster
    Member

    I like the idea of having no or very few config, but would also like a way to tell tools that a project uses prettier (see my first point).

    @vjeux has some ideas about this. I think a simple solution could be for an editor plugin to search for node_modules and check it prettier exists within it. We don't need a config file just to see if a project uses it.

  8. ljharb commented on Jan 13, 2017

    @ljharb

    The problem is that not everyone will adopt a tool like this all at once, thus the "generic format" for text needs to match the project's existing conventions. Disallowing config will mean that adopting prettier is an all-or-nothing approach, unless the project just happens to already comply with the convention prettier chooses, which - for the exact reasons you mention that the ecosystem could benefit from this tool - will prevent adoption of it, on any larger scale.

  9. kusold commented on Apr 18, 2017

    @kusold

    My use case is that at work the coding convention is different then the coding convention I prefer for personal projects, and I need prettier to integrate with my IDE.

    Here is my hack for adding a configuration file for prettier:

    ❯ cat .prettier  
    --no-semi --use-tabs
    

    You can then do:

    ❯ ./node_modules/.bin/prettier $(cat ./.prettier) $file
    

    And here is my IntelliJ External Tool configuration:
    screen shot 2017-04-18 at 12 28 59 pm

  10. kitze commented on Apr 25, 2017

    @kitze

    @kusold you're a lifesaver 🖐

  11. oztune commented on Apr 28, 2017

    @oztune

    Here's the real reason I don't think we need it: you shouldn't have to worry about what settings the project has. One of the hidden benefits with this kind of printer is that we're closer to the ideal where text is stored in a generic format and you can view it however you like.

    @jlongster I understand why you're trying to avoid project config options. I love the idea that each developer can view the code-base of a project with any formatting rules they prefer, but the repo keeps all the code formatted the way the project prefers.

    But... we have a different use-case that may require them. We have multiple separate projects, each in its own repo, and we want all the projects in our organization to share the same prettier rules (which are different than the default). Is there a way to share them that's DRY and doesn't require copy-pasting them across repos?

  12. kusold commented on Apr 28, 2017

    @kusold

    @oztune Probably the best option for you is to fork prettier-standard-formatter and set your own config options here. Publish to npm when done for easy sharing.

    Alternatively, using my comment above, you can create config files, then use npm scripts to run prettier.

  13. oztune commented on Apr 28, 2017

    @oztune

    @kusold Thanks for that link! Both of those are very practical solutions, but I'm also interested to hear from the authors if they intend to address this need formally.

  14. joshburgess commented on May 14, 2017

    @joshburgess

    I have to say it doesn't make much sense to require each and every editor to setup a prettier config individually. It really should be editor independent. Some people want trailing commas, no semis, single quotes, etc... If a project sets a list of these rules, contributors have to manually setup the proper rules to match the project according to the maintainers' preferences, which doesn't make sense. These rules should already be set for them by a configuration file in the project so that anyone using any editor doesn't have to do any extra setup to adhere to the project's style...

  15. 2 remaining items

  16. k15a commented on May 14, 2017

    @k15a
    Collaborator

    @joshburgess Very good points. Maybe the editor integrations should have an option to format with the project specific preferences or format in your own style.

    I think that people should stop using ESLint for styling related issues because prettier handles them better. In the other hand ESLint is pretty good at catching common errors like no default case in switch or unused variable.

  17. joshburgess commented on May 14, 2017

    @joshburgess

    @k15a For whatever it's worth, I'm reading this thread #1086 right now, and it seems to offer a promising solution.

    That sounds good to me. I don't really care if it's a standalone config file or a few lines in the package.json, as long as it solves the problem.

  18. MrLoh commented on Jul 7, 2017

    @MrLoh

    Is this still something that's ever gonna happen. I would be all for one way to write JS, but that's just not how the world works these days. Prettier has boiled it down to very few options though which is great. My problem is that I am working for different people and in one project they insist on semicolons and in the other they insist on no semicolons. It's not up to me to decide, so the only way around not having to go to the prettier atom settings every time I work on a different project would be having settings. Maybe they could be just inside the package.json, I don't care, but this is really cumbersome if you don't just work in one environment.

  19. vjeux commented on Jul 7, 2017

    @vjeux
    Contributor

    This is going to happen. We're working out the details right now

  20. mbrookes commented on Jul 8, 2017

    @mbrookes

    @vjeux If this is going to be .prettier or similar, please consider searching in the .config directory in the project root, (a place for large projects with many config files to store config files to tidy up the root directory).

    It's not a well adopted standard yet, but the more projects that do this, the more widespread it will become.

  21. reopened this on Jul 8, 2017
  22. ljharb commented on Jul 9, 2017

    @ljharb

    I'd prefer, like all projects everywhere else, for my config dotfiles to remain at the root of the repo. ls hides dotfiles by default, so there's no need to "tidy up" anything.

  23. MrLoh commented on Jul 9, 2017

    @MrLoh

    I think that's a misunderstanding @ljharb the suggestion is not to only look in a .config dir for a config file, but to look in this dir additionally to of course looking in the root dir.

  24. ljharb commented on Jul 9, 2017

    @ljharb

    Thanks for clarifying, as long as it prioritizes "root" over "root/.config", I'd have no objection to it looking in ".config" for those who prefer that style.

  25. mbrookes commented on Jul 9, 2017

    @mbrookes

    @ljharb ls does, but github doesn't, and yes, that's the way it would work.

  26. azz commented on Jul 10, 2017

    @azz
    Member

    As of #2434, the current default won't search .config directories, but you can pass prettier --config .config/.prettierrc to the CLI.

  27. added
    locked-due-to-inactivity
    on Jul 7, 2018
  28. locked as resolved and limited conversation to collaborators on Jul 7, 2018
  29. added
    status:has pr
    on Aug 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivitystatus:has pr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions