diff --git a/README.md b/README.md index 5c6b3b89..b90865f3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [Svelte] parser for [ESLint]. You can check it on [Online DEMO](https://sveltejs.github.io/svelte-eslint-parser/playground). -***Note that this parser has experimental support for Svelte v5, but may break with new versions of Svelte v5.*** +**_Note that this parser has experimental support for Svelte v5, but may break with new versions of Svelte v5._** [![NPM license](https://img.shields.io/npm/l/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser) [![NPM version](https://img.shields.io/npm/v/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser) @@ -50,21 +50,41 @@ npm install --save-dev eslint svelte-eslint-parser ## 📖 Usage -1. Write `overrides.parser` option into your `.eslintrc.*` file. +1. Write `parser` option into your ESLint Config file. 2. Use glob patterns or `--ext .svelte` CLI option. +### ESLint Config (`eslint.config.js`) + +```js +import js from "@eslint/js"; +import svelteParser from "svelte-eslint-parser"; +export default [ + js.configs.recommended, + { + files: ["**/*.svelte", "*.svelte"], + languageOptions: { + parser: svelteParser, + }, + }, +]; +``` + +### ESLint Config (`.eslintrc.*`) + ```json { - "extends": "eslint:recommended", - "overrides": [ - { - "files": ["*.svelte"], - "parser": "svelte-eslint-parser" - } - ] + "extends": "eslint:recommended", + "overrides": [ + { + "files": ["*.svelte"], + "parser": "svelte-eslint-parser" + } + ] } ``` +### CLI + ```console $ eslint "src/**/*.{js,svelte}" # or @@ -73,40 +93,92 @@ $ eslint src --ext .svelte ## 🔧 Options -`parserOptions` has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting. +[`parserOptions`] has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting. For example: ```json { - "parser": "svelte-eslint-parser", - "parserOptions": { - "sourceType": "module", - "ecmaVersion": 2021, - "ecmaFeatures": { - "globalReturn": false, - "impliedStrict": false, - "jsx": false - } + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 2021, + "ecmaFeatures": { + "globalReturn": false, + "impliedStrict": false, + "jsx": false } + } } ``` +[`parserOptions`]: https://eslint.org/docs/latest/use/configure/parser#configure-parser-options + ### parserOptions.parser You can use `parserOptions.parser` property to specify a custom parser to parse `