Commit Graph

114 Commits (master)

Author SHA1 Message Date
John Resig 793db3150a Write out change CLI changes synchronously. Fixes #1287. (#1292) 2017-04-15 14:06:20 -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
Christopher Chedeau 22f5ba0989 change semi default 2017-04-13 10:18:50 -07:00
Alex Rattray 5fa8df331e Add cli option for --no-semi (#1223) 2017-04-12 18:51:08 -07:00
Christopher Chedeau 8e1583fd16 Format the codebase using the pre-1.0 release (#1194) 2017-04-12 10:16:11 -07:00
Rafael Hengles 170e4d558a Refactored option to indent with tabs (#1026)
Refactored option to indent with tabs
2017-04-06 22:49:37 -04:00
Brian Holt eff5af6ca9 Add check method to Prettier Node API. (#1104)
* Add check method to Prettier. Make CLI use that method for list-different

* Catch in check and return false if it throws

* Remove catch/finally from Prettier list-different bin

* remove try catch in prettier bin for list-different
2017-04-03 09:54:10 -07:00
Christopher Chedeau e88e76cf92 Do not use more than one file descriptor at a time (#1048)
@cpojer made a great suggestion to use `fs.readFileSync` instead of the async version. prettier is CPU-bound and if you want parallelism you can spin up many instances of prettier.

Fixes #994
2017-03-20 10:14:33 -07:00
Davy Duperron 440ddc2e1a Remove unused code. (#1028) 2017-03-16 13:26:44 -07:00
Christopher Chedeau 205458a8d1 Introduce -l option (#854)
gofmt has this option and it's very handy for commit-hooks.

Fixes #851
2017-03-02 22:47:36 -05:00
Christopher Chedeau 7c4654b7a3 Run prettier on 0.19.0 (#793) 2017-02-23 09:57:51 -08:00
James Long 5d131027ce Make trailing-comma option support 2 different modes (#641)
* Make trailing-comma option support 2 different modes

* Add deprecation warning

* Add deprecation warning to API
2017-02-17 22:44:55 -05:00
Christopher Chedeau b93a207bb2 Run prettier on 0.17.0 2017-02-15 19:56:11 -08:00
Umidbek Karimov 997de74553 Use `readline` api to manipulate `process.stdout` output. (#687)
* User `readline` api to manipulate `process.stdout` output.

* Revert "prettification".
2017-02-14 13:44:14 -08:00
Christopher Chedeau f3d64b0ffc fix --debug-check 2017-02-13 19:25:28 -08:00
Christopher Chedeau 4dca78dbed Add option for putting > on the last line in jsx (#661)
Feel free to suggest a better name for the option. Otherwise it works great :)

Fixes #654
2017-02-13 12:57:05 -05:00
Umidbek Karimov 97fd8a8d81 Log filename with [update] or [ignore] flags during `--write` process. (#584)
* Make `--write` logs more informative.

* Add format duration to logs.

* Use colors instead of [ignore] and [update] labels.

* Remove `colors` dependency.

* Use `chalk` to colorize logs.

* Print filename before `format` and add duration info later.

* Print filename before read error.
2017-02-07 14:03:48 -05:00
Christopher Chedeau 4df5250f74 Add --debug-check cli option (#627)
This let's you run `pp(x) === pp(pp(x))` across an entire codebase quickly. I think it's small enough that we can merge it in to master while we are nailing down all the issues.

You can see the output in #610
2017-02-07 10:04:44 -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 c34013b1ee Run prettier on 0.13.0 (#497) 2017-01-28 07:50:22 -08: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
James Long f6708a5cca Fix integer CLI arguments (#452) 2017-01-24 16:07:05 -05:00
James Long cd2f7393ef Propagate breaks upwards automatically, introduce `breakParent`, and deprecate `multilineGroup` (#440) 2017-01-23 18:47:11 -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
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
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 d20a580655 Run prettier on the codebase (#354) 2017-01-20 10:12:37 -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 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
Christopher Chedeau 0f54791582 Run prettier through the codebase (#316)
It's a good idea to run it right after we do a release when the number of outstanding pull requests is low :)
2017-01-18 15:31:46 -08:00
Jeffrey Horn 40973641a3 add version flag (#294)
* add version flag

* set version on the api
2017-01-18 15:45:44 -05:00
Benjamin Tan bc9b1fde19 Add newline after shebang if necessary. (#215) 2017-01-17 17:16:40 -05:00
James Long 3af7da5748 Reprint all the files! 2017-01-13 15:03:53 -05:00
Christopher Chedeau df99ae56b0 Add test for shebang and move to index.js (#170)
When looking into adding a test, I realized that the logic was inside of bin/prettier.js and therefore only applying to the cli. Moving it to index.js and adding a test so that it's more robust :)
2017-01-13 13:39:07 -05:00
Jamie Webb ecb26b3432 treat shebang outside of parsing (#137)
* treat shebang outside of parsing

* use less costly indexOf and reuse format function

* avoid reprinting new line and potential double space at start

* move options back to format function
2017-01-13 12:57:27 -05:00
James Long ac6cb883c8 Merge pull request #113 from fortes/master
Enable reading from stdin
2017-01-11 11:29:50 -05:00
James Long 722e5b4477 Merge pull request #114 from dinoboff/docs-update-usage
docs: add globbing example
2017-01-11 11:28:06 -05:00
Damien Lebrun f1db144341 docs: add globbing example
Although prettier lacks options to filter project files to format by itself, most shells allow to submit multiple files with a filename expansion. Add an example using bash.
2017-01-11 16:05:31 +00:00
Filipe Fortes 9ffbd32723 Enable reading from stdin 2017-01-11 07:57:16 -08:00
James Long 83c378e8e8 Merge pull request #84 from vjeux/print_filename
Log the filename when --write is being used
2017-01-11 10:49:47 -05:00
Christopher Chedeau b8e6fc5cb0 Do not fatal when formatting throws
When you are formatting an entire codebase and a single file throw, it shouldn't stop the entire process.
2017-01-10 22:10:00 -08:00
Christopher Chedeau 0fdf14dbe6 Log the filename when --write is being used
This helps giving a sense of progress when printing a lot of files
2017-01-10 22:09:18 -08:00
Andrey Okonetchnikov 85dc8eb118 style: Run prettier on the source code 2017-01-10 21:47:52 +01:00
Andrey Okonetchnikov 1a77d072cc feature: Add support for passing multiple files
Fixes #58
2017-01-10 21:47:24 +01:00
Andrey Okonetchnikov 3b1762b3a9 chore: Added .js extension to ./bin/prettier 2017-01-10 21:45:51 +01:00
James Long 4abb8ce544 Support back to node v4 2017-01-10 12:18:22 -05:00
James Long a0edc2a520 Document more CLI flags in usage text 2017-01-09 23:22:58 -05:00
James Long 2e4eb91edc Improve CLI command 2017-01-09 23:03:35 -05:00
James Long 79e222bb53 Rename to `prettier` 2017-01-09 22:45:22 -05:00
James Long 27af6be07a Apply bracketSpacing option to array literals 2017-01-09 20:58:51 -05:00
James Long fc186c8df8 Add option for trailing commas in objects 2017-01-05 11:36:41 -05:00
James Long 9596695a12 Rename quotes config option to 2017-01-05 10:01:43 -05:00
James Long 599b4311bb Allow single quotes with --single-quotes option 2017-01-04 17:32:05 -05:00
James Long 8326963f2d Add option to include spaces inside object/array literals, default to false 2017-01-04 17:23:07 -05:00
James Long c9e24eb477 Add spaces around certain statements, add --write option, and more 2016-12-30 23:01:07 -05:00
James Long 0465bb5790 Add flow parser as an option, default to babylon 2016-12-30 21:23:50 -05:00
James Long 35d8546d27 Add Atom support 2016-11-30 10:05:38 -05:00
James Long d8313b03ce Add ability to call as API 2016-11-29 15:23:00 -05:00
James Long 29627ee520 initial 2016-11-29 12:14:10 -05:00