4 ms·
Prettier is a code formatter for JavaScript, like the hugely popular "gofmt". Highlights of the 1.0 announcement: - production-ready (and used, eg; React, Ocu
by rattray 10y ago
Prettier is a code formatter for JavaScript, like the hugely popular "gofmt".
Highlights of the 1.0 announcement:
- production-ready (and used, eg; React, Oculus, Cloudflare, etc)
- --no-semi option
- --use-tabs option
- parens that help indicate precedence
- many formatting improvements
There are a ton of edge cases in this work that really matter (read through the announcement for a few). Speaking as a contributor, this is some of the hardest stuff I've ever done (beats building a JS superset, http://lightscript.org http://lightscript.org). I've been super impressed by the prettier team.
- WhitneyLand 10y agoCan it handle escaped json string constants? For example this: http://whitneyland.com/2017/04/first-in-the-world-to-display-escaped-json.html http://whitneyland.com/2017/04/first-in-the-world-to-display...
- rattray 10y agoYou can try prettier online at https://prettier.github.io/prettier/ https://prettier.github.io/prettier/ Not sure exactly what you mean, but here's an example with JSON: https://prettier.github.io/prettier/#%7B%22content%22%3A%22x%20%3D%20%7B%5C%22name%5C%22%3A%5C%22Luke%20Skywalker%5C%22%2C%5C%22height%5C%22%3A%5C%221.72%20m%5C%22%2C%5C%22mass%5C%22%3A%5C%2277%20Kg%5C%22%2C%5C%22hair_color%5C%22%3A%5C%22Blond%5C%22%2C%5C%22skin_color%5C%22%3A%5C%22Caucasian%5C%22%2C%5C%22eye_color%5C%22%3A%5C%22Blue%5C%22%2C%5C%22birth_year%5C%22%3A%5C%2219%20BBY%5C%22%2C%5C%22gender%5C%22%3A%5C%22Male%5C%22%2C%5C%22homeworld%5C%22%3A%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Fplanets%2F1%2F%5C%22%2C%5C%22films%5C%22%3A%20%5B%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Ffilms%2F1%2F%5C%22%2C%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Ffilms%2F2%2F%5C%22%2C%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Ffilms%2F3%2F%5C%22%5D%2C%5C%22species%5C%22%3A%20%5B%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Fspecies%2F1%2F%5C%22%5D%2C%5C%22vehicles%5C%22%3A%20%5B%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Fvehicles%2F14%2F%5C%22%2C%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Fvehicles%2F30%2F%5C%22%5D%2C%5C%22starships%5C%22%3A%20%5B%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Fstarships%2F12%2F%5C%22%2C%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Fstarships%2F22%2F%5C%22%5D%2C%5C%22created%5C%22%3A%5C%222014-12-09T13%3A50%3A51.644000Z%5C%22%2C%5C%22edited%5C%22%3A%5C%222014-12-10T13%3A52%3A43.172000Z%5C%22%2C%5C%22url%5C%22%3A%5C%22http%3A%2F%2Fswapi.co%2Fapi%2Fpeople%2F1%2F%5C%22%7D%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3A%22none%22%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22parser%22%3A%22babylon%22%2C%22semi%22%3Atrue%2C%22useTabs%22%3Afalse%2C%22doc%22%3Afalse%7D%7D https://prettier.github.io/prettier/#%7B%22content%22%3A%22x... Prettier doesn't support JSON files per se (and doesn't currently plan to [0]), so you need to provide a leading `x = {...` or similar to ensure the { is parsed as an object instead of a block. [0] https://github.com/prettier/prettier/issues/322 https://github.com/prettier/prettier/issues/322
- WhitneyLand 10y agoLooks like it has no understanding of json at all. If you have a constant like this, except really long and ugly, there's quite a bit that can be done to make the code more readable. Maybe I'll add an issue and see if anyone else cares about it. var simpleJson = '{ "DevelopersNeedUXToo": [ { "Color": "Red", "Name": "Lee" } ] }'
- bradfitz 10y agoWe had configurability in early versions of gofmt but realized it was a mistake and kinda missed the whole point of having a code formatter, so we removed them.
- mrkgnao 10y agoWhile I understand the reasons for this (especially with the culture, for lack of a better word, around Go), I feel like this is a step backward in general. The "standard" Haskell formatter, hindent, did something similar. I found the maintainer's behavior admirable -- the style that was agreed on was very different from his own, but it was what he saw after analyzing publicly available code -- but what's the problem with custom formats if they're consistent across a whole codebase?
- weberc2 10y agoIn the case of Go, it's really advantageous to be able to jump into anyone's project and be able to read it without the additional impedance of adjusting to the new formatting model. I didn't think this would be that significant until I started participating in the Go community. This works together with Go's reduced feature set, so everyone's code ends up looking very similar.
- jaredklewis 10y agoWhat's the advantage of project specific, custom formats?
- gknoy 10y agoIt allows everyone in your company's dev organization share a common `standard` of JS style, which you have agreed on, even if it differs slightly in the way it bikesheds things like single-vs-double quotes or the presence of semicolons. (I mention `standard` because we use it as the basis for our linting rules, and would LOVE to use prettier to reformat our code.)
- dilap 10y agoit's something that doesn't matter that you don't ever have to worry about again. it's a huge win.