Commit Graph

146 Commits (19cd7d32278e0bc6ddab92e8c23bb8f682fa691f)

Author SHA1 Message Date
Anthony Sottile 19cd7d3227 Add pre-commit metadata directly to prettier (#2414) 2017-07-06 20:13:52 +02:00
Kushagra Gour 0b41ecb55b docs(README): update bash script to mimic lint-stage behavior (#2384) 2017-07-03 14:38:43 -07:00
Lucas Azzola 65bbbaec58 Add content to website (#2377)
* Add content to website

* Fix linting error

* Cleanup, extract content to JSON files
2017-07-03 12:48:05 +02:00
Haroen Viaene 863b1be4b5 docs(README): hype train clarification (#2354)
* docs(README): hype train clarification

* Update README.md
2017-06-29 07:48:42 -07:00
Jack Franklin 9ee3e581d4 (docs): Document using Prettier + Vim using ALE (#2333) 2017-06-28 09:20:34 -07:00
Lucas Azzola 5e51caca1b Add GraphQL to README (#2265)
* Add GraphQL to README

* Add JSON to main list of languages
2017-06-27 10:18:22 -07:00
Simon Lydell 174bbda7ef Minor readme cleanups 2017-06-26 17:42:28 +02:00
Lucas Azzola caa77fbfe8 Join range start and range end documentation 2017-06-25 12:44:18 +10:00
Lucas Azzola 438f5887e2 Add links to prettier's parsers
Since the parser API exposes the AST, it makes sense to point people towards the parsers we use so they can hack on them.
2017-06-25 12:27:49 +10:00
Lucas Azzola b93191d4de Explode the options table (#2244)
* Explode the options table

The options table in README was getting a bit unwieldy. This commit moves the options to a top-level section, and makes each setting hyperlink-able.

The `cursorOffset` setting has been moved from the list to the documentation for `formatWithCursor`.

* Fix typos/punctuation

* Fix --trailing-comma formatting
2017-06-24 07:52:34 -07:00
Lucas Azzola d8be8be57a Clean up API documentation 2017-06-24 18:13:02 +10:00
Lucas Azzola b2d5366897 Remove apostrophe from JetBrains 2017-06-23 23:01:12 +10:00
Chaim Lando f519c5f030 Add table of contents (#2230)
* add toc

* Wrap table of contents in <details> tag
2017-06-23 20:52:46 +10:00
Joe Critchley 5c61036fab Added definition of 'style' to README (#2221) 2017-06-21 13:34:34 -07:00
Simon Lydell e8fb9bddf7 Fix type in README.md 2017-06-21 20:12:18 +02:00
Christopher Chedeau 810ed8857c Update README.md 2017-06-21 10:44:53 -07:00
Lucas Azzola 58413cde3e docs(readme): use unordered lists in options section 2017-06-18 15:41:22 +10:00
Lucas Azzola af90402aab docs(readme): join API and CLI columns to prevent overflow 2017-06-18 15:25:24 +10:00
Joseph Frazier a42db30946 Add JSON support (#2173)
* Add JSON support

This fixes https://github.com/prettier/prettier/issues/1973 by using
[json-to-ast] to parse JSON, then converting the AST into a
mostly-Babylon AST, so as to piggyback on the existing printer logic.

Identifiers and literals are currently printed verbatim from the input,
but this could be improved upon later (at least for literals, not sure
about identifiers).

[json-to-ast]: https://github.com/vtrushin/json-to-ast

* Rename `json-to-ast` parser to `json`

See https://github.com/prettier/prettier/pull/2173#discussion_r122574644

* json: Use createError to have a pretty error

See https://github.com/prettier/prettier/pull/2173#discussion_r122574748

* json: Transform AST without mutations

See https://github.com/prettier/prettier/pull/2173#discussion_r122574690
2017-06-17 10:36:42 -10:00
George Chung 68550450b6 Typo fix (#2134) 2017-06-14 20:08:32 +10:00
Lucas Azzola d274e24e23 docs(readme): add "styled with prettier" badge 2017-06-13 10:45:08 +10:00
Cody Zuschlag 4cf94c95c7 add list of projects using prettier (#2104)
* doc(readme): add project logos using prettier

* doc(readme): link to npm dependents

* doc(readme): footnote for projects using prettier
2017-06-12 14:23:33 -07:00
Lucas Azzola 364c38de0d Implement custom parser API (#1783)
* feat(api): add custom parser API

* test(api): add integration test for parser resolution

* chore(api): fix build after resolving conflicts

* docs(api): document custom parser API

* docs(api): fix typo

* chore(build): add parse5 to build and support yarn test --prod
2017-06-12 16:51:12 +10:00
Jonas Gierer 2dba2a64da Add `prettier-github` to related projects 2017-06-11 18:59:29 +02:00
Lucas Azzola 026f9b4de7 docs: prune old vim links from the table of contents 2017-06-11 22:35:35 +10:00
Christopher Chedeau d062961ccf Create README.md 2017-06-08 16:57:26 -07:00
Mitermayer Reis 8a87681f66 Adding vim editor reference (#2041)
* Adding --stdin-filepath option in order to enable filetype inference from
stdin

* Creating vim editor integration docs

- Moving vim editor integration into editors directory
- Adding information about vim-prettier
2017-06-08 09:43:27 -07:00
Eugene Korbut 0222d8eefe Update README for emacs integration link (#2024) 2017-06-07 09:21:17 -07:00
tdeschryver 4291a8cedc Update single quote option in README (#1952)
* chore: add single quote note in readme

* chore: change readme text to quote format behaviour
2017-06-04 14:41:57 -07:00
Christian Hamburger Grøngaard 41688901f2 Make README more JavaScript agnostic (#1955)
- Prettier has grown into a more general tool.
2017-06-04 21:24:18 +10:00
Lucas Azzola fed9f0f4eb Mention TypeScript and CSS in the README (#1950)
* Mention TypeScript and CSS in the README.
* Collapse the table of contents with `<details>` tag.
* Clarifies the `--parser` option.
2017-06-03 20:03:30 -07:00
Christian Hamburger Grøngaard e0682a9558 Miscellaneous minor README fixes (#1943)
* Refer to "line length" instead of "line width"

- It's consistent with what it has been called in the section so far.

* Add missing punctuation

* Remove needless "just"s

- It's less condescending to a reader who doesn't know how to
"just" do these things.
2017-06-03 11:49:15 -07:00
Ryan Castner eb9ba74665 Update README.md (#1859) 2017-06-02 06:48:29 -07:00
Joseph Frazier 4bfeb9064d Add `cursorOffset` option for cursor translation (#1637)
* Add `formatWithCursor` API with `cursorOffset` option

This addresses https://github.com/prettier/prettier/issues/93 by
adding a new option, `cursorOffset`, that tells prettier to determine
the location of the cursor after the code has been formatted. This is
accessible through the API via a new function, `formatWithCursor`, which
returns a `{formatted: string, cursorOffset: ?number}`.

Here's a usage example:

```js
require("prettier").formatWithCursor(" 1", { cursorOffset: 2 });
// -> { formatted: '1;\n', cursorOffset: 1 }
```

* Add `--cursor-offset` CLI option

It will print out the offset instead of the formatted output. This
makes it easier to test. For example:

    echo ' 1' | prettier --stdin --cursor-offset 2
    # prints 1

* Add basic test of cursor translation

* Document `cursorOffset` option and `formatWithCursor()`

* Print translated cursor offset to stderr when --cursor-offset is given

This lets us continue to print the formatted code, while also
communicating the updated cursor position.

See https://github.com/prettier/prettier/pull/1637#discussion_r119735496

* doc-print cursor placeholder in comments.printComments()

See https://github.com/prettier/prettier/pull/1637#discussion_r119735149

* Compare array index to -1 instead of >= 0 to determine element presence

See https://github.com/prettier/prettier/pull/1637#discussion_r119736623

* Return {formatted, cursor} from printDocToString() instead of mutating options

See https://github.com/prettier/prettier/pull/1637#discussion_r119737354
2017-06-01 15:52:29 -07:00
Mitermayer Reis 0d9b04bc94 Adding --stdin-filepath option in order to enable filetype inference … (#1835)
* Adding --stdin-filepath option in order to enable filetype inference from stdin to allow chosing css parser

* Adding readme information on the filepath option

* Also including support for typescript parser inference.

* Running linter
2017-05-31 12:26:22 -07:00
Patrick Roumanoff 96b8119b4b added related projects Bookmarklet (#1824) 2017-05-30 21:50:51 -07:00
Marcel Mokoš f0683b8e1a Update README.md version of prettier in pre-commit (#1788)
- a version of prettier to latest in README in pre-commit config yaml example
2017-05-28 12:24:50 -07:00
Simon Lydell 01b953c580 Saying "Coming soon" doesn't really help anyway 2017-05-24 23:06:04 +02:00
Simon Lydell 4babc032cb Make it easier to find the WebStorm guide 2017-05-24 22:59:55 +02:00
Dara Hak 1f378b9755 Replace JetBrains with WebStorm in README.md (#1715)
The links are clearly about the WebStorm IDE and JetBrains is just the company's name.
This can be confusing for users.
2017-05-24 13:33:32 -07:00
Simon Lydell 0adeadb16e Link to node-glob's "glob primer"
As mentioned in #1707.
2017-05-24 18:17:31 +02:00
Michał Pierzchała 09df0fbe15 Extract contributing guide into separate document (#1702) 2017-05-24 08:32:20 -07:00
Michał Pierzchała 3a431d3fe7 Document --with-node-modules flag (#1701) 2017-05-24 03:25:45 -07:00
Joseph Frazier 330601c77d Find nearest node when formatting range (#1659)
* Move range extension code into helper functions

* Add findNodeByOffset() helper

This was adapted from cbc1929c64

* Test extending formatted range to entire node

* Fix extending formatted range to entire node

* Fix style errors

* Add run_file test function

This makes it possible to use different options on a per-file basis,
which is useful for things like range formatting tests.

* Test extending the format range to nearest parseable node

This means you can select the range of a `catch` clause, attempt to
format it, and have the `try` formatted as well, rather than throwing an
error.

* Fix extending the format range to nearest parseable node

This means you can select the range of a `catch` clause, attempt to
format it, and have the `try` formatted as well, rather than throwing an
error.

* Test that external indentation is left alone when formatting a range

* Preserve external indentation when formatting a range

* Dedupe range formatting traversal callbacks

* Simplify range formatting traversal using ast-types

See https://github.com/prettier/prettier/pull/1659#issuecomment-302974798

* Make range formatting traversal more efficient

There's less unnecessary parsing now.

* Fix style errors

* Add test where range expanding fails

* Fix test where range expanding fails

This makes sure that the range contains the entirety of the nodes
containing each of the range's endpoints.

* Add test for expanding range to beginning of line

* Pass test for expanding range to beginning of line

This makes it so that indentation before the range is added to the
formatted range.

* Don't parse/stringify AST to detect pre-range indentation

See https://github.com/prettier/prettier/pull/1659#discussion_r117790671

* When formatting a range, find closest statement rather than parsing

The `isStatement` implementation came from `docs/prettier.min.js`.

See https://github.com/prettier/prettier/pull/1659#issuecomment-303154770

* Add test for range-formatting a FunctionDeclaration's argument object

* Include FunctionDeclaration when searching for nearest node to range-format

From the spec, a Program is a series of SourceElements, each of which is
either a Statement or a FunctionDeclaration. See
https://www.ecma-international.org/ecma-262/5.1/#sec-A.5

* Remove unnecessary try-catch

See https://github.com/prettier/prettier/pull/1659#discussion_r117810096

* Add tests with multiple statements

See https://github.com/prettier/prettier/pull/1659#discussion_r117810753

* Remove unnecessary arguments from findNodeByOffset()

* Contract format range to ensure it starts/ends on nodes

* Specify test ranges in the fixtures

See https://github.com/prettier/prettier/pull/1659#discussion_r117811186

* Remove unnecessary comments from range fixtures

* Remove run_file test function

It's no longer used. This essentially reverts
8241216e68f2e0da997a4f558b03658d642c89a2

* Update range formatting docs

Clarify that the range expands to the nearest statement, and not to the
end of the line.

* Don't overwrite test options when detecting range

Now that multiple files share the same object again, we shouldn't be
re-assigning to it.

* Reuse already-read fixtures for AST_COMPARE=1 tests

* Remove `run_file` global from test eslintrc

* Undo package.json churn

`yarn` reformatted it before, but the whitespace visually sets off the
comment, so let's put it back how it was before.

See https://github.com/prettier/prettier/pull/1659#discussion_r117864655

* Remove misleading comments from isSourceElement

See https://github.com/prettier/prettier/pull/1659#discussion_r117865196

* Loop backwards through string instead of reversing it

See https://github.com/prettier/prettier/pull/1659#discussion_r117865759

* Don't recompute indent string when formatting range

See https://github.com/prettier/prettier/pull/1659#discussion_r117867268

* Rename findNodeByOffset to findNodeAtOffset

"Find x by y" is the common usage for finding an `x` by a key `y`.
However, since "by" has positional meaning, let's use "at" instead.

See https://github.com/prettier/prettier/pull/1659#discussion_r117865121

* Always trimRight() in formatRange and explain why

See https://github.com/prettier/prettier/pull/1659#discussion_r117864635

* Test formatting a range that crosses AST levels

See https://github.com/prettier/prettier/pull/1659#issuecomment-303243688

* Fix formatting a range that crosses AST levels

See https://github.com/prettier/prettier/pull/1659#issuecomment-303243688

* Remove unnecessary try-catch

See e52db5e9f9 (r117878763)

* Add test demonstrating range formatting indent detection

* Detect alignment from text on line before range, but don't reformat it

This avoids reformatting non-indentation that happens to precede the
range on the same line, while still correctly indenting the range based
on it.

See https://github.com/prettier/prettier/pull/1659#discussion_r117881430
2017-05-23 07:43:58 -07:00
Simon Lydell c2a3d23133 Improve the `--list-different` example
- Use double quotes for Windows support.
- Use the long flag for readability.
- Show that you should pass in your formatting options as well.
2017-05-22 20:30:10 +02:00
Mateusz Zatorski 0a5d035a85 Add example of `--list-different` flag usage to readme (#1665)
* Add example of `--list-different` flag usage to readme

* review fixes

* typo

* add code blocks
2017-05-22 11:27:24 -07:00
Christopher Chedeau 50e95d6c7c Update README.md 2017-05-21 13:37:58 -07:00
Christopher Chedeau 5e8125b96e Move options around 2017-05-21 13:21:29 -07:00
Christopher Chedeau 801519ec79 Warn against > 80 columns 2017-05-21 13:17:02 -07:00
Simon Lydell 378682350f Improve ESLint setup and fix errors (#1656)
* 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`.
2017-05-21 12:11:09 -07:00