Commit Graph

28 Commits (b861448dbf4f5fac83ac9555adf87989f03ee3a5)

Author SHA1 Message Date
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 f119d4a90f
Change run_spec to have explicit parser list (#3356) 2017-11-30 03:31:52 -03:00
Lucas Duailibe 15989df6e1 Group last argument if it's an empty object with a comment (#2758) 2017-09-05 12:22:25 -07:00
Stephen Scott 757037948a Improve JSX Formatting
* Arrow Function Expressions returning JSX will now add parens when the JSX breaks
* Conditional expressions within (or containing) JSX are formatted in a more natural way (for JSX), especiall when chained
* JSX in logical expressions (|| or &&) is always wrapped in parens

Fixes #2208
2017-07-13 10:20:42 -06:00
Karl O'Keeffe 5e76ea7bdd Allow single expressions in JSX to be inline 2017-07-10 20:02:30 +01:00
Karl O'Keeffe be600337eb Improve JSX output when there is a single expression (#2274) 2017-06-26 19:05:34 -07:00
Christopher Chedeau ffc1b3702e Remove parenthesis for JSX inside of arrow functions (#1733)
I didn't intend for putting parenthesis there in the first place but it slept through. Since it was going to trigger a ton of changes I held up changing it, but I feel like we need to do it sooner than later otherwise we're not going to be able to do it. A lot of people writing functional components are going to be very happy about this change :)
2017-05-25 16:26:49 -07:00
Christopher Chedeau e39209386c Only add parenthesis on ternaries inside of arrow functions if doesn't break (#1450)
This was added in order to follow some eslint rule but it's only confusing when it doesn't break, when it breaks the indentation makes it clear what is happening and you don't need parenthesis.

Fixes #1379
2017-05-01 14:32:52 -07:00
Christopher Chedeau 8d03423d17 Avoid breaking arguments for last arg expansion (#1305)
We've had this issue since the beginning and I tagged it as 1.0 but haven't managed to fix it by then. We shouldn't allow things to break in the argument list if we are in the last argument expansion mode. It turns out that we now have all the building blocks needed to fix this:
- have a special way to flag when we are printing the last argument expansion in the code that prints the argument list
- have a way to remove all the softlines from the argument list

Fixes #1301
2017-04-18 08:40:08 -07:00
Christopher Chedeau 1a0067eae4 re-run tests 2017-04-13 09:26:36 -07:00
Christopher Chedeau fe7ebc0cf7 Fix edge cases triggered by newlines in arrow functions (#1217)
This one is pretty crazy. In #927, I changed

```js
concat(["(", join(concat([", "]), printed), ")"]),
```

into

```js
concat(["(", join(concat([", "]), printedLastArgExpanded), ")"]),
```

which makes the example in #1203 look ugly. The crazy thing is that `JSON.stringify(printed) === JSON.stringify(printedLastArgExpanded)`. So they are deep equal but not the same object. In a non-mutative world, this should cause any problem, but we actually mutate those to propagate breaks.

In the break propagation, we only looked at the first one in case of a conditional group. But, because the two were the same object then it also applied to the second one and happened to be the correct behavior! When I changed that piece of code to be two distinct objects, it no longer worked by accident and caused a bunch of weird issues where breaks didn't propagate correctly.

The solution for this case is to propagate the breaks on all the conditions. I'm pretty sure that this is the expected behavior, we want to deeply recurse in all of them, we don't propagate it up the boundary anyway.

The other use case for `traverseInDoc()` is `findInDoc()`, right now it searches for the first conditional group but it seems very arbitrary. I changed it to not search on any and none of the tests are failing, so I think it's safe(tm). If it triggers weird behavior, then it'll at least be expected and not randomly explode at us if we move groups around.

I tried to go through all the conditions for `findInDoc()` but it triggers a few failures (the output look bad). I'm not really sure why. https://gist.github.com/vjeux/5fb7566cc3d65974817d512d1ef6abe1

Fix #1203
2017-04-13 09:21:18 -07:00
Christopher Chedeau f68531a45d Fix overflow for last argument expansion (#1224)
In #847, I used a heuristic to find if the element was going to be expanded. But, it wasn't 100% accurate because we couldn't know in which conditionalGroup we would land. We added a way for the parent to tell that function if we should be in `expandLastArg`. By replacing the condition by this variable, it now fixes the issues!

This is so good that adding the right abstraction fixes problems across the board :)

Fixes #997
2017-04-12 20:24:50 -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 2e63684ff5 Add parenthesis for no-confusing-arrow rule (#1182)
I'm unclear whether anyone was ever confused by this but the eslint page is kind of compelling

```js
// The intent is not clear
var x = a => 1 ? 2 : 3;
// Did the author mean this
var x = function (a) { return 1 ? 2 : 3 };
// Or this
var x = a <= 1 ? 2 : 3;
```

Adding a parenthesis makes it valid with `{"allowParens": true}` rule. Note that if this option is not enabled, the code would not pass lint in the first place.
2017-04-11 09:20:39 -07:00
Christopher Chedeau e0eb438e7b Add newline for bracket-less arrow functions that return calls (#927)
I've tried a lot of places where to fix this and this is the only one that gives correct results. This is likely not exhaustive but works for that use case. It's been reported twice in issues and I've seen it happen a few other times so we probably want to get it fixed.

Fixes #922
Fixes #797
2017-04-11 08:50:49 -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
Royce Townsend 9eb389b9f4 Group first arg for inline functions (#947)
* Group first arg for inline functions

* Group first arg. Unless there are comments.

* Group first arg. Allow second arg to be empty object/array.

This implementation has a side effect of disallowing empty objects/arrays in the should group last arg heuristic.
2017-03-18 11:20:07 -07:00
Christopher Chedeau 211e18bed2 Inline last arg function arguments (#847)
```js
SuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLongCall((err, result) => {
  // comment
});
```

currently breaks into

```js
SuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLongCall((
  err,
  result,
) => {
  // comment
});
```

which looks bad, instead this PR makes it break

```js
SuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperLongCall(
  (err, result) => {
    // comment
  }
);
```

which look better
2017-03-02 22:29:53 -05: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 77bf64c6b1 Print CallExpression comments inside of memberChain (#600)
I made sure that MemberExpressions where printed correctly but didn't do the same for CallExpression. Now it is! It is a bit less straightforward because the comments for the root CallExpression have already been printed, so we need to extract the first call out.

(This is the last place where we drop comments on the test suite, we can start enabling throwing when comments are dropped!)
2017-02-04 21:31:54 -05:00
Christopher Chedeau 4bd194e2ce Use breakParent inside of last arrow expansion (#559)
Fixes #549
Fixes #553
2017-02-03 16:15:21 -05:00
Christopher Chedeau d0bc2991f6 Reimplement MemberExpression printing (#469)
There are currently three issues related to suboptimal rendering of MemberExpression chains. The previous implementation was trying to flatten only a single group at the same time, but it didn't work well because we didn't have the full context to be able to make decisions.

In this implementation, I'm going through the entire chain at the same time and group it into logical units and make decisions based on this. It solves all the problems I can think of and if we need to tweak it in the future, it should be easy.

Fixes #268
Fixes #212
Fixes #21
2017-01-31 12:32:42 -08:00
Christopher Chedeau 410e75d858 Update snapshot tests from conflicting PRs 2017-01-31 09:39:00 -08:00
Christopher Chedeau 959235afd7 [RFC] Keep expanded objects expanded (#495)
Another attempt at solving the issue where objects are not expanded the way people expect. If there's any new line in the original source, it's going to expand it. This gives more control to the user in how the objects should be formatted.

Fixes #74
2017-01-30 09:08:55 -08:00
Christopher Chedeau cde322bff8 Add CallExpression to the last argument expansion whitelist (#470)
Fixes #274
2017-01-26 17:24:50 -05:00
Christopher Chedeau e13bb7dbba [RFC] Do not put spacing inside of arrays with bracketSpacing option enabled (#446)
Given the discussion on #296, it seems like there's debate between spaces around `{}` but no one puts spaces around `[]`. So changing the behavior to respect this.
2017-01-24 11:38:12 -08:00
Christopher Chedeau a4695b16f6 Last argument expansion works for arrow functions that return JSX (#211)
* Last argument expansion works for arrow functions that return JSX

Fixes #195

* Fixes #130
2017-01-15 00:04:50 -05:00