* 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`.
* Add `--range-start` and `--range-end` options to format only parts of the input
These options default to `0` and `Infinity`, respectively, so that the
entire input is formatted by default. However, if either option is
specified such that a node lies completely outside the resulting range,
the node will be treated as if it has a `// prettier-ignore` comment.
Related to https://github.com/prettier/prettier/pull/1577#issuecomment-300551179
Related to https://github.com/prettier/prettier/issues/1324
Related to https://github.com/prettier/prettier/issues/593
* printer: Extract hasPrettierIgnoreComment() helper
* Move isOutsideRange() to util
* Don't throw errors about comments outside range "not printing"
* Remove unnecessary check from isOutsideRange()
* Make --range-end exclusive
This lets it use the conventional way of specifying ranges in strings.
Note that if the rangeEnd in the tests is changed to 158, it will fail,
but it wouldn't have failed before this change.
* Change range formatting approach
NOTE: This doesn't pass its test yet. Note that since we're reading the
indentation from the first line, it is expected not to change. However,
a semicolon is added, and the lines outside the range are not changed.
The new approach is roughly:
* Require that the range exactly covers an integer number of lines of the input
* Detect the indentation of the line the range starts on
* Format the range's substring using `printAstToDoc`
* Add enough `indent`s to the doc to restore the detected indentation
* Format the doc to a string with `printDocToString`
* Prepend/append the original input before/after the range
See https://github.com/prettier/prettier/pull/1609#issuecomment-301582273
---
Given `tests/range/range.js`, run the following:
prettier tests/range/range.js --range-start 165 --range-end 246
See the range's text with:
dd if=tests/range/range.js ibs=1 skip=165 count=81 2>/dev/null
* Don't use default function parameters
Node v4 doesn't support them. See
http://node.green/#ES2015-syntax-default-function-parameters
* Hackily fix indentation of range formatting
See
https://github.com/prettier/prettier/pull/1609#issuecomment-301625368
Also update the snapshot to reflect that the indentation actually should
decrease by one space, since there were 13 spaces in the input and we
round down after dividing by tabWidth.
* Revert "printer: Extract hasPrettierIgnoreComment() helper"
See https://github.com/prettier/prettier/pull/1609#discussion_r116804853
This reverts commit 62bf068ca98f69d4a7fd0ae188b3554d409eee8d.
* Test automatically using the beginning of the rangeStart line and same for the end
See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076
* Fix automatically using the beginning of the rangeStart line and same for the end
See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076
* Propagate breaks after adding an indentation-triggering hardline
See c1a61ebde8 (r116805581)
* Extract getAlignmentSize(), use instead of countIndents()
See c1a61ebde8 (r116804694)
* Extract addAlignmentToDoc(), use instead of addIndentsToDoc()
See c1a61ebde8 (r116804694)
* Document that --range-start and --range-end include the entire line
* Fix rangeStart calculation
Before, it was incorrectly resulting in 1 when the originally provided
value was 0
* Extract formatRange() helper function
* Move getAlignmentSize() from printer to util
This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636241
* Move addAlignmentToDoc() from printer to doc-builders
This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636251
I'm a vim user, and I use prettier on a few of my projects, but not all.
The Prettier docs listed ways to make prettier run automatically on save
(and other autocmd events), but I needed a way to invoke it manually.
After spending some time finding the right vim config, I decided it
could be useful to others as well.
Fixes#1615
As discussed on #1564, improve the clarity of the descriptions for the bracketSpacing and semicolons options by describing what the options do rather than what their CLI overrides do; These were confusing as written because these options default to true, and their CLI overrides trigger the opposite behavior.
* Fix incorrect options documentation in README
The options section in the README (which appears to be the primary source of truth for documentation) had incorrectly conflated the bracketSpacing and jsxBracketSameLine options into a single table row (using the human readable name for one, the machine readable names for another, and combined descriptions of both). This patch splits the row into two accurate ones.
* Revise previous correction to options documention in README
Incorporating feedback in #1564
* Extract custom tests from tests/flow/
Approach:
1. Remove all .js files in tests/flow except .snap.js files.
2. Copy over all .js files from tests/ in the flow repo.
3. Go through the diff looking for deletions.
- It was easy to see which deletions were due to changes in the tests
due to updates in the flow repo.
- For the rest of the deletions, I used `git blame` to verify that
they had been added by us since the flow tests were copied over.
This makes tests/flow/ simply a copy of the tests from the flow repo,
making it easier to sync with the upstream flow tests in the future.
* Add a script for syncing the flow tests
* Sync the flow tests
* 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
* Moved Vim info to its own editor folder, started drafting new README
* Finished first draft, ready for PR
* Testing Readme layout
* Removed vim folder
* update the README to add a pre-commit hook
* remove comments
* better wording
* better quoting
* consistent prettier binary
* move the tr and fix the quoting
* fix quotes one last time
When reading the Readme file I noticed that the first `foo` method has only 3 args but every other `foo` method has 4. Therefore, I am adding a 4th arg to the first `foo` method for consistency.
* docs: add related projects
I think it may help adoption of `prettier` if
people don't have to change their entire coding
style all at once. These projects enable that.
* docs: add prettier-with-tabs to related projects
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.
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.