Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0367a70

Browse files
authored
docs: update custom parser docs (#19288)
1 parent da768d4 commit 0367a70

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

docs/src/extend/custom-parsers.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,29 @@ Once you've published the npm package, you can use it by adding the package to y
121121
npm install eslint-parser-myparser --save-dev
122122
```
123123

124-
Then add the custom parser to your ESLint configuration file with the `parser` property. For example:
124+
Then add the custom parser to your ESLint configuration file with the `languageOptions.parser` property. For example:
125+
126+
```js
127+
// eslint.config.js
128+
129+
const myparser = require("eslint-parser-myparser");
130+
131+
module.exports = [{
132+
languageOptions: {
133+
parser: myparser
134+
},
135+
// ... rest of configuration
136+
}];
137+
```
138+
139+
When using legacy configuration, specify the `parser` property as a string:
125140

126141
```js
127142
// .eslintrc.js
128143

129144
module.exports = {
130-
parser: 'eslint-parser-myparser',
131-
// ... rest of configuration
145+
parser: "eslint-parser-myparser",
146+
// ... rest of configuration
132147
};
133148
```
134149

@@ -161,6 +176,17 @@ module.exports = { parseForESLint };
161176

162177
Include the custom parser in an ESLint configuration file:
163178

179+
```js
180+
// eslint.config.js
181+
module.exports = [{
182+
languageOptions: {
183+
parser: require("./path/to/awesome-custom-parser")
184+
}
185+
}];
186+
```
187+
188+
Or if using legacy configuration:
189+
164190
```js
165191
// .eslintrc.json
166192
{

docs/src/extend/ways-to-extend.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ ESLint ships with a built-in JavaScript parser (Espree), but custom parsers allo
5555

5656
For example, the custom parser [@typescript-eslint/parser](https://typescript-eslint.io/packages/parser) extends ESLint to lint TypeScript code.
5757

58-
Custom parsers **cannot** be included in a plugin, unlike the other extension types.
58+
Custom parsers can be also included in a plugin.
5959

6060
To learn more about creating a custom parser, refer to [Custom Parsers](custom-parsers).

0 commit comments

Comments
 (0)