Skip to content

Commit

Permalink
docs: update custom parser docs (eslint#19288)
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime authored Dec 29, 2024
1 parent da768d4 commit 0367a70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
32 changes: 29 additions & 3 deletions docs/src/extend/custom-parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,29 @@ Once you've published the npm package, you can use it by adding the package to y
npm install eslint-parser-myparser --save-dev
```

Then add the custom parser to your ESLint configuration file with the `parser` property. For example:
Then add the custom parser to your ESLint configuration file with the `languageOptions.parser` property. For example:

```js
// eslint.config.js

const myparser = require("eslint-parser-myparser");

module.exports = [{
languageOptions: {
parser: myparser
},
// ... rest of configuration
}];
```

When using legacy configuration, specify the `parser` property as a string:

```js
// .eslintrc.js

module.exports = {
parser: 'eslint-parser-myparser',
// ... rest of configuration
parser: "eslint-parser-myparser",
// ... rest of configuration
};
```

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

Include the custom parser in an ESLint configuration file:

```js
// eslint.config.js
module.exports = [{
languageOptions: {
parser: require("./path/to/awesome-custom-parser")
}
}];
```

Or if using legacy configuration:

```js
// .eslintrc.json
{
Expand Down
2 changes: 1 addition & 1 deletion docs/src/extend/ways-to-extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ ESLint ships with a built-in JavaScript parser (Espree), but custom parsers allo

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

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

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

0 comments on commit 0367a70

Please sign in to comment.