github-pages-deploy-action/node_modules/eslint-config-prettier/README.md

912 lines
25 KiB
Markdown
Raw Normal View History

2020-03-31 20:57:48 +08:00
# eslint-config-prettier [![Build Status][travis-badge]][travis]
2020-03-07 11:45:40 +08:00
Turns off all rules that are unnecessary or might conflict with [Prettier].
2020-03-31 20:57:48 +08:00
This lets you use your favorite shareable config without letting its stylistic
choices get in the way when using Prettier.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
Note that this config _only_ turns rules _off,_ so it only makes sense using
it together with some other config.
2020-03-07 11:45:40 +08:00
## Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
2020-03-31 20:57:48 +08:00
2020-03-07 11:45:40 +08:00
- [Installation](#installation)
2020-03-31 20:40:00 +08:00
- [Excluding deprecated rules](#excluding-deprecated-rules)
2020-03-07 11:45:40 +08:00
- [CLI helper tool](#cli-helper-tool)
- [Example configuration](#example-configuration)
- [Special rules](#special-rules)
- [arrow-body-style and prefer-arrow-callback](#arrow-body-style-and-prefer-arrow-callback)
- [curly](#curly)
- [lines-around-comment](#lines-around-comment)
- [max-len](#max-len)
- [no-confusing-arrow](#no-confusing-arrow)
- [no-mixed-operators](#no-mixed-operators)
- [no-tabs](#no-tabs)
- [no-unexpected-multiline](#no-unexpected-multiline)
- [quotes](#quotes)
- [Enforce backticks](#enforce-backticks)
- [Forbid unnecessary backticks](#forbid-unnecessary-backticks)
- [Example _double_ quote configuration](#example-_double_-quote-configuration)
- [Example _single_ quote configuration](#example-_single_-quote-configuration)
- [vue/html-self-closing](#vuehtml-self-closing)
- [Other rules worth mentioning](#other-rules-worth-mentioning)
- [no-sequences](#no-sequences)
- [Contributing](#contributing)
- [License](#license)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Installation
2020-03-31 20:57:48 +08:00
Tip: First, you might be interested in installing [eslint-plugin-prettier].
Follow the instructions over there. This is optional, though.
2020-03-07 11:45:40 +08:00
Install eslint-config-prettier:
```
npm install --save-dev eslint-config-prettier
```
2020-03-31 20:57:48 +08:00
Then, add eslint-config-prettier to the "extends" array in your `.eslintrc.*`
file. Make sure to put it **last,** so it gets the chance to override other
configs.
2020-03-07 11:45:40 +08:00
```json
{
"extends": [
"some-other-config-you-use",
"prettier"
]
}
```
A few ESLint plugins are supported as well:
- [@typescript-eslint/eslint-plugin]
- [eslint-plugin-babel]
- [eslint-plugin-flowtype]
- [eslint-plugin-react]
- [eslint-plugin-standard]
- [eslint-plugin-unicorn]
- [eslint-plugin-vue]
Add extra exclusions for the plugins you use like so:
```json
{
"extends": [
"some-other-config-you-use",
"prettier",
"prettier/@typescript-eslint",
"prettier/babel",
"prettier/flowtype",
"prettier/react",
"prettier/standard",
"prettier/unicorn",
"prettier/vue"
]
}
```
2020-03-31 20:57:48 +08:00
If you extend a config which uses a plugin, it is recommended to add
`"prettier/that-plugin"` (if available). For example, [eslint-config-airbnb]
enables [eslint-plugin-react] rules, so `"prettier/react"` is needed:
2020-03-07 11:45:40 +08:00
```json
{
"extends": [
"airbnb",
"prettier",
"prettier/react"
]
}
```
2020-03-31 20:57:48 +08:00
If youre unsure which plugins are used, you can usually find them in your
`package.json`.
2020-03-31 20:40:00 +08:00
### Excluding deprecated rules
2020-03-31 20:57:48 +08:00
Some of the rules that eslint-config-prettier turns off may be deprecated.
**This is perfectly fine,** but if you really need to omit the
deprecated rules, you can do so by setting the
`ESLINT_CONFIG_PRETTIER_NO_DEPRECATED` environment variable to a non-empty
value. For example:
2020-03-31 20:40:00 +08:00
```
env ESLINT_CONFIG_PRETTIER_NO_DEPRECATED=true npx eslint-find-rules --deprecated index.js
```
2020-03-07 11:45:40 +08:00
## CLI helper tool
2020-03-31 20:57:48 +08:00
eslint-config-prettier also ships with a little CLI tool to help you check if
your configuration contains any rules that are unnecessary or conflict with
Prettier.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
First, add a script for it to package.json:
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
```json
{
"scripts": {
"eslint-check": "eslint --print-config path/to/main.js | eslint-config-prettier-check"
}
}
2020-03-07 11:45:40 +08:00
```
2020-03-31 20:57:48 +08:00
Then run `npm run eslint-check`. (Change `path/to/main.js` to a file that
exists in your project.)
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
In theory you need to run `eslint --print-config file.js |
eslint-config-prettier-check` for every single file in your project to be
100% sure that there are no conflicting rules, because ESLint supports having
different rules for different files. But usually youll have about the same
rules for all files, so it is enough to run the command on one file (pick one
that you wont be moving). If you use [multiple configuration files] or
[overrides], you can (but you probably dont need to!) run the above script
several times with different `--print-config` arguments, such as:
2020-03-07 11:45:40 +08:00
```
2020-03-31 20:57:48 +08:00
eslint --print-config index.js | eslint-config-prettier-check
eslint --print-config test/index.js | eslint-config-prettier-check
eslint --print-config legacy/main.js | eslint-config-prettier-check
2020-03-07 11:45:40 +08:00
```
Exit codes:
- 0: No problems found.
- 1: Unexpected error.
- 2: Conflicting rules found.
## Example configuration
```json
{
"extends": [
"standard",
"plugin:@typescript-eslint/recommended",
"plugin:flowtype/recommended",
"plugin:react/recommended",
"plugin:unicorn/recommended",
"plugin:vue/recommended",
"prettier",
"prettier/@typescript-eslint",
"prettier/babel",
"prettier/flowtype",
"prettier/react",
"prettier/standard",
"prettier/unicorn",
"prettier/vue"
],
"plugins": [
"@typescript-eslint",
"babel",
"flowtype",
2020-03-31 20:57:48 +08:00
"prettier",
2020-03-07 11:45:40 +08:00
"react",
"standard",
"unicorn",
"vue"
],
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"node": true
2020-03-31 20:57:48 +08:00
},
"rules": {
"prettier/prettier": "error"
2020-03-07 11:45:40 +08:00
}
}
```
## Special rules
2020-03-31 20:57:48 +08:00
There a few rules that eslint-config-prettier disables that actually can be
enabled in some cases.
2020-03-07 11:45:40 +08:00
- Some require certain options. The CLI helper tool validates this.
2020-03-31 20:57:48 +08:00
- Some require special attention when writing code. The CLI helper tool warns
you if any of those rules are enabled, but cant tell if anything is
problematic.
2020-03-07 11:45:40 +08:00
- Some can cause problems if using [eslint-plugin-prettier] and `--fix`.
2020-03-31 20:57:48 +08:00
For maximum ease of use, the special rules are disabled by default. If you want
them, you need to explicitly specify them in your ESLint config.
2020-03-07 11:45:40 +08:00
### [arrow-body-style] and [prefer-arrow-callback]
**These rules might cause problems if using [eslint-plugin-prettier] and `--fix`.**
2020-03-31 20:57:48 +08:00
If you use any of these rules together with the `prettier/prettier` rule from
[eslint-plugin-prettier], you can in some cases end up with invalid code due to
a bug in ESLints autofix.
2020-03-07 11:45:40 +08:00
These rules are safe to use if:
2020-03-31 20:57:48 +08:00
- You dont use [eslint-plugin-prettier]. In other words, you run `eslint --fix`
and `prettier --write` as separate steps.
- You _do_ use [eslint-plugin-prettier], but dont use `--fix`. (But then,
whats the point?)
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
You _can_ still use these rules together with [eslint-plugin-prettier] if you
want, because the bug does not occur _all the time._ But if you do, you need to
keep in mind that you might end up with invalid code, where you manually have to
insert a missing closing parenthesis to get going again.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
If youre fixing large of amounts of previously unformatted code, consider
temporarily disabling the `prettier/prettier` rule and running `eslint --fix`
and `prettier --write` separately.
2020-03-07 11:45:40 +08:00
See these issues for more information:
- [eslint-config-prettier#31]
- [eslint-config-prettier#71]
- [eslint-plugin-prettier#65]
2020-03-31 20:57:48 +08:00
When the autofix bug in ESLint has been fixed, the special case for these rules
can be removed.
2020-03-07 11:45:40 +08:00
### [curly]
**This rule requires certain options.**
2020-03-31 20:57:48 +08:00
If a block (for example after `if`, `else`, `for` or `while`) contains only one
statement, JavaScript allows omitting the curly braces around that statement.
This rule enforces if or when those optional curly braces should be omitted.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
If you use the `"multi-line"` or `"multi-or-nest"` option, the rule can conflict
with Prettier.
2020-03-07 11:45:40 +08:00
For example, the `"multi-line"` option allows this line:
```js
if (cart.items && cart.items[0] && cart.items[0].quantity === 0) updateCart(cart);
```
2020-03-31 20:57:48 +08:00
However, Prettier might consider the line too long and turn it into the
following, which the `"multi-line"` option does _not_ allow:
2020-03-07 11:45:40 +08:00
```js
if (cart.items && cart.items[0] && cart.items[0].quantity === 0)
updateCart(cart);
```
2020-03-31 20:57:48 +08:00
If you like this rule, it can be used just fine with Prettier as long as you
dont use the `"multi-line"` or `"multi-or-nest"` option.
2020-03-07 11:45:40 +08:00
Example ESLint configuration:
```json
{
"rules": {
"curly": ["error", "all"]
}
}
```
### [lines-around-comment]
**This rule can be used with certain options.**
2020-03-31 20:57:48 +08:00
This rule requires empty lines before and/or after comments. Prettier preserves
blank lines, with two exceptions:
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
- Several blank lines in a row are collapsed into a single blank line. This is
fine.
- Blank lines at the beginning and end of blocks, objects and arrays are always
removed. This may lead to conflicts.
2020-03-07 11:45:40 +08:00
By default, ESLint requires a blank line above the comment is this case:
```js
if (result) {
/* comment */
return result;
}
```
However, Prettier removes the blank line:
```js
if (result) {
/* comment */
return result;
}
```
2020-03-31 20:57:48 +08:00
If you like this rule, it can be used just fine with Prettier as long as you add
some extra configuration to allow comments at the start and end of blocks,
objects and arrays.
2020-03-07 11:45:40 +08:00
Example ESLint configuration:
```json
{
"rules": {
"lines-around-comment": [
"error",
{
"beforeBlockComment": true,
"afterBlockComment": true,
"beforeLineComment": true,
"afterLineComment": true,
"allowBlockStart": true,
"allowBlockEnd": true,
"allowObjectStart": true,
"allowObjectEnd": true,
"allowArrayStart": true,
"allowArrayEnd": true
}
]
}
}
```
### [max-len]
2020-03-31 20:40:00 +08:00
(The following applies to [vue/max-len] as well.)
2020-03-07 11:45:40 +08:00
**This rule requires special attention when writing code.**
2020-03-31 20:57:48 +08:00
Usually, Prettier takes care of following a maximum line length automatically.
However, there are cases where Prettier cant do anything, such as for long
strings, regular expressions and comments. Those need to be split up by a human.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
If youd like to enforce an even stricter maximum line length policy than
Prettier can provide automatically, you can enable this rule. Just remember to
keep `max-len`s options and Prettiers `printWidth` option in sync.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
Keep in mind that you might have to refactor code slightly if Prettier formats
lines in a way that the `max-len` rule does not approve of.
2020-03-07 11:45:40 +08:00
Example ESLint configuration:
```json
{
"rules": {
"max-len": ["error", {"code": 80, "ignoreUrls": true}]
}
}
```
### [no-confusing-arrow]
**This rule requires certain options.**
For example, the rule could warn about this line:
```js
var x = a => 1 ? 2 : 3;
```
2020-03-31 20:57:48 +08:00
With `{allowParens: true}` (the default since ESLint 6.0.0), adding
parentheses is considered a valid way to avoid the arrow confusion:
2020-03-07 11:45:40 +08:00
```js
2020-03-31 20:40:00 +08:00
var x = a => (1 ? 2 : 3);
2020-03-07 11:45:40 +08:00
```
2020-03-31 20:57:48 +08:00
While Prettier keeps those parentheses, it removes them if the line is long
enough to introduce a line break:
2020-03-07 11:45:40 +08:00
```js
2020-03-31 20:40:00 +08:00
EnterpriseCalculator.prototype.calculateImportantNumbers = inputNumber =>
1 ? 2 : 3;
2020-03-07 11:45:40 +08:00
```
2020-03-31 20:57:48 +08:00
With `{allowParens: false}`, ESLint instead suggests switching to an explicit
return:
2020-03-07 11:45:40 +08:00
```js
2020-03-31 20:40:00 +08:00
var x = a => { return 1 ? 2 : 3; };
2020-03-07 11:45:40 +08:00
```
2020-03-31 20:40:00 +08:00
That causes no problems with Prettier.
2020-03-31 20:57:48 +08:00
If you like this rule, it can be used just fine with Prettier as long as the
`allowParens` option is off.
2020-03-07 11:45:40 +08:00
Example ESLint configuration:
```json
{
"rules": {
2020-03-31 20:40:00 +08:00
"no-confusing-arrow": ["error", { "allowParens": false }]
2020-03-07 11:45:40 +08:00
}
}
```
2020-03-31 20:57:48 +08:00
(Note: The CLI helper tool considers `{allowParens: true}` to be the default,
which is the case since ESLint 6.0.0. The tool will produce a warning if you
use the default even if you use an older version of ESLint. It doesnt hurt
to explicitly set `{allowParens: false}` even though it is technically
redundant. This way you are prepared for a future ESLint upgrade and the CLI
tool can be kept simple.)
2020-03-31 20:40:00 +08:00
2020-03-07 11:45:40 +08:00
### [no-mixed-operators]
**This rule requires special attention when writing code.**
This rule forbids mixing certain operators, such as `&&` and `||`.
For example, the rule could warn about this line:
```js
var foo = a + b * c;
```
The rule suggests adding parentheses, like this:
```js
var foo = a + (b * c);
```
However, Prettier removes many “unnecessary” parentheses, turning it back to:
```js
var foo = a + b * c;
```
2020-03-31 20:57:48 +08:00
If you want to use this rule with Prettier, you need to split the expression
into another variable:
2020-03-07 11:45:40 +08:00
```js
var bar = b * c;
var foo = a + bar;
```
Keep in mind that Prettier prints _some_ “unnecessary” parentheses, though:
```js
var foo = (a && b) || c;
```
Example ESLint configuration:
```json
{
"rules": {
"no-mixed-operators": "error"
}
}
```
### [no-tabs]
**This rule requires certain Prettier options.**
2020-03-31 20:57:48 +08:00
This rule disallows the use of tab characters at all. It can be used just fine
with Prettier as long as you dont configure Prettier to indent using tabs.
2020-03-07 11:45:40 +08:00
Example ESLint configuration:
```json
{
"rules": {
"no-tabs": "error"
}
}
```
2020-03-31 20:57:48 +08:00
Example Prettier configuration (this is the default, so adding this is not
required):
2020-03-07 11:45:40 +08:00
```json
{
"useTabs": false
}
```
2020-03-31 20:57:48 +08:00
**Note:** Since [ESlint 5.7.0] this rule can be configured to work regardless of
your Prettier configuration:
2020-03-07 11:45:40 +08:00
```json
{
"rules": {
"no-tabs": ["error", {"allowIndentationTabs": true}]
}
}
```
A future version of eslint-config-prettier might check for that automatically.
### [no-unexpected-multiline]
**This rule requires special attention when writing code.**
2020-03-31 20:57:48 +08:00
This rule disallows confusing multiline expressions where a newline looks like
it is ending a statement, but is not.
2020-03-07 11:45:40 +08:00
For example, the rule could warn about this:
```js
var hello = "world"
[1, 2, 3].forEach(addNumber)
```
2020-03-31 20:57:48 +08:00
Prettier usually formats this in a way that makes it obvious that a semicolon
was missing:
2020-03-07 11:45:40 +08:00
```js
var hello = "world"[(1, 2, 3)].forEach(addNumber);
```
2020-03-31 20:57:48 +08:00
However, there are cases where Prettier breaks things into several lines such
that the `no-unexpected-multiline` conflicts.
2020-03-07 11:45:40 +08:00
```js
const value = text.trim().split("\n")[position].toLowerCase();
```
Prettier breaks it up into several lines, though, causing a conflict:
```js
const value = text
.trim()
.split("\n")
[position].toLowerCase();
```
2020-03-31 20:57:48 +08:00
If you like this rule, it can usually be used with Prettier without problems,
but occasionally you might need to either temporarily disable the rule or
refactor your code.
2020-03-07 11:45:40 +08:00
```js
const value = text
.trim()
.split("\n")
// eslint-disable-next-line no-unexpected-multiline
[position].toLowerCase();
// Or:
const lines = text.trim().split("\n");
const value = lines[position].toLowerCase();
```
2020-03-31 20:57:48 +08:00
**Note:** If you _do_ enable this rule, you have to run ESLint and Prettier as
two separate steps (and ESLint first) in order to get any value out of it.
Otherwise Prettier might reformat your code in such a way that ESLint never gets
a chance to report anything (as seen in the first example).
2020-03-07 11:45:40 +08:00
Example configuration:
```json
{
"rules": {
"no-unexpected-multiline": "error"
}
}
```
### [quotes]
2020-03-31 20:40:00 +08:00
(The following applies to [babel/quotes] and [@typescript-eslint/quotes] as well.)
2020-03-07 11:45:40 +08:00
**This rule requires certain options and certain Prettier options.**
2020-03-31 20:57:48 +08:00
Usually, you dont need this rule at all. But there are two cases where it could
be useful:
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
- To enforce the use of backticks rather than single or double quotes for
strings.
2020-03-07 11:45:40 +08:00
- To forbid backticks where regular strings could have been used.
#### Enforce backticks
2020-03-31 20:57:48 +08:00
If youd like all strings to use backticks (never quotes), enable the
`"backtick"` option.
2020-03-07 11:45:40 +08:00
Example ESLint configuration:
```json
{
"rules": {
"quotes": ["error", "backtick"]
}
}
```
#### Forbid unnecessary backticks
2020-03-31 20:57:48 +08:00
In the following example, the first array item could have been written with
quotes instead of backticks.
2020-03-07 11:45:40 +08:00
```js
const strings = [
`could have been a regular string`,
`
multiple
lines
`,
`uses ${interpolation}`,
String.raw`\tagged/`,
];
```
2020-03-31 20:57:48 +08:00
If youd like ESLint to enforce `` `could have been a regular string` `` being
written as either `"could have been a regular string"` or `'could have been a
regular string'`, you need to use some specific configuration. The `quotes` rule has two options, a string option and an object option.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
- The first (string) option needs to be set to `"single"` or `"double"` and be
kept in sync with Prettiers [singleQuote] option.
2020-03-07 11:45:40 +08:00
- The second (object) option needs the following properties:
- `"avoidEscape": true` to follow Prettiers [string formatting rules].
- `"allowTemplateLiterals": false` to disallow unnecessary backticks.
##### Example _double_ quote configuration
ESLint:
```json
{
"rules": {
"quotes": [
"error",
"double",
{ "avoidEscape": true, "allowTemplateLiterals": false }
]
}
}
```
Prettier (this is the default, so adding this is not required):
```json
{
"singleQuote": false
}
```
##### Example _single_ quote configuration
ESLint:
```json
{
"rules": {
"quotes": [
"error",
"single",
{ "avoidEscape": true, "allowTemplateLiterals": false }
]
}
}
```
Prettier:
```json
{
"singleQuote": true
}
```
### [vue/html-self-closing]
**This rule requires certain options.**
This rule enforces whether elements should be self-closing or not.
Prettier generally preserves the way you wrote your elements:
```vue
<div />
<div></div>
<MyComponent />
<MyComponent></MyComponent>
<svg><path d="" /></svg>
<svg><path d=""></path></svg>
```
2020-03-31 20:57:48 +08:00
But for known _void_ HTML elements, Prettier always uses the self-closing style.
For example, `<img>` is turned into `<img />`.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
If you like this rule, it can be used just fine with Prettier as long as you
set `html.void` to `"any"`.
2020-03-07 11:45:40 +08:00
Example ESLint configuration:
```json
{
"rules": {
"vue/html-self-closing": [
"error",
{
"html": {
"void": "any"
}
}
]
}
}
```
## Other rules worth mentioning
2020-03-31 20:57:48 +08:00
These rules dont conflict with Prettier, but have some gotchas when used with
Prettier.
2020-03-07 11:45:40 +08:00
### [no-sequences]
2020-03-31 20:57:48 +08:00
This rule forbids using JavaScripts confusing comma operator (sequence
expressions). This piece of code is not doing what it looks like:
2020-03-07 11:45:40 +08:00
```js
matrix[4, 7];
```
2020-03-31 20:57:48 +08:00
Prettier adds parentheses to the above to make it clear that a sequence
expression is used:
2020-03-07 11:45:40 +08:00
```js
matrix[(4, 7)];
```
2020-03-31 20:57:48 +08:00
However, the `no-sequences` rule allows comma operators if the expression
sequence is explicitly wrapped in parentheses. Since Prettier automatically
wraps them in parentheses, you might never see any warnings from ESLint about
comma operators.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
Ending up with an accidental sequence expression can easily happen while
refactoring. If you want ESLint to catch such mistakes, it is recommended to
forbid sequence expressions entirely using [no-restricted-syntax] \([as
mentioned in the `no-sequences` documentation][no-sequences-full]):
2020-03-07 11:45:40 +08:00
```json
{
"rules": {
"no-restricted-syntax": ["error", "SequenceExpression"]
}
}
```
2020-03-31 20:57:48 +08:00
If you still need to use the comma operator for some edge case, you can place an
`// eslint-disable-next-line no-restricted-syntax` comment on the line above the
expression. `no-sequences` can safely be disabled if you use the
`no-restricted-syntax` approach.
2020-03-07 11:45:40 +08:00
You can also supply a custom message if you want:
```json
{
"rules": {
"no-restricted-syntax": [
"error",
{
"selector": "SequenceExpression",
"message": "The comma operator is confusing and a common mistake. Dont use it!"
}
]
}
}
```
## Contributing
eslint-config-prettier has been tested with:
2020-03-31 20:40:00 +08:00
- ESLint 6.8.0
- eslint-config-prettier 5.1.0 and older were tested with ESLint 5.x
2020-03-07 11:45:40 +08:00
- eslint-config-prettier 2.10.0 and older were tested with ESLint 4.x
- eslint-config-prettier 2.1.1 and older were tested with ESLint 3.x
2020-03-31 20:57:48 +08:00
- prettier 1.19.1
- @typescript-eslint/eslint-plugin 2.18.0
2020-03-07 11:45:40 +08:00
- eslint-plugin-babel 5.3.0
2020-03-31 20:40:00 +08:00
- eslint-plugin-flowtype 4.6.0
2020-03-31 20:57:48 +08:00
- eslint-plugin-react 7.18.0
2020-03-31 20:40:00 +08:00
- eslint-plugin-standard 4.0.1
2020-03-31 20:57:48 +08:00
- eslint-plugin-unicorn 15.0.1
- eslint-plugin-vue 6.1.2
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
Have new rules been added since those versions? Have we missed any rules? Is
there a plugin you would like to see exclusions for? Open an issue or a pull
request!
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
If youd like to add support for eslint-plugin-foobar, this is how youd go
about it:
2020-03-07 11:45:40 +08:00
First, create `foobar.js`:
```js
"use strict";
module.exports = {
rules: {
"foobar/some-rule": "off"
}
};
```
Then, create `test-lint/foobar.js`:
```js
/* eslint-disable quotes */
"use strict";
// Prettier does not want spaces before the parentheses, but
// `plugin:foobar/recommended` wants one.
console.log();
```
2020-03-31 20:57:48 +08:00
`test-lint/foobar.js` must fail when used with eslint-plugin-foobar and
eslint-plugin-prettier at the same time until `"prettier/foobar"` is added to
the "extends" property of an ESLint config. The file should be formatted
according to Prettier, and that formatting should disagree with the plugin.
2020-03-07 11:45:40 +08:00
Finally, you need to mention the plugin in several places:
- Add `"foobar.js"` to the "files" field in `package.json`.
- Add eslint-plugin-foobar to the "devDependencies" field in `package.json`.
2020-03-31 20:57:48 +08:00
- Make sure that at least one rule from eslint-plugin-foobar gets used in
`.eslintrc.base.js`.
- Add it to the list of supported plugins, to the example config and to
Contributing section in `README.md`.
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
When youre done, run `npm test` to verify that you got it all right. It runs
several other npm scripts:
2020-03-07 11:45:40 +08:00
2020-03-31 20:57:48 +08:00
- `"test:lint"` makes sure that the files in `test-lint/` pass ESLint when
the exclusions from eslint-config-prettier are used. It also lints the code of
eslint-config-prettier itself.
2020-03-07 11:45:40 +08:00
- `"test:lint-verify-fail"` is run by a test in `test/lint-verify-fail.test.js`.
- `"test:lint-rules"` is run by a test in `test/rules.test.js`.
- `"test:jest"` runs unit tests that check a number of things:
- That eslint-plugin-foobar is mentioned in all the places shown above.
2020-03-31 20:57:48 +08:00
- That no unknown rules are turned off. This helps catching typos, for
example.
2020-03-07 11:45:40 +08:00
- That the CLI works.
2020-03-31 20:57:48 +08:00
- `"test:cli-sanity"` and `"test:cli-sanity-warning"` are sanity checks for the
CLI.
2020-03-07 11:45:40 +08:00
## License
[MIT](LICENSE).
[@typescript-eslint/eslint-plugin]: https://github.com/typescript-eslint/typescript-eslint
2020-03-31 20:40:00 +08:00
[@typescript-eslint/quotes]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/quotes.md
2020-03-31 20:57:48 +08:00
[ESlint 5.7.0]: https://eslint.org/blog/2018/10/eslint-v5.7.0-released
[Prettier]: https://github.com/prettier/prettier
2020-03-07 11:45:40 +08:00
[arrow-body-style]: https://eslint.org/docs/rules/arrow-body-style
[babel/quotes]: https://github.com/babel/eslint-plugin-babel#rules
[curly]: https://eslint.org/docs/rules/curly
[eslint-config-airbnb]: https://www.npmjs.com/package/eslint-config-airbnb
[eslint-config-prettier#31]: https://github.com/prettier/eslint-config-prettier/issues/31
[eslint-config-prettier#71]: https://github.com/prettier/eslint-config-prettier/issues/71
[eslint-plugin-babel]: https://github.com/babel/eslint-plugin-babel
[eslint-plugin-flowtype]: https://github.com/gajus/eslint-plugin-flowtype
[eslint-plugin-prettier#65]: https://github.com/prettier/eslint-plugin-prettier/issues/65
[eslint-plugin-prettier]: https://github.com/prettier/eslint-plugin-prettier
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
[eslint-plugin-standard]: https://github.com/xjamundx/eslint-plugin-standard
[eslint-plugin-unicorn]: https://github.com/sindresorhus/eslint-plugin-unicorn
[eslint-plugin-vue]: https://github.com/vuejs/eslint-plugin-vue
[lines-around-comment]: https://eslint.org/docs/rules/lines-around-comment
[max-len]: https://eslint.org/docs/rules/max-len
[multiple configuration files]: https://eslint.org/docs/user-guide/configuring#configuration-cascading-and-hierarchy
[no-confusing-arrow]: https://eslint.org/docs/rules/no-confusing-arrow
[no-mixed-operators]: https://eslint.org/docs/rules/no-mixed-operators
[no-restricted-syntax]: https://eslint.org/docs/rules/no-restricted-syntax
[no-sequences-full]: https://eslint.org/docs/rules/no-sequences#when-not-to-use-it
[no-sequences]: https://eslint.org/docs/rules/no-sequences
[no-tabs]: https://eslint.org/docs/rules/no-tabs
[no-unexpected-multiline]: https://eslint.org/docs/rules/no-unexpected-multiline
[overrides]: https://eslint.org/docs/user-guide/configuring#configuration-based-on-glob-patterns
[prefer-arrow-callback]: https://eslint.org/docs/rules/prefer-arrow-callback
[quotes]: https://eslint.org/docs/rules/quotes
2020-03-31 20:57:48 +08:00
[singleQuote]: https://prettier.io/docs/en/options.html#quotes
2020-03-07 11:45:40 +08:00
[string formatting rules]: https://prettier.io/docs/en/rationale.html#strings
2020-03-31 20:57:48 +08:00
[travis-badge]: https://travis-ci.org/prettier/eslint-config-prettier.svg?branch=master
[travis]: https://travis-ci.org/prettier/eslint-config-prettier
2020-03-07 11:45:40 +08:00
[vue/html-self-closing]: https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-self-closing.md
2020-03-31 20:40:00 +08:00
[vue/max-len]: https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/max-len.md