I originally wanted to expand it but I think that it may not be a good decision because it's very common for them to be empty and you want it to take as little space as possible.
I tried to remove all those conditions but I think that there are valid places where we always want to expand like empty if/for/while loops.
Fixes#778
In addition to Observable, $ or _, we should also add `this` to the list of things that are likely factory and not objects you want to apply things on directly.
I added a way to make the function call break on its own line when it doesn't fit in one line and indent. But I think that only having the indentation is enough, having the call on its own line feels weird.
Fixes#777
Previously we would blindly put leading comments of the next expression, but we didn't account for a real trailing comment. By checking if the leadingNode is on the same line, we can correctly put it there when needed
Fixes#685
* Add handleAssignmentPatternComments helper function.
* Add new tests 🎉.
* Remove unecessary arg in function.
* Reorder it.
* Experimental fix for key comments in the printComments function.
* Pull master and switch to @vjeux implementation.
* Fix bad rebase.
* Add additional checking for enclosingNode in handleObjectProperty function.
There is an off by one error which made the algorithm not work all the time. In many cases, it actually is the opposite, so whenever you save, it adds/removes that line. I noticed it during the --debug-check run on our codebase but didn't investigate.
Fixes#723
This has come up many times in the past and while going through the fb codebase, there are a few instances where we group array elements logically using empty lines and it's a shame that they are gone.
I've started the discussion around it but I think that it was a mistake. It feels weird to add parenthesis on object values sometimes but not others. I think that it's best to let prettier do its work on staying under 80 columns based on the rules we added.
We inline function definitions but we shouldn't inline new expressions,
835befebf5 introduced both call expressions and new expressions. Call expressions have been removed but looks like new haven't.
In the current demo, every time the code in the left panel is changed,
the new code is stored in the URL hash, which pushes a new history
entry. This effectively "breaks" the back button. This change calls
`history.replaceState` instead, so a single click of the back button
will return the browser to whatever page was open before navigating to
the demo.
This was surprisingly easy to write!
Technically, it doesn't ignore the next line but the next expression or block but I'm guessing that people are already used to `// eslint-disable-next-line` so it's going to be an easier learning curve.
Fixes#120
* Extend ReturnStatement case to better handle comments in argument 🎉.
* Update test.
* Add missing space between return and left parenthese.
* Fix current tests and add new tests.
* Do not break one-liner returns.
* Revert specific test.
* Patch from #683.
In #563 it looked odd that there was no space before `//`, it turns out that we don't automatically go to the new line for dangling comments. I think that we just should no matter what, so this is what this diff does.
Fixes#563
* Inject source text into printAstToDoc function.
* Add getNodeSource helper function.
* Fix Flow drawback with missing DeclareTypeAlias by checking the node source.
* Add new test.
* Fix getNodeSource helper function.
* Revert text injection.
* Refactor DeclareTypeAlias printing.
* Drop expensive getNodeSource helper function 🗑️.
* Refactor declareTypeAlias case in printer.
* Update tests.
* Implement the same logic for DeclareInterface.
* Update the tests.
* Fix missing semicolons and typo.
* Put Flow specific node detection code into own helper function 🚀.
* Refactor isFlowNodeStartingWithDeclare helper function.
* Simplify isFlowNodeStartingWithDeclare helper function.
* Rename test spec.
* Update tests.
When there is a comment right before the first `.`, we want to force break such that the comment is printed on its own line.
Note: this needs to be based on-top of #667 as it always indent the first `.`
Fixes#613