From 3a5fc6571a1856e0ed69be3e61dd4bf53ac43258 Mon Sep 17 00:00:00 2001 From: Ika Date: Sun, 20 Jan 2019 15:59:39 +0800 Subject: [PATCH] Release 1.16.0 --- .github/ISSUE_TEMPLATE/formatting.md | 2 +- .github/ISSUE_TEMPLATE/integration.md | 2 +- CHANGELOG.md | 6 ++++ package.json | 2 +- website/versioned_docs/version-stable/api.md | 10 +++--- website/versioned_docs/version-stable/cli.md | 34 +++++++++++++++++++ .../version-stable/configuration.md | 2 +- .../versioned_docs/version-stable/options.md | 7 ++-- .../versioned_docs/version-stable/plugins.md | 1 + .../version-stable/precommit.md | 10 +++--- .../versioned_docs/version-stable/webstorm.md | 10 +++--- 11 files changed, 64 insertions(+), 22 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/formatting.md b/.github/ISSUE_TEMPLATE/formatting.md index 9c21eced34d0..3e53edde425b 100644 --- a/.github/ISSUE_TEMPLATE/formatting.md +++ b/.github/ISSUE_TEMPLATE/formatting.md @@ -26,7 +26,7 @@ Tip! Don't write this stuff manually. --> -**Prettier 1.15.3** +**Prettier 1.16.0** [Playground link](https://prettier.io/playground/#.....) ```sh # Options (if any): diff --git a/.github/ISSUE_TEMPLATE/integration.md b/.github/ISSUE_TEMPLATE/integration.md index 63d571282b2a..1c3e441ea9e7 100644 --- a/.github/ISSUE_TEMPLATE/integration.md +++ b/.github/ISSUE_TEMPLATE/integration.md @@ -19,7 +19,7 @@ BEFORE SUBMITTING AN ISSUE: --> **Environments:** -- Prettier Version: 1.15.3 +- Prettier Version: 1.16.0 - Running Prettier via: - Runtime: - Operating System: diff --git a/CHANGELOG.md b/CHANGELOG.md index 3434cc189853..37a1ded4dc1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.16.0 + +[diff](https://github.com/prettier/prettier/compare/1.15.3...1.16.0) + +🔗 [Release Notes](https://prettier.io/blog/2019/01/20/1.16.0.html) + # 1.15.3 [diff](https://github.com/prettier/prettier/compare/1.15.2...1.15.3) diff --git a/package.json b/package.json index 09183ba6247e..603ccf3521d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prettier", - "version": "1.16.0-dev", + "version": "1.16.0", "description": "Prettier is an opinionated code formatter", "bin": { "prettier": "./bin/prettier.js" diff --git a/website/versioned_docs/version-stable/api.md b/website/versioned_docs/version-stable/api.md index 133a6d645655..f5468dd25d35 100644 --- a/website/versioned_docs/version-stable/api.md +++ b/website/versioned_docs/version-stable/api.md @@ -13,13 +13,13 @@ const prettier = require("prettier"); `format` is used to format text using Prettier. [Options](options.md) may be provided to override the defaults. ```js -prettier.format("foo ( );", { semi: false, parser: "babylon" }); +prettier.format("foo ( );", { semi: false, parser: "babel" }); // -> "foo()" ``` ## `prettier.check(source [, options])` -`check` checks to see if the file has been formatted with Prettier given those options and returns a `Boolean`. This is similar to the `--list-different` parameter in the CLI and is useful for running Prettier in CI scenarios. +`check` checks to see if the file has been formatted with Prettier given those options and returns a `Boolean`. This is similar to the `--check` or `--list-different` parameter in the CLI and is useful for running Prettier in CI scenarios. ## `prettier.formatWithCursor(source [, options])` @@ -28,7 +28,7 @@ prettier.format("foo ( );", { semi: false, parser: "babylon" }); The `cursorOffset` option should be provided, to specify where the cursor is. This option cannot be used with `rangeStart` and `rangeEnd`. ```js -prettier.formatWithCursor(" 1", { cursorOffset: 2, parser: "babylon" }); +prettier.formatWithCursor(" 1", { cursorOffset: 2, parser: "babel" }); // -> { formatted: '1;\n', cursorOffset: 1 } ``` @@ -131,8 +131,8 @@ Prettier's built-in parsers are exposed as properties on the `parsers` argument. ```js prettier.format("lodash ( )", { - parser(text, { babylon }) { - const ast = babylon(text); + parser(text, { babel }) { + const ast = babel(text); ast.program.body[0].expression.callee.name = "_"; return ast; } diff --git a/website/versioned_docs/version-stable/cli.md b/website/versioned_docs/version-stable/cli.md index b3249f1d29c1..65c70aedd9cf 100644 --- a/website/versioned_docs/version-stable/cli.md +++ b/website/versioned_docs/version-stable/cli.md @@ -22,6 +22,38 @@ Don't forget the quotes around the globs! The quotes make sure that Prettier exp Prettier CLI will ignore files located in `node_modules` directory. To opt-out from this behavior use `--with-node-modules` flag. +## `--check` + +When you want to check if your files are formatted, you can run Prettier with the `--check` flag (or `-c`). +This will output a human-friendly message and a list of unformatted files, if any. + +```bash +prettier --check "src/**/*.js" +``` + +Console output if all files are formatted: + +``` +Checking formatting... +All matched files use Prettier code style! +``` + +Console output if some of the files require re-formatting: + +``` +Checking formatting... +src/fileA.js +src/fileB.js +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. +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. + +If you need to pipe the list of unformatted files to another command, you can use [`--list-different`](cli.md#list-different) flag instead of `--check`. + ## `--debug-check` If you're worried that Prettier will change the correctness of your code, add `--debug-check` to the command. This will cause Prettier to print an error message if it detects that code correctness might have changed. Note that `--write` cannot be used with `--debug-check`. @@ -73,6 +105,8 @@ Another useful flag is `--list-different` (or `-l`) which prints the filenames o prettier --single-quote --list-different "src/**/*.js" ``` +You can also use [`--check`](cli.md#check) flag, which works the same way as `--list-different`, but also prints a human-friendly summary message to stdout. + ## `--no-config` Do not look for a configuration file. The default settings will be used. diff --git a/website/versioned_docs/version-stable/configuration.md b/website/versioned_docs/version-stable/configuration.md index e38bcd318454..0aa138f6dd72 100644 --- a/website/versioned_docs/version-stable/configuration.md +++ b/website/versioned_docs/version-stable/configuration.md @@ -109,7 +109,7 @@ For example, to get Prettier to format its own `.prettierrc` file, you can do: } ``` -You can also switch to the `flow` parser instead of the default `babylon` for .js files: +You can also switch to the `flow` parser instead of the default `babel` for .js files: ```json { diff --git a/website/versioned_docs/version-stable/options.md b/website/versioned_docs/version-stable/options.md index 8f61a4e9b85b..097479a673c7 100644 --- a/website/versioned_docs/version-stable/options.md +++ b/website/versioned_docs/version-stable/options.md @@ -177,11 +177,12 @@ Specify which parser to use. Prettier automatically infers the parser from the input file path, so you shouldn't have to change this setting. -Both the `babylon` and `flow` parsers support the same set of JavaScript features (including Flow type annotations). They might differ in some edge cases, so if you run into one of those you can try `flow` instead of `babylon`. +Both the `babel` and `flow` parsers support the same set of JavaScript features (including Flow type annotations). They might differ in some edge cases, so if you run into one of those you can try `flow` instead of `babel`. Valid options: -- `"babylon"` (via [@babel/parser](https://github.com/babel/babel/tree/master/packages/babel-parser)) +- `"babel"` (via [@babel/parser](https://github.com/babel/babel/tree/master/packages/babel-parser)) _Named `"babylon"` until v1.16.0_ +- `"babel-flow"` (Same as `"babel"` but enables Flow parsing explicitly to avoid ambiguity) _First available in v1.16.0_ - `"flow"` (via [flow-parser](https://github.com/facebook/flow/tree/master/src/parser)) - `"typescript"` (via [typescript-estree](https://github.com/JamesHenry/typescript-estree)) _First available in v1.4.0_ - `"css"` (via [postcss-scss](https://github.com/postcss/postcss-scss) and [postcss-less](https://github.com/shellscape/postcss-less), autodetects which to use) _First available in v1.7.1_ @@ -311,7 +312,7 @@ If you want to make sure that your git repository only contains Linux-style line 1. Set `endOfLine` option to `lf` 1. Configure [a pre-commit hook](precommit.md) that will run Prettier -1. Configure Prettier to run in your CI pipeline (e.g. using [`prettier-check` npm package](https://www.npmjs.com/package/prettier-check)) +1. Configure Prettier to run in your CI pipeline using [`--check` flag](cli.md#check) 1. Ask Windows users to run `git config core.autocrlf false` before working on your repo so that git did not convert `LF` to `CRLF` on checkout. Alternatively, you can add `* text=auto eol=lf` to the repo's `.gitattributes` file to achieve this. diff --git a/website/versioned_docs/version-stable/plugins.md b/website/versioned_docs/version-stable/plugins.md index 45b368774d46..3ce00324d24c 100644 --- a/website/versioned_docs/version-stable/plugins.md +++ b/website/versioned_docs/version-stable/plugins.md @@ -51,6 +51,7 @@ Providing at least one path to `--plugin-search-dir`/`pluginSearchDirs` turns of - [`prettier-plugin-java`](https://github.com/thorbenvh8/prettier-java) by [**@thorbenvh8**](https://github.com/thorbenvh8) - [`prettier-plugin-pg`](https://github.com/benjie/prettier-plugin-pg) by [**@benjie**](https://github.com/benjie) - [`prettier-plugin-ruby`](https://github.com/iamsolankiamit/prettier-ruby) by [**@iamsolankiamit**](https://github.com/iamsolankiamit) +- [`prettier-plugin-solidity`](https://github.com/prettier-solidity/prettier-plugin-solidity) by [**@mattiaerre**](https://github.com/mattiaerre) ## Developing Plugins diff --git a/website/versioned_docs/version-stable/precommit.md b/website/versioned_docs/version-stable/precommit.md index f6fa76d687e2..ba3f6a8fdb21 100644 --- a/website/versioned_docs/version-stable/precommit.md +++ b/website/versioned_docs/version-stable/precommit.md @@ -104,14 +104,14 @@ Alternately you can save this script as `.git/hooks/pre-commit` and give it exec ```bash #!/bin/sh -jsfiles=$(git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" | tr '\n' ' ') -[ -z "$jsfiles" ] && exit 0 +FILES=$(git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" | sed 's| |\\ |g') +[ -z "$FILES" ] && exit 0 -# Prettify all staged .js files -echo "$jsfiles" | xargs ./node_modules/.bin/prettier --write +# Prettify all selected files +echo "$FILES" | xargs ./node_modules/.bin/prettier --write # Add back the modified/prettified files to staging -echo "$jsfiles" | xargs git add +echo "$FILES" | xargs git add exit 0 ``` diff --git a/website/versioned_docs/version-stable/webstorm.md b/website/versioned_docs/version-stable/webstorm.md index 2a80cd3d8991..6aedade909f3 100644 --- a/website/versioned_docs/version-stable/webstorm.md +++ b/website/versioned_docs/version-stable/webstorm.md @@ -18,9 +18,9 @@ For older IDE versions, please follow the instructions below. To automatically format your files using `prettier` on save, you can use a [File Watcher](https://plugins.jetbrains.com/plugin/7177-file-watchers). -In the _Settings/Preferences_ dialog (`⌘,` on Mac or `Ctrl+Alt+S` on Windows and Linux), click **File Watchers** under **Tools** and click **+** to add a new watcher. +Go to _Preferences | Tools | File Watchers_ and click **+** to add a new watcher. -Select Prettier from the list, review the configuration, add any additional arguments if needed, and click OK. +In Webstorm 2018.2, select Prettier from the list, review the configuration, add any additional arguments if needed, and click OK. In older IDE versions, select Custom and do the following configuration: @@ -41,11 +41,11 @@ In older IDE versions, select Custom and do the following configuration: If you are using ESLint with [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier), use the `Fix ESLint Problems` action to reformat the currect file – find it using _Find Action_ (`Cmd/Ctrl-Shift-A`) or [add a keyboard shortcut](https://www.jetbrains.com/help/webstorm/configuring-keyboard-shortcuts.html) to it in _Preferences | Keymap_ and then use it. -Make sure that the ESLint integration is enabled in the _Settings/Preferences_ dialog (`⌘,` on Mac or `Ctrl+Alt+S` on Windows) click **ESLint** under **Languages & Frameworks | JavaScript | Code Quality Tools** +Make sure that the ESLint integration is enabled in _Preferences | Languages & Frameworks | JavaScript | Code Quality Tools | ESLint_. ### Using Prettier as External Tool -In the _Settings/Preferences_ dialog (`⌘,` on Mac or `Ctrl+Alt+S` on Windows and Linux) click **External Tools** under **Tools** and click **+** to add a new tool. Let’s name it **Prettier**. +Go to _Preferences | Tools | External Tools_ and click **+** to add a new tool. Let’s name it **Prettier**. - **Program**: `prettier` on macOS and Linux or `C:\Users\user_name\AppData\Roaming\npm\prettier.cmd` on Windows (or whatever `npm prefix -g` returns), if Prettier is installed globally - **Parameters**: `--write [other options] $FilePathRelativeToProjectRoot$` @@ -59,4 +59,4 @@ Press `Cmd/Ctrl-Shift-A` (_Find Action_), search for _Prettier_, and then hit `E It will run `prettier` for the current file. -You can [add a keyboard shortcut](https://www.jetbrains.com/help/webstorm/configuring-keyboard-shortcuts.html) to run this External tool configuration in the _Settings/Preferences_ dialog (`⌘,` on Mac or `Ctrl+Alt+S` on Windows and Linux) click **Keymap**. +You can [add a keyboard shortcut](https://www.jetbrains.com/help/webstorm/configuring-keyboard-shortcuts.html) to run this External tool configuration in _Preferences | Keymap_.