Skip to content

Commit 71349a1

Browse files
bpmutterbtmills
andauthored
docs: Configure a Parser page (#16803)
* docs: Configure a Parser page Resolves #16762 * Apply suggestions from code review Co-authored-by: Brandon Mills <[email protected]> --------- Co-authored-by: Brandon Mills <[email protected]>
1 parent de7e925 commit 71349a1

4 files changed

Lines changed: 45 additions & 34 deletions

File tree

docs/src/use/configure/ignore.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ eleventyNavigation:
44
key: ignore files
55
parent: configure
66
title: Ignore Files
7-
order: 6
7+
order: 7
88

99
---
1010

docs/src/use/configure/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ All of these options give you fine-grained control over how ESLint treats your c
4949

5050
* [Configure Plugins](./plugins#configure-plugins)
5151
* [Specify a Processor](./plugins#specify-a-processor)
52-
* [Configure Parsers](./plugins#configure-a-parser)
52+
53+
[**Configure a Parser**](./parser)
54+
55+
* [Configure a Custom Parser](./parser#configure-a-custom-parser)
5356

5457
[**Ignore Files**](ignore)
5558

docs/src/use/configure/parser.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: Configure a Parser
3+
eleventyNavigation:
4+
key: configure parser
5+
parent: configure
6+
title: Configure a Parser
7+
order: 6
8+
---
9+
10+
You can 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.
11+
12+
## Configure a Custom Parser
13+
14+
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:
15+
16+
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.
17+
1. It must conform to the [parser interface](../../extend/custom-parsers).
18+
19+
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.
20+
21+
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:
22+
23+
```json
24+
{
25+
"parser": "esprima",
26+
"rules": {
27+
"semi": "error"
28+
}
29+
}
30+
```
31+
32+
The following parsers are compatible with ESLint:
33+
34+
* [Esprima](https://www.npmjs.com/package/esprima)
35+
* [@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.
36+
* [@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.
37+
38+
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.

docs/src/use/configure/plugins.md

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: Configure Plugins & Parsers
2+
title: Configure Plugins
33
eleventyNavigation:
44
key: configure plugins
55
parent: configure
6-
title: Configure Plugins & Parsers
6+
title: Configure Plugins
77
order: 5
88

99
---
@@ -15,8 +15,6 @@ You can extend ESLint with plugins in a variety of different ways. Plugins can i
1515
* Custom environments.
1616
* Custom processors to extract JavaScript code from other kinds of files or preprocess code before linting.
1717

18-
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.
19-
2018
## Configure Plugins
2119

2220
ESLint supports the use of third-party plugins. Before using a plugin, you have to install it using npm.
@@ -161,31 +159,3 @@ Processors may make named code blocks such as `0.js` and `1.js`. ESLint handles
161159
```
162160

163161
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`.
164-
165-
## Configure a Parser
166-
167-
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:
168-
169-
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.
170-
1. It must conform to the [parser interface](../../extend/custom-parsers).
171-
172-
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.
173-
174-
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:
175-
176-
```json
177-
{
178-
"parser": "esprima",
179-
"rules": {
180-
"semi": "error"
181-
}
182-
}
183-
```
184-
185-
The following parsers are compatible with ESLint:
186-
187-
* [Esprima](https://www.npmjs.com/package/esprima)
188-
* [@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.
189-
* [@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.
190-
191-
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.

0 commit comments

Comments
 (0)