* 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.
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
* 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
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.
* Use babel-code-frame for syntax errors
* Support the `--color` option more explicitly
* Update rollup config to handle babel-code-frame
* Use exact dependencies
- 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.
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
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 :)
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.
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 :)
* 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
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.