Commit Graph

384 Commits (1d356651a38b8921e668013449d0a32bf3c7c4c7)

Author SHA1 Message Date
Simon Lydell 1d356651a3 Mention eslint-plugin-prettier in Related Projects (#490) 2017-01-26 15:06:49 -08:00
Christopher Chedeau cde322bff8 Add CallExpression to the last argument expansion whitelist (#470)
Fixes #274
2017-01-26 17:24:50 -05:00
Alex Rattray 60fa5dae29 Don't break up JSXOpeningElement if it only has a single text attribute (#488) 2017-01-26 17:22:56 -05:00
Christopher Chedeau 6ade2a1e4a Maintain windows line ending (#472)
It's nice that we print line endings in a single place, it was super easy to preserve them :)

Fixes #92
2017-01-26 14:16:42 -08:00
Christopher Chedeau 0957c8672a Indent computed member (#471)
Fixes #136
2017-01-26 14:58:47 -05:00
Alex Rattray 72c9424c53 Indent ternaries (#484) 2017-01-26 11:58:40 -08:00
James Long eaddd4b3e6 Refactor comment algorithm and improve newline/spaces detection (fixes #483, #275, #135, #78, #36) (#482) 2017-01-26 11:57:43 -08:00
Christopher Chedeau 573936aacc [RFC] Hug Conditionals in JSX (#473)
Conditionals are very common in JSX and it is unfortunate that they take up so much vertical space in the current prettier.

This pull request does a few tweaks:
 - It hugs ConditionalExpression (ternary) and LogicalExpression (&&) inside of `{}` in a jsx child, not an attribute
 - It doesn't output parenthesis if your parent is a LogicalExpression (&&)

Fixes #317
2017-01-26 14:51:08 -05:00
Simon Lydell 239521e97d CLI improvements (#478)
* Add `--help` CLI flag

* Don't pick up unknown CLI options

This prevents people from adding new CLI options in the future, but
forgetting to add it explicitly to minimist, resulting in a false
"Ignored unknown option" warning.

* Add `-h` and `-v` option aliases

It always bugs me when those don't do `--help` and `--version` for no
reason in CLIs.

* Allow `echo 'test' | prettier` without the `--stdin` flag

* Improve CLI error handling and validation

- Handle errors the same way both when using stdin and when using files.
- Print validation errors nicely.
- Validate int options, instead of silently ignoring bad input.
- Warn about unknown parsers, falling back to babylon. If a new parser
  is added in the future, this allows graceful degradation for tools
  running an older version of prettier. (Just like how unknown options
  are warnings instead of errors.)
- Add comments.

* Run prettier on bin/prettier.js
2017-01-26 10:13:32 -08:00
Davy Duperron 03b4ed2fcf Added parens around in operator in for loops 🚀. (#468) 2017-01-25 14:24:25 -08:00
Christopher Chedeau 620cb7be19 Add break points for class declaration (#466)
```js
class A extends B implements C {
  method() {}
}
```

now outputs

```js
class A
  extends B
  implements C {
  method() {}
}
```

Fixes #147
2017-01-25 16:36:55 -05:00
Kent C. Dodds f8853ba856 docs: add related projects (#456)
* docs: add related projects

I think it may help adoption of `prettier` if
people don't have to change their entire coding
style all at once. These projects enable that.

* docs: add prettier-with-tabs to related projects
2017-01-25 16:33:38 -05:00
Christopher Chedeau 888c7a52dd Put decorators on the same line (#459)
Mobx is the only popular JavaScript library that I know about which uses decorators. They put things on the same line so we should follow their conventions.

The logic implemented here is the following: if there is one decorator, it's on the same line. If there is more than one, they are each on their own line.

Fixes #325
2017-01-25 16:30:09 -05:00
Christopher Chedeau 1334dbc781 Preserve new lines after directives (#464)
It's annoying that the line after `"use strict";` gets eaten away on babylon. This fixes it :)

Fixes #216
2017-01-25 16:26:09 -05:00
Christopher Chedeau b4f1649d1a Fix spurious whitespace (#463)
This was introduced by #314 where `line` should have been `softline`. By the way, I was going to propose renaming `line` to `line_or_space` and `softline` to `line_or_nothing` which should make it more explicit what is going on.

Fixes #461
2017-01-25 16:24:16 -05:00
Henry Zhu d08c006902 Explain that you can pass options to the spec runner (#460) 2017-01-25 09:30:48 -08:00
Henry Zhu 6e68f7495f Support printing import("a") (#458) 2017-01-25 07:33:48 -08:00
James Long f8f0b340e0 Update lockfile 2017-01-24 18:18:36 -05:00
daleroy 69b5d098e9 Update package.json, use ast-types 0.9.4 (#453)
Add Flow's DeclareExportAllDeclaration type has been merged into benjamn/ast-types so the forks are now in sync.
2017-01-24 18:08:35 -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
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