From 60dbacd9fef052bda46aa96ed1152abc49791f73 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Sat, 20 Jul 2024 19:05:31 +0900 Subject: [PATCH] move playground --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- README.md | 2 +- .../lib/components/ESLintPlayground.svelte | 278 ------------------ .../src/lib/eslint/RulesSettings.svelte | 268 ----------------- .../src/lib/eslint/scripts/json.js | 68 ----- .../lib/eslint/scripts/state/deserialize.js | 46 --- .../src/lib/eslint/scripts/state/index.js | 2 - .../src/lib/eslint/scripts/state/serialize.js | 43 --- docs-svelte-kit/src/lib/header/Header.svelte | 10 +- docs-svelte-kit/src/lib/utils.js | 2 - docs/README.md | 2 +- docs/playground.md | 12 - 12 files changed, 11 insertions(+), 724 deletions(-) delete mode 100644 docs-svelte-kit/src/lib/components/ESLintPlayground.svelte delete mode 100644 docs-svelte-kit/src/lib/eslint/RulesSettings.svelte delete mode 100644 docs-svelte-kit/src/lib/eslint/scripts/json.js delete mode 100644 docs-svelte-kit/src/lib/eslint/scripts/state/deserialize.js delete mode 100644 docs-svelte-kit/src/lib/eslint/scripts/state/index.js delete mode 100644 docs-svelte-kit/src/lib/eslint/scripts/state/serialize.js delete mode 100644 docs/playground.md 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..610a270d6 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._** diff --git a/docs-svelte-kit/src/lib/components/ESLintPlayground.svelte b/docs-svelte-kit/src/lib/components/ESLintPlayground.svelte deleted file mode 100644 index ce705f0af..000000000 --- a/docs-svelte-kit/src/lib/components/ESLintPlayground.svelte +++ /dev/null @@ -1,278 +0,0 @@ - - - - -
-
- {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 @@ - - -
-
- - -
-
    - {#each filteredCategories as category (category.title)} - {#if category.rules.length} -
  • - -
    - -
    - - {#if !categoryState[category.title].close} -
      - {#each category.rules as rule (rule.ruleId)} -
    • - - -
    • - {/each} -
    - {/if} -
  • - {/if} - {/each} -
-
- - 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 +