Skip to content
This repository has been archived by the owner on Aug 10, 2020. It is now read-only.

Add prettier to ensure consistent formatting #30

Closed
joealden opened this issue Feb 16, 2018 · 3 comments
Closed

Add prettier to ensure consistent formatting #30

joealden opened this issue Feb 16, 2018 · 3 comments

Comments

@joealden
Copy link
Contributor

Firstly, I would like to give a massive thanks to the BuckleScript team for an amazing project!

I had just cloned this repo as I want to make some improvements to the docs site, and I realized that when I went to edit any of the .md files, my editor was messing with the current formatting because I have the prettier extension installed. You have probably heard of prettier by now, but if you haven't, have a look at their website here.

I think prettier would make a great addition to the docs siterepo as it would format both the .md files that contain the documentation text, as well as the .js, .css and .html files that are used to build the site.

This would be useful because, from a quick look into the source files, I can see some inconsistencies in formatting. For example, sometimes trailing commas are used and sometimes they are not. It would also mean that possible new contributors (Like me!) wouldn't have to worry about how the project wants their files formatted, the editor / project would do it for me.

This could be done in two ways (Or both for better DX):

  1. A prettier config file (.prettierrc) could be created at the root of the project, and a contributor's editor could recognize the file and format the files respecting these settings. The benefit of this approach is that it doesn't require much change. However, the issue is that if the contributor is not using the prettier plugin in their editor, or they just don't have one available, the code could be formatted wrong, and it would have to be changed before being merged.
  2. A pre-commit hook could be added that runs prettier on the files that a contributor has staged. This would ensure that files commited to the repo were formatted correctly. The downside is that it adds a little bit more complexity to the project.

As mentioned above, I think that both 1 and 2 could be done together, so that when the contributor is developing, their editor will format the code correctly if they have the plugin installed, but if they don't then it doesn't matter because the pre-commit hook will format the files correctly anyway.

From what I have read of the source files, I think a config such as this would fit the project (Please correct this if it doesn't line up with the projects formatting style):

{
  "printWidth": 80,
  "semi": true,
  "singleQuote": false,
  "useTabs": false,
  "tabWidth": 2,
  "bracketSpacing": true,
  "trailingComma": "none",
  "proseWrap": "always"
}

Thanks for reading!

@joealden
Copy link
Contributor Author

Also, I would happily create a PR to add this to the project. I just need to know if it is something that would be wanted!

@joealden
Copy link
Contributor Author

This would make it quite a bit easier for me to submit some PRs, as the really long lines make it difficult to check diffs in my editor.

@bobzhang
Copy link
Member

bobzhang commented Mar 1, 2018

hi @joealden , thanks for your interest in contribution. Currently there are not many contributors to this repo, as one of primary contributors, I am not motivated to learn a new tool(there are too many js tools already). But I don't mind accept PR which contains whitespace diffs, thanks

@bobzhang bobzhang closed this as completed Mar 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants