Commit Graph

33 Commits (master)

Author SHA1 Message Date
Sosuke Suzuki 8f0fdba4ba JavaScript: Fix ugly formatting parens wrap binary expressions… (#6441)
* Modify to break specific call expression correctly

* Add tests

* Update CHANGELOG.unreleased.md

* Add tests

* Fix tests

* Add pr link
2019-09-07 14:46:00 +02:00
JounQin e5fbef238d docs: fix possible typo AFAIK (#6341) 2019-07-30 11:48:14 +02:00
Ika 4af3dd4b07
test: improve snapshots (#5521)
- before
  ```
  ${input}${"~".repeat(printWidth)}
  ${output}
  ```
- after
  ```
  ===options===
  ${options}
  ${" ".repeat(printWidth)}| printWidth
  ====input====
  ${input}
  ===output====
  ${output}
  =============
  ```
2018-11-25 16:21:14 +08:00
Kevin Gibbons cbcd24a5b2 Correct parentheses for mixed exp/mod (#5243)
Fixes #5238.

cc @duailibe for the [original change](https://github.com/prettier/prettier/pull/4413). I basically undid that PR because it didn't look to me like `shouldFlatten` made sense as the place to introduce the behavior it was going for, but I might have misunderstood something.
2018-10-12 12:33:47 -04:00
Lucas Duailibe ed6a2d9055
Prevent JSX from breaking a logical expression chain (#5092) 2018-10-10 14:11:37 -03:00
Simen Bekkhus 51b7c02e12 Upgrade jest to 22 (#4782)
* chore: upgrade Jest

* chore: update snapshots

* chore: lock down babel dependency using invalid syntax

* 2 args to test.skip

* use jest 22 for now

* Revert "2 args to test.skip"

This reverts commit 691fdc3f99e320f2303958f2b503f7b4c93fa455.

* remove snapshot name from matcher

* fix standalone tests skips
2018-07-03 03:06:29 -03:00
Lucas Duailibe e3223fe9af Prevent flattening multiplicative operations (#4407) 2018-05-02 23:48:40 +02:00
Lucas Duailibe f119d4a90f
Change run_spec to have explicit parser list (#3356) 2017-11-30 03:31:52 -03:00
Lucas Duailibe 9b0d6b8de0 Fix different precedence binary expression when inlining (#2827) 2017-09-20 17:07:51 +02:00
Lucas Duailibe bba7dcf498 Fix break on conditional expressions inside return
Fixes #2777

Since we can't break after `return` and don't add `()` around
ConditionalExpressions' tests, we end up with some weird indentation when
breaking.
2017-09-10 04:13:47 -06:00
Lucas Duailibe 2c37697f82 Fix chained logical expressions with objects/array/etc inlined 2017-09-07 21:57:07 -06:00
Lucas Azzola bac9658687 Flatten x & y & z, and x ^ y ^ z, fixes #2445 (#2490) 2017-07-15 12:54:33 +02:00
Lucas Azzola 4a320a9332 Add supervisory parens for bitwise operations (#2429)
* Add supervisory parens for bitwise operations, fixes #2424

* Flatten x | y | z
2017-07-08 17:31:28 +10:00
Lucas Azzola 7e96e01fba Add more supervisory parens, closes #187 (#2423) 2017-07-07 15:57:17 +02:00
Lucas Azzola 2a58e6bc06 test(typescript): enable typescript-verify on most tests (#1781) 2017-05-27 17:57:07 -07:00
Christopher Chedeau 62679f20f0 Indent conditions inside of !() (#1731)
This has been a longstanding issue and I thought it would be hard to do, but turns out it is pretty easy!

Fixes #774
2017-05-25 16:26:34 -07:00
Dmitry Rybin 1d9478a61f Fix boolean for empty objects (#1590)
* Add test for empty object in logical expression

* Add check for empty object and array in shouldInlineLogicalExpression

* Review fixes, add additional case with function call
2017-05-12 07:48:03 -07:00
Christopher Chedeau bb232d48a3 Inline chained conditionals inside of jsx attribute (#1519)
Fixes #1515
2017-05-05 21:44:50 -07:00
Christopher Chedeau bae08d4e7e Only break for conditionals (#1350)
We only want to break for && and ||, not for ===
2017-04-19 13:18:01 -07:00
Christopher Chedeau aafcf5f381 Break if () if conditional inside breaks (#1344)
Fixes #868
2017-04-19 10:43:48 -07:00
Jan Kassens b82220b20f Prittier printing of snapshots (#1190)
This uses a custom snapshot serializer to reduce escaping in snapshot files and
make them easier to read.

Snapshot serializers are documented here:
https://facebook.github.io/jest/docs/configuration.html#snapshotserializers-array-string
2017-04-12 13:41:51 -07:00
Christopher Chedeau c3199359b0 Revert "Improve snapshot naming" (#1070)
* Revert "Remove mutation in `printBinaryishExpressions` (#1067)"

This reverts commit e7312ad7b2.

* Revert "Make it clear what parser was used in each snapshot (#1068)"

This reverts commit 4f7ae4815b.
2017-03-21 17:38:28 -07:00
ChristianHersevoort 4f7ae4815b Make it clear what parser was used in each snapshot (#1068) 2017-03-21 14:47:23 -07:00
Christopher Chedeau ce6e897950 [RFC] Fix comment location for binary expressions (#1043)
The root cause is that we're calling `printComments` with an empty string, meaning that the leading/trailing comments are not correctly inserted at the right location.

So, the way to fix it is to call `p => concat(parts)` but because we're mutating the array in place, it doesn't work. We need to mutate it and create a copy. But, the root call is actually checking the shape of the parts array which our code is now breaking...

```js
          // Don't include the initial expression in the indentation
          // level. The first item is guaranteed to be the first
          // left-most expression.
          parts.length > 0 ? parts[0] : "",
```

The consequence is that binary expressions are no longer indented if the first expression has a comment (but now it places the comment properly!), which seems like a good trade-off.

I'm not sure if we should merge this one or instead refactor this code such that it doesn't rely on mutation and looking at the shape of the printed tree. `printMemberChain` is a good thing to reference for inspiration.

Fixes #946
2017-03-21 12:13:13 -07:00
Christopher Chedeau 7105f972b4 [RFC] Add softline to assignment of binary expressions (#871)
Printing the first line of a binary expression next to the `=` leads to weird cases where the first expression is parenthesised and doens't read well with chained conditionals as they don't align well. This makes it behave the same was as `if` tests.

Fixes #863
2017-03-15 09:45:40 -07:00
Kevin Gibbons dc2fa2cdd0 Fix #951: properly parenthesize ** expressions (#952) 2017-03-08 13:11:53 -08:00
Christopher Chedeau 5523c4f56b Inline short expressions for boolean operators too (#826)
In #605 I restricted it to binary operations as I didn't know how it would affect boolean operations but it turns out the same technique solves problems that people are reporting. So doesn't make sense to restrict it.

Fixes #824
2017-03-02 22:45:26 -05:00
Christopher Chedeau 1d02ca7849 [RFC] Add parenthesis around && inside of || (#780)
It seems like precedence for this combination of operators is very unclear to people (myself included) and consistently adding parenthesis there would be good.

Fixes #773
2017-02-23 09:27:00 -08:00
Rogelio Guzman d45e157563 Upgrade to Jest 19 (#762)
* Upgrade to Jest 19

* Use exact versions for Jest
2017-02-21 13:59:19 -08:00
Christopher Chedeau 00e5014e00 Align boolean inside of arrow functions (#691)
We already do it for if/... but it looks weird for arrow function body.
2017-02-15 20:00:02 -08:00
Christopher Chedeau 0c00290dd3 Inline objects & arrays as right part of a boolean expression (#692)
This is a common pattern to write default values.
2017-02-15 09:41:06 -05:00
Christopher Chedeau 4a00bc33a5 Put short elements at right of single binary expression on same line (#605)
I've been trying to come up with a heuristic to stop putting small elements on a new line and I just realized that all the cases I found out only involved a single binary expression. If there's only a single operation, we can just put them on the same line (if it fits) and it's not going to look weird.

We do the same thing for MemberExpression where we only break if there are more than one ".".

Fixes #583
Fixes #503
2017-02-09 10:44:03 -05:00
Christopher Chedeau 3375cfe605 Move tests around (#454)
* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
2017-01-24 14:35:37 -08:00