Skip to content

Commit

Permalink
Release 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thorn0 committed May 9, 2021
1 parent 7cfa9aa commit 2afc3b9
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Don't fill the form below manually! Let a program create a report for you:
-->

**Prettier 2.2.1**
**Prettier 2.3.0**
[Playground link](https://prettier.io/playground/#.....)

```sh
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE:

**Environments:**

- Prettier Version: 2.2.1
- Prettier Version: 2.3.0
- Running Prettier via: <!-- CLI, Node.js API, Browser API, etc. -->
- Runtime: <!-- Node.js v14, Chrome v83, etc. -->
- Operating System: <!-- Windows, Linux, macOS, etc. -->
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.3.0

[diff](https://github.com/prettier/prettier/compare/2.2.1...2.3.0)

🔗 [Release Notes](https://prettier.io/blog/2021/05/09/2.3.0.html)

# 2.2.1

[diff](https://github.com/prettier/prettier/compare/2.2.0...2.2.1)
Expand Down
26 changes: 13 additions & 13 deletions docs/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ See below for examples.
### Global

```html
<script src="https://unpkg.com/prettier@2.2.1/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.2.1/parser-graphql.js"></script>
<script src="https://unpkg.com/prettier@2.3.0/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.3.0/parser-graphql.js"></script>
<script>
prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -48,8 +48,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack

```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.2.1/esm/standalone.mjs";
import parserGraphql from "https://unpkg.com/prettier@2.2.1/esm/parser-graphql.mjs";
import prettier from "https://unpkg.com/prettier@2.3.0/esm/standalone.mjs";
import parserGraphql from "https://unpkg.com/prettier@2.3.0/esm/parser-graphql.mjs";
prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -62,8 +62,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack

```js
define([
"https://unpkg.com/prettier@2.2.1/standalone.js",
"https://unpkg.com/prettier@2.2.1/parser-graphql.js",
"https://unpkg.com/prettier@2.3.0/standalone.js",
"https://unpkg.com/prettier@2.3.0/parser-graphql.js",
], (prettier, ...plugins) => {
prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -88,8 +88,8 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
### Worker

```js
importScripts("https://unpkg.com/prettier@2.2.1/standalone.js");
importScripts("https://unpkg.com/prettier@2.2.1/parser-graphql.js");
importScripts("https://unpkg.com/prettier@2.3.0/standalone.js");
importScripts("https://unpkg.com/prettier@2.3.0/parser-graphql.js");
prettier.format("type Query { hello: String }", {
parser: "graphql",
plugins: prettierPlugins,
Expand All @@ -102,8 +102,8 @@ If you want to format [embedded code](options.md#embedded-language-formatting),

```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.2.1/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.2.1/esm/parser-babel.mjs";
import prettier from "https://unpkg.com/prettier@2.3.0/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.3.0/esm/parser-babel.mjs";
console.log(
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
Expand All @@ -119,9 +119,9 @@ The HTML code embedded in JavaScript stays unformatted because the `html` parser

```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.2.1/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.2.1/esm/parser-babel.mjs";
import parserHtml from "https://unpkg.com/prettier@2.2.1/esm/parser-html.mjs";
import prettier from "https://unpkg.com/prettier@2.3.0/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.3.0/esm/parser-babel.mjs";
import parserHtml from "https://unpkg.com/prettier@2.3.0/esm/parser-html.mjs";
console.log(
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prettier",
"version": "2.3.0-dev",
"version": "2.3.0",
"description": "Prettier is an opinionated code formatter",
"bin": "./bin/prettier.js",
"repository": "prettier/prettier",
Expand Down
93 changes: 53 additions & 40 deletions website/versioned_docs/version-stable/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Browser
original_id: browser
---

Run Prettier in the browser using its **standalone** version. This version only formats the code and has no support for config files, ignore files, CLI usage, or automatic loading of plugins.
Run Prettier in the browser using its **standalone** version. This version doesn’t depend on Node.js. It only formats the code and has no support for config files, ignore files, CLI usage, or automatic loading of plugins.

The standalone version comes as:

Expand All @@ -15,50 +15,26 @@ The [`browser` field](https://github.com/defunctzombie/package-browser-field-spe

### `prettier.format(code, options)`

Unlike the `format` function from the [main API](api.md#prettierformatsource--options), this function does not load plugins automatically, so a `plugins` property is required if you want to load [plugins](#plugins). Additionally, the parsers included in the Prettier package won’t be loaded automatically, so you need to load them as plugins before using them.
Required options:

See [Usage](#usage) below for examples.
- **[`parser`](options.md#parser) (or [`filepath`](options.md#file-path))**: One of these options has to be specified for Prettier to know which parser to use.

## Plugins
- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files named

All available plugins are files named `parser-*.js` in <https://unpkg.com/browse/prettier@2.2.1/> and `parser-*.mjs` in <https://unpkg.com/browse/prettier@2.2.1/esm/>.
- `parser-*.js` in <https://unpkg.com/browse/prettier@2.2.1/> and
- `parser-*.mjs` in <https://unpkg.com/browse/prettier@2.2.1/esm/>

If you want format embed code, you need load related plugins too, for example
You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option.

```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.2.1/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.2.1/esm/parser-babel.mjs";
prettier.format("const html = /* HTML */ `<DIV> </DIV>`", {
parser: "babel",
plugins: [parserBabel],
});
</script>
```

the HTML code inside JavaScript code won't get formatted, because it requires `html` parser too, correct usage

```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.2.1/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.2.1/esm/parser-babel.mjs";
import parserHtml from "https://unpkg.com/prettier@2.2.1/esm/parser-html.mjs";
prettier.format("const html = /* HTML */ `<DIV> </DIV>`", {
parser: "babel",
plugins: [parserBabel, parserHtml],
});
</script>
```
See below for examples.

## Usage

### Global

```html
<script src="https://unpkg.com/prettier@2.2.1/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.2.1/parser-graphql.js"></script>
<script src="https://unpkg.com/prettier@2.3.0/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.3.0/parser-graphql.js"></script>
<script>
prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -73,8 +49,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack

```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.2.1/esm/standalone.mjs";
import parserGraphql from "https://unpkg.com/prettier@2.2.1/esm/parser-graphql.mjs";
import prettier from "https://unpkg.com/prettier@2.3.0/esm/standalone.mjs";
import parserGraphql from "https://unpkg.com/prettier@2.3.0/esm/parser-graphql.mjs";
prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -87,8 +63,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack

```js
define([
"https://unpkg.com/prettier@2.2.1/standalone.js",
"https://unpkg.com/prettier@2.2.1/parser-graphql.js",
"https://unpkg.com/prettier@2.3.0/standalone.js",
"https://unpkg.com/prettier@2.3.0/parser-graphql.js",
], (prettier, ...plugins) => {
prettier.format("type Query { hello: String }", {
parser: "graphql",
Expand All @@ -113,10 +89,47 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
### Worker

```js
importScripts("https://unpkg.com/prettier@2.2.1/standalone.js");
importScripts("https://unpkg.com/prettier@2.2.1/parser-graphql.js");
importScripts("https://unpkg.com/prettier@2.3.0/standalone.js");
importScripts("https://unpkg.com/prettier@2.3.0/parser-graphql.js");
prettier.format("type Query { hello: String }", {
parser: "graphql",
plugins: prettierPlugins,
});
```

## Parser plugins for embedded code

If you want to format [embedded code](options.md#embedded-language-formatting), you need to load related plugins too. For example:

```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.3.0/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.3.0/esm/parser-babel.mjs";
console.log(
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
parser: "babel",
plugins: [parserBabel],
})
);
// Output: const html = /* HTML */ `<DIV> </DIV>`;
</script>
```

The HTML code embedded in JavaScript stays unformatted because the `html` parser hasn’t been loaded. Correct usage:

```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.3.0/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.3.0/esm/parser-babel.mjs";
import parserHtml from "https://unpkg.com/prettier@2.3.0/esm/parser-html.mjs";
console.log(
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
parser: "babel",
plugins: [parserBabel, parserHtml],
})
);
// Output: const html = /* HTML */ `<div></div>`;
</script>
```
38 changes: 13 additions & 25 deletions website/versioned_docs/version-stable/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ prettier --write .

This command formats all files supported by Prettier in the current directory and its subdirectories.

It’s recommended to always make sure that `prettier --write .` only formats what you want in your project. Use a [.prettierignore](ignore.md) file to ignore things that should not be formatted.
It’s recommended to always make sure that `prettier --write .` only formats what you want in your project. Use a [`.prettierignore`](ignore.md) file to ignore things that should not be formatted.

A more complicated example:

Expand All @@ -44,7 +44,7 @@ Given a list of paths/patterns, the Prettier CLI first treats every entry in it

- Otherwise, the entry is resolved as a glob pattern using the [glob syntax from the `fast-glob` module](https://github.com/mrmlnc/fast-glob#pattern-syntax).

Prettier CLI will ignore files located in `node_modules` directory. To opt out from this behavior use `--with-node-modules` flag.
Prettier CLI will ignore files located in `node_modules` directory. To opt out from this behavior, use `--with-node-modules` flag.

To escape special characters in globs, one of the two escaping syntaxes can be used: `prettier "\[my-dir]/*.js"` or `prettier "[[]my-dir]/*.js"`. Both match all JS files in a directory named `[my-dir]`, however the latter syntax is preferable as the former doesn’t work on Windows, where backslashes are treated as path separators.

Expand Down Expand Up @@ -73,7 +73,7 @@ Checking formatting...
[warn] Code style issues found in the above file(s). Forgot to run Prettier?
```

The command will return exit code 1 in the second case, which is helpful inside the CI pipelines.
The command will return exit code `1` in the second case, which is helpful inside the CI pipelines.
Human-friendly status messages help project contributors react on possible problems.
To minimise the number of times `prettier --check` finds unformatted files, you may be interested in configuring a [pre-commit hook](precommit.md) in your repo.
Applying this practice will minimise the number of times the CI fails because of code formatting problems.
Expand All @@ -84,9 +84,9 @@ If you need to pipe the list of unformatted files to another command, you can u

| Code | Information |
| ---- | ----------------------------------- |
| 0 | Everything formatted properly |
| 1 | Something wasn’t formatted properly |
| 2 | Something’s wrong with Prettier |
| `0` | Everything formatted properly |
| `1` | Something wasn’t formatted properly |
| `2` | Something’s wrong with Prettier |

## `--debug-check`

Expand Down Expand Up @@ -115,22 +115,6 @@ If you don’t have a configuration file, or want to ignore it if it does exist,

Path to a file containing patterns that describe files to ignore. By default, Prettier looks for `./.prettierignore`.

## `--require-pragma`

Require a special comment, called a pragma, to be present in the file’s first docblock comment in order for Prettier to format it.

```js
/**
* @prettier
*/
```

Valid pragmas are `@prettier` and `@format`.

## `--insert-pragma`

Insert a `@format` pragma to the top of formatted files when pragma is absent. Works well when used in tandem with `--require-pragma`.

## `--list-different`

Another useful flag is `--list-different` (or `-l`) which prints the filenames of files that are different from Prettier formatting. If there are differences the script errors out, which is useful in a CI scenario.
Expand Down Expand Up @@ -159,17 +143,17 @@ Config file take precedence over CLI options

**prefer-file**

If a config file is found will evaluate it and ignore other CLI options. If no config file is found CLI options will evaluate as normal.
If a config file is found will evaluate it and ignore other CLI options. If no config file is found, CLI options will evaluate as normal.

This option adds support to editor integrations where users define their default configuration but want to respect project specific configuration.

## `--no-editorconfig`

Don’t take .editorconfig into account when parsing configuration. See the [`prettier.resolveConfig` docs](api.md) for details.
Don’t take `.editorconfig` into account when parsing configuration. See the [`prettier.resolveConfig` docs](api.md) for details.

## `--with-node-modules`

Prettier CLI will ignore files located in `node_modules` directory. To opt-out from this behavior use `--with-node-modules` flag.
Prettier CLI will ignore files located in `node_modules` directory. To opt out from this behavior, use `--with-node-modules` flag.

## `--write`

Expand Down Expand Up @@ -213,3 +197,7 @@ With `--ignore-unknown` (or `-u`), prettier will ignore unknown files matched by
```console
$ prettier "**/*" --write --ignore-unknown
```

## `--no-error-on-unmatched-pattern`

Prevent errors when pattern is unmatched.
10 changes: 10 additions & 0 deletions website/versioned_docs/version-stable/ignore.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,13 @@ hello: world
{{/my-crazy-component}}
</div>
```

## Command Line File Patterns

For one-off commands, when you want to exclude some files without adding them to `.prettierignore`, negative patterns can come in handy:

```bash
prettier --write . '!**/*.{js,jsx,vue}'
```

See [fast-glob](https://prettier.io/docs/en/cli.html#file-patterns) to learn more about advanced glob syntax.
4 changes: 2 additions & 2 deletions website/versioned_docs/version-stable/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ yarn add --dev --exact prettier

<!--END_DOCUSAURUS_CODE_TABS-->

Then, create an empty config file to let editors and other tooling know you are using Prettier:
Then, create an empty config file to let editors and other tools know you are using Prettier:

<!-- Note: `echo "{}" > .prettierrc.json` would result in `"{}"<SPACE>` on Windows. The below version works in cmd.exe, bash, zsh, fish. -->

Expand Down Expand Up @@ -69,7 +69,7 @@ yarn prettier --write .
If you have a CI setup, run the following as part of it to make sure that everyone runs Prettier. This avoids merge conflicts and other collaboration issues!

```bash
prettier --check .
npx prettier --check .
```

`--check` is like `--write`, but only checks that files are already formatted, rather than overwriting them. `prettier --write` and `prettier --check` are the most common ways to run Prettier.
Expand Down
Loading

0 comments on commit 2afc3b9

Please sign in to comment.