Commit Graph

743 Commits (08e4e2c04c1b57ace85110c7e5c285848b62df9a)

Author SHA1 Message Date
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
Christopher Chedeau 4a4e1817be Do not merge member chain if there's a comment in-between (#1218)
Fixes #1198
2017-04-12 17:26:58 -07:00
Christopher Chedeau 5d8ffd0c2e Fix own line last if comment (#1219)
Fixes #1205
2017-04-12 17:26:44 -07:00
Christopher Chedeau ee7cfa9501 Ignore empty statement in switch newline detection (#1220)
Fixes #1200
2017-04-12 17:26:31 -07:00
Brian Ng 3a7559be58 Preserve comment for last arg of ObjectMethod (#1216)
* Preserve comment after last arg of ObjectMethod

* Preserve comment after last arg with default value
2017-04-12 16:32:04 -07:00
Christopher Chedeau ea957ed64a Fix function trailing comment location (#1195)
It turns out that we can't reliably detect with the ast if a comment is before or after the ). In order to fix this same problem with `if` I added the `getNextNonSpaceNonCommentCharacter` function. We can use the same here to fix the problem.

Fixes #933
2017-04-12 14:18:29 -07:00
Brian Ng 32eecabc6d Stabilize comments on ObjectTypeAnnotation (#1214) 2017-04-12 14:13:34 -07:00
Jan Kassens b82220b20f Prittier printing of snapshots (#1190)
This uses a custom snapshot serializer to reduce escaping in snapshot files and
make them easier to read.

Snapshot serializers are documented here:
https://facebook.github.io/jest/docs/configuration.html#snapshotserializers-array-string
2017-04-12 13:41:51 -07:00
Christopher Chedeau 8e1583fd16 Format the codebase using the pre-1.0 release (#1194) 2017-04-12 10:16:11 -07:00
James Long 9a5b447c7f Propagate hard breaks within member expressions (fixes #1117) (#1193) 2017-04-12 09:26:27 -07:00
Alex Rattray 36bec87d17 Enable no-semi mode and protect against ASI failures (#1129) 2017-04-11 13:50:47 -07:00
Christopher Chedeau e3aa878187 Allow to break for member expressions after = (#1188)
This should address a concern of #1036
2017-04-11 11:37:46 -07:00
Christopher Chedeau 523f64ff14 Add ability to break for top member expression (#1036)
It turns out that the top member expression doesn't go through the member chain logic. Let's give it the ability to break for now.

Fixes #1031
2017-04-11 11:37:35 -07:00
Christopher Chedeau b6edf96cc4 Improve jsx output for style components (#1144)
* Hug template literals inside of JSXExpressionContainer

We already hug a bunch of things inside of `{}`. It seems that it's a good idea to do it for template literals as well. I don't think I've seen anyone actually indent them.

Fixes #1090

* Inline jsx elements with single template literal expression

If there is a single expression and a single template literal, then a lot of people in the jsx-style world inline it. I've also myself used this for markdown and printed it that way. So we probably should print it that way.

Note that I'm checking for children.length === 1, this means that if there's any whitespace, this is not going to be true and will not enter this case. So it WON'T reformat

```js
<style>
  {`
     color: red;
  `}
</style>
```

into

```js
<style>{`
    color: red;
`}</style>
```

which is great. You have to opt-in to the second style in order to get it.

Fixes #1090
2017-04-11 09:33:02 -07:00
Christopher Chedeau 2e63684ff5 Add parenthesis for no-confusing-arrow rule (#1182)
I'm unclear whether anyone was ever confused by this but the eslint page is kind of compelling

```js
// The intent is not clear
var x = a => 1 ? 2 : 3;
// Did the author mean this
var x = function (a) { return 1 ? 2 : 3 };
// Or this
var x = a <= 1 ? 2 : 3;
```

Adding a parenthesis makes it valid with `{"allowParens": true}` rule. Note that if this option is not enabled, the code would not pass lint in the first place.
2017-04-11 09:20:39 -07:00