Common-voice: Code style: Apply prettier for consistent code formatting

Created on 23 Aug 2017  路  9Comments  路  Source: mozilla/common-voice

Prettier is essentially a code formatter (initially for JS, but now also supports TS). It takes care of all code formatting so code contributors could just code in any style and then apply this code formatter so that code style across contributors are (mostly) consistent. Lots of open source projects already use Prettier, notable ones are React, Webpack, Yarn, Babel.

All 9 comments

I definitely think consistent code formatting is a worthwhile goal to improve readability and thereby maintainability. 馃憤

Since it's not reasonable to expect all contributors on an open-source project to use the same editor/IDE, I think a separate tool like this is a good way to go.

As this needs to be run by individual developers, I'd suggest that we also add some kind of style checking. It would be ideal if prettier can do this, since we'd have only a single ruleset then, but if not, something like tslint can probably do the job. This style checking should then be included in the Travis CI build for automatic enforcement.

@mikehenrty are there any particular points about code style that are important for you?

I think it makes sense to wait for @mikehenrty's feedback before we start crafting a ruleset for this :)

@kenrick95 Is there currently a problem with the consistency of the coding style in the project?

@jdittrich there are, in particular, no stated guidelines for the code in this project. so people contributing will just use whatever they think fits (or whatever they like best), making the overall code base less and less consistent over time. IMO this hurts readability and thereby maintainability of the code base.

this particular issue was created after @kenrick95 and I noticed this in a review of one of their PRs :)

related: Collect and document contribution guidelines #423

I'm totally on board for this, just need to find the time :)

@kenrick95 if you have any experience with prettier, would you mind trying to drop it into this project, and see how many changes it makes or would require?

if it's a small thing (e.g. with a standard ruleset), would be great start to just get it in. we could then refine the ruleset to our liking as we go along

@nevik @kenrick95, I'm working on this right now. the best part about prettier is that it is pretty opinionated about js style, and our formatting options are small. i'll ask for both your feedback once i have a reasonable PR. stay tuned!

perfect! looking forward to seeing that :D

Alright, I took a stab at this. Would love some feedback in #455.

Was this page helpful?
0 / 5 - 0 ratings