diff --git a/README.md b/README.md index 01eb6bdfa..2b446eb49 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,4 @@ -# Introduction - -`eslint-plugin-svelte` is the official [ESLint] plugin for [Svelte]. -It provides many unique check rules by using the template AST. -You can check on the [Online DEMO](https://eslint-online-playground.netlify.app/#eslint-plugin-svelte%20with%20typescript). - -> [!NOTE] -> This document is in development.\ -> Please refer to the document for the version you are using.\ -> For example, -> and + [![NPM license](https://img.shields.io/npm/l/eslint-plugin-svelte.svg)](https://www.npmjs.com/package/eslint-plugin-svelte) [![NPM version](https://img.shields.io/npm/v/eslint-plugin-svelte.svg)](https://www.npmjs.com/package/eslint-plugin-svelte) @@ -24,253 +14,224 @@ You can check on the [Online DEMO](https://eslint-online-playground.netlify.app/ [![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/atlassian/changesets) -## :name_badge: What is this plugin? - -[ESLint] plugin for [Svelte]. -It provides many unique check rules using the AST generated by [svelte-eslint-parser]. - -### ❗ Attention - -#### Cannot be used with eslint-plugin-svelte3 - -The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3]. +
-[svelte-eslint-parser]: https://github.com/sveltejs/svelte-eslint-parser -[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3 +# eslint-plugin-svelte -#### Experimental support for Svelte v5 +## ESLint plugin for Svelte using AST -We are working on support for Svelte v5, but it is still an experimental feature. Please note that rules and features related to Svelte v5 may be changed or removed in minor versions without notice. +[Live Demo](https://eslint-online-playground.netlify.app/#eslint-plugin-svelte%20with%20typescript) • +[Documentation](https://sveltejs.github.io/eslint-plugin-svelte/) • +[Discord](https://svelte.dev/chat) - - -## Versioning policy - -This plugin follows [Semantic Versioning](https://semver.org/). -However, unlike [ESLint’s Semantic Versioning Policy](https://github.com/eslint/eslint#semantic-versioning-policy), this plugin adds new rules to its configs even in minor releases. For example, if you are using the recommended config, a minor update may add new rules, which could cause new lint errors in your project. -While [ESLint’s Semantic Versioning Policy](https://github.com/eslint/eslint#semantic-versioning-policy) only adds new rules to configs in major releases, most users (myself included) don’t regularly monitor new rules. This makes it challenging to manually add them to projects whenever they are introduced. -By adding new rules to configs in minor releases, this plugin ensures users can adopt them more easily. If any new rules cause issues, you can simply disable them. I believe this approach helps maintain and improve code quality with minimal effort. - -## Migration Guide +
-To migrate from `eslint-plugin-svelte` v1, or [`@ota-meshi/eslint-plugin-svelte`](https://www.npmjs.com/package/@ota-meshi/eslint-plugin-svelte), please refer to the [migration guide](https://sveltejs.github.io/eslint-plugin-svelte/migration/). + -## :book: Documentation +## Introduction -See [documents](https://sveltejs.github.io/eslint-plugin-svelte/). +`eslint-plugin-svelte` is the official [ESLint](https://eslint.org/) plugin for [Svelte](https://svelte.dev/). +It leverages the AST generated by [svelte-eslint-parser](https://github.com/sveltejs/svelte-eslint-parser) to provide custom linting for Svelte. +Note that `eslint-plugin-svelte` and `svelte-eslint-parser` cannot be used alongside [eslint-plugin-svelte3](https://github.com/sveltejs/eslint-plugin-svelte3). -## :cd: Installation +## Installation ```bash -npm install --save-dev eslint eslint-plugin-svelte svelte +npm install --save-dev svelte eslint eslint-plugin-svelte globals ``` -> **Requirements** +> [!NOTE] > -> - ESLint v8.57.1, v9.0.0 and above -> - Node.js v18.20.4, v20.18.0, v22.10.0 and above - - +> **Requirements:** +> +> - ESLint v8.57.1, v9.0.0, and above +> - Node.js v18.20.4, v20.18.0, v22.10.0, and above -## :book: Usage +## Configuration -### Configuration +Use the `eslint.config.js` file to configure rules. For more details, see the [ESLint documentation](https://eslint.org/docs/latest/use/configure/configuration-files-new). -Use `eslint.config.js` file to configure rules. See also: . - -Example **eslint.config.js**: +### JavaScript project ```js -import eslintPluginSvelte from 'eslint-plugin-svelte'; +// eslint.config.js +import js from '@eslint/js'; +import svelte from 'eslint-plugin-svelte'; +import globals from 'globals'; +import svelteConfig from './svelte.config.js'; + +/** @type {import('eslint').Linter.Config[]} */ export default [ - // add more generic rule sets here, such as: - // js.configs.recommended, - ...eslintPluginSvelte.configs.recommended, + js.configs.recommended, + ...svelte.configs.recommended, + { + languageOptions: { + globals: { + ...globals.browser, + ...globals.node // Add this if you are using SvelteKit in non-SPA mode + } + } + }, + { + files: [ + '*.svelte', + '**/*.svelte', + '*.svelte.ts', + '**/*.svelte.ts', + '*.svelte.js', + '**/*.svelte.js' + ], + languageOptions: { + parserOptions: { + // We recommend importing and specifying svelte.config.js. + // By doing so, some rules in eslint-plugin-svelte will automatically read the configuration and adjust their behavior accordingly. + // While certain Svelte settings may be statically loaded from svelte.config.js even if you don’t specify it, + // explicitly specifying it ensures better compatibility and functionality. + svelteConfig + } + } + }, { rules: { - // override/add rules settings here, such as: + // Override or add rule settings here, such as: // 'svelte/rule-name': 'error' } } ]; ``` -This plugin provides configs: - -- `eslintPluginSvelte.configs.base` ... Configuration to enable correct Svelte parsing. -- `eslintPluginSvelte.configs.recommended` ... Above, plus rules to prevent errors or unintended behavior. -- `eslintPluginSvelte.configs.prettier` ... Turns off rules that may conflict with [Prettier](https://prettier.io/) (You still need to configure prettier to work with svelte yourself, for example by using [prettier-plugin-svelte](https://github.com/sveltejs/prettier-plugin-svelte).). -- `eslintPluginSvelte.configs.all` ... All rules. This configuration is not recommended for production use because it changes with every minor and major version of `eslint-plugin-svelte`. Use it at your own risk. +### TypeScript project -See [the rule list](https://sveltejs.github.io/eslint-plugin-svelte/rules/) to get the `rules` that this plugin provides. - -#### Parser Configuration - -If you have specified a parser, you need to configure a parser for `.svelte`. - -For example, if you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `