Commit Graph

406 Commits (cb347378c67cc2a2e7eacb03661dbecf1950f62b)

Author SHA1 Message Date
Christopher Chedeau cb347378c6 Fix range for object newline detection (#520)
It turns out that the range is not inclusive. It incorrectly included a \n after and would expand way more objects than we intended to.

I found it while running prettier on the codebase.

I'll make 0.14.1 for this.
2017-01-30 09:54:19 -08:00
Christopher Chedeau f88c95031e 0.14.0 2017-01-30 09:41:09 -08:00
Simon Lydell d27482e2fc Print numbers in a uniform way (#498)
* Print numbers in a uniform way

- Still preserve the radix (binary, octal, hexadecimal or decimal) used
  in the original source code.
- Still preserve scientific notation.
- Add 0 to fractions. `.1` -> `0.1`
- Remove trailing dots from integers. `1.` -> `1`
- Always print the radix letters lowercase. `0b`, `0o`, `0x`
- Always print scientific notation lowercase. `1e1`
- Always print hexadecimal digits uppercase. `0x123ABCDEF`
- Remove unneeded plus in scientific notation. `1e+1` -> `1e1`
- Remove unneeded zeroes in scientific notation. `1e-001` -> `1e-1`
- Preserve leading zeroes in non-decimal radix. This can be useful when
  working in binary, and having both `0b111000` and `0b000111` for
  example.

* Always print numbers lowercase

* Remove trailing dot in scientific notation

* Update snapshots
2017-01-30 09:36:23 -08:00
Christopher Chedeau d5e0fd5c65 Do not always put an empty lines after directives (#505)
It turns out that I need to call skipNewLine before calling hasNewLine in order to figure out if there's an empty line right after. Oops.

Fixes #504
2017-01-30 09:10:54 -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
Simon Lydell 94afacd2eb Mention eslint-config-prettier (#516) 2017-01-30 10:22:49 -05:00
Christopher Chedeau 9cfc645659 Don't print trailing commas for object destructuring and rest (#512)
Fixes #507
2017-01-30 10:07:03 -05:00
Umidbek Karimov 8d786e5352 Add documentation for JetBrains products. (#509)
* Add documentation for JetBrains products.

* Fix typos in `jetbrains/README.md`

* Remove examples with `npm run` and `yarn`
2017-01-30 10:06:35 -05:00
Christopher Chedeau 98a052f9a1 Remove extra group when printing object values (#502)
It turns out that in an unlikely turn of event, the inner group can be inline and not print the opening paren but the outer group breaks and outputs the closing paren which generates invalid JavaScript.

I tried removing the group altogether and no tests failed, so I'm assuming the group wasn't needed in the first place. If it was, we should add tests to cover this.

Fixes #501
2017-01-30 10:03:40 -05:00
Simon Lydell 17add13860 Only write to files if the change (#511)
Fixes #506.
2017-01-29 07:09:22 -08:00
Christopher Chedeau 3f776bed3d 0.13.1 hotfix 2017-01-28 08:19:00 -08:00
Christopher Chedeau c34013b1ee Run prettier on 0.13.0 (#497) 2017-01-28 07:50:22 -08:00
Simon Lydell d548ef0790 Add missing jest-validate to dependencies (#500) 2017-01-28 07:49:57 -08:00
MarekMatejkaKCL 56f27a8ccf Adding a 4th arg to foo function for consistency (#499)
When reading the Readme file I noticed that the first `foo` method has only 3 args but every other `foo` method has 4. Therefore, I am adding a 4th arg to the first `foo` method for consistency.
2017-01-27 18:49:23 -08:00
Christopher Chedeau 94b137ac47 0.13.0 2017-01-27 14:41:30 -08:00
Christopher Chedeau 32059f6914 Proper support for dangling comments (#492)
* Proper support for dangling comments

In one code path, the dangling comment case is not properly handled. So I added the dangling comment, but it turns out that we only print manually in two node types: Program and BlockStatement. I made the generic printComment function print it everywhere but those two nodes. I tried to get rid of those special cases but unfortunately we need them there otherwise they are not printed at the right place.

Fixes #20

* Output dangling comments in specific places
2017-01-27 16:09:15 -05:00
Alex Rattray a9b7016c71 [JSX] Handle each line of text separately, allow up to one extra newline (#455)
* [JSX] Treat each line of text in a paragraph as its own group

* [JSX] Allow one extra newline
2017-01-27 14:20:01 -05:00
Christopher Chedeau 956779ec17 Preserve empty line after comment (#493)
The logic was already working, it was just special-cased to the first comment of the file! Presumably because the new line detection logic used to be broken ;)

I manually checked the first 10 snapshots and they are all legit, so I assume that all of them are.

Fixes #356
2017-01-27 14:05:41 -05:00
Christopher Chedeau 8f26568bc8 Properly print comments for BinaryExpression (#494)
We don't call the generic print on the BinaryExpression itself, so we need to manually print those comments. It's going to be useful for my work on the MemberExpression :)
2017-01-27 14:03:44 -05:00
James Long aaea8b1150 Simplify arrow functions that use blocks (fixes #268) (#496) 2017-01-27 13:39:17 -05:00
Christopher Chedeau caf7f2a6f2 0.12.0 2017-01-26 20:24:17 -08:00
Christopher Chedeau 612574d02d Stop using conditionalGroup inside of UnionTypeAnnotation (#491)
It's actually not needed to use conditionalGroup as we can use ifBreak for it. I was able to do it just for cleanup and found out that it also fixed two of the bugs we have with comments. That's great :p

Fixes #485
Fixes #486
2017-01-26 21:41:50 -05:00
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