From 0367a70a43346f1b9df8be75d38f98f9cfe4007c Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Sun, 29 Dec 2024 15:12:48 +0100 Subject: [PATCH] docs: update custom parser docs (#19288) --- docs/src/extend/custom-parsers.md | 32 ++++++++++++++++++++++++++++--- docs/src/extend/ways-to-extend.md | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/src/extend/custom-parsers.md b/docs/src/extend/custom-parsers.md index f9cbb9f08726..80b08eea2f3d 100644 --- a/docs/src/extend/custom-parsers.md +++ b/docs/src/extend/custom-parsers.md @@ -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 }; ``` @@ -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 { diff --git a/docs/src/extend/ways-to-extend.md b/docs/src/extend/ways-to-extend.md index 3bf8314e1afa..2684d340974a 100644 --- a/docs/src/extend/ways-to-extend.md +++ b/docs/src/extend/ways-to-extend.md @@ -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).