Commit Graph

345 Commits (6b3d3bc066c415c8a5f9dc96c3984e0b5fc8ef5e)

Author SHA1 Message Date
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
Christopher Chedeau d944ebf6db Ignore EmptyStatement inside of switch case (#391)
Fixes #378
2017-01-22 12:33:21 -08:00
Simon Lydell 8ed75acf46 Output strings with the minimum amount of escaped quotes (#390)
* Add tests for quotes

* Update test snapshots

* Output strings with the minimum amount of escaped quotes

* Update test snapshots

* Move tests/prettier/quotes.js into tests/quotes/strings.js

* Update test snapshots
2017-01-22 12:32:43 -08:00
Brian Ng e31203f4bf Fix some parens cases for UpdateExpressions (#381) 2017-01-21 20:14:22 -08:00
Simon Lydell 40748a2dc9 Fix CLI options (#369)
- Add missing options to minimist. This removes "Ignored unknown
  option:" warnings for options that actually exists.
- Put more interesting options closer to the top.
- Consistenly use full sentences.
2017-01-21 16:48:18 -08:00
Simon Lydell b8ecf6e5ad s/jscodefmt/prettier/ (#370) 2017-01-21 16:42:13 -08:00
Simon Lydell 4611020214 Warn if using deprecated CLI options (#364)
* Warn if using deprecated CLI options

* Warn if using deprecated API options
2017-01-21 09:23:29 -08:00
Simon Lydell e4f67d8a2f Exit with an error if an unknown CLI option is passed (#365)
* Exit with an error if an unknown CLI option is passed

* Only warn for unknown CLI options
2017-01-21 09:11:34 -08:00
Christopher Chedeau 4bc859b1fc Fix export extension output (#361)
Fixes #360
cc @randycoulman
2017-01-20 19:20:31 -08:00
Brian Ng b953ff0835 Add parens for default export FunctionExpressions (#345)
* Add parens for default export FunctionExpressions

* add exception for ArrowFunctionExpression

* add additional test cases

* thanks bakkot :)
2017-01-20 19:17:16 -08:00
Henry Zhu 237e6f44bc Use a Symbol instead of the private dep (#359) 2017-01-20 15:55:24 -08:00
Christopher Chedeau 21729d8207 Drop jsesc (#357)
Even though JSON.stringify is not 100% correct, this is only used for debugging and doesn't warrant adding a dependency for it.
2017-01-20 14:55:41 -08:00
Christopher Chedeau 080b7f8ec4 Swap quotes (#355)
- During the first iteration, we printed the unescaped values which let to printing invalid JavaScript characters and bad things like invisible characters.
- During the second iteration, we escaped everything, which generated valid JavaScript but you lost your emojis and chinese/cyrillic characters

In this iteration, which I hope will be the last one, we maintain the string exactly as encoded and only swap quotes. The swap quotes implementation is a bit convoluted but I think it works.
2017-01-20 14:47:52 -08:00
Christopher Chedeau d20a580655 Run prettier on the codebase (#354) 2017-01-20 10:12:37 -08:00
Christopher Chedeau 92f14d79df v0.0.10 (#353) 2017-01-20 10:00:01 -08:00
Christopher Chedeau c468fde106 Add debugging support for doc IR (#347)
This PR adds two things:

`--debug-print-doc` command that prints the formatted doc

```js
echo "<div>&lt;</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
  groupConditional(
    group([
      group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
      "&lt;",
      "</",
      "div",
      ">"
    ]),
    [
      group([
        group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
        "&lt;",
        "</",
        "div",
        ">"
      ]),
      group([
        group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
        indent(2, groupBreak([ hardline(), "&lt;" ])),
        hardline(),
        "</",
        "div",
        ">"
      ])
    ]
  ),
  ";",
  hardline()
];
```

The ability to view the IR in real time on the browser display:

![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)

The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 09:54:32 -08:00
Christopher Chedeau 896bb5b26d Indent while test the same way as if test (#352)
Fixes #312
2017-01-20 09:42:16 -08:00
Brian Ng 9fc85eb30d Remove parens around AwaitExpression in ternary (#346) 2017-01-19 19:18:02 -08:00
Christopher Chedeau d8d5c7bc55 Introduce --parser/parser option and deprecate --flow-parser/useFlowParser (#342)
The previous API was inconsistent. The new one is

```js
--parser flow
--parser babylon

{parser: 'flow'}
{parser: 'babylon'}
```

if we ever want to add new parsers in the future it'll allow that more easily.

I put a console.log in parser.js in both functions and tested that the test suite worked both with and without the change in run_spec. I also tested that both the previous and new command line options are working.

At some point in the future we'll likely want to get rid of the old api but might as well keep supporting it so we don't break anyone for now.
2017-01-19 14:35:12 -08:00
Kevin Gibbons a8ca2b21f4 Add semicolon to more default exports (#343) 2017-01-19 14:30:36 -08:00
Christopher Chedeau 658998c5b1 Refactor index.js (#340)
Extracted out parse and attachComments. Moved the options normalization in the exported function.

This way, we have a super clean format function :)

```js
function format(text, opts) {
  const ast = parse(text, opts);
  attachComments(text, ast, opts)
  const doc = printAstToDoc(ast, opts)
  const str = printDocToString(doc, opts.printWidth)
  return str;
}
```
2017-01-19 14:18:22 -08:00