Update prettier to the latest version 🚀 #176
Conversation
Codecov Report
@@ Coverage Diff @@
## master #176 +/- ##
=======================================
Coverage 92.91% 92.91%
=======================================
Files 9 9
Lines 240 240
=======================================
Hits 223 223
Misses 17 17 Continue to review full report at Codecov.
|
Version 1.0.1 just got published. |
Version 1.1.0 just got published.Update to this version instead 🚀 CommitsThe new version differs by 12 commits .
See the full diff. |
Version 1.2.0 just got published.Update to this version instead 🚀 CommitsThe new version differs by 26 commits .
There are 26 commits in total. See the full diff. |
Version 1.2.1 just got published. |
Version 1.2.2 just got published. |
Version 1.3.0 just got published.Update to this version instead 🚀 Release Notes1.3.0Facebook Adoption UpdateThe reason why I (@vjeux) embarked on this journey working on prettier has always been to get the entire Facebook codebase converted over. I would like to give an update on how it is going and what is the process to get there. The first projects to adopt prettier were Jest, React and immutable-js. Those are small codebases in the order of hundreds of files that have their own infrastructure. There are 5 or less people working on them full time. Then, Oculus and Nuclide converted their codebase over. The scale is bigger with a few thousands of files and tens of full time contributors but looks pretty similar to the first projects. The conversions went in one big codemod and that's it. Now, the entire Facebook codebase is way bigger than this and it's not feasible to just convert everything in one go and to convince everyone that their entire codebase is going to be reformatted under their feet. So we need to find a more incremental approach. Scaling adoptionRunning prettier on a piece of code is a pretty expensive operation, it makes your pull request look bad because of a lot of unrelated changes and it causes merge conflicts for all the outstanding pull requests. So once a file has been formatted, you should do everything to make sure it remains formatted.
We finally got all those things wired up 1.5 weeks ago and the reception has been insane. Many people from various teams converted their codebase to prettier on their own. As of today, 15% of Facebook codebase has been converted over! When I started working on prettier, I had a hunch that people were hungry for tools to solve formatting. But I had no idea that once the tooling was in place, people would rush to convert their codebase over! This is great confirmation that this project is useful to people and not just a gimmicky tool. TypeScript Support Progress@despairblue, @azz and @JamesHenry have been hard at work around getting TypeScript supported by prettier as it's the top requested feature. 2000 out of 11000 files in the TypeScript test suite are not yet properly printed. You can follow progress on #1480 and do not hesitate to help out! FlowAdd trailing commas on flow generics (#1381)The // Before type Errors = Immutable.Map< Ahohohhohohohohohohohohohohooh, Fbt | Immutable.Map<ErrorIndex, Fbt> >; Inline nullable in flow generics (#1426)The phase after printing things correctly is to tweak the output to make it closer to the way people write code in practice. Inlining optional flow types is a small thing that makes a difference. // Before type Cursor = Promise< ?{ newCursor?: number, formatted: string, } >; Allow flow declarations to break on StringLiteralTypeAnnotations (#1437)We can always find more places to add breaks when things don't fit 80 columns. This time it's around declaring a type as a constant string. // Before export type AdamPlacementValidationSingleErrorKey = 'SOME_FANCY_TARGETS.GLOBAL_TARGET'; Add space around
|
Version 1.3.1 just got published. |
Version 1.4.0 just got published.Update to this version instead 🚀 Release Notes1.4.0: TypeScript and CSS supportTypeScript SupportThis is the most requested feature for prettier. With 1.4.0, you can now use prettier to format your The way prettier works is by using those project to generate an AST representation of the code and print it. Both babylon (the parser that powers babel) and flow are producing an AST approximately following the estree format for the JavaScript parts and then have special nodes for Flow-specific ones. TypeScript, the same way as Flow, introduces special nodes for the syntax it introduces. Unfortunately, it doesn't follow the estree format for the rest of the JavaScript language. This puts us in a rough spot with prettier as we would have to essentially completely fork it in order to print TypeScript. This incompatibility with the AST is not a new problem and another project struggled with it: ESLint. Because the AST is different, none of the ESLint rules are working. Fortunately for us, @JamesHenry and @soda0289 wrote a project called typescript-eslint-parser which takes a TypeScript AST and convert it to an estree one, just what we need for prettier! After that project got setup inside of prettier, @azz, @despairblue and @Pajn implemented all the TypeScript-specific nodes and ensured that the 13k tests of the TypeScript test suite are correctly passing. This was a huge undertaking and it is finally ready to be used :) We tested prettier on the biggest TypeScript projects we could find on GitHub to ensure that it prints correct code. We haven't spent a lot of time trying to optimize the way code is formatted yet, so if you see something strange, please raise an issue! CSS, Less and SCSS SupportWhile TypeScript is the most requested feature from open source, CSS is the biggest one from Facebook engineers. Once you are used to pretty print your code in one language, you want to do it everywhere! It turns out that CSS is a much smaller language than JavaScript and supporting it only took a few days. We are using postcss by @ai as the underlying parser which is able to parse CSS, Less and SCSS. We also depend on postcss-values-parser, postcss-selector-parser by @ben-eb postcss-media-query-parser by @dryoma. Unfortunately, postcss right now doesn't parse Sass nor Stylus. We'd be happy to support them if someone is willing to do the work of printing them. Note that prettier is currently just formatting the code, it does not respect any options yet such as Editor IntegrationThe first phase of the project was to make prettier output correct and good looking code. Now that it's in a good shape, we can spend time on making the integrations better. We just introduced support for two great features: maintain cursor position and being able to format a range instead of the entire file. Note that we just landed the support inside of prettier itself, none of the editor integrations are using it yet. Also, we haven't really tried them out in practice so we're likely going to have to fix rough edges with them! Add
|
Version 1.4.1 just got published. |
Version 1.4.2 just got published. |
Version 1.4.3 just got published. |
Version 1.4.4 just got published. |
Version 1.0.0 of prettier just got published.
The version 1.0.0 is not covered by your current version range.
Without accepting this pull request your project will work just like it did before. There might be a bunch of new features, fixes and perf improvements that the maintainers worked on for you though.
I recommend you look into these changes and try to get onto the latest version of prettier.
Given that you have a decent test suite, a passing build is a strong indicator that you can take advantage of these changes by merging the proposed change into your project. Otherwise this branch is a great starting point for you to work on the update.
Commits
The new version differs by 123 commits .
23756cd
1.0
1a0067e
re-run tests
fe7ebc0
Fix edge cases triggered by newlines in arrow functions (#1217)
3709105
Remove now unused getFirstString (#1231)
4d9edec
Fix trailing comma for rest element in Babylon (#1230)
4dfe92a
Ensure JSXOpeningElement does not break with single text attr on Babylon (#1229)
485028c
Fix ALL_PASERS typo in run_spec (#1227)
27d827a
Remove hasContent (#1222)
33fdcae
Remove isCurlyBracket and isEmptyBlock (#1221)
f68531a
Fix overflow for last argument expansion (#1224)
5fa8df3
Add cli option for --no-semi (#1223)
4a4e181
Do not merge member chain if there's a comment in-between (#1218)
5d8ffd0
Fix own line last if comment (#1219)
ee7cfa9
Ignore empty statement in switch newline detection (#1220)
3a7559b
Preserve comment for last arg of ObjectMethod (#1216)
There are 123 commits in total. See the full diff.
Not sure how things should work exactly?
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