diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 71b3c970b..ce9bdc71a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -79,7 +79,7 @@ body: placeholder: | https://github.com/[your]/[repo] or - https://sveltejs.github.io/eslint-plugin-svelte/playground/#[hash] + https://eslint-online-playground.netlify.app/#[hash] validations: required: true - type: textarea diff --git a/README.md b/README.md index 9a6c25600..5a16a8666 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ `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://sveltejs.github.io/eslint-plugin-svelte/playground/). +You can check on the [Online DEMO](https://eslint-online-playground.netlify.app/#eslint-plugin-svelte%20with%20typescript). **_We are working on experimental support for Svelte v5, but may break with new versions of Svelte v5._** @@ -44,11 +44,11 @@ We are working on support for Svelte v5, but it is still an experimental feature 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 +## 📖 Documentation See [documents](https://sveltejs.github.io/eslint-plugin-svelte/). -## :cd: Installation +## 💿 Installation ```bash npm install --save-dev eslint eslint-plugin-svelte svelte @@ -61,7 +61,7 @@ npm install --save-dev eslint eslint-plugin-svelte svelte -## :book: Usage +## 📖 Usage @@ -343,7 +343,7 @@ eslint --ext .js,.svelte src eslint "src/**/*.{js,svelte}" ``` -## :computer: Editor Integrations +## 💻 Editor Integrations ### Visual Studio Code @@ -367,9 +367,9 @@ Example **.vscode/settings.json**: -:wrench: Indicates that the rule is fixable, and using `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the reported problems. -:bulb: Indicates that some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). -:star: Indicates that the rule is included in the `plugin:svelte/recommended` config. +🔧 Indicates that the rule is fixable, and using `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the reported problems. +💡 Indicates that some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). +⭐️ Indicates that the rule is included in the `plugin:svelte/recommended` config. @@ -381,21 +381,21 @@ These rules relate to possible syntax or logic errors in Svelte code: |:--------|:------------|:---| | [svelte/infinite-reactive-loop](https://sveltejs.github.io/eslint-plugin-svelte/rules/infinite-reactive-loop/) | Svelte runtime prevents calling the same reactive statement twice in a microtask. But between different microtask, it doesn't prevent. | | | [svelte/no-dom-manipulating](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/) | disallow DOM manipulating | | -| [svelte/no-dupe-else-if-blocks](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks/) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: | +| [svelte/no-dupe-else-if-blocks](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks/) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | ⭐️ | | [svelte/no-dupe-on-directives](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-on-directives/) | disallow duplicate `on:` directives | | -| [svelte/no-dupe-style-properties](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-style-properties/) | disallow duplicate style properties | :star: | +| [svelte/no-dupe-style-properties](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-style-properties/) | disallow duplicate style properties | ⭐️ | | [svelte/no-dupe-use-directives](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-use-directives/) | disallow duplicate `use:` directives | | -| [svelte/no-dynamic-slot-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dynamic-slot-name/) | disallow dynamic slot name | :star::wrench: | +| [svelte/no-dynamic-slot-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dynamic-slot-name/) | disallow dynamic slot name | ⭐️🔧 | | [svelte/no-export-load-in-svelte-module-in-kit-pages](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-export-load-in-svelte-module-in-kit-pages/) | disallow exporting load functions in `*.svelte` module in SvelteKit page components. | | -| [svelte/no-not-function-handler](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-not-function-handler/) | disallow use of not function in event handler | :star: | -| [svelte/no-object-in-text-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches/) | disallow objects in text mustache interpolation | :star: | +| [svelte/no-not-function-handler](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-not-function-handler/) | disallow use of not function in event handler | ⭐️ | +| [svelte/no-object-in-text-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches/) | disallow objects in text mustache interpolation | ⭐️ | | [svelte/no-reactive-reassign](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-reassign/) | disallow reassigning reactive values | | -| [svelte/no-shorthand-style-property-overrides](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-shorthand-style-property-overrides/) | disallow shorthand style properties that override related longhand properties | :star: | +| [svelte/no-shorthand-style-property-overrides](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-shorthand-style-property-overrides/) | disallow shorthand style properties that override related longhand properties | ⭐️ | | [svelte/no-store-async](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-store-async/) | disallow using async/await inside svelte stores because it causes issues with the auto-unsubscribing features | | -| [svelte/no-unknown-style-directive-property](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unknown-style-directive-property/) | disallow unknown `style:property` | :star: | +| [svelte/no-unknown-style-directive-property](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unknown-style-directive-property/) | disallow unknown `style:property` | ⭐️ | | [svelte/require-store-callbacks-use-set-param](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-store-callbacks-use-set-param/) | store callbacks must use `set` param | | -| [svelte/require-store-reactive-access](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-store-reactive-access/) | disallow to use of the store itself as an operand. Need to use $ prefix or get function. | :wrench: | -| [svelte/valid-compile](https://sveltejs.github.io/eslint-plugin-svelte/rules/valid-compile/) | disallow warnings when compiling. | :star: | +| [svelte/require-store-reactive-access](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-store-reactive-access/) | disallow to use of the store itself as an operand. Need to use $ prefix or get function. | 🔧 | +| [svelte/valid-compile](https://sveltejs.github.io/eslint-plugin-svelte/rules/valid-compile/) | disallow warnings when compiling. | ⭐️ | | [svelte/valid-prop-names-in-kit-pages](https://sveltejs.github.io/eslint-plugin-svelte/rules/valid-prop-names-in-kit-pages/) | disallow props other than data or errors in SvelteKit page components. | | ## Security Vulnerability @@ -404,7 +404,7 @@ These rules relate to security vulnerabilities in Svelte code: | Rule ID | Description | | |:--------|:------------|:---| -| [svelte/no-at-html-tags](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-at-html-tags/) | disallow use of `{@html}` to prevent XSS attack | :star: | +| [svelte/no-at-html-tags](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-at-html-tags/) | disallow use of `{@html}` to prevent XSS attack | ⭐️ | | [svelte/no-target-blank](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-target-blank/) | disallow `target="_blank"` attribute without `rel="noopener noreferrer"` | | ## Best Practices @@ -415,17 +415,17 @@ These rules relate to better ways of doing things to help you avoid problems: |:--------|:------------|:---| | [svelte/block-lang](https://sveltejs.github.io/eslint-plugin-svelte/rules/block-lang/) | disallows the use of languages other than those specified in the configuration for the lang attribute of ` - - - -
-
- {time} -
-
- -
- -
-
    - {#each messages as msg, i (`${msg.line}:${msg.column}:${msg.ruleId}@${i}`)} -
  1. - : - {msg.message} - ({msg.ruleId}) -
  2. - {/each} -
-
-
-
-
- - diff --git a/docs-svelte-kit/src/lib/eslint/RulesSettings.svelte b/docs-svelte-kit/src/lib/eslint/RulesSettings.svelte deleted file mode 100644 index 8fdf4ada0..000000000 --- a/docs-svelte-kit/src/lib/eslint/RulesSettings.svelte +++ /dev/null @@ -1,268 +0,0 @@ - - -
-
- - -
- -
- - diff --git a/docs-svelte-kit/src/lib/eslint/scripts/json.js b/docs-svelte-kit/src/lib/eslint/scripts/json.js deleted file mode 100644 index 43a17bafb..000000000 --- a/docs-svelte-kit/src/lib/eslint/scripts/json.js +++ /dev/null @@ -1,68 +0,0 @@ -export function processJsonValue(options, ctx, value) { - const type = typeof value; - if (type === 'string' || type === 'number' || type === 'boolean' || value === null) { - ctx.appendText(JSON.stringify(value)); - return; - } else if (type !== 'object') { - ctx.appendText('"?"'); - return; - } - if (Array.isArray(value)) { - ctx.appendText('[\n').indent(); - const arr = [...value]; - while (arr.length) { - ctx.appendIndent(); - const e = arr.shift(); - processJsonValue(options, ctx, e); - if (arr.length) { - ctx.appendText(','); - } - ctx.appendText('\n'); - } - ctx.outdent().appendIndent().appendText(']'); - } else { - let entries = Object.entries(value); - const valueIsNode = isNode(value); - if (valueIsNode) { - ctx.pushNode(value); - const typeEntry = entries.find(([key]) => key === 'type'); - const locEntries = options.showLocations - ? entries.filter(([key]) => key === 'loc' || key === 'range') - : []; - entries = entries.filter( - ([key]) => - key !== 'type' && - key !== 'loc' && - key !== 'range' && - key !== 'parent' && - !((key === 'start' || key === 'end') && typeof value.start === 'number') - ); - if (typeEntry) entries.unshift(typeEntry); - entries.push(...locEntries); - } - ctx.appendText('{\n').indent(); - while (entries.length) { - const [key, val] = entries.shift(); - ctx.appendIndent(); - processJsonValue(options, ctx, key); - ctx.appendText(': '); - processJsonValue(options, ctx, val); - if (entries.length) { - ctx.appendText(','); - } - ctx.appendText('\n'); - } - ctx.outdent().appendIndent().appendText('}'); - - if (valueIsNode) { - ctx.popNode(); - } - } -} - -/** - * Check if given value is node - */ -function isNode(value) { - return value != null && Array.isArray(value.range) && 'loc' in value && 'type' in value; -} diff --git a/docs-svelte-kit/src/lib/eslint/scripts/state/deserialize.js b/docs-svelte-kit/src/lib/eslint/scripts/state/deserialize.js deleted file mode 100644 index ab8ffdfe3..000000000 --- a/docs-svelte-kit/src/lib/eslint/scripts/state/deserialize.js +++ /dev/null @@ -1,46 +0,0 @@ -import pako from 'pako'; - -/** - * Deserialize a given serialized string then update this object. - * @param {string} serializedString A serialized string. - * @returns {object} The deserialized state. - */ -export function deserializeState(serializedString) { - const state = { - code: undefined, - rules: undefined - }; - - if (serializedString === '') { - return state; - } - - try { - const compressedString = window.atob(serializedString); - const uint8Arr = pako.inflate(Uint8Array.from(compressedString, (c) => c.charCodeAt(0))); - - const jsonText = new TextDecoder().decode(uint8Arr); - const json = JSON.parse(jsonText); - - if (typeof json === 'object' && json != null) { - if (typeof json.code === 'string') { - state.code = json.code; - } - if (json.useEslintPluginSvelte3 === true) { - state.useEslintPluginSvelte3 = true; - } - - if (typeof json.rules === 'object' && json.rules != null) { - state.rules = {}; - for (const id of Object.keys(json.rules)) { - state.rules[id] = json.rules[id] === 2 ? 'error' : 'off'; - } - } - } - } catch (error) { - // eslint-disable-next-line no-console -- Demo - console.error(error); - } - - return state; -} diff --git a/docs-svelte-kit/src/lib/eslint/scripts/state/index.js b/docs-svelte-kit/src/lib/eslint/scripts/state/index.js deleted file mode 100644 index e04dbd277..000000000 --- a/docs-svelte-kit/src/lib/eslint/scripts/state/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from './deserialize'; -export * from './serialize'; diff --git a/docs-svelte-kit/src/lib/eslint/scripts/state/serialize.js b/docs-svelte-kit/src/lib/eslint/scripts/state/serialize.js deleted file mode 100644 index 02d0b8d80..000000000 --- a/docs-svelte-kit/src/lib/eslint/scripts/state/serialize.js +++ /dev/null @@ -1,43 +0,0 @@ -import pako from 'pako'; - -/** - * Get only enabled rules to make the serialized data smaller. - * @param {object} allRules The rule settings. - * @returns {object} The rule settings for the enabled rules. - */ -function getEnabledRules(allRules) { - return Object.keys(allRules).reduce((map, id) => { - if (allRules[id] === 'error') { - map[id] = 2; - } - return map; - }, {}); -} - -/** - * Serialize a given state as a base64 string. - * @param {State} state The state to serialize. - * @returns {string} The serialized string. - */ -export function serializeState(state) { - const saveData = { - code: state.code, - rules: state.rules ? getEnabledRules(state.rules) : undefined, - useEslintPluginSvelte3: state.useEslintPluginSvelte3 - }; - const jsonString = JSON.stringify(saveData); - - const uint8Arr = new TextEncoder().encode(jsonString); - const compressedString = String.fromCharCode(...pako.deflate(uint8Arr)); - const base64 = - (typeof window !== 'undefined' && window.btoa(compressedString)) || compressedString; - - // eslint-disable-next-line no-console -- Demo - console.log( - `The compress rate of serialized string: ${((100 * base64.length) / jsonString.length).toFixed( - 1 - )}% (${jsonString.length}B → ${base64.length}B)` - ); - - return base64; -} diff --git a/docs-svelte-kit/src/lib/header/Header.svelte b/docs-svelte-kit/src/lib/header/Header.svelte index 0fc55b112..39a867218 100644 --- a/docs-svelte-kit/src/lib/header/Header.svelte +++ b/docs-svelte-kit/src/lib/header/Header.svelte @@ -53,8 +53,14 @@
  • Rules
  • -
  • - Playground +
  • + + Playground +