New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Configuring Plugins page intro, page tweaks, and rename #16534
Changes from 7 commits
eda62c6
8f94e76
4f2de6c
0a3b275
7a0c4bd
ffa3c30
3ef40fb
fb138fd
40cd2fd
60d23ad
20286ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,93 +1,25 @@ | ||||||
--- | ||||||
title: Plugins | ||||||
title: Plugins & Parsers | ||||||
layout: doc | ||||||
bpmutter marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
eleventyNavigation: | ||||||
key: configuring plugins | ||||||
parent: configuring | ||||||
title: Configuring Plugins | ||||||
title: Configuring Plugins & Parsers | ||||||
order: 4 | ||||||
|
||||||
--- | ||||||
|
||||||
## Specifying Parser | ||||||
You can extend ESLint with plugins in a variety of different ways. Plugins can include: | ||||||
|
||||||
By default, ESLint uses [Espree](https://github.com/eslint/espree) as its parser. You can optionally specify that a different parser should be used in your configuration file so long as the parser meets the following requirements: | ||||||
* Custom processors to extract JavaScript code from other kinds of files or preprocess code before linting. | ||||||
* Custom rules to validate if your code meets a certain expectation, and what to do if it does not meet that expectation. | ||||||
* Custom configurations. | ||||||
nzakas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
1. It must be a Node module loadable from the config file where the parser is used. Usually, this means you should install the parser package separately using npm. | ||||||
1. It must conform to the [parser interface](../../developer-guide/working-with-custom-parsers). | ||||||
|
||||||
Note that even with these compatibilities, there are no guarantees that an external parser will work correctly with ESLint and ESLint will not fix bugs related to incompatibilities with other parsers. | ||||||
|
||||||
To indicate the npm module to use as your parser, specify it using the `parser` option in your `.eslintrc` file. For example, the following specifies to use Esprima instead of Espree: | ||||||
|
||||||
```json | ||||||
{ | ||||||
"parser": "esprima", | ||||||
"rules": { | ||||||
"semi": "error" | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
The following parsers are compatible with ESLint: | ||||||
|
||||||
* [Esprima](https://www.npmjs.com/package/esprima) | ||||||
* [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser) - A wrapper around the [Babel](https://babeljs.io) parser that makes it compatible with ESLint. | ||||||
* [@typescript-eslint/parser](https://www.npmjs.com/package/@typescript-eslint/parser) - A parser that converts TypeScript into an ESTree-compatible form so it can be used in ESLint. | ||||||
|
||||||
Note when using a custom parser, the `parserOptions` configuration property is still required for ESLint to work properly with features not in ECMAScript 5 by default. Parsers are all passed `parserOptions` and may or may not use them to determine which features to enable. | ||||||
|
||||||
## Specifying Processor | ||||||
|
||||||
Plugins may provide processors. Processors can extract JavaScript code from other kinds of files, then let ESLint lint the JavaScript code or processors can convert JavaScript code in preprocessing for some purpose. | ||||||
|
||||||
To specify processors in a configuration file, use the `processor` key with the concatenated string of a plugin name and a processor name by a slash. For example, the following enables the processor `a-processor` that the plugin `a-plugin` provided: | ||||||
|
||||||
```json | ||||||
{ | ||||||
"plugins": ["a-plugin"], | ||||||
"processor": "a-plugin/a-processor" | ||||||
} | ||||||
``` | ||||||
|
||||||
To specify processors for specific kinds of files, use the combination of the `overrides` key and the `processor` key. For example, the following uses the processor `a-plugin/markdown` for `*.md` files. | ||||||
|
||||||
```json | ||||||
{ | ||||||
"plugins": ["a-plugin"], | ||||||
"overrides": [ | ||||||
{ | ||||||
"files": ["*.md"], | ||||||
"processor": "a-plugin/markdown" | ||||||
} | ||||||
] | ||||||
} | ||||||
``` | ||||||
|
||||||
Processors may make named code blocks such as `0.js` and `1.js`. ESLint handles such a named code block as a child file of the original file. You can specify additional configurations for named code blocks in the `overrides` section of the config. For example, the following disables the `strict` rule for the named code blocks which end with `.js` in markdown files. | ||||||
|
||||||
```json | ||||||
{ | ||||||
"plugins": ["a-plugin"], | ||||||
"overrides": [ | ||||||
{ | ||||||
"files": ["*.md"], | ||||||
"processor": "a-plugin/markdown" | ||||||
}, | ||||||
{ | ||||||
"files": ["**/*.md/*.js"], | ||||||
"rules": { | ||||||
"strict": "off" | ||||||
} | ||||||
} | ||||||
] | ||||||
} | ||||||
``` | ||||||
|
||||||
ESLint checks the file path of named code blocks then ignores those if any `overrides` entry didn't match the file path. Be sure to add an `overrides` entry if you want to lint named code blocks other than `*.js`. | ||||||
You can also use custom parsers to convert JavaScript code into an abstract syntax tree for ESLint to evaluate. You might want to add a custom parser if your code isn't compatible with ESLint's default parser, Espree. | ||||||
|
||||||
## Configuring Plugins | ||||||
|
||||||
ESLint supports the use of third-party plugins. Before using the plugin, you have to install it using npm. | ||||||
ESLint supports the use of third-party plugins. Before using a plugin, you have to install it using npm. | ||||||
|
||||||
To configure plugins inside of a configuration file, use the `plugins` key, which contains a list of plugin names. The `eslint-plugin-` prefix can be omitted from the plugin name. | ||||||
|
||||||
|
@@ -111,14 +43,16 @@ And in YAML: | |||||
|
||||||
**Notes:** | ||||||
|
||||||
1. Plugins are resolved relative to the config file. In other words, ESLint will load the plugin as a user would obtain by running `require('eslint-plugin-pluginname')` in the config file. | ||||||
1. Plugins are resolved relative to the config file. In other words, ESLint loads the plugin as a user would obtain by running `require('eslint-plugin-pluginname')` in the config file. | ||||||
2. Plugins in the base configuration (loaded by `extends` setting) are relative to the derived config file. For example, if `./.eslintrc` has `extends: ["foo"]` and the `eslint-config-foo` has `plugins: ["bar"]`, ESLint finds the `eslint-plugin-bar` from `./node_modules/` (rather than `./node_modules/eslint-config-foo/node_modules/`) or ancestor directories. Thus every plugin in the config file and base configurations is resolved uniquely. | ||||||
|
||||||
### Naming convention | ||||||
|
||||||
#### Include a plugin | ||||||
|
||||||
The `eslint-plugin-` prefix can be omitted for non-scoped packages | ||||||
The `eslint-plugin-` prefix can be omitted for both non-scoped and scoped packages. | ||||||
|
||||||
A non-scoped package: | ||||||
|
||||||
```js | ||||||
{ | ||||||
|
@@ -130,7 +64,7 @@ The `eslint-plugin-` prefix can be omitted for non-scoped packages | |||||
} | ||||||
``` | ||||||
|
||||||
The same rule does apply to scoped packages: | ||||||
A scoped package: | ||||||
|
||||||
```js | ||||||
{ | ||||||
|
@@ -145,7 +79,7 @@ The same rule does apply to scoped packages: | |||||
|
||||||
#### Use a plugin | ||||||
|
||||||
When using rules, environments or configs defined by plugins, they must be referenced following the convention: | ||||||
Rules, environments, and configurations defined in plugins must be referenced with the following convention: | ||||||
|
||||||
* `eslint-plugin-foo` → `foo/a-rule` | ||||||
* `@foo/eslint-plugin` → `@foo/a-config` | ||||||
|
@@ -178,3 +112,80 @@ For example: | |||||
// ... | ||||||
} | ||||||
``` | ||||||
|
||||||
### Specifying Processor | ||||||
|
||||||
Plugins may provide processors. Processors can extract JavaScript code from other kinds of files, then let ESLint lint the JavaScript code. Alternatively, processors can convert JavaScript code during preprocessing. | ||||||
|
||||||
To specify processors in a configuration file, use the `processor` key with the concatenated string of a plugin name and a processor name by a slash. For example, the following enables the processor `a-processor` that the plugin `a-plugin` provided: | ||||||
|
||||||
```json | ||||||
{ | ||||||
"plugins": ["a-plugin"], | ||||||
"processor": "a-plugin/a-processor" | ||||||
} | ||||||
``` | ||||||
|
||||||
To specify processors for specific kinds of files, use the combination of the `overrides` key and the `processor` key. For example, the following uses the processor `a-plugin/markdown` for `*.md` files. | ||||||
|
||||||
```json | ||||||
{ | ||||||
"plugins": ["a-plugin"], | ||||||
"overrides": [ | ||||||
{ | ||||||
"files": ["*.md"], | ||||||
"processor": "a-plugin/markdown" | ||||||
} | ||||||
] | ||||||
} | ||||||
``` | ||||||
|
||||||
Processors may make named code blocks such as `0.js` and `1.js`. ESLint handles such a named code block as a child file of the original file. You can specify additional configurations for named code blocks in the `overrides` section of the config. For example, the following disables the `strict` rule for the named code blocks which end with `.js` in markdown files. | ||||||
|
||||||
```json | ||||||
{ | ||||||
"plugins": ["a-plugin"], | ||||||
"overrides": [ | ||||||
{ | ||||||
"files": ["*.md"], | ||||||
"processor": "a-plugin/markdown" | ||||||
}, | ||||||
{ | ||||||
"files": ["**/*.md/*.js"], | ||||||
"rules": { | ||||||
"strict": "off" | ||||||
} | ||||||
} | ||||||
] | ||||||
} | ||||||
``` | ||||||
|
||||||
ESLint checks the file path of named code blocks then ignores those if any `overrides` entry didn't match the file path. Be sure to add an `overrides` entry if you want to lint named code blocks other than `*.js`. | ||||||
bpmutter marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
## Configuring Parsers | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping everything singular
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. made singular and removed the "-ing" form on all section headers on the page. in future PR, should update all section headings across entire docs set to be not "-ing" form of word to align w the pages names in the new IA. |
||||||
|
||||||
By default, ESLint uses [Espree](https://github.com/eslint/espree) as its parser. You can optionally specify that a different parser should be used in your configuration file if the parser meets the following requirements: | ||||||
|
||||||
1. It must be a Node module loadable from the config file where the parser is used. Usually, this means you should install the parser package separately using npm. | ||||||
1. It must conform to the [parser interface](../../developer-guide/working-with-custom-parsers). | ||||||
|
||||||
Note that even with these compatibilities, there are no guarantees that an external parser works correctly with ESLint. ESLint does not fix bugs related to incompatibilities with other parsers. | ||||||
|
||||||
To indicate the npm module to use as your parser, specify it using the `parser` option in your `.eslintrc` file. For example, the following specifies to use Esprima instead of Espree: | ||||||
|
||||||
```json | ||||||
{ | ||||||
"parser": "esprima", | ||||||
"rules": { | ||||||
"semi": "error" | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
The following parsers are compatible with ESLint: | ||||||
|
||||||
* [Esprima](https://www.npmjs.com/package/esprima) | ||||||
* [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser) - A wrapper around the [Babel](https://babeljs.io) parser that makes it compatible with ESLint. | ||||||
* [@typescript-eslint/parser](https://www.npmjs.com/package/@typescript-eslint/parser) - A parser that converts TypeScript into an ESTree-compatible form so it can be used in ESLint. | ||||||
|
||||||
Note that when using a custom parser, the `parserOptions` configuration property is still required for ESLint to work properly with features not in ECMAScript 5 by default. Parsers are all passed `parserOptions` and may or may not use them to determine which features to enable. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I feel this part to be quite confusing 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this wording is fine and shouldn't hold up this PR. We can continue tweaking later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be singular to avoid breaking the link and for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed all to be plural, consistent w other similar links on the page.
also updated the #anchor-links to match updated page anchors that don't use "-ing" form (see this comment for context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I ❤️ consistency. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#16578