Commit Graph

907 Commits (6f0707a995bb71bd34c02dd36b7314c995ac0523)

Author SHA1 Message Date
Christopher Chedeau 3dc7562743 Don't inline paren at right of arguments (#1345)
Fixes #1338
2017-04-19 10:44:00 -07:00
Christopher Chedeau aafcf5f381 Break if () if conditional inside breaks (#1344)
Fixes #868
2017-04-19 10:43:48 -07:00
Christopher Chedeau 042e603a6e Fix arrow function parenthesis with comments in flow (#1339)
`leadingComment` and `trailingComment` are babylon-specific, we should use `comments` which is what prettier adds.

Fixes #1335
2017-04-19 10:43:31 -07:00
Simon Lydell 938f0e3404 Improve regex printing (#1341)
- Print the raw regex for Flow, just like for Babylon.
- Sort regex flags.

Fixes #1334.
2017-04-19 10:24:13 -07:00
Brent Vatne e2fbaaf1f3 Update link to @vjeux's React London presentation (#1330) 2017-04-19 10:22:01 -07:00
Simon Lydell 706640d6dd Optimize `prettier --help` for humans (#1340) 2017-04-19 09:04:47 -07:00
Danny Arnold cb79d82569 add printer branch for TSFirstTypeNode (#1332)
* add TSFirstTypeNode

* add test for TSFirstTypeNode
2017-04-19 09:03:55 -07:00
Joseph Frazier dc499ba990 Add information about Vim's other autocmd events (#1333)
This lets you configure Vim to format your code even more frequently.
2017-04-18 15:30:16 -07:00
Kevin Gibbons 565106dd63 Add parentheses for assignment as body of arrow (#1326) 2017-04-18 13:28:33 -07:00
Joseph Frazier 652e2f90fb Add prettier_d to Related Projects (#1328)
`prettier_d` is like [eslint_d], but it runs `prettier` instead of
`eslint`. This eliminates the Node.js startup delay from all but the
first run of `prettier_d`, making it a snappier experience.

[eslint_d]: https://github.com/mantoni/eslint_d.js

Related discussion:
* https://github.com/prettier/prettier/issues/575#issuecomment-277368389
* https://github.com/prettier/prettier/issues/918#issuecomment-294130268
* https://github.com/prettier/prettier/pull/753#issuecomment-294339207
2017-04-18 13:27:36 -07:00
Simen Bekkhus 2e613cb37a Add jestbrains filewatcher docs (#1310) 2017-04-18 09:47:38 -07:00
Pi Lanningham 5e7503dadd Add typescript as a valid parser value (#1318)
* Add typescript as a valid parser value

Now that typescript development has started, each contributor has been adding this as a supported flag themselves.

This just adds it as an allowed option, with a warning that support for this parser is experimental.

I also tried to structure this a bit future proof, in case other experimental parsers come along.

* Simplifies the code at vjeux's request

Rather than a notion of "experimental" parsers, we'll just leave typescript out of the documentation until it's supported.
2017-04-18 09:42:03 -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 5995af25a3 Bail when traversing === groups (#1294)
This is the second part of the fix for the performance regression seen in #1250. In #1217, for correctness reasons, we're now traversing all the conditional groups. This means that we're now in O(n^2). But, in practice, many of those groups are === between each others. So we only need to recurse through one of the instances to know if it's going to break.

This makes the first example go from not terminating to being instant. The second one going from not terminating to taking ~1s. We can also make it instant by tweaking the printing phase, but that's for another PR.
2017-04-18 08:39:47 -07:00
Christopher Chedeau 08e4e2c04c Do not print the sub-tree when using prettier-ignore (#1286)
In #1250, @jeresig reported that adding // prettier-ignore on a file that has a ton of conditional group still took 1.7s. The issue is that we're printing before checking for the comment. Swaping the two had the unfortunate side effect of not marking the comments as being printed, so I had to skip that safety check if there's a prettier-ignore.

With this change, adding prettier-ignore makes the file be printed instantly!
2017-04-18 07:51:50 -07:00
Tim 67a137f6d5 Double quotes for option values in Readme file (#1314) 2017-04-17 15:07:38 -07:00
Christopher Chedeau 9cd4517a64 Fix template literal comments (#1296)
The implementation was checking if the comment was inside of the expression range, which seems like a good idea. Unfortunately, the expression range is not what's inside of `${}` but the actual AST node, which incidentally doesn't include comments. So the logic was off and returned `undefined` which threw afterwards.

Another solution is to find the first quasi where start is > comment start. This means that the comment appeared between the quasi before and this one... therefore in the expression before!

The flow parser has issues with unicode where it makes node location invalid, there are likely other places where node locations are off. So instead of throwing with a weird error, let's attach it to the first one if it doesn't work.

Fixes #1293
2017-04-17 11:35:12 -04:00
Jon Stevens 8f2c20872b FIX: more documentation for jetbrains (#1265)
* FIX: more documentation for jetbrains

* FIX: clarification of the cloning and FileDirRelativeToProjectRoot
2017-04-17 11:24:53 -04:00
Hawken Rives 3e5b123c37 Skip globbing filenames with node-glob when the filename is not a glob (#1307)
* add a check to skip node-glob if the filename is not a glob

* add a return to prevent extra globbing
2017-04-16 21:12:49 -07:00
Aviv Rosental d6e5e6be60 omit 'doc' key from options object before passing it to format() (#1299) 2017-04-16 11:32:06 -07:00
Giorgio Polvara 1625730755 Remove emoji part from lint-staged's name (#1302) 2017-04-16 09:47:08 -07:00
John Resig 793db3150a Write out change CLI changes synchronously. Fixes #1287. (#1292) 2017-04-15 14:06:20 -07:00
Ethan Cohen 8ba3fc8623 Add --dev option to suggested install cmd (#1289)
Prettier should be saved to `devDependencies`
2017-04-15 07:05:38 -07:00
Janic Duplessis f3155c3fc1 Fix isPreviousLineEmpry on Windows (#1263) 2017-04-14 16:02:19 -07:00
Bill Mill 306870a2a0 match jsx files in pre-commit hook (#1276) 2017-04-14 11:16:17 -04:00
Christopher Chedeau ad637d0744 1.1.0
This fixes a regression from 0.22 around member expressions breaking and fixes no-semi placement around leading comments, plus some other minor fixes.
2017-04-13 18:40:04 -07:00
Christopher Chedeau 17051ece2c [WIP] no-semi comments (#1257)
It doesn't yet work but I think it's close
2017-04-13 18:33:46 -07:00
Axel 088754fb1e Fixing n.comments check in printer (#1239) 2017-04-13 18:32:13 -07:00
Christopher Chedeau 6a259b60b5 Get rid of fixFaultyLocations code (#1252)
As I was debugging #1248, I found out that the code to fix was actually making things worse. The other two branches are for decorators and deleting some random value of a function. I ran all the tests and the flow object is actually now preserving empty lines and didn't change anything else.

I'd rather remove all those and if something comes up then fix it properly upstream than having those crutches that we don't know why they exist anymore.
2017-04-13 18:32:03 -07:00
Christopher Chedeau 9d616fc840 Remove trailing whitespace (#1259)
In #1257, I discovered that if there's a `""` doc at the end, it's not going to trim the previous one correctly. It also happens to fix a few existing things.
2017-04-13 18:31:49 -07:00
Christopher Chedeau 61183f8ca6 Use a whitelist instead of blacklist for member breaking (#1261) 2017-04-13 18:31:21 -07:00
Jason Laster 2078225daa Fix flow union params (#1251) 2017-04-13 17:54:20 -07:00
Christopher Chedeau 97c662b87b Do not inline member expressions as part of assignments (#1256)
This is a regression from #1036 and #1188.

Fixes #1241
Fixes #1236
2017-04-13 20:09:00 -04:00
Jason Laster 1802545865 Document debugging strategies (#1253) 2017-04-13 15:50:21 -07:00
franxois 19b7febe9e Fix : ReferenceError: err is not defined (#1254)
Would fix an error I had 
It catch an error "e" but try to display "err"
2017-04-13 15:49:53 -07:00
Mike Wilcox 6ecbb99e8a fix small typo (#1255) 2017-04-13 15:49:27 -07:00
Douglas Wade d39654fa8b [1242]: Prettier 1.0 is the stabler release we've been waiting for (#1243) 2017-04-13 14:23:14 -07:00
Christopher Chedeau 22f5ba0989 change semi default 2017-04-13 10:18:50 -07:00
Christopher Chedeau 33c8a26cd6 Support semi and useTabs options in docs (#1232) 2017-04-13 09:31:37 -07:00
Christopher Chedeau 23756cdc59 1.0 2017-04-13 09:28:42 -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 3709105199 Remove now unused getFirstString (#1231) 2017-04-13 08:34:49 -07:00
Brian Ng 4d9edec4e1 Fix trailing comma for rest element in Babylon (#1230) 2017-04-13 07:10:08 -07:00
Brian Ng 4dfe92a76b Ensure JSXOpeningElement does not break with single text attr on Babylon (#1229) 2017-04-13 07:09:40 -07:00
Brian Ng 485028c32f Fix ALL_PASERS typo in run_spec (#1227) 2017-04-13 07:08:55 -07:00
Christopher Chedeau 27d827aba6 Remove hasContent (#1222)
A content is a node that isn't an empty statement.
2017-04-12 20:25:58 -07:00
Christopher Chedeau 33fdcaec8b Remove isCurlyBracket and isEmptyBlock (#1221)
We shouldn't be reading from the printed document but instead look at the AST. This was really easy, it can either be EmptyStatement, BlockStatement or anything else.
2017-04-12 20:25:44 -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
Alex Rattray 5fa8df331e Add cli option for --no-semi (#1223) 2017-04-12 18:51:08 -07:00