Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prettier

Package Overview
Dependencies
Maintainers
3
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier - npm Package Compare versions

Comparing version 1.5.3 to 1.6.0-beta2

package.json~

35

package.json
{
"name": "prettier",
"version": "1.5.3",
"description": "Prettier is an opinionated JavaScript formatter",
"version": "1.6.0-beta2",
"description": "Prettier is an opinionated code formatter",
"bin": {

@@ -9,2 +9,3 @@ "prettier": "./bin/prettier.js"

"repository": "prettier/prettier",
"homepage": "https://prettier.io",
"author": "James Long",

@@ -16,9 +17,13 @@ "license": "MIT",

"babel-preset-es2015": "6.24.1",
"codecov": "2.2.0",
"cross-env": "5.0.1",
"cross-spawn": "5.1.0",
"eslint": "3.19.0",
"eslint": "4.1.1",
"eslint-friendly-formatter": "3.0.0",
"eslint-plugin-prettier": "2.1.1",
"eslint-plugin-import": "2.6.1",
"eslint-plugin-prettier": "2.1.2",
"eslint-plugin-react": "7.1.0",
"jest": "20.0.0",
"mkdirp": "^0.5.1",
"prettier": "1.4.2",
"prettier": "1.5.2",
"rimraf": "2.6.1",

@@ -32,2 +37,3 @@ "rollup": "0.41.1",

"rollup-plugin-replace": "1.1.1",
"shelljs": "0.7.8",
"sw-toolbox": "3.6.0",

@@ -40,18 +46,5 @@ "uglify-es": "3.0.15",

"test-integration": "jest tests_integration",
"lint": "EFF_NO_LINK_RULES=true eslint . --format 'node_modules/eslint-friendly-formatter'",
"build": "./scripts/build/build.sh"
},
"jest": {
"setupFiles": [
"<rootDir>/tests_config/run_spec.js"
],
"snapshotSerializers": [
"<rootDir>/tests_config/raw-serializer.js"
],
"testRegex": "jsfmt\\.spec\\.js$|__tests__/.*\\.js$",
"testPathIgnorePatterns": [
"tests/new_react",
"tests/more_react"
]
"lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter",
"build": "./scripts/build/build.js"
}
}
}

231

README.md

@@ -5,2 +5,3 @@ # Prettier

