Commit Graph

583 Commits (7443f4cbd6268ec3b0663c058bda99d13633cba0)

Author SHA1 Message Date
Kevin Gibbons 7443f4cbd6 Parenthesize function expressions in expression position (#941)
* refactor needsParens for function expressions

* snapshots

* comment
2017-03-07 18:53:42 -08:00
Alex Rattray 50602aecbb [JSX] Break if opening element breaks (#942) 2017-03-07 17:19:05 -08:00
Kevin Gibbons 06987e9948 cleanup needsParens (#935) 2017-03-07 14:43:05 -08:00
Davy Duperron 1b6ddf9a7f Fix binary op as body in arrow expression (#921)
* Implement new logic for wrapping binary op in arrowFunctionExpression.

* Add new test cases.

* Reuse new helper function in order to fix #917.

* Add new test case.

* Extend heuristic to dive deeper into mixed types.

* Add new test.

* Enhance logic to cover more cases.

* Add new test cases.

* Disable Flow as it gets BindExpression as an unexpected token.

* Simplify getCombinedDeepest function.

* Add missing case.

* Extract all conditions in switch cases to one top level condition.

* Refactor implementation to make it cleaner and also handle ExpressionStatement.

* Update related test cases.

* Add new test case.

* Make condition less expensive.

* Clean up unecessary conditions, simplify condition involving startsWithOpenCurlyBrace.

* Update and add new test cases for better coverage.

* Remove unecessary condition, refactor canBeFirstInStatement to drop some useless parens.

* Update test cases accordingly 🚀.
2017-03-07 13:24:47 -08:00
Patrick Camacho 513b57db3a Update README.md (#928)
typo fix
2017-03-07 11:38:58 -08:00
Davy Duperron 008ac1c479 Fix files with comments only (#813)
* Add new handleOnlyComments function.

* Update tests.

* Update test as the printer forces a trailing newline if there were any contents.

* Implement a different heuristic.

* Update tests.

* Add directives checking in handleOnlyComments function.

* Add directives checking in handleOnlyComments function (amend to retrigger CI).

* Remove duplicate.
2017-03-07 11:02:45 -08:00
Andrey Okonetchnikov 3045829a61 Update lint-staged docs to use husky for less config. (#923) 2017-03-07 09:53:00 -08:00
Kim Joar Bekkelund a5ad490467 Do not break long it/test calls when template literal (#893)
* Do not break long it/test calls when template literal

* expressions and newlines
2017-03-07 08:36:03 -08:00
Simon Lydell 25bbe1accb Improve readme CLI usage example (#910)
- Use double quotes for cmd.exe support. See #761.
- Remove redundant example and merge it into the previous.
2017-03-06 03:45:16 -08:00
Davy Duperron 4dde054bb3 Fix binary expression instanceof in arrow function expression (#913)
* Add fix for parens of BinaryExpression with instanceof op embedded into ArrowFunctionExpression.

* Add new test 🚀.
2017-03-06 03:44:48 -08:00
Simon Lydell b91d6384a6 Fix 0.5e0 (#911)
* Don't generate invalid scientific notation

Fixes #902.

* Remove unnecessary scientific notation (1e0)
2017-03-06 03:44:05 -08:00
Jed Watson 74b6466ee7 Add CLI Example to Readme (#909)
Simple change to add a real world example of CLI usage, because it wasn't immediately obvious to me how it should actually look
2017-03-05 21:51:51 -08:00
Davy Duperron 3f6259554e Fix broken export comment (#899)
* Add new helper function to convert comments as blocks in ExportNamedDeclaration.

* Add new test.

* Switch to a leading position.

* Update test accordingly.
2017-03-05 21:49:07 -08:00
Brian Ng f6bbc2ed2e Fix bug with importing empty type (#904) 2017-03-05 19:08:42 -08:00
Davy Duperron c852d1631c Fix unprinted comments in destructuring (#898)
* Add handlePropertyComments printing function.

* Add new test.
2017-03-05 14:40:03 -08:00
Davy Duperron 2ef9896567 Fix object expression in arrow function expression (#897)
* Add new case for keeping parens around ObjectExpression in ArrowFunctionExpression.

* Add new test.
2017-03-05 13:04:50 -08:00
Brian Ng 860a9fd6d4 Ensure no parens for JSX inside of an ArrayExpression (#895) 2017-03-05 08:56:07 -08:00
David Ascher c8c91d4af3 Fix typo (#891)
I believe that the instructions for pre-commit config are off by a character.
2017-03-04 11:47:35 -08:00
Brian Ng 226fd85d8f Fix paren removal on UnionTypeAnnotation (#878) 2017-03-03 17:37:00 -08:00
Christopher Chedeau be7b5ea120 Run 0.21.0 (#876) 2017-03-03 15:39:37 -08:00
Christopher Chedeau b570154dd5 0.21.0 2017-03-03 14:03:36 -08:00
Christopher Chedeau 7d24b0a1ff Fix flow union comments (#853)
The comments infra has been architected with trailing operators and fails for leading `|`. Instead of having leading comments, we can put trailing comments on the previous one and use the same technique as assignment to deal with the indentation.

Fixes #849
2017-03-03 13:54:45 -08:00
Christopher Chedeau 184382dd00 Do not break long it calls (#842)
This happens very frequently that naming a test makes the entire line go > 80 columns and requires to indent everything which takes a lot more space. We've had this being reported multiple times and it also affects a lot of tests inside of fb.

Fixes #159

(Note, this is built on-top of #841 but github doesn't handle stacked pull requests well...)
2017-03-03 16:48:29 -05:00
Christopher Chedeau fe38dab45a Fix comment for `call( // comment` (#858)
This is a pretty exotic way to put a comment and it's been a long time since I have seen prettier output be as broken :)

Fixes #857
2017-03-03 16:47:13 -05:00
Christopher Chedeau 735f07fa4f Do not put \n after label (#860)
This is a leftover from the recast prototype, it hasn't been touched since then. I have never seen anyone not put the label on the same line.

Fixes #859
2017-03-03 16:46:40 -05:00
Christopher Chedeau fa9dca362e Add parenthesis around assignments (#862)
This is a neat trick from the React codebase. It helps highlight the fact that this is an assignment and not a comparison which is subtle to realize.

Fixes #861
2017-03-03 16:46:11 -05:00
Christopher Chedeau 205458a8d1 Introduce -l option (#854)
gofmt has this option and it's very handy for commit-hooks.

Fixes #851
2017-03-02 22:47:36 -05: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 3649835ce0 Keep parenthesis on export default function (#844)
It turns out that my fix was not correct. We should not add parenthesis for FunctionDeclaration instead of checking if the function expression is named.

Fixes #819
2017-03-02 22:39:22 -05: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
Christopher Chedeau 4b237d331e Fix jsx expression comment that break (#852)
In #596, I fixed a bunch of jsx expression comment edge cases and happened to add a softline there. But it turns out that it's not needed and is actually harmful :)

Fixes #712
2017-03-02 22:27:08 -05:00
Christopher Chedeau 516f5900d8 Stabilize import as comments (#855)
Since this is extremely rare, I just took the easy way out and if you are adding a comment inside the "as" node, I just move it outside. We could be more fancy but that works.

Fixes #620
2017-03-02 22:22:33 -05:00
Christopher Chedeau 705ac7d3cf Do not break require calls (#841)
This has come up a couple times on the issue tracker on the react-native-web discussion about Twitter internals. It seems like there's a concensus that people don't break long require calls and they'd rather have it go > 80 columns.

Fixes #303
Fixes #752
2017-03-02 22:21:02 -05:00
Christopher Chedeau a91bb5f2ec Fix travis build image 2017-03-02 19:20:45 -08:00
Christopher Chedeau d90af427fb Fix comment after the last argument of a function (#856)
The issue is that the comment algorithm attaches it to the return type / value but we want to attach it to the previous one.

Fixes #612
2017-03-02 22:17:22 -05:00
Alex Rattray 475208d22a [JSX] Don't wrap JSX Elements in parentheses if they are inside JSX Expression Containers (#845) 2017-03-01 12:05:57 -08:00
Christopher Chedeau 198a9e4e49 Run prettier 0.20.0 (#835) 2017-03-01 09:37:02 -08:00
Christopher Chedeau f1548e76bd re-run snapshot tests 2017-03-01 09:11:54 -08:00
Alex Rattray aef1ac61c9 [JSX] Break before and after jsx whitespace (#836) 2017-02-28 13:30:54 -08:00
Christopher Chedeau e09bdd4447 0.20.0 2017-02-28 10:49:30 -08:00
Christopher Chedeau d6e3815c19 Allow breaking for logical expressions in member chains (#827)
I'm not really sure what a general rule is for those, but starting with LogicalExpressions should be good. Outside of identifiers, function calls and logical expressions, there aren't a lot of things you'd put there in real code anyway.

Fixes #822
2017-02-28 09:31:04 -08:00
Simon Lydell 25340671d3 Update list of related projects (#833) 2017-02-28 09:24:08 -08:00
Christopher Chedeau 61482662cc Migrate class comments to the beginning (#831)
Instead of trying to figure out a complicated way to preserve their correct position, it's easier to just migrate those comments before the class.

Fixes #693
Fixes #694
2017-02-28 11:23:15 -05:00
Christopher Chedeau 2ea1dbcb6a Fix indentation of a merged group (#828)
Printing a merged group indented was actually not the right fix. The right fix was to print them in a single line. It used to have this behavior when I was mutating the first group but now that I don't anymore I need to reproduce this condition.

Fixes #823
2017-02-28 10:55:32 -05:00
Christopher Chedeau c17bcabc0b Preserve new lines for comments after `=` (#830)
The `hasLeadingOwnLineComment` helper is going to be useful for other places where we just used `n.comments` as a proxy for it.

Fixes #660
2017-02-28 10:00:28 -05:00
Christopher Chedeau 4540f473e9 Put short body of arrow functions on the same line (#829)
By adding a group, we can avoid adding a newline if the expression fits in a single line.

Fixes #800
2017-02-27 17:18:43 -05:00
Christopher Chedeau edf2bde590 Fix trailing commas in docs (#825)
I also added support for parser dropdown and stop minifying the bundle so that the flow parser actually works.

Fixes #816
2017-02-27 17:02:41 -05:00
Spencer Dixon a59e2c652f Adds another preset to related projects (#820) 2017-02-27 16:50:38 -05:00
Christopher Chedeau 08b8a5f2e7 Do not put parenthesis around not named default export (#819)
We need to add parenthesis around function expressions if they are named otherwise the name leak, but if the function is not named then it's just superfluous.

The conditional change is due to a bad use of switch case where it would fall through the next one. We don't want parenthesis there.
2017-02-27 16:46:17 -05:00
Christopher Chedeau 443a5d6d66 Properly support `do` (#811)
The code that supported `do` was likely from some recast time and didn't work anymore.
2017-02-27 10:49:08 -05:00