From 9baef952e83a8e07acfc476193666768e58c3994 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 20 Jun 2021 12:11:32 +0900 Subject: [PATCH 1/2] Add indent rule --- README.md | 1 + docs/rules/README.md | 1 + docs/rules/indent.md | 75 ++ package.json | 1 + src/rules/indent-helpers/ast.ts | 22 + src/rules/indent-helpers/commons.ts | 135 +++ src/rules/indent-helpers/es.ts | 997 ++++++++++++++++++ src/rules/indent-helpers/index.ts | 416 ++++++++ src/rules/indent-helpers/svelte.ts | 494 +++++++++ src/rules/indent.ts | 46 + src/types.ts | 8 +- src/utils/rules.ts | 2 + .../rules/indent/invalid/.eslintrc.js | 8 + .../indent/invalid/4-indent/_config.json | 3 + .../invalid/4-indent/test01-errors.json | 367 +++++++ .../invalid/4-indent/test01-input.svelte | 96 ++ .../invalid/4-indent/test01-output.svelte | 96 ++ .../rules/indent/invalid/await01-errors.json | 352 +++++++ .../rules/indent/invalid/await01-input.svelte | 85 ++ .../indent/invalid/await01-output.svelte | 85 ++ .../rules/indent/invalid/each01-errors.json | 292 +++++ .../rules/indent/invalid/each01-input.svelte | 77 ++ .../rules/indent/invalid/each01-output.svelte | 77 ++ .../rules/indent/invalid/if01-errors.json | 157 +++ .../rules/indent/invalid/if01-input.svelte | 40 + .../rules/indent/invalid/if01-output.svelte | 40 + .../rules/indent/invalid/key01-errors.json | 57 + .../rules/indent/invalid/key01-input.svelte | 23 + .../rules/indent/invalid/key01-output.svelte | 23 + .../indent/invalid/script-array01-errors.json | 102 ++ .../invalid/script-array01-input.svelte | 25 + .../invalid/script-array01-output.svelte | 25 + .../invalid/script-binary01-errors.json | 212 ++++ .../invalid/script-binary01-input.svelte | 48 + .../invalid/script-binary01-output.svelte | 48 + .../indent/invalid/script-block01-errors.json | 27 + .../invalid/script-block01-input.svelte | 10 + .../invalid/script-block01-output.svelte | 10 + .../indent/invalid/script-break01-errors.json | 117 ++ .../invalid/script-break01-input.svelte | 28 + .../invalid/script-break01-output.svelte | 28 + .../indent/invalid/script-call01-errors.json | 182 ++++ .../indent/invalid/script-call01-input.svelte | 44 + .../invalid/script-call01-output.svelte | 44 + .../indent/invalid/script-class01-errors.json | 247 +++++ .../invalid/script-class01-input.svelte | 57 + .../invalid/script-class01-output.svelte | 57 + .../invalid/script-conditional01-errors.json | 242 +++++ .../invalid/script-conditional01-input.svelte | 55 + .../script-conditional01-output.svelte | 55 + .../invalid/script-do-while01-errors.json | 42 + .../invalid/script-do-while01-input.svelte | 13 + .../invalid/script-do-while01-output.svelte | 13 + .../invalid/script-export01-errors.json | 232 ++++ .../invalid/script-export01-input.svelte | 51 + .../invalid/script-export01-output.svelte | 51 + .../indent/invalid/script-expr01-errors.json | 142 +++ .../indent/invalid/script-expr01-input.svelte | 33 + .../invalid/script-expr01-output.svelte | 33 + .../indent/invalid/script-for01-errors.json | 292 +++++ .../indent/invalid/script-for01-input.svelte | 63 ++ .../indent/invalid/script-for01-output.svelte | 63 ++ .../invalid/script-function01-errors.json | 232 ++++ .../invalid/script-function01-input.svelte | 54 + .../invalid/script-function01-output.svelte | 54 + .../indent/invalid/script-if01-errors.json | 297 ++++++ .../indent/invalid/script-if01-input.svelte | 68 ++ .../indent/invalid/script-if01-output.svelte | 68 ++ .../invalid/script-import01-errors.json | 232 ++++ .../invalid/script-import01-input.svelte | 58 + .../invalid/script-import01-output.svelte | 58 + .../invalid/script-member01-errors.json | 152 +++ .../invalid/script-member01-input.svelte | 38 + .../invalid/script-member01-output.svelte | 38 + .../indent/invalid/script-prop01-errors.json | 142 +++ .../indent/invalid/script-prop01-input.svelte | 33 + .../invalid/script-prop01-output.svelte | 33 + .../invalid/script-switch01-errors.json | 107 ++ .../invalid/script-switch01-input.svelte | 26 + .../invalid/script-switch01-output.svelte | 26 + .../indent/invalid/script-try01-errors.json | 197 ++++ .../indent/invalid/script-try01-input.svelte | 45 + .../indent/invalid/script-try01-output.svelte | 45 + .../indent/invalid/script-unary01-errors.json | 132 +++ .../invalid/script-unary01-input.svelte | 31 + .../invalid/script-unary01-output.svelte | 31 + .../indent/invalid/switch-case/_config.json | 3 + .../switch-case/script-switch01-errors.json | 107 ++ .../switch-case/script-switch01-input.svelte | 26 + .../switch-case/script-switch01-output.svelte | 26 + .../indent/invalid/tab-indent/_config.json | 3 + .../invalid/tab-indent/test01-errors.json | 367 +++++++ .../invalid/tab-indent/test01-input.svelte | 96 ++ .../invalid/tab-indent/test01-output.svelte | 96 ++ .../invalid/tab-indent/test02-errors.json | 367 +++++++ .../invalid/tab-indent/test02-input.svelte | 96 ++ .../invalid/tab-indent/test02-output.svelte | 96 ++ .../rules/indent/invalid/test01-errors.json | 367 +++++++ .../rules/indent/invalid/test01-input.svelte | 96 ++ .../rules/indent/invalid/test01-output.svelte | 96 ++ .../rules/indent/valid/test01-input.svelte | 96 ++ tests/src/rules/indent.ts | 12 + tests/utils/utils.ts | 6 +- tools/lib/load-rules.ts | 5 +- typings/eslint-utils/index.d.ts | 24 + 105 files changed, 10945 insertions(+), 4 deletions(-) create mode 100644 docs/rules/indent.md create mode 100644 src/rules/indent-helpers/ast.ts create mode 100644 src/rules/indent-helpers/commons.ts create mode 100644 src/rules/indent-helpers/es.ts create mode 100644 src/rules/indent-helpers/index.ts create mode 100644 src/rules/indent-helpers/svelte.ts create mode 100644 src/rules/indent.ts create mode 100644 tests/fixtures/rules/indent/invalid/.eslintrc.js create mode 100644 tests/fixtures/rules/indent/invalid/4-indent/_config.json create mode 100644 tests/fixtures/rules/indent/invalid/4-indent/test01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/4-indent/test01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/4-indent/test01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/await01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/await01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/await01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/each01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/each01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/each01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/if01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/if01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/if01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/key01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/key01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/key01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-array01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-array01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-array01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-binary01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-binary01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-binary01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-block01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-block01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-block01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-break01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-break01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-break01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-call01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-call01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-call01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-class01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-class01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-class01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-conditional01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-conditional01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-conditional01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-do-while01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-do-while01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-do-while01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-export01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-export01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-export01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-expr01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-expr01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-expr01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-for01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-for01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-for01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-function01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-function01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-function01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-if01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-if01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-if01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-import01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-import01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-import01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-member01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-member01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-member01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-prop01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-prop01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-prop01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-switch01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-switch01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-switch01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-try01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-try01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-try01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-unary01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-unary01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-unary01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/switch-case/_config.json create mode 100644 tests/fixtures/rules/indent/invalid/switch-case/script-switch01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/switch-case/script-switch01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/switch-case/script-switch01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/tab-indent/_config.json create mode 100644 tests/fixtures/rules/indent/invalid/tab-indent/test01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/tab-indent/test01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/tab-indent/test01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/tab-indent/test02-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/tab-indent/test02-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/tab-indent/test02-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/test01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/test01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/test01-output.svelte create mode 100644 tests/fixtures/rules/indent/valid/test01-input.svelte create mode 100644 tests/src/rules/indent.ts create mode 100644 typings/eslint-utils/index.d.ts diff --git a/README.md b/README.md index e41b4fa83..e1fa4772a 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,7 @@ The rules with the following star :star: are included in the configs. |:--------|:------------|:---| | [@ota-meshi/svelte/button-has-type](https://ota-meshi.github.io/eslint-plugin-svelte/rules/button-has-type.html) | disallow usage of button without an explicit type attribute | | | [@ota-meshi/svelte/comment-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/comment-directive.html) | support comment-directives in HTML template | :star: | +| [@ota-meshi/svelte/indent](https://ota-meshi.github.io/eslint-plugin-svelte/rules/indent.html) | enforce consistent indentation | :wrench: | | [@ota-meshi/svelte/max-attributes-per-line](https://ota-meshi.github.io/eslint-plugin-svelte/rules/max-attributes-per-line.html) | enforce the maximum number of attributes per line | :wrench: | | [@ota-meshi/svelte/no-at-debug-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-debug-tags.html) | disallow the use of `{@debug}` | :star: | | [@ota-meshi/svelte/no-at-html-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-html-tags.html) | disallow use of `{@html}` to prevent XSS attack | :star: | diff --git a/docs/rules/README.md b/docs/rules/README.md index 4f32b7739..f0329b559 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -13,6 +13,7 @@ The rules with the following star :star: are included in the `plugin:@ota-meshi/ |:--------|:------------|:---| | [@ota-meshi/svelte/button-has-type](./button-has-type.md) | disallow usage of button without an explicit type attribute | | | [@ota-meshi/svelte/comment-directive](./comment-directive.md) | support comment-directives in HTML template | :star: | +| [@ota-meshi/svelte/indent](./indent.md) | enforce consistent indentation | :wrench: | | [@ota-meshi/svelte/max-attributes-per-line](./max-attributes-per-line.md) | enforce the maximum number of attributes per line | :wrench: | | [@ota-meshi/svelte/no-at-debug-tags](./no-at-debug-tags.md) | disallow the use of `{@debug}` | :star: | | [@ota-meshi/svelte/no-at-html-tags](./no-at-html-tags.md) | disallow use of `{@html}` to prevent XSS attack | :star: | diff --git a/docs/rules/indent.md b/docs/rules/indent.md new file mode 100644 index 000000000..a997b7a99 --- /dev/null +++ b/docs/rules/indent.md @@ -0,0 +1,75 @@ +--- +pageClass: "rule-details" +sidebarDepth: 0 +title: "@ota-meshi/svelte/indent" +description: "enforce consistent indentation" +--- + +# @ota-meshi/svelte/indent + +> enforce consistent indentation + +- :exclamation: **_This rule has not been released yet._** +- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. + +## :book: Rule Details + +This rule enforces a consistent indentation style in `.svelte`. The default style is 2 spaces. + +- This rule checks all tags, also all expressions in directives and mustaches. +- In the expressions, this rule supports ECMAScript 2020 syntaxes. It ignores unknown AST nodes, but it might be confused by non-standard syntaxes. + + + + + +```html + + + + + + + +``` + + + +## :wrench: Options + +```json +{ + "@ota-meshi/svelte/indent": [ + "error", + { + "indent": 2, + "ignoredNodes": [], + "switchCase": 1 + } + ] +} +``` + +- `indent` (`number | "tab"`) ... The type of indentation. Default is `2`. If this is a number, it's the number of spaces for one indent. If this is `"tab"`, it uses one tab for one indent. +- `ignoredNodes` ... Can be used to disable indentation checking for any AST node. This accepts an array of [selectors](https://eslint.org/docs/developer-guide/selectors). If an AST node is matched by any of the selectors, the indentation of tokens which are direct children of that node will be ignored. This can be used as an escape hatch to relax the rule if you disagree with the indentation that it enforces for a particular syntactic pattern. +- `switchCase` ... Enforces indentation level for case clauses in switch statements. Default is `1`. + +## :mag: Implementation + +- [Rule source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/src/rules/indent.ts) +- [Test source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/tests/src/rules/indent.ts) diff --git a/package.json b/package.json index 4d4eea4bc..9f212498d 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "homepage": "https://github.com/ota-meshi/eslint-plugin-svelte#readme", "dependencies": { "debug": "^4.3.1", + "eslint-utils": "^3.0.0", "svelte-eslint-parser": "^0.3.0" }, "peerDependencies": { diff --git a/src/rules/indent-helpers/ast.ts b/src/rules/indent-helpers/ast.ts new file mode 100644 index 000000000..2cbcfc973 --- /dev/null +++ b/src/rules/indent-helpers/ast.ts @@ -0,0 +1,22 @@ +import type { AST } from "svelte-eslint-parser" +import type * as ESTree from "estree" +type AnyToken = AST.Token | AST.Comment +/** + * Check whether the given token is a whitespace. + */ +export function isWhitespace( + token: AnyToken | ESTree.Comment | null | undefined, +): boolean { + return token != null && token.type === "HTMLText" && !token.value.trim() +} + +/** + * Check whether the given token is a not whitespace. + */ +export function isNotWhitespace( + token: AnyToken | ESTree.Comment | null | undefined, +): boolean { + return ( + token != null && (token.type !== "HTMLText" || Boolean(token.value.trim())) + ) +} diff --git a/src/rules/indent-helpers/commons.ts b/src/rules/indent-helpers/commons.ts new file mode 100644 index 000000000..d689e86c1 --- /dev/null +++ b/src/rules/indent-helpers/commons.ts @@ -0,0 +1,135 @@ +import type { ASTNode, SourceCode } from "../../types" +import type { AST } from "svelte-eslint-parser" +import { isOpeningParenToken, isClosingParenToken } from "eslint-utils" +import { isNotWhitespace, isWhitespace } from "./ast" + +type AnyToken = AST.Token | AST.Comment + +export type IndentOptions = { + indentChar: " " | "\t" + indentSize: number + switchCase: number + ignoredNodes: string[] +} +export type IndentContext = { + sourceCode: SourceCode + options: IndentOptions + /** + * Set offset to the given tokens. + */ + setOffset: ( + token: AnyToken | null | undefined | (AnyToken | null | undefined)[], + offset: number, + baseToken: AnyToken, + ) => void + /** + * Copy offset to the given tokens from srcToken. + */ + copyOffset: ( + token: AnyToken | null | undefined | (AnyToken | null | undefined)[], + srcToken: AnyToken, + ) => void + + /** + * Set baseline offset to the given token. + */ + setOffsetBaseLine: ( + token: AnyToken | null | undefined | (AnyToken | null | undefined)[], + offset: number, + ) => void + /** + * Ignore all tokens of the given node. + */ + ignore: (node: ASTNode) => void +} + +/** + * Set offset to the given nodes. + * The first node is offsetted from the given base token. + */ +export function setOffsetNodes( + { sourceCode, setOffset }: IndentContext, + nodes: (ASTNode | AnyToken | null | undefined)[], + baseNodeOrToken: ASTNode | AnyToken, + lastNodeOrToken: ASTNode | AnyToken | null, + offset: number, +): void { + const baseToken = sourceCode.getFirstToken(baseNodeOrToken) + + let prevToken = sourceCode.getLastToken(baseNodeOrToken) + for (const node of nodes) { + if (node == null) { + continue + } + const elementTokens = getFirstAndLastTokens( + sourceCode, + node, + prevToken.range[1], + ) + + let t: AnyToken | null = prevToken + while ( + (t = sourceCode.getTokenAfter(t, { + includeComments: true, + filter: isNotWhitespace, + })) != null && + t.range[1] <= elementTokens.firstToken.range[0] + ) { + setOffset(t, offset, baseToken) + } + setOffset(elementTokens.firstToken, offset, baseToken) + + prevToken = elementTokens.lastToken + } + + if (lastNodeOrToken) { + const lastToken = sourceCode.getFirstToken(lastNodeOrToken) + let t: AnyToken | null = prevToken + while ( + (t = sourceCode.getTokenAfter(t, { + includeComments: true, + filter: isNotWhitespace, + })) != null && + t.range[1] <= lastToken.range[0] + ) { + setOffset(t, offset, baseToken) + } + setOffset(lastToken, 0, baseToken) + } +} + +/** + * Get the first and last tokens of the given node. + * If the node is parenthesized, this gets the outermost parentheses. + * If the node have whitespace at the start and the end, they will be skipped. + */ +export function getFirstAndLastTokens( + sourceCode: SourceCode, + node: ASTNode | AnyToken, + borderOffset = 0, +): { firstToken: AST.Token; lastToken: AST.Token } { + let firstToken = sourceCode.getFirstToken(node) + let lastToken = sourceCode.getLastToken(node) + + // Get the outermost left parenthesis if it's parenthesized. + let left: AST.Token | null, right: AST.Token | null + while ( + (left = sourceCode.getTokenBefore(firstToken)) != null && + (right = sourceCode.getTokenAfter(lastToken)) != null && + isOpeningParenToken(left) && + isClosingParenToken(right) && + borderOffset <= left.range[0] + ) { + firstToken = left + lastToken = right + } + + while (isWhitespace(firstToken) && firstToken.range[0] < lastToken.range[0]) { + firstToken = sourceCode.getTokenAfter(firstToken) as AST.Token + } + while (isWhitespace(lastToken) && firstToken.range[0] < lastToken.range[0]) { + lastToken = sourceCode.getTokenBefore(lastToken) as AST.Token + } + + return { firstToken, lastToken } +} diff --git a/src/rules/indent-helpers/es.ts b/src/rules/indent-helpers/es.ts new file mode 100644 index 000000000..0b88abfbf --- /dev/null +++ b/src/rules/indent-helpers/es.ts @@ -0,0 +1,997 @@ +import type { AST } from "svelte-eslint-parser" +import type * as ESTree from "estree" +import type { ASTNode } from "../../types" +import type { IndentContext } from "./commons" +import { getFirstAndLastTokens } from "./commons" +import { setOffsetNodes } from "./commons" +import { + isArrowToken, + isClosingBraceToken, + isClosingBracketToken, + isClosingParenToken, + isNotClosingParenToken, + isNotOpeningParenToken, + isOpeningBraceToken, + isOpeningBracketToken, + isOpeningParenToken, + isSemicolonToken, +} from "eslint-utils" + +type NodeWithParent = + | (Exclude & { parent: ASTNode }) + | AST.SvelteProgram + | AST.SvelteReactiveStatement +type NodeListenerMap = { + [key in NodeWithParent["type"]]: T extends { type: key } ? T : never +} + +type NodeListener = { + [T in keyof NodeListenerMap]: (node: NodeListenerMap[T]) => void +} + +/** + * Creates AST event handlers for ES nodes. + * + * @param context The rule context. + * @returns AST event handlers. + */ +export function defineVisitor(context: IndentContext): NodeListener & { + ":expression": (node: ESTree.Expression) => void + ":statement": (node: ESTree.Statement) => void +} { + const { sourceCode, options, setOffsetBaseLine, setOffset } = context + + /** + * Find the root of left node. + */ + function getRootLeft( + node: + | ESTree.AssignmentExpression + | ESTree.AssignmentPattern + | ESTree.BinaryExpression + | ESTree.LogicalExpression, + ) { + let target = node + let parent = getParent(target) + while ( + parent && + (parent.type === "AssignmentExpression" || + parent.type === "AssignmentPattern" || + parent.type === "BinaryExpression" || + parent.type === "LogicalExpression") + ) { + const prevToken = sourceCode.getTokenBefore(target) + if (prevToken && isOpeningParenToken(prevToken)) { + break + } + target = parent + parent = getParent(target) + } + return target.left + } + + const visitor = { + Program(node: AST.SvelteProgram) { + for (const body of node.body) { + if (body.type === "SvelteText" && !body.value.trim()) { + continue + } + setOffsetBaseLine(sourceCode.getFirstToken(body), 0) + } + }, + ArrayExpression(node: ESTree.ArrayExpression | ESTree.ArrayPattern) { + setOffsetNodes( + context, + node.elements, + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + ArrayPattern(node: ESTree.ArrayPattern) { + visitor.ArrayExpression(node) + }, + ArrowFunctionExpression(node: ESTree.ArrowFunctionExpression) { + const [firstToken, secondToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + const leftToken = node.async ? secondToken : firstToken + const arrowToken = sourceCode.getTokenBefore(node.body, { + filter: isArrowToken, + includeComments: false, + }) + + if (node.async) { + setOffset(secondToken, 1, firstToken) + } + if (isOpeningParenToken(leftToken)) { + const rightToken = sourceCode.getTokenAfter( + node.params[node.params.length - 1] || leftToken, + { filter: isClosingParenToken, includeComments: false }, + ) + setOffsetNodes(context, node.params, leftToken, rightToken, 1) + } + + setOffset(arrowToken, 1, firstToken) + + const bodyFirstToken = sourceCode.getFirstToken(node.body) + setOffset( + bodyFirstToken, + isOpeningBraceToken(bodyFirstToken) ? 0 : 1, + firstToken, + ) + }, + AssignmentExpression( + node: + | ESTree.AssignmentExpression + | ESTree.AssignmentPattern + | ESTree.BinaryExpression + | ESTree.LogicalExpression, + ) { + const leftNode = getRootLeft(node) + const opToken = sourceCode.getTokenAfter(node.left, { + filter: isNotClosingParenToken, + includeComments: false, + })! + const rightToken = getFirstAndLastTokens( + sourceCode, + node.right, + ).firstToken + + setOffset( + [opToken, rightToken], + 1, + getFirstAndLastTokens(sourceCode, leftNode).firstToken, + ) + }, + AssignmentPattern(node: ESTree.AssignmentPattern) { + visitor.AssignmentExpression(node) + }, + BinaryExpression(node: ESTree.BinaryExpression) { + visitor.AssignmentExpression(node) + }, + LogicalExpression(node: ESTree.LogicalExpression) { + visitor.AssignmentExpression(node) + }, + AwaitExpression( + node: + | ESTree.AwaitExpression + | ESTree.RestElement + | ESTree.SpreadElement + | ESTree.UnaryExpression, + ) { + // `await`, `...`, or UnaryOperator + const firstToken = sourceCode.getFirstToken(node) + const nextToken = sourceCode.getTokenAfter(firstToken) + + setOffset(nextToken, 1, firstToken) + }, + RestElement(node: ESTree.RestElement) { + visitor.AwaitExpression(node) + }, + SpreadElement(node: ESTree.SpreadElement) { + visitor.AwaitExpression(node) + }, + UnaryExpression(node: ESTree.UnaryExpression) { + visitor.AwaitExpression(node) + }, + BlockStatement(node: ESTree.BlockStatement | ESTree.ClassBody) { + setOffsetNodes( + context, + node.body, + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + ClassBody(node: ESTree.ClassBody) { + visitor.BlockStatement(node) + }, + BreakStatement(node: ESTree.BreakStatement | ESTree.ContinueStatement) { + if (node.label) { + const firstToken = sourceCode.getFirstToken(node) + const nextToken = sourceCode.getTokenAfter(firstToken) + + setOffset(nextToken, 1, firstToken) + } + }, + ContinueStatement(node: ESTree.ContinueStatement) { + visitor.BreakStatement(node) + }, + CallExpression(node: ESTree.CallExpression) { + const firstToken = sourceCode.getFirstToken(node) + const leftParenToken = sourceCode.getTokenAfter(node.callee, { + filter: isOpeningParenToken, + includeComments: false, + })! + const rightParenToken = sourceCode.getLastToken(node) + + for (const optionalToken of sourceCode.getTokensBetween( + sourceCode.getLastToken(node.callee), + leftParenToken, + { filter: isOptionalToken, includeComments: false }, + )) { + setOffset(optionalToken, 1, firstToken) + } + + setOffset(leftParenToken, 1, firstToken) + setOffsetNodes( + context, + node.arguments, + leftParenToken, + rightParenToken, + 1, + ) + }, + CatchClause(node: ESTree.CatchClause) { + const catchToken = sourceCode.getFirstToken(node) + + if (node.param != null) { + const leftParenToken = sourceCode.getTokenBefore(node.param)! + const rightParenToken = sourceCode.getTokenAfter(node.param) + + setOffset(leftParenToken, 1, catchToken) + setOffsetNodes( + context, + [node.param], + leftParenToken, + rightParenToken, + 1, + ) + } + const bodyToken = sourceCode.getFirstToken(node.body) + setOffset(bodyToken, 0, catchToken) + }, + ClassDeclaration(node: ESTree.ClassDeclaration | ESTree.ClassExpression) { + const classToken = sourceCode.getFirstToken(node) + + if (node.id != null) { + setOffset(sourceCode.getFirstToken(node.id), 1, classToken) + } + if (node.superClass != null) { + const extendsToken = sourceCode.getTokenAfter(node.id || classToken)! + const superClassToken = sourceCode.getTokenAfter(extendsToken) + setOffset(extendsToken, 1, classToken) + setOffset(superClassToken, 1, extendsToken) + } + const bodyToken = sourceCode.getFirstToken(node.body) + setOffset(bodyToken, 0, classToken) + }, + ClassExpression(node: ESTree.ClassExpression) { + visitor.ClassDeclaration(node) + }, + ConditionalExpression(node: ESTree.ConditionalExpression) { + const questionToken = sourceCode.getTokenAfter(node.test, { + filter: isNotClosingParenToken, + includeComments: false, + })! + + const consequentToken = sourceCode.getTokenAfter(questionToken) + const colonToken = sourceCode.getTokenAfter(node.consequent, { + filter: isNotClosingParenToken, + includeComments: false, + })! + const alternateToken = sourceCode.getTokenAfter(colonToken) + + let baseNode = node + let parent = getParent(baseNode) + while ( + parent && + parent.type === "ConditionalExpression" && + parent.alternate === baseNode + ) { + baseNode = parent + parent = getParent(baseNode) + } + const baseToken = sourceCode.getFirstToken(baseNode) + + setOffset([questionToken, colonToken], 1, baseToken) + setOffset(consequentToken, 1, questionToken) + setOffset(alternateToken, 1, colonToken) + }, + DoWhileStatement(node: ESTree.DoWhileStatement) { + const doToken = sourceCode.getFirstToken(node) + const whileToken = sourceCode.getTokenAfter(node.body, { + filter: isNotClosingParenToken, + includeComments: false, + })! + const leftParenToken = sourceCode.getTokenAfter(whileToken)! + const rightParenToken = sourceCode.getTokenAfter(node.test)! + + const bodyFirstToken = sourceCode.getFirstToken(node.body) + setOffset( + bodyFirstToken, + isOpeningBraceToken(bodyFirstToken) ? 0 : 1, + doToken, + ) + + setOffset(whileToken, 0, doToken) + setOffset(leftParenToken, 1, whileToken) + setOffsetNodes(context, [node.test], leftParenToken, rightParenToken, 1) + }, + ExportAllDeclaration(node: ESTree.ExportAllDeclaration) { + const exportToken = sourceCode.getFirstToken(node) + const tokens = sourceCode.getTokensBetween(exportToken, node.source) + const fromIndex = tokens.findIndex((t) => t.value === "from") + const fromToken = tokens[fromIndex] + const beforeTokens = tokens.slice(0, fromIndex) + const afterTokens = [ + ...tokens.slice(fromIndex + 1), + sourceCode.getFirstToken(node.source), + ] + + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- type bug? + if (!(node as any).exported) { + // export * from "mod" + setOffset(beforeTokens, 1, exportToken) + } else { + // export * as foo from "mod" + const asIndex = beforeTokens.findIndex((t) => t.value === "as") + setOffset(beforeTokens.slice(0, asIndex), 1, exportToken) + setOffset(beforeTokens.slice(asIndex), 1, beforeTokens[asIndex - 1]) + } + setOffset(fromToken, 0, exportToken) + setOffset(afterTokens, 1, fromToken) + }, + ExportDefaultDeclaration(node: ESTree.ExportDefaultDeclaration) { + const exportToken = sourceCode.getFirstToken(node) + const declarationToken = getFirstAndLastTokens( + sourceCode, + node.declaration, + ).firstToken + const defaultTokens = sourceCode.getTokensBetween( + exportToken, + declarationToken, + ) + setOffset([...defaultTokens, declarationToken], 1, exportToken) + }, + ExportNamedDeclaration(node: ESTree.ExportNamedDeclaration) { + const exportToken = sourceCode.getFirstToken(node) + if (node.declaration) { + // export var foo = 1; + const declarationToken = sourceCode.getFirstToken(node.declaration) + setOffset(declarationToken, 1, exportToken) + } else { + const firstSpecifier = node.specifiers[0] + if (!firstSpecifier || firstSpecifier.type === "ExportSpecifier") { + // export {foo, bar}; or export {foo, bar} from "mod"; + const leftBraceTokens = sourceCode.getTokensBetween( + exportToken, + firstSpecifier, + ) + const rightBraceToken = sourceCode.getLastToken(node, { + filter: isClosingBraceToken, + includeComments: false, + })! + setOffset(leftBraceTokens, 0, exportToken) + setOffsetNodes( + context, + node.specifiers, + leftBraceTokens[leftBraceTokens.length - 1], + rightBraceToken, + 1, + ) + + if (node.source) { + const [fromToken, ...tokens] = sourceCode.getTokensBetween( + rightBraceToken, + node.source, + ) + + setOffset(fromToken, 0, exportToken) + setOffset( + [...tokens, sourceCode.getFirstToken(node.source)], + 1, + fromToken, + ) + } + } else { + // maybe babel-eslint + } + } + }, + ExportSpecifier(node: ESTree.ExportSpecifier) { + const [firstToken, ...tokens] = sourceCode.getTokens(node) + setOffset(tokens, 1, firstToken) + }, + ForInStatement(node: ESTree.ForInStatement | ESTree.ForOfStatement) { + const forToken = sourceCode.getFirstToken(node) + const awaitToken = + (node.type === "ForOfStatement" && + node.await && + sourceCode.getTokenAfter(forToken)) || + null + const leftParenToken = sourceCode.getTokenAfter(awaitToken || forToken)! + const leftToken = sourceCode.getFirstToken(node.left) + const inOrOfToken = sourceCode.getTokenAfter(node.left, { + filter: isNotClosingParenToken, + includeComments: false, + })! + const rightToken = sourceCode.getTokenAfter(inOrOfToken) + const rightParenToken = sourceCode.getTokenBefore(node.body, { + filter: isNotOpeningParenToken, + includeComments: false, + })! + + if (awaitToken != null) { + setOffset(awaitToken, 0, forToken) + } + setOffset(leftParenToken, 1, forToken) + setOffset(leftToken, 1, leftParenToken) + setOffset([inOrOfToken, rightToken], 1, leftToken) + setOffset(rightParenToken, 0, leftParenToken) + + const bodyFirstToken = sourceCode.getFirstToken(node.body) + setOffset( + bodyFirstToken, + isOpeningBraceToken(bodyFirstToken) ? 0 : 1, + forToken, + ) + }, + ForOfStatement(node: ESTree.ForOfStatement) { + visitor.ForInStatement(node) + }, + ForStatement(node: ESTree.ForStatement) { + const forToken = sourceCode.getFirstToken(node) + const leftParenToken = sourceCode.getTokenAfter(forToken)! + const rightParenToken = sourceCode.getTokenBefore(node.body, { + filter: isNotOpeningParenToken, + includeComments: false, + }) + + setOffset(leftParenToken, 1, forToken) + setOffsetNodes( + context, + [node.init, node.test, node.update], + leftParenToken, + rightParenToken, + 1, + ) + + const bodyFirstToken = sourceCode.getFirstToken(node.body) + setOffset( + bodyFirstToken, + isOpeningBraceToken(bodyFirstToken) ? 0 : 1, + forToken, + ) + }, + FunctionDeclaration( + node: ESTree.FunctionDeclaration | ESTree.FunctionExpression, + ) { + const firstToken = sourceCode.getFirstToken(node) + let leftParenToken, bodyBaseToken + if (isOpeningParenToken(firstToken)) { + // method + leftParenToken = firstToken + bodyBaseToken = sourceCode.getFirstToken(getParent(node)!) + } else { + const functionToken = node.async + ? sourceCode.getTokenAfter(firstToken)! + : firstToken + const starToken = node.generator + ? sourceCode.getTokenAfter(functionToken) + : null + const idToken = node.id && sourceCode.getFirstToken(node.id) + + if (node.async) { + setOffset(functionToken, 0, firstToken) + } + if (node.generator) { + setOffset(starToken, 1, firstToken) + } + if (node.id != null) { + setOffset(idToken, 1, firstToken) + } + + leftParenToken = sourceCode.getTokenAfter( + idToken || starToken || functionToken, + )! + bodyBaseToken = firstToken + } + + const rightParenToken = sourceCode.getTokenAfter( + node.params[node.params.length - 1] || leftParenToken, + { filter: isClosingParenToken, includeComments: false }, + )! + const bodyToken = sourceCode.getFirstToken(node.body) + + setOffset(leftParenToken, 1, bodyBaseToken) + setOffsetNodes(context, node.params, leftParenToken, rightParenToken, 1) + setOffset(bodyToken, 0, bodyBaseToken) + }, + FunctionExpression(node: ESTree.FunctionExpression) { + visitor.FunctionDeclaration(node) + }, + IfStatement(node: ESTree.IfStatement) { + const [ifToken, ifLeftParenToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + const ifRightParenToken = sourceCode.getTokenBefore(node.consequent, { + filter: isClosingParenToken, + includeComments: false, + }) + + setOffset(ifLeftParenToken, 1, ifToken) + setOffset(ifRightParenToken, 0, ifLeftParenToken) + + const consequentFirstToken = sourceCode.getFirstToken(node.consequent) + setOffset( + consequentFirstToken, + isOpeningBraceToken(consequentFirstToken) ? 0 : 1, + ifToken, + ) + + if (node.alternate != null) { + const elseToken = sourceCode.getTokenAfter(node.consequent, { + filter: isNotClosingParenToken, + includeComments: false, + })! + + setOffset(elseToken, 0, ifToken) + + const alternateFirstToken = sourceCode.getFirstToken(node.alternate) + setOffset( + alternateFirstToken, + isOpeningBraceToken(alternateFirstToken) ? 0 : 1, + elseToken, + ) + } + }, + ImportDeclaration(node: ESTree.ImportDeclaration) { + const importToken = sourceCode.getFirstToken(node) + const tokens = sourceCode.getTokensBetween(importToken, node.source) + const fromIndex = tokens.map((t) => t.value).lastIndexOf("from") + const { fromToken, beforeTokens, afterTokens } = + fromIndex >= 0 + ? { + fromToken: tokens[fromIndex], + beforeTokens: tokens.slice(0, fromIndex), + afterTokens: [ + ...tokens.slice(fromIndex + 1), + sourceCode.getFirstToken(node.source), + ], + } + : { + fromToken: null, + beforeTokens: [...tokens, sourceCode.getFirstToken(node.source)], + afterTokens: [], + } + + const namedSpecifiers: ESTree.ImportSpecifier[] = [] + for (const specifier of node.specifiers) { + let removeTokens + if (specifier.type === "ImportSpecifier") { + namedSpecifiers.push(specifier) + removeTokens = sourceCode.getTokens(specifier) + } else { + removeTokens = sourceCode.getTokens(specifier) + removeTokens.shift() + } + for (const token of removeTokens) { + const i = beforeTokens.indexOf(token) + if (i >= 0) { + beforeTokens.splice(i, 1) + } + } + } + if (namedSpecifiers.length) { + const leftBrace = sourceCode.getTokenBefore(namedSpecifiers[0])! + const rightBrace = sourceCode.getTokenAfter( + namedSpecifiers[namedSpecifiers.length - 1], + ) + setOffsetNodes(context, namedSpecifiers, leftBrace, rightBrace, 1) + } + + if ( + beforeTokens.every( + (t) => isOpeningBraceToken(t) || isClosingBraceToken(t), + ) + ) { + setOffset(beforeTokens, 0, importToken) + } else { + setOffset(beforeTokens, 1, importToken) + } + if (fromToken) { + setOffset(fromToken, 0, importToken) + setOffset(afterTokens, 1, fromToken) + } + }, + ImportExpression(node: ESTree.ImportExpression) { + const firstToken = sourceCode.getFirstToken(node) + const rightToken = sourceCode.getLastToken(node) + const leftToken = sourceCode.getTokenAfter(firstToken, { + filter: isOpeningParenToken, + includeComments: false, + })! + + setOffset(leftToken, 1, firstToken) + setOffsetNodes(context, [node.source], leftToken, rightToken, 1) + }, + ImportNamespaceSpecifier(node: ESTree.ImportNamespaceSpecifier) { + const tokens = sourceCode.getTokens(node) + const firstToken = tokens.shift()! + setOffset(tokens, 1, firstToken) + }, + ImportSpecifier(node: ESTree.ImportSpecifier) { + if (node.local.range![0] !== node.imported.range![0]) { + const tokens = sourceCode.getTokens(node) + const firstToken = tokens.shift()! + setOffset(tokens, 1, firstToken) + } + }, + LabeledStatement( + node: ESTree.LabeledStatement | AST.SvelteReactiveStatement, + ) { + const labelToken = sourceCode.getFirstToken(node) + const colonToken = sourceCode.getTokenAfter(labelToken)! + const bodyToken = sourceCode.getTokenAfter(colonToken) + + setOffset([colonToken, bodyToken], 1, labelToken) + }, + SvelteReactiveStatement(node: AST.SvelteReactiveStatement) { + visitor.LabeledStatement(node) + }, + MemberExpression(node: ESTree.MemberExpression | ESTree.MetaProperty) { + const objectToken = sourceCode.getFirstToken(node) + if (node.type === "MemberExpression" && node.computed) { + const leftBracketToken = sourceCode.getTokenBefore(node.property, { + filter: isOpeningBracketToken, + includeComments: false, + })! + const rightBracketToken = sourceCode.getTokenAfter(node.property, { + filter: isClosingBracketToken, + includeComments: false, + }) + + for (const optionalToken of sourceCode.getTokensBetween( + sourceCode.getLastToken(node.object), + leftBracketToken, + { filter: isOptionalToken, includeComments: false }, + )) { + setOffset(optionalToken, 1, objectToken) + } + + setOffset(leftBracketToken, 1, objectToken) + setOffsetNodes( + context, + [node.property], + leftBracketToken, + rightBracketToken, + 1, + ) + } else { + const dotToken = sourceCode.getTokenBefore(node.property)! + const propertyToken = sourceCode.getTokenAfter(dotToken) + + setOffset([dotToken, propertyToken], 1, objectToken) + } + }, + MetaProperty(node: ESTree.MetaProperty) { + visitor.MemberExpression(node) + }, + MethodDefinition(node: ESTree.MethodDefinition | ESTree.Property) { + const isMethod = node.type === "MethodDefinition" || node.method === true + + const firstToken = sourceCode.getFirstToken(node) + const keyTokens = getFirstAndLastTokens(sourceCode, node.key) + const prefixTokens = sourceCode.getTokensBetween( + firstToken, + keyTokens.firstToken, + ) + if (node.computed) { + prefixTokens.pop() // pop [ + } + setOffset(prefixTokens, 0, firstToken) + + let lastKeyToken + if (node.computed) { + const leftBracketToken = sourceCode.getTokenBefore( + keyTokens.firstToken, + )! + const rightBracketToken = (lastKeyToken = sourceCode.getTokenAfter( + keyTokens.lastToken, + )!) + setOffset(leftBracketToken, 0, firstToken) + setOffsetNodes( + context, + [node.key], + leftBracketToken, + rightBracketToken, + 1, + ) + } else { + setOffset(keyTokens.firstToken, 0, firstToken) + lastKeyToken = keyTokens.lastToken + } + + if (isMethod) { + const leftParenToken = sourceCode.getTokenAfter(lastKeyToken) + setOffset(leftParenToken, 1, lastKeyToken) + } else if (node.type === "Property" && !node.shorthand) { + const colonToken = sourceCode.getTokenAfter(lastKeyToken)! + const valueToken = sourceCode.getTokenAfter(colonToken) + + setOffset([colonToken, valueToken], 1, lastKeyToken) + } + }, + Property(node: ESTree.Property) { + visitor.MethodDefinition(node) + }, + NewExpression(node: ESTree.NewExpression) { + const newToken = sourceCode.getFirstToken(node) + const calleeTokens = getFirstAndLastTokens(sourceCode, node.callee) + setOffset(calleeTokens.firstToken, 1, newToken) + + if ( + node.arguments.length || + calleeTokens.lastToken.range[1] < node.range![1] + ) { + const rightParenToken = sourceCode.getLastToken(node) + const leftParenToken = sourceCode.getTokenAfter(calleeTokens.lastToken)! + + setOffset(leftParenToken, 1, calleeTokens.firstToken) + setOffsetNodes( + context, + node.arguments, + leftParenToken, + rightParenToken, + 1, + ) + } + }, + ObjectExpression(node: ESTree.ObjectExpression | ESTree.ObjectPattern) { + setOffsetNodes( + context, + node.properties, + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + ObjectPattern(node: ESTree.ObjectPattern) { + visitor.ObjectExpression(node) + }, + ReturnStatement(node: ESTree.ReturnStatement | ESTree.ThrowStatement) { + if (node.argument) { + const firstToken = sourceCode.getFirstToken(node) + const nextToken = sourceCode.getTokenAfter(firstToken) + + setOffset(nextToken, 1, firstToken) + } + }, + ThrowStatement(node: ESTree.ThrowStatement) { + visitor.ReturnStatement(node) + }, + SequenceExpression(node: ESTree.SequenceExpression) { + const firstToken = sourceCode.getFirstToken(node) + setOffsetNodes(context, node.expressions, firstToken, null, 0) + }, + SwitchCase(node: ESTree.SwitchCase) { + const caseToken = sourceCode.getFirstToken(node) + if (node.test != null) { + const testTokens = getFirstAndLastTokens(sourceCode, node.test) + const colonToken = sourceCode.getTokenAfter(testTokens.lastToken) + setOffset([testTokens.firstToken, colonToken], 1, caseToken) + } else { + const colonToken = sourceCode.getTokenAfter(caseToken) + setOffset(colonToken, 1, caseToken) + } + + if ( + node.consequent.length === 1 && + node.consequent[0].type === "BlockStatement" + ) { + setOffset(sourceCode.getFirstToken(node.consequent[0]), 0, caseToken) + } else { + for (const statement of node.consequent) { + setOffset( + getFirstAndLastTokens(sourceCode, statement).firstToken, + 1, + caseToken, + ) + } + } + }, + SwitchStatement(node: ESTree.SwitchStatement) { + const switchToken = sourceCode.getFirstToken(node) + const { firstToken: leftParenToken, lastToken: rightParenToken } = + getFirstAndLastTokens(sourceCode, node.discriminant) + const leftBraceToken = sourceCode.getTokenAfter(rightParenToken)! + const rightBraceToken = sourceCode.getLastToken(node) + + setOffset(leftParenToken, 1, switchToken) + setOffsetNodes( + context, + [node.discriminant], + leftParenToken, + rightParenToken, + 1, + ) + setOffset(leftBraceToken, 0, switchToken) + setOffsetNodes( + context, + node.cases, + leftBraceToken, + rightBraceToken, + options.switchCase, + ) + }, + TaggedTemplateExpression(node: ESTree.TaggedTemplateExpression) { + const tagTokens = getFirstAndLastTokens(sourceCode, node.tag) + setOffset(sourceCode.getFirstToken(node.quasi), 1, tagTokens.firstToken) + }, + TemplateLiteral(node: ESTree.TemplateLiteral) { + const firstToken = sourceCode.getFirstToken(node) + const quasiTokens = node.quasis + .slice(1) + .map((n) => sourceCode.getFirstToken(n)) + const expressionToken = node.quasis + .slice(0, -1) + .map((n) => sourceCode.getTokenAfter(n)) + + setOffset(quasiTokens, 0, firstToken) + setOffset(expressionToken, 1, firstToken) + }, + TryStatement(node: ESTree.TryStatement) { + const tryToken = sourceCode.getFirstToken(node) + const tryBlockToken = sourceCode.getFirstToken(node.block) + + setOffset(tryBlockToken, 0, tryToken) + + if (node.handler != null) { + const catchToken = sourceCode.getFirstToken(node.handler) + setOffset(catchToken, 0, tryToken) + } + + if (node.finalizer != null) { + const finallyToken = sourceCode.getTokenBefore(node.finalizer) + const finallyBlockToken = sourceCode.getFirstToken(node.finalizer) + setOffset([finallyToken, finallyBlockToken], 0, tryToken) + } + }, + UpdateExpression(node: ESTree.UpdateExpression) { + const firstToken = sourceCode.getFirstToken(node) + const nextToken = sourceCode.getTokenAfter(firstToken) + setOffset(nextToken, 1, firstToken) + }, + VariableDeclaration(node: ESTree.VariableDeclaration) { + setOffsetNodes( + context, + node.declarations, + sourceCode.getFirstToken(node), + null, + 1, + ) + }, + VariableDeclarator(node: ESTree.VariableDeclarator) { + if (node.init != null) { + const idToken = sourceCode.getFirstToken(node) + const eqToken = sourceCode.getTokenAfter(node.id)! + const initToken = sourceCode.getTokenAfter(eqToken) + + setOffset([eqToken, initToken], 1, idToken) + } + }, + WhileStatement(node: ESTree.WhileStatement | ESTree.WithStatement) { + const firstToken = sourceCode.getFirstToken(node) + const leftParenToken = sourceCode.getTokenAfter(firstToken)! + const rightParenToken = sourceCode.getTokenBefore(node.body, { + filter: isClosingParenToken, + includeComments: false, + })! + + setOffset(leftParenToken, 1, firstToken) + setOffset(rightParenToken, 0, leftParenToken) + + const bodyFirstToken = sourceCode.getFirstToken(node.body) + setOffset( + bodyFirstToken, + isOpeningBraceToken(bodyFirstToken) ? 0 : 1, + firstToken, + ) + }, + WithStatement(node: ESTree.WithStatement) { + visitor.WhileStatement(node) + }, + YieldExpression(node: ESTree.YieldExpression) { + if (node.argument != null) { + const [yieldToken, secondToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + + setOffset(secondToken, 1, yieldToken) + if (node.delegate) { + setOffset(sourceCode.getTokenAfter(secondToken), 1, yieldToken) + } + } + }, + + // ---------------------------------------------------------------------- + // SINGLE TOKEN NODES + // ---------------------------------------------------------------------- + DebuggerStatement() { + // noop + }, + EmptyStatement() { + // noop + }, + Identifier() { + // noop + }, + ImportDefaultSpecifier() { + // noop + }, + Literal() { + // noop + }, + Super() { + // noop + }, + TemplateElement() { + // noop + }, + ThisExpression() { + // noop + }, + // ---------------------------------------------------------------------- + // WRAPPER NODES + // ---------------------------------------------------------------------- + ExpressionStatement() { + // noop + }, + ChainExpression() { + // noop + }, + } + + return { + ...visitor, + ":statement"(node: ESTree.Statement) { + const firstToken = sourceCode.getFirstToken(node) + const lastToken = sourceCode.getLastToken(node) + if (isSemicolonToken(lastToken) && firstToken !== lastToken) { + const next = sourceCode.getTokenAfter(lastToken) + if (!next || lastToken.loc.start.line < next.loc.start.line) { + // Lone semicolons + setOffset(lastToken, 0, firstToken) + } + } + }, + ":expression"(node: ESTree.Expression) { + // Proc parentheses. + let leftToken = sourceCode.getTokenBefore(node) + let rightToken = sourceCode.getTokenAfter(node) + let firstToken = sourceCode.getFirstToken(node) + + while ( + leftToken && + isOpeningParenToken(leftToken) && + rightToken && + isClosingParenToken(rightToken) + ) { + setOffset(firstToken, 1, leftToken) + setOffset(rightToken, 0, leftToken) + + firstToken = leftToken + leftToken = sourceCode.getTokenBefore(leftToken) + rightToken = sourceCode.getTokenAfter(rightToken) + } + }, + } +} + +/** Get the parent node from the given node */ +function getParent(node: ESTree.Node): ESTree.Node | null { + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore + return (node as any).parent || null +} + +/** + * Checks whether given text is known button type + */ +function isOptionalToken(token: { type: string; value: string }): boolean { + return token.type === "Punctuator" && token.value === "?." +} diff --git a/src/rules/indent-helpers/index.ts b/src/rules/indent-helpers/index.ts new file mode 100644 index 000000000..5d686eb92 --- /dev/null +++ b/src/rules/indent-helpers/index.ts @@ -0,0 +1,416 @@ +import type { AST } from "svelte-eslint-parser" +import type * as ESTree from "estree" +import type { ASTNode, RuleContext, RuleListener } from "../../types" +import * as SV from "./svelte" +import * as ES from "./es" +import { isNotWhitespace } from "./ast" +import { isCommentToken } from "eslint-utils" +import type { IndentOptions } from "./commons" + +type IndentUserOptions = { + indent?: number | "tab" + switchCase?: number + ignoredNodes?: string[] +} +type AnyToken = AST.Token | AST.Comment + +/** + * Normalize options. + * @param type The type of indentation. + * @param options Other options. + * @param defaultOptions The default value of options. + * @returns Normalized options. + */ +function parseOptions( + options: IndentUserOptions, + defaultOptions: Partial, +): IndentOptions { + const ret: IndentOptions = { + indentChar: " ", + indentSize: 2, + switchCase: 1, + ignoredNodes: [], + ...defaultOptions, + } + + if (Number.isSafeInteger(options.indent)) { + ret.indentSize = Number(options.indent) + } else if (options.indent === "tab") { + ret.indentChar = "\t" + ret.indentSize = 1 + } + + if (options.switchCase != null && Number.isSafeInteger(options.switchCase)) { + ret.switchCase = options.switchCase + } + + if (options.ignoredNodes != null) { + ret.ignoredNodes = options.ignoredNodes + } + + return ret +} + +/** + * Creates AST event handlers for html-indent. + * + * @param context The rule context. + * @param defaultOptions The default value of options. + * @returns AST event handlers. + */ +export function defineVisitor( + context: RuleContext, + defaultOptions: Partial, +): RuleListener { + if (!context.getFilename().endsWith(".svelte")) return {} + + const options = parseOptions(context.options[0] || {}, defaultOptions) + const sourceCode = context.getSourceCode() + const offsets = new Map< + AnyToken, + | { + baseToken: AnyToken + offset: number + baseline: false + expectedIndent?: number + } + | { + baseToken?: undefined + offset: number + baseline: true + expectedIndent?: number + } + >() + const ignoreTokens = new Set() + + /** + * Set offset to the given tokens. + */ + function setOffset( + token: AnyToken | null | undefined | (AnyToken | null | undefined)[], + offset: number, + baseToken: AnyToken, + ) { + if (!token) { + return + } + if (Array.isArray(token)) { + for (const t of token) { + setOffset(t, offset, baseToken) + } + return + } + if (token === baseToken) { + return + } + offsets.set(token, { + baseToken, + offset, + baseline: false, + }) + } + + /** + * Copy offset to the given tokens from srcToken. + */ + function copyOffset( + token: AnyToken | null | undefined | (AnyToken | null | undefined)[], + srcToken: AnyToken, + ): void { + if (!token) { + return + } + const offsetData = offsets.get(srcToken) + if (!offsetData) { + return + } + if (!offsetData.baseline) { + setOffset(token, offsetData.offset, offsetData.baseToken) + } else { + setOffsetBaseLine(token, offsetData.offset) + } + } + + /** + * Set baseline offset to the given token. + */ + function setOffsetBaseLine( + token: AnyToken | null | undefined | (AnyToken | null | undefined)[], + offset: number, + ) { + if (!token) { + return + } + if (Array.isArray(token)) { + for (const t of token) { + setOffsetBaseLine(t, offset) + } + return + } + offsets.set(token, { + offset, + baseline: true, + expectedIndent: undefined, + }) + } + + /** + * Ignore all tokens of the given node. + */ + function ignore(node: ASTNode) { + for (const token of sourceCode.getTokens(node)) { + ignoreTokens.add(token) + } + } + + /** + * Get the text of the indentation part of the given location. + */ + function getIndentText({ line, column }: { line: number; column: number }) { + return sourceCode.lines[line - 1].slice(0, column) + } + + /** + * Calculate correct indentation of the given token. + */ + function getExpectedIndentFromToken(token: AnyToken): number | null { + const offsetInfo = offsets.get(token) + if (offsetInfo == null) { + return null + } + if (offsetInfo.expectedIndent != null) { + return offsetInfo.expectedIndent + } + if (offsetInfo.baseline) { + return offsetInfo.offset * options.indentSize + } + const baseIndent = getExpectedIndentFromToken(offsetInfo.baseToken) + if (baseIndent == null) { + return null + } + return baseIndent + offsetInfo.offset * options.indentSize + } + + /** + * Calculate correct indentation of the line of the given tokens. + */ + function getExpectedIndentFromTokens(tokens: AnyToken[]) { + for (const token of tokens) { + if (ignoreTokens.has(token)) { + return null + } + const expectedIndent = getExpectedIndentFromToken(token) + if (expectedIndent != null) { + return expectedIndent + } + } + return null + } + + /** Save expected indent to give tokens */ + function saveExpectedIndent(tokens: AnyToken[], expectedIndent: number) { + for (const token of tokens) { + const offsetInfo = offsets.get(token) + if (offsetInfo == null) { + continue + } + offsetInfo.expectedIndent ??= expectedIndent + } + } + + /** + * Validate the given token with the pre-calculated expected indentation. + */ + function validateToken(token: AnyToken, expectedIndent: number) { + const line = token.loc.start.line + const indentText = getIndentText(token.loc.start) + + // `indentText` contains non-whitespace characters. + if (indentText.trim() !== "") { + return + } + + const actualIndent = token.loc.start.column + + const mismatchCharIndexes: number[] = [] + for (let i = 0; i < indentText.length; ++i) { + if (indentText[i] !== options.indentChar) { + mismatchCharIndexes.push(i) + } + } + if (actualIndent !== expectedIndent) { + const loc = { + start: { line, column: 0 }, + end: { line, column: actualIndent }, + } + context.report({ + loc, + messageId: "unexpectedIndentation", + data: { + expectedIndent: String(expectedIndent), + actualIndent: String(actualIndent), + expectedUnit: options.indentChar === "\t" ? "tab" : "space", + actualUnit: mismatchCharIndexes.length + ? "whitespace" + : options.indentChar === "\t" + ? "tab" + : "space", + expectedIndentPlural: expectedIndent === 1 ? "" : "s", + actualIndentPlural: actualIndent === 1 ? "" : "s", + }, + fix(fixer) { + return fixer.replaceTextRange( + [ + sourceCode.getIndexFromLoc(loc.start), + sourceCode.getIndexFromLoc(loc.end), + ], + options.indentChar.repeat(expectedIndent), + ) + }, + }) + return + } + + for (const i of mismatchCharIndexes) { + const loc = { + start: { line, column: i }, + end: { line, column: i + 1 }, + } + context.report({ + loc, + messageId: "unexpectedChar", + data: { + expected: JSON.stringify(options.indentChar), + actual: JSON.stringify(indentText[i]), + }, + fix(fixer) { + return fixer.replaceTextRange( + [ + sourceCode.getIndexFromLoc(loc.start), + sourceCode.getIndexFromLoc(loc.end), + ], + options.indentChar, + ) + }, + }) + } + } + + /** Process line tokens */ + function processLine( + tokens: AnyToken[], + prevComments: AST.Comment[], + prevToken: AnyToken | null, + ) { + const firstToken = tokens[0] + const actualIndent = firstToken.loc.start.column + const expectedIndent = getExpectedIndentFromTokens(tokens) + if (expectedIndent == null) { + saveExpectedIndent(tokens, actualIndent) + return + } + saveExpectedIndent(tokens, expectedIndent) + + let prev = prevToken + if (prevComments.length) { + if (prev && prev.loc.end.line < prevComments[0].loc.start.line) { + validateToken(prevComments[0], expectedIndent) + } + prev = prevComments[prevComments.length - 1] + } + if (prev && prev.loc.end.line < tokens[0].loc.start.line) { + validateToken(tokens[0], expectedIndent) + } + } + + const indentContext = { + sourceCode, + options, + setOffset, + copyOffset, + setOffsetBaseLine, + ignore, + } + const nodesVisitor = { + ...ES.defineVisitor(indentContext), + ...SV.defineVisitor(indentContext), + } + const knownNodes = new Set(Object.keys(nodesVisitor)) + + /** + * Build a visitor combined with a visitor to handle the given ignore selector. + */ + function compositingIgnoresVisitor(visitor: RuleListener): RuleListener { + for (const ignoreSelector of options.ignoredNodes) { + const key = `${ignoreSelector}:exit` + + if (visitor[key]) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore + const handler = visitor[key] as any + visitor[key] = function (node: never, ...args: never[]) { + const ret = handler.call(this, node, ...args) + ignore(node) + return ret + } + } else { + visitor[key] = ignore + } + } + + return visitor + } + + return compositingIgnoresVisitor({ + ...nodesVisitor, + "*:exit"(node: ASTNode) { + // Ignore tokens of unknown nodes. + if (!knownNodes.has(node.type)) { + ignore(node) + } + }, + "Program:exit"(node: ESTree.Program) { + let prevToken: AnyToken | null = null + for (const { prevComments, tokens } of iterateLineTokens()) { + processLine(tokens, prevComments, prevToken) + prevToken = tokens[tokens.length - 1] + } + + /** Iterate line tokens */ + function* iterateLineTokens() { + let line = 0 + let prevComments: AST.Comment[] = [] + let bufferTokens: AnyToken[] = [] + for (const token of sourceCode.getTokens(node, { + includeComments: true, + filter: isNotWhitespace, + })) { + const thisLine = token.loc.start.line + if (line === thisLine || bufferTokens.length === 0) { + bufferTokens.push(token) + } else { + if ( + isCommentToken(bufferTokens[0]) && + bufferTokens.every(isCommentToken) + ) { + prevComments.push(bufferTokens[0]) + } else { + yield { + prevComments, + tokens: bufferTokens, + } + prevComments = [] + } + bufferTokens = [token] + } + line = thisLine + } + if (bufferTokens.length && !bufferTokens.every(isCommentToken)) { + yield { + prevComments, + tokens: bufferTokens, + } + } + } + }, + }) +} diff --git a/src/rules/indent-helpers/svelte.ts b/src/rules/indent-helpers/svelte.ts new file mode 100644 index 000000000..dd5225aec --- /dev/null +++ b/src/rules/indent-helpers/svelte.ts @@ -0,0 +1,494 @@ +import type { AST } from "svelte-eslint-parser" +import type { ASTNode } from "../../types" +import { isNotWhitespace } from "./ast" +import type { IndentContext } from "./commons" +import { getFirstAndLastTokens } from "./commons" +import { setOffsetNodes } from "./commons" +type NodeWithParent = Exclude< + AST.SvelteNode, + AST.SvelteProgram | AST.SvelteReactiveStatement +> +type NodeListenerMap = { + [key in NodeWithParent["type"]]: T extends { type: key } ? T : never +} + +type NodeListener = { + [T in keyof NodeListenerMap]: (node: NodeListenerMap[T]) => void +} +const PREFORMATTED_ELEMENT_NAMES = ["pre", "textarea"] + +/** + * Creates AST event handlers for svelte nodes. + * + * @param context The rule context. + * @returns AST event handlers. + */ +export function defineVisitor(context: IndentContext): NodeListener { + const { setOffset, sourceCode, copyOffset, ignore } = context + const visitor = { + // ---------------------------------------------------------------------- + // ELEMENTS + // ---------------------------------------------------------------------- + SvelteScriptElement(node: AST.SvelteScriptElement) { + setOffsetNodes(context, node.body, node.startTag, node.endTag, 1) + }, + SvelteStyleElement(node: AST.SvelteStyleElement) { + node.children.forEach(ignore) + }, + SvelteElement(node: AST.SvelteElement) { + if ( + (node.name.type !== "Identifier" && node.name.type !== "SvelteName") || + !PREFORMATTED_ELEMENT_NAMES.includes(node.name.name) + ) { + if (node.endTag) { + setOffsetNodes( + context, + node.children.filter(isNotEmptyTextNode), + node.startTag, + node.endTag, + 1, + ) + } + } else { + const startTagToken = sourceCode.getFirstToken(node) + const endTagToken = node.endTag && sourceCode.getFirstToken(node.endTag) + setOffset(endTagToken, 0, startTagToken) + node.children.forEach(ignore) + } + }, + // ---------------------------------------------------------------------- + // TAGS + // ---------------------------------------------------------------------- + SvelteStartTag(node: AST.SvelteStartTag) { + const openToken = sourceCode.getFirstToken(node) + const closeToken = sourceCode.getLastToken(node) + + setOffsetNodes(context, node.attributes, openToken, closeToken, 1) + if (node.selfClosing) { + const slash = sourceCode.getTokenBefore(closeToken)! + if (slash.value === "/") { + setOffset(slash, 0, openToken) + } + } + }, + SvelteEndTag(node: AST.SvelteEndTag) { + const openToken = sourceCode.getFirstToken(node) + const closeToken = sourceCode.getLastToken(node) + setOffsetNodes(context, [], openToken, closeToken, 1) + }, + // ---------------------------------------------------------------------- + // ATTRIBUTES + // ---------------------------------------------------------------------- + // eslint-disable-next-line complexity -- X( + SvelteAttribute( + node: + | AST.SvelteAttribute + | AST.SvelteDirective + | AST.SvelteSpecialDirective, + ) { + const keyToken = sourceCode.getFirstToken(node) + const eqToken = sourceCode.getTokenAfter(node.key) + + if (eqToken != null && eqToken.range[1] <= node.range[1]) { + setOffset(eqToken, 1, keyToken) + + const valueStartToken = sourceCode.getTokenAfter(eqToken) + if ( + valueStartToken != null && + valueStartToken.range[1] <= node.range[1] + ) { + setOffset(valueStartToken, 1, keyToken) + + const values = node.type === "SvelteAttribute" ? node.value : [] + // process quoted + let processedValues = false + if (valueStartToken.type === "Punctuator") { + const quoted = ['"', "'"].includes(valueStartToken.value) + const mustache = !quoted && valueStartToken.value === "{" + if (quoted || mustache) { + const last = sourceCode.getLastToken(node) + if ( + last.type === "Punctuator" && + ((quoted && last.value === valueStartToken.value) || + (mustache && last.value === "}")) + ) { + setOffset(last, 0, valueStartToken) + + setOffsetNodes(context, values, valueStartToken, last, 1) + processedValues = true + } + } + } + if (!processedValues) { + for (const val of values) { + const token = sourceCode.getFirstToken(val) + setOffset(token, 0, valueStartToken) + } + } + } + } + }, + SvelteDirective(node: AST.SvelteDirective) { + visitor.SvelteAttribute(node) + }, + SvelteSpecialDirective(node: AST.SvelteSpecialDirective) { + visitor.SvelteAttribute(node) + }, + SvelteShorthandAttribute( + node: AST.SvelteShorthandAttribute | AST.SvelteSpreadAttribute, + ) { + const openToken = sourceCode.getFirstToken(node) + const closeToken = sourceCode.getLastToken(node) + setOffsetNodes(context, [], openToken, closeToken, 1) + }, + SvelteSpreadAttribute(node: AST.SvelteSpreadAttribute) { + visitor.SvelteShorthandAttribute(node) + }, + // ---------------------------------------------------------------------- + // ATTRIBUTE KEYS + // ---------------------------------------------------------------------- + SvelteDirectiveKey(_node: AST.SvelteDirectiveKey) { + // noop + }, + SvelteSpecialDirectiveKey(_node: AST.SvelteSpecialDirectiveKey) { + // noop + }, + // ---------------------------------------------------------------------- + // CONTENTS + // ---------------------------------------------------------------------- + SvelteText(node: AST.SvelteText) { + const tokens = sourceCode.getTokens(node, { + filter: isNotWhitespace, + includeComments: false, + }) + const first = tokens.shift()! + copyOffset(tokens, first) + }, + SvelteLiteral(node: AST.SvelteLiteral) { + const tokens = sourceCode.getTokens(node, { + filter: isNotWhitespace, + includeComments: false, + }) + const first = tokens.shift()! + copyOffset(tokens, first) + }, + // ---------------------------------------------------------------------- + // MUSTACHE TAGS + // ---------------------------------------------------------------------- + SvelteMustacheTag(node: AST.SvelteMustacheTag) { + const openToken = sourceCode.getFirstToken(node) + const closeToken = sourceCode.getLastToken(node) + setOffsetNodes(context, [node.expression], openToken, closeToken, 1) + }, + SvelteDebugTag(node: AST.SvelteDebugTag) { + const openToken = sourceCode.getFirstToken(node) + const closeToken = sourceCode.getLastToken(node) + setOffsetNodes(context, node.identifiers, openToken, closeToken, 1) + }, + // ---------------------------------------------------------------------- + // BLOCKS + // ---------------------------------------------------------------------- + SvelteIfBlock(node: AST.SvelteIfBlock) { + const [openToken, ...ifTokens] = sourceCode.getFirstTokens(node, { + count: node.elseif ? 3 : 2, + includeComments: false, + }) + setOffset(ifTokens, 1, openToken) + const exp = getFirstAndLastTokens(sourceCode, node.expression) + setOffset(exp.firstToken, 1, ifTokens[0]) + + const closeOpenTagToken = sourceCode.getTokenAfter(exp.lastToken) + setOffset(closeOpenTagToken, 0, openToken) + + for (const child of node.children) { + const token = sourceCode.getFirstToken(child, { + includeComments: false, + filter: isNotWhitespace, + }) + setOffset(token, 1, openToken) + } + + if (node.else) { + setOffset(sourceCode.getFirstToken(node.else), 0, openToken) + if ( + node.else.children.length === 1 && + node.else.children[0].type === "SvelteIfBlock" && + node.else.children[0].elseif + ) { + // else if + return + } + } + const [openCloseTagToken, endIfToken, closeCloseTagToken] = + sourceCode.getLastTokens(node, { + count: 3, + includeComments: false, + }) + setOffset(openCloseTagToken, 0, openToken) + setOffset(endIfToken, 1, openCloseTagToken) + setOffset(closeCloseTagToken, 0, openCloseTagToken) + }, + SvelteElseBlock(node: AST.SvelteElseBlock) { + if ( + node.children.length === 1 && + node.children[0].type === "SvelteIfBlock" && + node.children[0].elseif + ) { + return + } + const [openToken, elseToken, closeToken] = sourceCode.getFirstTokens( + node, + { + count: 3, + includeComments: false, + }, + ) + setOffset(elseToken, 1, openToken) + setOffset(closeToken, 0, openToken) + + for (const child of node.children) { + const token = sourceCode.getFirstToken(child, { + includeComments: false, + filter: isNotWhitespace, + }) + setOffset(token, 1, openToken) + } + }, + SvelteEachBlock(node: AST.SvelteEachBlock) { + const [openToken, eachToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + setOffset(eachToken, 1, openToken) + setOffsetNodes( + context, + [node.expression, node.context, node.index], + eachToken, + null, + 1, + ) + if (node.key) { + const key = getFirstAndLastTokens(sourceCode, node.key) + setOffset(key.firstToken, 1, eachToken) + const closeOpenTagToken = sourceCode.getTokenAfter(key.lastToken) + setOffset(closeOpenTagToken, 0, openToken) + } else { + const closeOpenTagToken = sourceCode.getTokenAfter( + node.index || node.context, + ) + setOffset(closeOpenTagToken, 0, openToken) + } + + for (const child of node.children) { + const token = sourceCode.getFirstToken(child, { + includeComments: false, + filter: isNotWhitespace, + }) + setOffset(token, 1, openToken) + } + if (node.else) { + setOffset(sourceCode.getFirstToken(node.else), 0, openToken) + } + + const [openCloseTagToken, endEachToken, closeCloseTagToken] = + sourceCode.getLastTokens(node, { + count: 3, + includeComments: false, + }) + setOffset(openCloseTagToken, 0, openToken) + setOffset(endEachToken, 1, openCloseTagToken) + setOffset(closeCloseTagToken, 0, openCloseTagToken) + }, + SvelteAwaitBlock(node: AST.SvelteAwaitBlock) { + const [openToken, awaitToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + setOffset(awaitToken, 1, openToken) + const exp = getFirstAndLastTokens(sourceCode, node.expression) + setOffset(exp.firstToken, 1, awaitToken) + + if (node.pending) { + const closeOpenTagToken = sourceCode.getTokenAfter(exp.lastToken) + setOffset(closeOpenTagToken, 0, openToken) + + setOffset( + sourceCode.getFirstToken(node.pending, { + includeComments: false, + filter: isNotWhitespace, + }), + 1, + openToken, + ) + } + + if (node.then) { + if (!node.pending) { + // {#await expression then value} + const thenToken = sourceCode.getTokenAfter(exp.lastToken)! + setOffset(thenToken, 1, openToken) + if (node.then.value) { + setOffset(sourceCode.getFirstToken(node.then.value), 1, thenToken) + } + const closeOpenTagToken = sourceCode.getTokenAfter( + node.then.value || thenToken, + ) + setOffset(closeOpenTagToken, 0, openToken) + } else { + // {:then value} + setOffset(sourceCode.getFirstToken(node.then), 0, openToken) + } + } + if (node.catch) { + if (!node.pending && !node.then) { + // {#await expression catch error} + const catchToken = sourceCode.getTokenAfter(exp.lastToken)! + setOffset(catchToken, 1, openToken) + if (node.catch.error) { + setOffset(sourceCode.getFirstToken(node.catch.error), 1, catchToken) + } + const closeOpenTagToken = sourceCode.getTokenAfter( + node.catch.error || catchToken, + ) + setOffset(closeOpenTagToken, 0, openToken) + } else { + // {:catch value} + setOffset(sourceCode.getFirstToken(node.catch), 0, openToken) + } + } + + const [openCloseTagToken, endAwaitToken, closeCloseTagToken] = + sourceCode.getLastTokens(node, { + count: 3, + includeComments: false, + }) + setOffset(openCloseTagToken, 0, openToken) + setOffset(endAwaitToken, 1, openCloseTagToken) + setOffset(closeCloseTagToken, 0, openCloseTagToken) + }, + SvelteAwaitPendingBlock(node: AST.SvelteAwaitPendingBlock) { + const first = sourceCode.getFirstToken(node, { + includeComments: false, + filter: isNotWhitespace, + })! + for (const child of node.children) { + const token = sourceCode.getFirstToken(child, { + includeComments: false, + filter: isNotWhitespace, + }) + copyOffset(token, first) + } + }, + SvelteAwaitThenBlock(node: AST.SvelteAwaitThenBlock) { + const parent = node.parent + if (parent.pending) { + // {:then value} + const [openToken, thenToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + setOffset(thenToken, 1, openToken) + if (node.value) { + const valueToken = sourceCode.getFirstToken(node.value) + setOffset(valueToken, 1, thenToken) + } + const closeOpenTagToken = sourceCode.getTokenAfter( + node.value || thenToken, + ) + setOffset(closeOpenTagToken, 0, openToken) + } + const openToken = sourceCode.getFirstToken(node) + + for (const child of node.children) { + const token = sourceCode.getFirstToken(child, { + includeComments: false, + filter: isNotWhitespace, + }) + setOffset(token, 1, openToken) + } + }, + SvelteAwaitCatchBlock(node: AST.SvelteAwaitCatchBlock) { + const parent = node.parent + if (parent.pending || parent.then) { + // {:catch error} + const [openToken, catchToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + setOffset(catchToken, 1, openToken) + if (node.error) { + const errorToken = sourceCode.getFirstToken(node.error) + setOffset(errorToken, 1, catchToken) + } + const closeOpenTagToken = sourceCode.getTokenAfter( + node.error || catchToken, + ) + setOffset(closeOpenTagToken, 0, openToken) + } + const openToken = sourceCode.getFirstToken(node) + + for (const child of node.children) { + const token = sourceCode.getFirstToken(child, { + includeComments: false, + filter: isNotWhitespace, + }) + setOffset(token, 1, openToken) + } + }, + SvelteKeyBlock(node: AST.SvelteKeyBlock) { + const [openToken, keyToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + setOffset(keyToken, 1, openToken) + const exp = getFirstAndLastTokens(sourceCode, node.expression) + setOffset(exp.firstToken, 1, keyToken) + + const closeOpenTagToken = sourceCode.getTokenAfter(exp.lastToken) + setOffset(closeOpenTagToken, 0, openToken) + + for (const child of node.children) { + const token = sourceCode.getFirstToken(child, { + includeComments: false, + filter: isNotWhitespace, + }) + setOffset(token, 1, openToken) + } + + const [openCloseTagToken, endAwaitToken, closeCloseTagToken] = + sourceCode.getLastTokens(node, { + count: 3, + includeComments: false, + }) + setOffset(openCloseTagToken, 0, openToken) + setOffset(endAwaitToken, 1, openCloseTagToken) + setOffset(closeCloseTagToken, 0, openCloseTagToken) + }, + // ---------------------------------------------------------------------- + // COMMENTS + // ---------------------------------------------------------------------- + SvelteHTMLComment(_node: AST.SvelteHTMLComment) { + // noop + }, + // ---------------------------------------------------------------------- + // NAMES + // ---------------------------------------------------------------------- + SvelteName(_node: AST.SvelteName) { + // noop + }, + SvelteMemberExpressionName(_node: AST.SvelteMemberExpressionName) { + // noop + }, + } + + return visitor +} + +/** + * Check whether the given node is not an empty text node. + * @param node The node to check. + * @returns `false` if the token is empty text node. + */ +function isNotEmptyTextNode(node: ASTNode) { + return !(node.type === "SvelteText" && node.value.trim() === "") +} diff --git a/src/rules/indent.ts b/src/rules/indent.ts new file mode 100644 index 000000000..affb093dd --- /dev/null +++ b/src/rules/indent.ts @@ -0,0 +1,46 @@ +import { createRule } from "../utils" +import { defineVisitor } from "./indent-helpers" + +export default createRule("indent", { + meta: { + docs: { + description: "enforce consistent indentation", + recommended: false, + }, + fixable: "whitespace", + schema: [ + { + type: "object", + properties: { + indent: { + anyOf: [{ type: "integer", minimum: 1 }, { enum: ["tab"] }], + }, + switchCase: { type: "integer", minimum: 0 }, + ignoredNodes: { + type: "array", + items: { + allOf: [ + { type: "string" }, + { not: { type: "string", pattern: ":exit$" } }, + { not: { type: "string", pattern: "^\\s*$" } }, + ], + }, + uniqueItems: true, + additionalItems: false, + }, + }, + additionalProperties: false, + }, + ], + messages: { + unexpectedChar: + "Expected {{expected}} character, but found {{actual}} character.", + unexpectedIndentation: + "Expected indentation of {{expectedIndent}} {{expectedUnit}}{{expectedIndentPlural}} but found {{actualIndent}} {{actualUnit}}{{actualIndentPlural}}.", + }, + type: "layout", // "problem", + }, + create(context) { + return defineVisitor(context, {}) + }, +}) diff --git a/src/types.ts b/src/types.ts index 340ae4000..e108e4369 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,7 +9,9 @@ import type { AST } from "svelte-eslint-parser" import type * as ESTree from "estree" export type ASTNode = AST.SvelteNode | ESTree.Node -type ASTNodeWithParent = ASTNode & { parent: ASTNode } +type ASTNodeWithParent = + | (Exclude & { parent: ASTNode }) + | AST.SvelteProgram type ASTNodeListenerMap = { [key in ASTNodeWithParent["type"]]: T extends { type: key } ? T : never } @@ -200,6 +202,7 @@ export interface SourceCode { options?: { includeComments?: boolean }, ): AST.Token | AST.Comment | null + getFirstToken(node: NodeOrToken): AST.Token getFirstToken( node: NodeOrToken, options?: Parameters[1], @@ -210,6 +213,7 @@ export interface SourceCode { options?: Parameters[1], ): (AST.Token | AST.Comment)[] + getLastToken(node: NodeOrToken): AST.Token getLastToken( node: NodeOrToken, options?: Parameters[1], @@ -220,6 +224,7 @@ export interface SourceCode { options?: Parameters[1], ): (AST.Token | AST.Comment)[] + getTokenBefore(node: NodeOrToken): AST.Token | null getTokenBefore( node: NodeOrToken, options?: Parameters[1], @@ -230,6 +235,7 @@ export interface SourceCode { options?: Parameters[1], ): (AST.Token | AST.Comment)[] + getTokenAfter(node: NodeOrToken): AST.Token | null getTokenAfter( node: NodeOrToken, options?: Parameters[1], diff --git a/src/utils/rules.ts b/src/utils/rules.ts index 793ea0838..6b7e2bf00 100644 --- a/src/utils/rules.ts +++ b/src/utils/rules.ts @@ -1,6 +1,7 @@ import type { RuleModule } from "../types" import buttonHasType from "../rules/button-has-type" import commentDirective from "../rules/comment-directive" +import indent from "../rules/indent" import maxAttributesPerLine from "../rules/max-attributes-per-line" import noAtDebugTags from "../rules/no-at-debug-tags" import noAtHtmlTags from "../rules/no-at-html-tags" @@ -15,6 +16,7 @@ import system from "../rules/system" export const rules = [ buttonHasType, commentDirective, + indent, maxAttributesPerLine, noAtDebugTags, noAtHtmlTags, diff --git a/tests/fixtures/rules/indent/invalid/.eslintrc.js b/tests/fixtures/rules/indent/invalid/.eslintrc.js new file mode 100644 index 000000000..a875636b1 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/.eslintrc.js @@ -0,0 +1,8 @@ +"use strict" + +module.exports = { + rules: { + "no-sparse-arrays": "off", + "no-unused-expressions": "off", + }, +} diff --git a/tests/fixtures/rules/indent/invalid/4-indent/_config.json b/tests/fixtures/rules/indent/invalid/4-indent/_config.json new file mode 100644 index 000000000..46f8def4c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/4-indent/_config.json @@ -0,0 +1,3 @@ +{ + "options": [{ "indent": 4 }] +} diff --git a/tests/fixtures/rules/indent/invalid/4-indent/test01-errors.json b/tests/fixtures/rules/indent/invalid/4-indent/test01-errors.json new file mode 100644 index 000000000..115087cba --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/4-indent/test01-errors.json @@ -0,0 +1,367 @@ +[ + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 24 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 24 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 24 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 60, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 62, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 63, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 64, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 69, + "column": 1 + }, + { + "message": "Expected indentation of 20 spaces but found 0 spaces.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 73, + "column": 1 + }, + { + "message": "Expected indentation of 16 spaces but found 0 spaces.", + "line": 74, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 75, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 76, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 77, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 78, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 79, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 80, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 81, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 82, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 83, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 84, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 85, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/4-indent/test01-input.svelte b/tests/fixtures/rules/indent/invalid/4-indent/test01-input.svelte new file mode 100644 index 000000000..16e32ee8a --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/4-indent/test01-input.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/fixtures/rules/indent/invalid/4-indent/test01-output.svelte b/tests/fixtures/rules/indent/invalid/4-indent/test01-output.svelte new file mode 100644 index 000000000..5a35121fb --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/4-indent/test01-output.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/fixtures/rules/indent/invalid/await01-errors.json b/tests/fixtures/rules/indent/invalid/await01-errors.json new file mode 100644 index 000000000..1dd049c5c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/await01-errors.json @@ -0,0 +1,352 @@ +[ + { + "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 2 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 60, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 62, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 64, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 69, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 73, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 75, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 76, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 77, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 78, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 79, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 80, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 81, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 82, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 83, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 84, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/await01-input.svelte b/tests/fixtures/rules/indent/invalid/await01-input.svelte new file mode 100644 index 000000000..e974a395c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/await01-input.svelte @@ -0,0 +1,85 @@ + + + + +
+{#await expression} +... +{:then name} +... +{:catch name} +... +{/await} + +{#await expression} +... +{:then name} +... +{/await} + +{#await expression then name} +... +{/await} + +{#await expression catch name} +... +{/await} + + +{ +#await +expression +} +... +{ +:then +name +} +... +{ +:catch +name +} +... +{ +/await +} + +{ +#await +expression +} +... +{ +:then +name +} +... +{ +/await +} + +{ +#await +expression +then +name +} +... +{ +/await +} + +{ +#await +expression +catch +name +} +... +{ +/await +} +
diff --git a/tests/fixtures/rules/indent/invalid/await01-output.svelte b/tests/fixtures/rules/indent/invalid/await01-output.svelte new file mode 100644 index 000000000..99f0fa713 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/await01-output.svelte @@ -0,0 +1,85 @@ + + + + +
+ {#await expression} + ... + {:then name} + ... + {:catch name} + ... + {/await} + + {#await expression} + ... + {:then name} + ... + {/await} + + {#await expression then name} + ... + {/await} + + {#await expression catch name} + ... + {/await} + + + { + #await + expression + } + ... + { + :then + name + } + ... + { + :catch + name + } + ... + { + /await + } + + { + #await + expression + } + ... + { + :then + name + } + ... + { + /await + } + + { + #await + expression + then + name + } + ... + { + /await + } + + { + #await + expression + catch + name + } + ... + { + /await + } +
diff --git a/tests/fixtures/rules/indent/invalid/each01-errors.json b/tests/fixtures/rules/indent/invalid/each01-errors.json new file mode 100644 index 000000000..e0fec9ae7 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/each01-errors.json @@ -0,0 +1,292 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 60, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 62, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 63, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 64, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 69, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 73, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 74, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/each01-input.svelte b/tests/fixtures/rules/indent/invalid/each01-input.svelte new file mode 100644 index 000000000..6f773b4b9 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/each01-input.svelte @@ -0,0 +1,77 @@ + + + +

The Famous Cats of YouTube

+ + + + +
    +{ +#each +cats +as +{ +id, +name +} +, +i +} +
  • +{i + 1}: {name} +
  • +{ +/each +} +{ +#each +cats +as +c +, +index +( +c +. +id +) +} +{ +c +} +{ +index +} +{ +/each +} +{ +#each +cats +as +cat +} +{cat.name} +{ +:else +} +... +{ +/each +} +
+ + diff --git a/tests/fixtures/rules/indent/invalid/each01-output.svelte b/tests/fixtures/rules/indent/invalid/each01-output.svelte new file mode 100644 index 000000000..6a1420191 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/each01-output.svelte @@ -0,0 +1,77 @@ + + + +

The Famous Cats of YouTube

+ + + + +
    + { + #each + cats + as + { + id, + name + } + , + i + } +
  • + {i + 1}: {name} +
  • + { + /each + } + { + #each + cats + as + c + , + index + ( + c + . + id + ) + } + { + c + } + { + index + } + { + /each + } + { + #each + cats + as + cat + } + {cat.name} + { + :else + } + ... + { + /each + } +
+ + diff --git a/tests/fixtures/rules/indent/invalid/if01-errors.json b/tests/fixtures/rules/indent/invalid/if01-errors.json new file mode 100644 index 000000000..cf29edf2a --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/if01-errors.json @@ -0,0 +1,157 @@ +[ + { + "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": 9, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 6 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 4 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 37, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/if01-input.svelte b/tests/fixtures/rules/indent/invalid/if01-input.svelte new file mode 100644 index 000000000..b30981f5e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/if01-input.svelte @@ -0,0 +1,40 @@ + + + + +
+{#if a} +
+{/if} +{ +#if +a +} +
+{ +/if +} +{ +#if +a +} +
+{ +:else +if +b +} +
+{ +:else +} +
+{ +/if +} +
+ + diff --git a/tests/fixtures/rules/indent/invalid/if01-output.svelte b/tests/fixtures/rules/indent/invalid/if01-output.svelte new file mode 100644 index 000000000..67a87c5f4 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/if01-output.svelte @@ -0,0 +1,40 @@ + + + + +
+ {#if a} +
+ {/if} + { + #if + a + } +
+ { + /if + } + { + #if + a + } +
+ { + :else + if + b + } +
+ { + :else + } +
+ { + /if + } +
+ + diff --git a/tests/fixtures/rules/indent/invalid/key01-errors.json b/tests/fixtures/rules/indent/invalid/key01-errors.json new file mode 100644 index 000000000..1a2fb0c58 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/key01-errors.json @@ -0,0 +1,57 @@ +[ + { + "message": "Expected indentation of 2 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 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 20, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/key01-input.svelte b/tests/fixtures/rules/indent/invalid/key01-input.svelte new file mode 100644 index 000000000..19531234c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/key01-input.svelte @@ -0,0 +1,23 @@ + + + + +
+{#key value} + +{/key} + +{ +#key +value +} + +{ +/key +} +
+ + diff --git a/tests/fixtures/rules/indent/invalid/key01-output.svelte b/tests/fixtures/rules/indent/invalid/key01-output.svelte new file mode 100644 index 000000000..728f45006 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/key01-output.svelte @@ -0,0 +1,23 @@ + + + + +
+ {#key value} + + {/key} + + { + #key + value + } + + { + /key + } +
+ + diff --git a/tests/fixtures/rules/indent/invalid/script-array01-errors.json b/tests/fixtures/rules/indent/invalid/script-array01-errors.json new file mode 100644 index 000000000..262722d45 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-array01-errors.json @@ -0,0 +1,102 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 6 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 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-array01-input.svelte b/tests/fixtures/rules/indent/invalid/script-array01-input.svelte new file mode 100644 index 000000000..8de51689f --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-array01-input.svelte @@ -0,0 +1,25 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-array01-output.svelte b/tests/fixtures/rules/indent/invalid/script-array01-output.svelte new file mode 100644 index 000000000..1506ec41c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-array01-output.svelte @@ -0,0 +1,25 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-binary01-errors.json b/tests/fixtures/rules/indent/invalid/script-binary01-errors.json new file mode 100644 index 000000000..fbcd79c56 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-binary01-errors.json @@ -0,0 +1,212 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 4 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 45, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-binary01-input.svelte b/tests/fixtures/rules/indent/invalid/script-binary01-input.svelte new file mode 100644 index 000000000..8a1235c99 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-binary01-input.svelte @@ -0,0 +1,48 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-binary01-output.svelte b/tests/fixtures/rules/indent/invalid/script-binary01-output.svelte new file mode 100644 index 000000000..61e2bc1ec --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-binary01-output.svelte @@ -0,0 +1,48 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-block01-errors.json b/tests/fixtures/rules/indent/invalid/script-block01-errors.json new file mode 100644 index 000000000..e22f405d1 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-block01-errors.json @@ -0,0 +1,27 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-block01-input.svelte b/tests/fixtures/rules/indent/invalid/script-block01-input.svelte new file mode 100644 index 000000000..674707fbb --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-block01-input.svelte @@ -0,0 +1,10 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-block01-output.svelte b/tests/fixtures/rules/indent/invalid/script-block01-output.svelte new file mode 100644 index 000000000..d856694f2 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-block01-output.svelte @@ -0,0 +1,10 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-break01-errors.json b/tests/fixtures/rules/indent/invalid/script-break01-errors.json new file mode 100644 index 000000000..24213363c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-break01-errors.json @@ -0,0 +1,117 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 25, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-break01-input.svelte b/tests/fixtures/rules/indent/invalid/script-break01-input.svelte new file mode 100644 index 000000000..c58726ce1 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-break01-input.svelte @@ -0,0 +1,28 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-break01-output.svelte b/tests/fixtures/rules/indent/invalid/script-break01-output.svelte new file mode 100644 index 000000000..e6b54b9c1 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-break01-output.svelte @@ -0,0 +1,28 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-call01-errors.json b/tests/fixtures/rules/indent/invalid/script-call01-errors.json new file mode 100644 index 000000000..b1c8afd0b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-call01-errors.json @@ -0,0 +1,182 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 6 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 6 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 40, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-call01-input.svelte b/tests/fixtures/rules/indent/invalid/script-call01-input.svelte new file mode 100644 index 000000000..fe0af1f6c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-call01-input.svelte @@ -0,0 +1,44 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-call01-output.svelte b/tests/fixtures/rules/indent/invalid/script-call01-output.svelte new file mode 100644 index 000000000..0a4631c75 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-call01-output.svelte @@ -0,0 +1,44 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-class01-errors.json b/tests/fixtures/rules/indent/invalid/script-class01-errors.json new file mode 100644 index 000000000..09b619051 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-class01-errors.json @@ -0,0 +1,247 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 6 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 4 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 54, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-class01-input.svelte b/tests/fixtures/rules/indent/invalid/script-class01-input.svelte new file mode 100644 index 000000000..e020ba799 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-class01-input.svelte @@ -0,0 +1,57 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-class01-output.svelte b/tests/fixtures/rules/indent/invalid/script-class01-output.svelte new file mode 100644 index 000000000..7ee713b1f --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-class01-output.svelte @@ -0,0 +1,57 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-conditional01-errors.json b/tests/fixtures/rules/indent/invalid/script-conditional01-errors.json new file mode 100644 index 000000000..491ac8e8f --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-conditional01-errors.json @@ -0,0 +1,242 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 52, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-conditional01-input.svelte b/tests/fixtures/rules/indent/invalid/script-conditional01-input.svelte new file mode 100644 index 000000000..4764a2cd6 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-conditional01-input.svelte @@ -0,0 +1,55 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-conditional01-output.svelte b/tests/fixtures/rules/indent/invalid/script-conditional01-output.svelte new file mode 100644 index 000000000..019677f7b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-conditional01-output.svelte @@ -0,0 +1,55 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-do-while01-errors.json b/tests/fixtures/rules/indent/invalid/script-do-while01-errors.json new file mode 100644 index 000000000..242c33bd3 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-do-while01-errors.json @@ -0,0 +1,42 @@ +[ + { + "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 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 10, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-do-while01-input.svelte b/tests/fixtures/rules/indent/invalid/script-do-while01-input.svelte new file mode 100644 index 000000000..c2ea87a8c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-do-while01-input.svelte @@ -0,0 +1,13 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-do-while01-output.svelte b/tests/fixtures/rules/indent/invalid/script-do-while01-output.svelte new file mode 100644 index 000000000..74980203d --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-do-while01-output.svelte @@ -0,0 +1,13 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-export01-errors.json b/tests/fixtures/rules/indent/invalid/script-export01-errors.json new file mode 100644 index 000000000..1874139c7 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-export01-errors.json @@ -0,0 +1,232 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 48, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-export01-input.svelte b/tests/fixtures/rules/indent/invalid/script-export01-input.svelte new file mode 100644 index 000000000..4e699a3ed --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-export01-input.svelte @@ -0,0 +1,51 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-export01-output.svelte b/tests/fixtures/rules/indent/invalid/script-export01-output.svelte new file mode 100644 index 000000000..83c7bf4a0 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-export01-output.svelte @@ -0,0 +1,51 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-expr01-errors.json b/tests/fixtures/rules/indent/invalid/script-expr01-errors.json new file mode 100644 index 000000000..201466bcf --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-expr01-errors.json @@ -0,0 +1,142 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 2 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 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 30, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-expr01-input.svelte b/tests/fixtures/rules/indent/invalid/script-expr01-input.svelte new file mode 100644 index 000000000..3820b1bd8 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-expr01-input.svelte @@ -0,0 +1,33 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-expr01-output.svelte b/tests/fixtures/rules/indent/invalid/script-expr01-output.svelte new file mode 100644 index 000000000..65cb0e65d --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-expr01-output.svelte @@ -0,0 +1,33 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-for01-errors.json b/tests/fixtures/rules/indent/invalid/script-for01-errors.json new file mode 100644 index 000000000..25de9be98 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-for01-errors.json @@ -0,0 +1,292 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 8 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 2 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 4 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 60, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-for01-input.svelte b/tests/fixtures/rules/indent/invalid/script-for01-input.svelte new file mode 100644 index 000000000..eb3c55719 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-for01-input.svelte @@ -0,0 +1,63 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-for01-output.svelte b/tests/fixtures/rules/indent/invalid/script-for01-output.svelte new file mode 100644 index 000000000..e75c80778 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-for01-output.svelte @@ -0,0 +1,63 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-function01-errors.json b/tests/fixtures/rules/indent/invalid/script-function01-errors.json new file mode 100644 index 000000000..b75d3b06b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-function01-errors.json @@ -0,0 +1,232 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 2 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 2 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 51, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-function01-input.svelte b/tests/fixtures/rules/indent/invalid/script-function01-input.svelte new file mode 100644 index 000000000..94b7c2570 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-function01-input.svelte @@ -0,0 +1,54 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-function01-output.svelte b/tests/fixtures/rules/indent/invalid/script-function01-output.svelte new file mode 100644 index 000000000..f083169eb --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-function01-output.svelte @@ -0,0 +1,54 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-if01-errors.json b/tests/fixtures/rules/indent/invalid/script-if01-errors.json new file mode 100644 index 000000000..1bdc9a417 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-if01-errors.json @@ -0,0 +1,297 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 60, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 62, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 63, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 64, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 65, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-if01-input.svelte b/tests/fixtures/rules/indent/invalid/script-if01-input.svelte new file mode 100644 index 000000000..d3db4929f --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-if01-input.svelte @@ -0,0 +1,68 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-if01-output.svelte b/tests/fixtures/rules/indent/invalid/script-if01-output.svelte new file mode 100644 index 000000000..7a8b5122e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-if01-output.svelte @@ -0,0 +1,68 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-import01-errors.json b/tests/fixtures/rules/indent/invalid/script-import01-errors.json new file mode 100644 index 000000000..ffa7635ed --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-import01-errors.json @@ -0,0 +1,232 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 2 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 2 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 55, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-import01-input.svelte b/tests/fixtures/rules/indent/invalid/script-import01-input.svelte new file mode 100644 index 000000000..d8919147e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-import01-input.svelte @@ -0,0 +1,58 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-import01-output.svelte b/tests/fixtures/rules/indent/invalid/script-import01-output.svelte new file mode 100644 index 000000000..6ec756de1 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-import01-output.svelte @@ -0,0 +1,58 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-member01-errors.json b/tests/fixtures/rules/indent/invalid/script-member01-errors.json new file mode 100644 index 000000000..cfb67563e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-member01-errors.json @@ -0,0 +1,152 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 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": 17, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 35, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-member01-input.svelte b/tests/fixtures/rules/indent/invalid/script-member01-input.svelte new file mode 100644 index 000000000..c35abcae1 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-member01-input.svelte @@ -0,0 +1,38 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-member01-output.svelte b/tests/fixtures/rules/indent/invalid/script-member01-output.svelte new file mode 100644 index 000000000..8b8257283 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-member01-output.svelte @@ -0,0 +1,38 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-prop01-errors.json b/tests/fixtures/rules/indent/invalid/script-prop01-errors.json new file mode 100644 index 000000000..c9ba029be --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-prop01-errors.json @@ -0,0 +1,142 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 30, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-prop01-input.svelte b/tests/fixtures/rules/indent/invalid/script-prop01-input.svelte new file mode 100644 index 000000000..59a48207e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-prop01-input.svelte @@ -0,0 +1,33 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-prop01-output.svelte b/tests/fixtures/rules/indent/invalid/script-prop01-output.svelte new file mode 100644 index 000000000..2c058709c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-prop01-output.svelte @@ -0,0 +1,33 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-switch01-errors.json b/tests/fixtures/rules/indent/invalid/script-switch01-errors.json new file mode 100644 index 000000000..07830f382 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-switch01-errors.json @@ -0,0 +1,107 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 9, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 6 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-switch01-input.svelte b/tests/fixtures/rules/indent/invalid/script-switch01-input.svelte new file mode 100644 index 000000000..6960ad1ff --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-switch01-input.svelte @@ -0,0 +1,26 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-switch01-output.svelte b/tests/fixtures/rules/indent/invalid/script-switch01-output.svelte new file mode 100644 index 000000000..c7f667b88 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-switch01-output.svelte @@ -0,0 +1,26 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-try01-errors.json b/tests/fixtures/rules/indent/invalid/script-try01-errors.json new file mode 100644 index 000000000..a824a409e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-try01-errors.json @@ -0,0 +1,197 @@ +[ + { + "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 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 2 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 4 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 42, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-try01-input.svelte b/tests/fixtures/rules/indent/invalid/script-try01-input.svelte new file mode 100644 index 000000000..1f7f7764d --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-try01-input.svelte @@ -0,0 +1,45 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-try01-output.svelte b/tests/fixtures/rules/indent/invalid/script-try01-output.svelte new file mode 100644 index 000000000..d5216bf50 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-try01-output.svelte @@ -0,0 +1,45 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-unary01-errors.json b/tests/fixtures/rules/indent/invalid/script-unary01-errors.json new file mode 100644 index 000000000..2b9548b33 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-unary01-errors.json @@ -0,0 +1,132 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 8 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 2 spaces but found 0 spaces.", + "line": 10, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 28, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-unary01-input.svelte b/tests/fixtures/rules/indent/invalid/script-unary01-input.svelte new file mode 100644 index 000000000..5da13719b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-unary01-input.svelte @@ -0,0 +1,31 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-unary01-output.svelte b/tests/fixtures/rules/indent/invalid/script-unary01-output.svelte new file mode 100644 index 000000000..80c12b82d --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-unary01-output.svelte @@ -0,0 +1,31 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/switch-case/_config.json b/tests/fixtures/rules/indent/invalid/switch-case/_config.json new file mode 100644 index 000000000..b1b6e4ebc --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/switch-case/_config.json @@ -0,0 +1,3 @@ +{ + "options": [{ "switchCase": 0 }] +} diff --git a/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-errors.json b/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-errors.json new file mode 100644 index 000000000..67dbd46ee --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-errors.json @@ -0,0 +1,107 @@ +[ + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "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 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 4 spaces but found 0 spaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 20, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-input.svelte b/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-input.svelte new file mode 100644 index 000000000..a55e0160e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-input.svelte @@ -0,0 +1,26 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-output.svelte b/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-output.svelte new file mode 100644 index 000000000..eef04dbfe --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/switch-case/script-switch01-output.svelte @@ -0,0 +1,26 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/tab-indent/_config.json b/tests/fixtures/rules/indent/invalid/tab-indent/_config.json new file mode 100644 index 000000000..e5c08bebb --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/tab-indent/_config.json @@ -0,0 +1,3 @@ +{ + "options": [{ "indent": "tab" }] +} diff --git a/tests/fixtures/rules/indent/invalid/tab-indent/test01-errors.json b/tests/fixtures/rules/indent/invalid/tab-indent/test01-errors.json new file mode 100644 index 000000000..83361130d --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/tab-indent/test01-errors.json @@ -0,0 +1,367 @@ +[ + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 0 tabs.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 0 tabs.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 0 tabs.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 0 tabs.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 0 tabs.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 0 tabs.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 0 tabs.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 6 tabs but found 0 tabs.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 6 tabs but found 0 tabs.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 6 tabs but found 0 tabs.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 0 tabs.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 0 tabs.", + "line": 60, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 0 tabs.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 62, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 63, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 64, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 69, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 0 tabs.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 0 tabs.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 73, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 0 tabs.", + "line": 74, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 0 tabs.", + "line": 75, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 0 tabs.", + "line": 76, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 0 tabs.", + "line": 77, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 0 tabs.", + "line": 78, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 79, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 80, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 81, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 0 tabs.", + "line": 82, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 83, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 84, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 0 tabs.", + "line": 85, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/tab-indent/test01-input.svelte b/tests/fixtures/rules/indent/invalid/tab-indent/test01-input.svelte new file mode 100644 index 000000000..79b6a8d4a --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/tab-indent/test01-input.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/fixtures/rules/indent/invalid/tab-indent/test01-output.svelte b/tests/fixtures/rules/indent/invalid/tab-indent/test01-output.svelte new file mode 100644 index 000000000..0f553dad7 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/tab-indent/test01-output.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/fixtures/rules/indent/invalid/tab-indent/test02-errors.json b/tests/fixtures/rules/indent/invalid/tab-indent/test02-errors.json new file mode 100644 index 000000000..7853b26e0 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/tab-indent/test02-errors.json @@ -0,0 +1,367 @@ +[ + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 3, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 4, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 5, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 8 whitespaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 8 whitespaces.", + "line": 14, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 15, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 16, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 8 whitespaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 8 whitespaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 12 whitespaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 8 whitespaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 12 whitespaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 6 tabs but found 24 whitespaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 6 tabs but found 24 whitespaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 6 tabs but found 24 whitespaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 12 whitespaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 12 whitespaces.", + "line": 60, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 12 whitespaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 62, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 63, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 64, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 69, + "column": 1 + }, + { + "message": "Expected indentation of 5 tabs but found 20 whitespaces.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 12 whitespaces.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 73, + "column": 1 + }, + { + "message": "Expected indentation of 4 tabs but found 16 whitespaces.", + "line": 74, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 12 whitespaces.", + "line": 75, + "column": 1 + }, + { + "message": "Expected indentation of 3 tabs but found 12 whitespaces.", + "line": 76, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 8 whitespaces.", + "line": 77, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 8 whitespaces.", + "line": 78, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 79, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 80, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 81, + "column": 1 + }, + { + "message": "Expected indentation of 2 tabs but found 8 whitespaces.", + "line": 82, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 83, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 84, + "column": 1 + }, + { + "message": "Expected indentation of 1 tab but found 4 whitespaces.", + "line": 85, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/tab-indent/test02-input.svelte b/tests/fixtures/rules/indent/invalid/tab-indent/test02-input.svelte new file mode 100644 index 000000000..77cf6fb28 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/tab-indent/test02-input.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/fixtures/rules/indent/invalid/tab-indent/test02-output.svelte b/tests/fixtures/rules/indent/invalid/tab-indent/test02-output.svelte new file mode 100644 index 000000000..ab913d54e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/tab-indent/test02-output.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/fixtures/rules/indent/invalid/test01-errors.json b/tests/fixtures/rules/indent/invalid/test01-errors.json new file mode 100644 index 000000000..fb7176c7e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/test01-errors.json @@ -0,0 +1,367 @@ +[ + { + "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 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 11, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 12, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 13, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 17, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 18, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 43, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 44, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 45, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 51, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 60, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 62, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 63, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 64, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 69, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 73, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 74, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 75, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 76, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 77, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 78, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 79, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 80, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 81, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 82, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 83, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 84, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 85, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/test01-input.svelte b/tests/fixtures/rules/indent/invalid/test01-input.svelte new file mode 100644 index 000000000..5ca4f8686 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/test01-input.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/fixtures/rules/indent/invalid/test01-output.svelte b/tests/fixtures/rules/indent/invalid/test01-output.svelte new file mode 100644 index 000000000..4c7045b11 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/test01-output.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/fixtures/rules/indent/valid/test01-input.svelte b/tests/fixtures/rules/indent/valid/test01-input.svelte new file mode 100644 index 000000000..4c7045b11 --- /dev/null +++ b/tests/fixtures/rules/indent/valid/test01-input.svelte @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+ + + +
+
+
+
+
+ + + + + diff --git a/tests/src/rules/indent.ts b/tests/src/rules/indent.ts new file mode 100644 index 000000000..5051b6ba2 --- /dev/null +++ b/tests/src/rules/indent.ts @@ -0,0 +1,12 @@ +import { RuleTester } from "eslint" +import rule from "../../../src/rules/indent" +import { loadTestCases } from "../../utils/utils" + +const tester = new RuleTester({ + parserOptions: { + ecmaVersion: 2020, + sourceType: "module", + }, +}) + +tester.run("indent", rule as any, loadTestCases("indent")) diff --git a/tests/utils/utils.ts b/tests/utils/utils.ts index 0b69c8b39..f9716cf68 100644 --- a/tests/utils/utils.ts +++ b/tests/utils/utils.ts @@ -180,6 +180,10 @@ function writeFixtures( [ruleName]: ["error", ...(config.options || [])], }, parser: "svelte-eslint-parser", + parserOptions: { + ecmaVersion: 2020, + sourceType: "module", + }, }, config.filename, ) @@ -193,7 +197,7 @@ function writeFixtures( column: m.column, })), null, - 4, + 2, )}\n`, "utf8", ) diff --git a/tools/lib/load-rules.ts b/tools/lib/load-rules.ts index e00a90e59..934c75918 100644 --- a/tools/lib/load-rules.ts +++ b/tools/lib/load-rules.ts @@ -7,9 +7,10 @@ import fs from "fs" */ function readRules() { const rulesLibRoot = path.resolve(__dirname, "../../src/rules") - const result = fs.readdirSync(rulesLibRoot) const rules = [] - for (const name of result) { + for (const name of fs + .readdirSync(rulesLibRoot) + .filter((n) => n.endsWith(".ts"))) { const ruleName = name.replace(/\.ts$/u, "") const ruleId = `@ota-meshi/svelte/${ruleName}` // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -- ignore diff --git a/typings/eslint-utils/index.d.ts b/typings/eslint-utils/index.d.ts new file mode 100644 index 000000000..63c2a768b --- /dev/null +++ b/typings/eslint-utils/index.d.ts @@ -0,0 +1,24 @@ +import type { AST } from "svelte-eslint-parser" +type Token = { type: string; value: string } +export function isArrowToken(token: Token): boolean +export function isCommaToken(token: Token): boolean +export function isSemicolonToken(token: Token): boolean +export function isColonToken(token: Token): boolean +export function isOpeningParenToken(token: Token): boolean +export function isClosingParenToken(token: Token): boolean +export function isOpeningBracketToken(token: Token): boolean +export function isClosingBracketToken(token: Token): boolean +export function isOpeningBraceToken(token: Token): boolean +export function isClosingBraceToken(token: Token): boolean +export function isCommentToken(token: Token): token is AST.Comment +export function isNotArrowToken(token: Token): boolean +export function isNotCommaToken(token: Token): boolean +export function isNotSemicolonToken(token: Token): boolean +export function isNotColonToken(token: Token): boolean +export function isNotOpeningParenToken(token: Token): boolean +export function isNotClosingParenToken(token: Token): boolean +export function isNotOpeningBracketToken(token: Token): boolean +export function isNotClosingBracketToken(token: Token): boolean +export function isNotOpeningBraceToken(token: Token): boolean +export function isNotClosingBraceToken(token: Token): boolean +export function isNotCommentToken(token: Token): boolean From 86d07d696b04165ea3125e13bdac32b20792aee3 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 20 Jun 2021 19:32:22 +0900 Subject: [PATCH 2/2] fix --- src/rules/indent-helpers/es.ts | 25 ++++++++++++++++--- .../rules/indent/invalid/.eslintrc.js | 3 +++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/rules/indent-helpers/es.ts b/src/rules/indent-helpers/es.ts index 0b88abfbf..b6d291beb 100644 --- a/src/rules/indent-helpers/es.ts +++ b/src/rules/indent-helpers/es.ts @@ -671,9 +671,12 @@ export function defineVisitor(context: IndentContext): NodeListener & { MetaProperty(node: ESTree.MetaProperty) { visitor.MemberExpression(node) }, - MethodDefinition(node: ESTree.MethodDefinition | ESTree.Property) { - const isMethod = node.type === "MethodDefinition" || node.method === true - + MethodDefinition( + node: + | ESTree.MethodDefinition + | ESTree.Property + | ESTree.PropertyDefinition, + ) { const firstToken = sourceCode.getFirstToken(node) const keyTokens = getFirstAndLastTokens(sourceCode, node.key) const prefixTokens = sourceCode.getTokensBetween( @@ -706,7 +709,10 @@ export function defineVisitor(context: IndentContext): NodeListener & { lastKeyToken = keyTokens.lastToken } - if (isMethod) { + if ( + node.type === "MethodDefinition" || + (node.type === "Property" && node.method === true) + ) { const leftParenToken = sourceCode.getTokenAfter(lastKeyToken) setOffset(leftParenToken, 1, lastKeyToken) } else if (node.type === "Property" && !node.shorthand) { @@ -714,6 +720,11 @@ export function defineVisitor(context: IndentContext): NodeListener & { const valueToken = sourceCode.getTokenAfter(colonToken) setOffset([colonToken, valueToken], 1, lastKeyToken) + } else if (node.type === "PropertyDefinition" && node.value != null) { + const eqToken = sourceCode.getTokenAfter(lastKeyToken)! + const initToken = sourceCode.getTokenAfter(eqToken) + + setOffset([eqToken, initToken], 1, lastKeyToken) } }, Property(node: ESTree.Property) { @@ -753,6 +764,9 @@ export function defineVisitor(context: IndentContext): NodeListener & { ObjectPattern(node: ESTree.ObjectPattern) { visitor.ObjectExpression(node) }, + PropertyDefinition(node: ESTree.PropertyDefinition) { + visitor.MethodDefinition(node) + }, ReturnStatement(node: ESTree.ReturnStatement | ESTree.ThrowStatement) { if (node.argument) { const firstToken = sourceCode.getFirstToken(node) @@ -927,6 +941,9 @@ export function defineVisitor(context: IndentContext): NodeListener & { Literal() { // noop }, + PrivateIdentifier() { + // noop + }, Super() { // noop }, diff --git a/tests/fixtures/rules/indent/invalid/.eslintrc.js b/tests/fixtures/rules/indent/invalid/.eslintrc.js index a875636b1..496509f71 100644 --- a/tests/fixtures/rules/indent/invalid/.eslintrc.js +++ b/tests/fixtures/rules/indent/invalid/.eslintrc.js @@ -4,5 +4,8 @@ module.exports = { rules: { "no-sparse-arrays": "off", "no-unused-expressions": "off", + "no-var": "off", + "getter-return": "off", + "no-new": "off", }, }