Commit Graph

365 Commits (3375cfe6050721d2f08956ecb056e3d33155975f)

Author SHA1 Message Date
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
James Long f6708a5cca Fix integer CLI arguments (#452) 2017-01-24 16:07:05 -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
James Long 45f1dc8a01 Update snapshots 2017-01-24 14:24:14 -05:00
Davy Duperron 409d4b6eb5 Ability to break on `:` for objects (#314) 2017-01-24 14:20:24 -05:00
James Long 3aa267d5e8 Remove `multilineGroup` (#450) 2017-01-24 13:54:01 -05:00
Christopher Chedeau d753e56a2a Better error message for assertDoc (#449)
Right now it says that the boolean expression fails which is not super useful. Instead, now it prints the actual value.
2017-01-24 13:53:54 -05:00
Christopher Chedeau fb52e7a5c8 Do not put a newline on empty `{}` for functions (#447)
The original intent of it was for `if then else` and `try catch` as they aren't likely to be empty, but it accidentally caught function bodys, which have many valid reasons to be empty. Let's special case those out.
2017-01-24 12:37:01 -05:00
Christopher Chedeau 4c82f4a2ab Refactor traversal (#442)
- Introduce findInDocs that avoids some annoying boilerplate when you want to get a value while traversing the docs
- Implement a hasStopped function that stops the traversal when you found the value you needed
2017-01-23 20:16:26 -05:00
Michał Pierzchała ee0484521c Fix typo in variable name (#441) 2017-01-23 15:47:34 -08:00
James Long cd2f7393ef Propagate breaks upwards automatically, introduce `breakParent`, and deprecate `multilineGroup` (#440) 2017-01-23 18:47:11 -05:00
Michał Pierzchała 66fe2f78fa Validate user-provided config with jest-validate (#301)
* Validate user-provided config with jest-validate

* Don't use object shorthand

* Update jest-validate to 18.2

* Fix Node4 destructuring from require

* Make use of jest-validate for deprecation message

* Remove chalk reference
2017-01-23 16:33:58 -05:00
Simon Lydell c230562f65 Explain the `--color` option in a comment (#434) 2017-01-23 16:29:57 -05:00
Simon Lydell 4ce637d69c Don't print double newlines at EOF to stdout (#437)
If you use the `--write` option, the files will end with a single
newline as expected. But if you let prettier print to stdout instead and
redirect that into a file, it will contain _two_ newlines at the end.

Demonstration of the correct `--write` behavior:

```
$ cat tmp.js
function test() {
  return "hello";
}
$ wc -l tmp.js
3 tmp.js
$ ./bin/prettier.js tmp.js --write
tmp.js
$ cat tmp.js
function test() {
  return "hello";
}
$ wc -l tmp.js
3 tmp.js
```

Notice how an extra line is added when redirecting stdout:

```
$ ./bin/prettier.js tmp.js > tmp2.js
$ cat tmp2.js
function test() {
  return "hello";
}

$ wc -l tmp2.js
4 tmp2.js
```

With this commit things work as expected:

```
$ ./bin/prettier.js tmp.js > tmp2.js
$ cat tmp2.js
function test() {
  return "hello";
}
$ wc -l tmp2.js
3 tmp2.js
```

Fixes #377.
2017-01-23 13:10:26 -08:00
Christopher Chedeau 5861c90913 Proper parenthesis for yield and await in conditional (#436)
Turns out, we need to always parenthesis when it's the first part of a conditional for both yield and await.

Fixes #433
2017-01-23 10:25:38 -08:00
Christopher Chedeau ae2fb73425 [WIP] Add rationale document (#372)
* [WIP] Add rationale document

I think it would be great to have such a document. This way we don't have to explain the same things over and over again on the issues and it helps users and contributors know what they are getting into.

This is a very rough draft with a lot of empty content but I think it shows the idea.

* Improve Rationale.md

- Fix typos.
- Consistently use "prettier does x" instead of "prettier is going to do
  x" or "prettier will do x"-
- Simplify language.

* Add bit about correctness
2017-01-23 09:56:17 -08:00
Christopher Chedeau b1b313091d Run prettier for 0.11.0 (#435) 2017-01-23 09:49:46 -08:00
Christopher Chedeau ef531274f7 0.11.0 2017-01-23 09:40:01 -08:00
Christopher Chedeau 93c8270eee Update yarn.lock 2017-01-23 09:16:47 -08:00
Simon Lydell bb1884320b Use babel-code-frame for syntax errors (#367)
* Use babel-code-frame for syntax errors

* Support the `--color` option more explicitly

* Update rollup config to handle babel-code-frame

* Use exact dependencies
2017-01-23 09:10:51 -08:00
Simon Lydell 6b3d3bc066 Add glob support to the CLI (#363)
* Add glob support to the CLI

Fixes #145. Fixes #362.

* Update README.md regarding globs

* Use exact dependency for glob
2017-01-23 10:37:57 -05:00
Riley Tomasek 515379435c Improve vim integration section (#416) 2017-01-23 10:27:52 -05:00
Shigeaki Okazaki 62f15f51ce Update commands.md (#430) 2017-01-23 10:26:52 -05:00
Christopher Chedeau d9d704fd00 Revert "Workaround flow bug around trailing comma" (#429) 2017-01-22 20:52:30 -08:00
Christopher Chedeau d7a44bae10 Add parenthesis when class expressions are left of a ternary (#428)
Fixes #426
2017-01-22 20:32:17 -08:00
Christopher Chedeau 4369e66017 Workaround flow bug around trailing comma (#427)
Fixes #425
2017-01-22 20:31:43 -08:00
Christopher Chedeau 3d4e0bf166 Re-run snapshot tests 2017-01-22 19:31:59 -08:00
Brian Ng 895709b4ca Fix missing parens around object in MemberExpression (#424) 2017-01-22 19:29:30 -08:00
Christopher Chedeau b13124bed4 Add parenthesis for class expression on left of member expression (#421)
Fixes #414
2017-01-22 19:05:46 -08:00
Christopher Chedeau d7992886dd Add parenthesis around export default assignments (#423)
Fixes #413
2017-01-22 19:05:33 -08:00
Christopher Chedeau 2acc3e5ea6 Add parenthesis around assignment for arrow function body (#422)
Fixes #412
2017-01-22 19:04:00 -08:00
Christopher Chedeau d57d8450dc Add parenthesis for yield inside of a conditional (#418)
Fixes #411
2017-01-22 19:03:43 -08:00
Brian Ng 2a0e7b575c Ensure computed method names don't lose quotes (#419) 2017-01-22 18:41:31 -08:00
Christopher Chedeau 105a164423 Add parenthesis around class expression when left side of call expression (#409)
Fixes #402
2017-01-22 16:22:49 -08:00
Christopher Chedeau c8615ed9a6 Add parenthesis for arrow function inside of ternary (#408)
This one is really weird

```js
if (() => {} ? 1 : 0) {}
```

parses fine but

```js
if (() => {
} ? 1 : 0) {}
```

is a syntax error. Let's always add a parenthesis.

Note that no one is every going to write this in practice, this is really useless :p
2017-01-22 16:16:57 -08:00
Christopher Chedeau 41d92c1187 Fix in inside of the first group of a for (#406)
Fixes #405
2017-01-22 15:52:35 -08:00
Christopher Chedeau 2f220de204 Fix various parenthesis issues on the left side of template (#404) 2017-01-22 15:43:57 -08:00
Christopher Chedeau e45a9b0582 Also do the class extend parenthesis for class expressions (#403) 2017-01-22 15:35:45 -08:00
Christopher Chedeau 4a47eff474 Fix +++x (#401)
Fixes #379
2017-01-22 15:21:25 -08:00
Christopher Chedeau 95df4ff655 Remove trailing comma for array destructuring with rest (#400)
Fixes #394
2017-01-22 15:20:47 -08:00
Brian Ng badab37dd1 Remove unneeded parens for FunctionExpression inside LogicalExpression (#399) 2017-01-22 15:00:13 -08:00
Christopher Chedeau bf32905c3f Fix parenthesis in object as left-hand-side of template (#398)
Fixes #392
2017-01-22 14:33:34 -08:00
Christopher Chedeau b77703a942 Fix class inside of binary expression missing parenthesis (#397)
Fixes #395
2017-01-22 14:33:04 -08:00
Christopher Chedeau fac5cd0801 Fix class extends parenthesis (#396)
This should fix all of the issues with the fuzzer :)

Fixes #387
2017-01-22 14:19:53 -08:00
Charles Pick 9a71a907e5 add formatAST() for formatting ASTs directly (#393) 2017-01-22 14:00:23 -08:00
Christopher Chedeau 7be4994d1a Empty switch should not have an empty line (#384)
Fixes #368
2017-01-22 12:40:46 -08:00
Christopher Chedeau 3d95e8317b Fix forced trailing comma (#382)
We shouldn't output trailing commas when there is a forced one when we break.

Fixes #380
2017-01-22 12:34:35 -08:00
Christopher Chedeau 1f92218a06 Fix empty labels (#383)
We actually need this `;` for EmptyStatement, otherwise it applies to the next block of code. (Creating a label with an empty statement is completely useless, but it triggers a lot in the fuzz testing tool)

Fixes #376
2017-01-22 12:34:27 -08:00
Christopher Chedeau 58a97ab597 Fix missing semi-colon in for loop and var body (#388)
We avoid adding a `;` for a variable declaration in for loop but this is only meant if the var declaration is inside of the `()` part of the for loop. Not if the body part.

Fixes #385
2017-01-22 12:34:14 -08:00
Christopher Chedeau 1a9e5e9022 Support multiple standalones in import (#389)
There was an assertion that there would be only one, it turned out not to be the case.

Fixes #386
2017-01-22 12:34:00 -08:00