From 473ffe9f7d5b6c032a8039a7c847d6b6d6cab888 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 12 Jan 2022 19:32:21 +0900 Subject: [PATCH] Support for svelte v3.46 syntax --- package.json | 2 +- src/rules/indent-helpers/svelte.ts | 9 ++++ .../indent/invalid/const-tag01-errors.json | 47 +++++++++++++++++++ .../indent/invalid/const-tag01-input.svelte | 17 +++++++ .../indent/invalid/const-tag01-output.svelte | 17 +++++++ .../indent/invalid/deubg-tag01-errors.json | 22 +++++++++ .../indent/invalid/deubg-tag01-input.svelte | 7 +++ .../indent/invalid/deubg-tag01-output.svelte | 7 +++ 8 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/rules/indent/invalid/const-tag01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/const-tag01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/const-tag01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/deubg-tag01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/deubg-tag01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/deubg-tag01-output.svelte diff --git a/package.json b/package.json index 963dfc8b1..53ce491ee 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "debug": "^4.3.1", "eslint-utils": "^3.0.0", "sourcemap-codec": "^1.4.8", - "svelte-eslint-parser": "^0.9.0" + "svelte-eslint-parser": "^0.10.0" }, "peerDependencies": { "eslint": "^7.0.0 || ^8.0.0-0", diff --git a/src/rules/indent-helpers/svelte.ts b/src/rules/indent-helpers/svelte.ts index c3868644e..184555439 100644 --- a/src/rules/indent-helpers/svelte.ts +++ b/src/rules/indent-helpers/svelte.ts @@ -206,6 +206,15 @@ export function defineVisitor(context: IndentContext): NodeListener { const closeToken = sourceCode.getLastToken(node) offsets.setOffsetElementList(node.identifiers, openToken, closeToken, 1) }, + SvelteConstTag(node: AST.SvelteConstTag) { + const openToken = sourceCode.getFirstToken(node) + const constToken = sourceCode.getTokenAfter(openToken) + const declarationToken = sourceCode.getFirstToken(node.declaration) + const closeToken = sourceCode.getLastToken(node) + offsets.setOffsetToken(constToken, 1, openToken) + offsets.setOffsetToken(declarationToken, 1, openToken) + offsets.setOffsetToken(closeToken, 0, openToken) + }, // ---------------------------------------------------------------------- // BLOCKS // ---------------------------------------------------------------------- diff --git a/tests/fixtures/rules/indent/invalid/const-tag01-errors.json b/tests/fixtures/rules/indent/invalid/const-tag01-errors.json new file mode 100644 index 000000000..9e82da825 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/const-tag01-errors.json @@ -0,0 +1,47 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 16, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/const-tag01-input.svelte b/tests/fixtures/rules/indent/invalid/const-tag01-input.svelte new file mode 100644 index 000000000..25c7353d6 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/const-tag01-input.svelte @@ -0,0 +1,17 @@ + + + + +{#each boxes as box} +{ +@const +area += +box.width +* +box.height +} +{box.width} * {box.height} = {area} +{/each} diff --git a/tests/fixtures/rules/indent/invalid/const-tag01-output.svelte b/tests/fixtures/rules/indent/invalid/const-tag01-output.svelte new file mode 100644 index 000000000..556be6016 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/const-tag01-output.svelte @@ -0,0 +1,17 @@ + + + + +{#each boxes as box} + { + @const + area + = + box.width + * + box.height + } + {box.width} * {box.height} = {area} +{/each} diff --git a/tests/fixtures/rules/indent/invalid/deubg-tag01-errors.json b/tests/fixtures/rules/indent/invalid/deubg-tag01-errors.json new file mode 100644 index 000000000..7687cd41b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/deubg-tag01-errors.json @@ -0,0 +1,22 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 6, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/deubg-tag01-input.svelte b/tests/fixtures/rules/indent/invalid/deubg-tag01-input.svelte new file mode 100644 index 000000000..1fd5f7ab7 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/deubg-tag01-input.svelte @@ -0,0 +1,7 @@ + +{ +@debug +var1 +, +var2 +} diff --git a/tests/fixtures/rules/indent/invalid/deubg-tag01-output.svelte b/tests/fixtures/rules/indent/invalid/deubg-tag01-output.svelte new file mode 100644 index 000000000..811ebd2f3 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/deubg-tag01-output.svelte @@ -0,0 +1,7 @@ + +{ + @debug + var1 + , + var2 +}