[![Build Status](https://travis-ci.org/prettier/prettier.svg?branch=master)](https://travis-ci.org/prettier/prettier)
[![Codecov](https://img.shields.io/codecov/c/github/prettier/prettier.svg)](https://codecov.io/gh/prettier/prettier)
[![NPM version](https://img.shields.io/npm/v/prettier.svg)](https://www.npmjs.com/package/prettier)

@@ -37,10 +38,3 @@ [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](#badge)

+ [Pre-commit Hook](#pre-commit-hook)
* [Option 1. lint-staged](#option-1-lint-staged)
* [Option 2. pre-commit](#option-2-pre-commit)
* [Option 3. bash script](#option-3-bash-script)
+ [API](#api)
- [`prettier.format`](#prettierformatsource--options)
- [`prettier.check`](#prettierchecksource--options)
- [`prettier.formatWithCursor`](#prettierformatwithcursorsource--options)
- [Custom Parser API](#custom-parser-api)
+ [Excluding code from formatting](#excluding-code-from-formatting)

@@ -59,2 +53,8 @@ * [Options](#options)

+ [Filepath](#filepath)
<!--
* [Configuration File](#configuration-file)
+ [Basic Configuration](#basic-configuration)
+ [Configuration Overrides](#configuration-overrides)
+ [Configuration Schema](#configuration-schema)
-->
* [Editor Integration](#editor-integration)

@@ -164,3 +164,3 @@ + [Atom](#atom)

Purely technical aspects of the projects aren't the only thing people look into when choosing to adopt Prettier. Who built and uses it and how quickly it spreads through the community have a non trivial impact.
Purely technical aspects of the projects aren't the only thing people look into when choosing to adopt Prettier. Who built and uses it and how quickly it spreads through the community has a non-trivial impact.
- “The amazing thing, for me, is: 1) Announced 2 months ago. 2) Already adopted by, it seems, every major JS project. 3) 7000 stars, 100,000 npm downloads/mo”

@@ -175,10 +175,10 @@ - “Was built by the same people as React & React Native.”

<tr>
<td><p align="center"><a href="https://facebook.github.io/react/"><img src="images/react-200x100.png" alt="React" width="200" height="100"><br>React</a></p></td>
<td><p align="center"><a href="https://facebook.github.io/jest/"><img src="images/jest-200x100.png" alt="Jest" width="200" height="100"><br>Jest</a></p></td>
<td><p align="center"><a href="https://yarnpkg.com"><img src="images/yarn-200x100.png" alt="Yarn" width="200" height="100"><br>Yarn</a></p></td>
<td><p align="center"><a href="https://facebook.github.io/react/"><img src="website/static/images/react-200x100.png" alt="React" width="200" height="100"><br>React</a></p></td>
<td><p align="center"><a href="https://facebook.github.io/jest/"><img src="website/static/images/jest-200x100.png" alt="Jest" width="200" height="100"><br>Jest</a></p></td>
<td><p align="center"><a href="https://yarnpkg.com"><img src="website/static/images/yarn-200x100.png" alt="Yarn" width="200" height="100"><br>Yarn</a></p></td>
</tr>
<tr>
<td><p align="center"><a href="https://babeljs.io/"><img src="images/babel-200x100.png" alt="Babel" width="200" height="100"><br>Babel</a></p></td>
<td><p align="center"><a href="https://zeit.co/"><img src="images/zeit-200x100.png" alt="Zeit" width="200" height="100"><br>Zeit</a></p></td>
<td><p align="center"><a href="https://webpack.js.org/api/cli/"><img src="images/webpack-200x100.png" alt="Webpack-cli" width="200" height="100"><br>Webpack-cli</a></p></td>
<td><p align="center"><a href="https://babeljs.io/"><img src="website/static/images/babel-200x100.png" alt="Babel" width="200" height="100"><br>Babel</a></p></td>
<td><p align="center"><a href="https://zeit.co/"><img src="website/static/images/zeit-200x100.png" alt="Zeit" width="200" height="100"><br>Zeit</a></p></td>
<td><p align="center"><a href="https://webpack.js.org/api/cli/"><img src="website/static/images/webpack-200x100.png" alt="Webpack-cli" width="200" height="100"><br>Webpack-cli</a></p></td>
</tr>

@@ -194,3 +194,3 @@ </table>

Prettier makes this whole category of rules not needed anymore! Prettier is going to reprint the entire program from scratch in a consistent way, so it's not possible for the programmer to make a mistake there anymore :)
Prettier alleviates the need for this whole category of rules! Prettier is going to reprint the entire program from scratch in a consistent way, so it's not possible for the programmer to make a mistake there anymore :)

@@ -245,7 +245,7 @@ **Code-quality rules**: eg [no-unused-vars](http://eslint.org/docs/rules/no-unused-vars), [no-extra-bind](http://eslint.org/docs/rules/no-extra-bind), [no-implicit-globals](http://eslint.org/docs/rules/no-implicit-globals), [prefer-promise-reject-errors](http://eslint.org/docs/rules/prefer-promise-reject-errors)...

#### `--with-node-modules`
Prettier CLI will ignore files located in `node_modules` directory. To opt-out from this behavior use `--with-node-modules` flag.
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`.
#### `--list-different`

@@ -257,3 +257,33 @@ 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.

```
<!--
#### `--find-config-path` and `--config`
If you are repeatedly formatting individual files with `prettier`, you will incur a small performance cost
when prettier attempts to look up a [configuration file](#configuration-file). In order to skip this, you may
ask prettier to find the config file once, and re-use it later on.
```bash
prettier --find-config-path ./my/file.js
./my/.prettierrc
```
This will provide you with a path to the configuration file, which you can pass to `--config`:
```bash
prettier --config ./my/.prettierrc --write ./my/file.js
```
You can also use `--config` if your configuration file lives somewhere where prettier cannot find it,
such as a `config/` directory.
If you don't have a configuration file, or want to ignore it if it does exist,
you can pass `--no-config` instead.
-->
#### `--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`.
### ESLint

@@ -268,3 +298,3 @@

// .eslintrc
// .eslintrc.json
{

@@ -324,2 +354,3 @@ "plugins": [

```
There is a limitation where if you stage specific lines this approach will stage the whole file after regardless. See this [issue](https://github.com/okonet/lint-staged/issues/62) for more info.

@@ -331,15 +362,14 @@ See https://github.com/okonet/lint-staged#configuration for more details about how you can configure lint-staged.

Copy the following config in your pre-commit config yaml file:
Copy the following config into your `.pre-commit-config.yaml` file:
```yaml
- repo: https://github.com/awebdeveloper/pre-commit-prettier
- repo: https://github.com/prettier/prettier
sha: '' # Use the sha or tag you want to point at
hooks:
- id: prettier
additional_dependencies: ['prettier@1.4.2']
```
```
Find more info from [here](https://github.com/awebdeveloper/pre-commit-prettier).
Find more info from [here](http://pre-commit.com).

@@ -355,10 +385,9 @@ ##### Option 3. bash script

diffs=$(node_modules/.bin/prettier -l $jsfiles)
[ -z "$diffs" ] && exit 0
# Prettify all staged .js files
echo "$jsfiles" | xargs ./node_modules/.bin/prettier --write
echo "here"
echo >&2 "Javascript files must be formatted with Prettier. Please run:"
echo >&2 "node_modules/.bin/prettier --write "$diffs""
# Add back the modified/prettified files to staging
echo "$jsfiles" | xargs git add
exit 1
exit 0
```

@@ -368,4 +397,2 @@

The API has three functions: `format`, `check`, and `formatWithCursor`.
```js

@@ -401,2 +428,29 @@ const prettier = require("prettier");

<!--
#### `prettier.resolveConfig([filePath] [, options])`
`resolveConfig` can be used to resolve configuration for a given source file.
The function optionally accepts an input file path as an argument, which defaults to the current working directory.
A promise is returned which will resolve to:
* An options object, providing a [config file](#configuration-file) was found.
* `null`, if no file was found.
The promise will be rejected if there was an error parsing the configuration file.
If `options.withCache` is `false`, all caching will be bypassed.
```js
const text = fs.readFileSync(filePath, "utf8");
prettier.resolveConfig(filePath).then(options => {
const formatted = prettier.format(text, options);
})
```
#### `prettier.clearConfigCache()`
As you repeatedly call `resolveConfig`, the file system structure will be cached for performance.
This function will clear the cache. Generally this is only needed for editor integrations that
know that the file system has changed since the last format took place.
-->
#### Custom Parser API

@@ -462,8 +516,10 @@

### Print Width
Specify the length of line that the printer will wrap on.
Specify the line length that the printer will wrap on.
**We strongly recommend against using more than 80 columns.**
> **For readability we recommend against using more than 80 characters:**
>
>In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum.
>
> Prettier, on the other hand, strives to fit the most code into every line. With the print width set to 120, prettier may produce overly compact, or otherwise undesirable code.
Prettier works by cramming as much content as possible until it reaches the limit, which happens to work well for 80 columns but makes lines that are very crowded. When a bigger column count is used in styleguides, it usually means that code is allowed to go beyond 80 columns, but not to make every single line go there, like Prettier would do.
Default | CLI Override | API Override

@@ -511,3 +567,4 @@ --------|--------------|-------------

### Trailing Commas
Print trailing commas wherever possible.
Print trailing commas wherever possible when multi-line. (A single-line array,
for example, never gets trailing commas.)

@@ -517,3 +574,3 @@ Valid options:

* `"es5"` - Trailing commas where valid in ES5 (objects, arrays, etc.)
* `"all"` - Trailing commas wherever possible (function arguments). This requires node 8 or a [transform](https://babeljs.io/docs/plugins/syntax-trailing-function-commas/).
* `"all"` - Trailing commas wherever possible (including function arguments). This requires node 8 or a [transform](https://babeljs.io/docs/plugins/syntax-trailing-function-commas/).

@@ -536,3 +593,3 @@ Default | CLI Override | API Override

### JSX Brackets
Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line.
Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line (does not apply to self closing elements).

@@ -567,3 +624,3 @@ Default | CLI Override | API Override

* [`postcss`](https://github.com/postcss/postcss) _Since v1.4.0_
* [`json`](https://github.com/vtrushin/json-to-ast) _Since v1.5.0_
* [`json`](https://github.com/babel/babylon/tree/f09eb3200f57ea94d51c2a5b1facf2149fb406bf#babylonparseexpressioncode-options) _Since v1.5.0_
* [`graphql`](https://github.com/graphql/graphql-js/tree/master/src/language) _Since v1.5.0_

@@ -590,3 +647,87 @@

<!--
## Configuration File
Prettier uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for configuration file support.
This means you can configure prettier via:
* A `.prettierrc` file, written in YAML or JSON.
* A `prettier.config.js` file that exports an object.
* A `"prettier"` key in your `package.json` file.
The configuration file will be resolved starting from the location of the file being formatted,
and searching up the file tree until a config file is (or isn't) found.
The options to the configuration file are the same the [API options](#options).
### Basic Configuration
JSON:
```json
// .prettierrc
{
"printWidth": 100,
"parser": "flow"
}
```
YAML:
```yaml
# .prettierrc
printWidth: 100
parser: flow
```
### Configuration Overrides
Prettier borrows eslint's [override format](http://eslint.org/docs/user-guide/configuring#example-configuration).
This allows you to apply configuration to specific files.
JSON:
```json
{
"semi": false,
"overrides": [{
"files": "*.test.js",
"options": {
"semi": true
}
}]
}
```
YAML:
```yaml
semi: false
overrides:
- files: "*.test.js"
options:
semi: true
```
`files` is required for each override, and may be a string or array of strings.
`excludeFiles` may be optionally provided to exclude files for a given rule, and may also be a string or array of strings.
To get prettier to format its own `.prettierrc` file, you can do:
```json
{
"overrides": [{
"files": ".prettierrc",
"options": { "parser": "json" }
}]
}
```
For more information on how to use the CLI to locate a file, see the [CLI](#cli) section.
### Configuration Schema
If you'd like a JSON schema to validate your configuration, one is available here: http://json.schemastore.org/prettierrc.
-->
## Editor Integration

@@ -606,3 +747,3 @@

Vim users can simply install either [sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat) or [mitermayer](https://github.com/mitermayer)/[vim-prettier](https://github.com/mitermayer/vim-prettier), for more details see [this directory](https://github.com/prettier/prettier/tree/master/editors/vim)
Vim users can simply install either [sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat), [w0rp](https://github.com/w0rp)/[ale](https://github.com/w0rp/ale), or [prettier](https://github.com/prettier)/[vim-prettier](https://github.com/prettier/vim-prettier), for more details see [this directory](https://github.com/prettier/prettier/tree/master/editors/vim).

@@ -615,3 +756,3 @@ ### Visual Studio Code

[Check its repository for configuration and shortcuts](https://github.com/esbenp/prettier-vscode)
[Check its repository for configuration and shortcuts](https://github.com/prettier/prettier-vscode)

@@ -642,3 +783,3 @@ ### Visual Studio

All of JSX and Flow syntax is supported. In fact, the test suite in
`tests` *is* the entire Flow test suite and they all pass.
`tests/flow` *is* the entire Flow test suite and they all pass.

@@ -662,5 +803,7 @@ Prettier also supports [TypeScript](https://www.typescriptlang.org/), CSS, [LESS](http://lesscss.org/), [SCSS](http://sass-lang.com), [JSON](http://json.org/), and [GraphQL](http://graphql.org/).

- [`neutrino-preset-prettier`](https://github.com/SpencerCDixon/neutrino-preset-prettier) allows you to use Prettier as a Neutrino preset
- [`prettier_d`](https://github.com/josephfrazier/prettier_d.js) runs Prettier as a server to avoid Node.js startup delay
- [`prettier_d`](https://github.com/josephfrazier/prettier_d.js) runs Prettier as a server to avoid Node.js startup delay. It also supports configuration via `.prettierrc`, `package.json`, and `.editorconfig`.
- [`Prettier Bookmarklet`](https://prettier.glitch.me/) provides a bookmarklet and exposes a REST API for Prettier that allows to format CodeMirror editor in your browser
- [`prettier-github`](https://github.com/jgierer12/prettier-github) formats code in GitHub comments
- [`rollup-plugin-prettier`](https://github.com/mjeanroy/rollup-plugin-prettier) allows you to use Prettier with Rollup
- [`markdown-magic-prettier`](https://github.com/camacho/markdown-magic-prettier) allows you to use Prettier to format JS [codeblocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/) in Markdown files via [Markdown Magic](https://github.com/DavidWells/markdown-magic)

@@ -667,0 +810,0 @@ ## Technical Details

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc