I wanted to see how hard it would be to add support for CSS inside of prettier. Turns out, it's not that hard. I spent a few hours printing post-css values and getting all the stylefmt unit tests to not throw.
* Improve ESLint setup
- Uses `eslint:recommended` + a handful more rules.
- Uses .eslintignore so that editors can understand which files to lint.
- Uses .eslintrc<strong>.js</strong> so more editors get syntax highlighting.
* Fix ESLint errors
About half of them were fixed by `eslint . --fix`.
* Allow `--write` to be used with `--list-different`
This makes it possible to simultaneously check for formatting errors and
fix them, which can be useful for CI services. For example, a CI service
could run:
prettier --list-different --write $FILES || git diff --exit-code
to show the formatting errors. Before this change, it would be necessary
to do:
prettier --list-different $FILES || (prettier --write $FILES; git diff --exit-code)
Here are some commands which are useful to verify that the outputs and
exit codes of `prettier --list-different` and `prettier --write` have
not changed:
./bin/prettier.js --list-different index.js src/*.js bin/*.js; echo $?
./bin/prettier.js --write index.js src/*.js bin/*.js; echo $?
* fixup! Allow `--write` to be used with `--list-different`
* Run AST comparison tests on Travis
It looks like some of these currently fail, so we should probably also
sort that out.
Inspired by https://github.com/prettier/prettier/issues/1552
* tests: Use specified parser when AST_COMPARE=1
This fixes some of the tests with AST_COMPARE=1
* Move cleanAST() into prettier.__debug
This makes it available for tests to use.
* AST_COMPARE=1 uses cleanAst() instead of removeEmptyStatements()
Ths fixes some of the tests with AST_COMPARE=1
* Export parse() from src/parser.js
This makes it available for tests to use.
* tests: Use specified parser more when AST_COMPARE=1
This is a continuation of commit 86437a66d326919897fe89891a25824870f5bb79
This fixes some of the tests with AST_COMPARE=1
* massageAST: remove leadingComments/trailingComments
This fixes some of the tests with AST_COMPARE=1
* massageAST: remove `extra`
This fixes some of the tests with AST_COMPARE=1
* tests_config/run_spec.js: Rename variables for clarity
* AST_COMPARE=1 tests compare unstringified objects
This makes the test error output shorter.
* fixup! Export parse() from src/parser.js
* Revert "Run AST comparison tests on Travis"
See https://github.com/prettier/prettier/pull/1553#issuecomment-300027747
This reverts commit 49873a956c532f23fd216551a35ae35c1a18407e.
* fixup! fixup! Export parse() from src/parser.js
* parser: Require babel-code-frame only when needed
This addresses:
* https://github.com/prettier/prettier/pull/1553#discussion_r115386253
* https://github.com/prettier/prettier/pull/1553#discussion_r115386250
* parser: Don't export now-unused parseWith* functions
Addresses https://github.com/prettier/prettier/pull/1553#discussion_r115386964
* Move cleanAST/massageAST into own file, don't export
This addresses:
* https://github.com/prettier/prettier/pull/1553#discussion_r115386993
* https://github.com/prettier/prettier/pull/1553#discussion_r115386611
* Don't destructure require() result (Node v4 compat.)
* Fix copy/paste error
* 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.
* 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
@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
* 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.