From 8c6d4776084685d8b5690c67921c9e76b7623cca Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 20 Jun 2021 23:52:37 +0900 Subject: [PATCH 01/11] Add support for TS to indent rule --- .eslintrc.js | 6 + src/rules/indent-helpers/commons.ts | 27 +- src/rules/indent-helpers/es.ts | 2 +- src/rules/indent-helpers/index.ts | 7 +- src/rules/indent-helpers/svelte.ts | 6 +- src/rules/indent-helpers/ts.ts | 404 ++++++++++++++++++ src/types.ts | 6 +- .../ts/ts-type-annotation01-errors.json | 132 ++++++ .../ts/ts-type-annotation01-input.svelte | 33 ++ .../ts/ts-type-annotation01-output.svelte | 33 ++ .../ts/ts-type-annotation02-errors.json | 92 ++++ .../ts/ts-type-annotation02-input.svelte | 23 + .../ts/ts-type-annotation02-output.svelte | 23 + .../indent/invalid/ts/ts-types01-errors.json | 357 ++++++++++++++++ .../indent/invalid/ts/ts-types01-input.svelte | 77 ++++ .../invalid/ts/ts-types01-output.svelte | 77 ++++ tests/src/rules/indent.ts | 4 + tests/utils/utils.ts | 4 + 18 files changed, 1301 insertions(+), 12 deletions(-) create mode 100644 src/rules/indent-helpers/ts.ts create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types01-output.svelte diff --git a/.eslintrc.js b/.eslintrc.js index 452935c22..90181610a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -37,6 +37,12 @@ module.exports = { { files: ["*.svelte"], parser: "svelte-eslint-parser", + parserOptions: { + parser: { + ts: "@typescript-eslint/parser", + js: "espree", + }, + }, }, { files: ["*.ts"], diff --git a/src/rules/indent-helpers/commons.ts b/src/rules/indent-helpers/commons.ts index d689e86c1..5a048a5c2 100644 --- a/src/rules/indent-helpers/commons.ts +++ b/src/rules/indent-helpers/commons.ts @@ -3,7 +3,12 @@ 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 AnyToken = AST.Token | AST.Comment +export type MaybeNode = { + type: string + range: [number, number] + loc: AST.SourceLocation +} export type IndentOptions = { indentChar: " " | "\t" @@ -49,9 +54,9 @@ export type IndentContext = { */ export function setOffsetNodes( { sourceCode, setOffset }: IndentContext, - nodes: (ASTNode | AnyToken | null | undefined)[], - baseNodeOrToken: ASTNode | AnyToken, - lastNodeOrToken: ASTNode | AnyToken | null, + nodes: (ASTNode | AnyToken | MaybeNode | null | undefined)[], + baseNodeOrToken: ASTNode | AnyToken | MaybeNode, + lastNodeOrToken: ASTNode | AnyToken | MaybeNode | null, offset: number, ): void { const baseToken = sourceCode.getFirstToken(baseNodeOrToken) @@ -105,7 +110,7 @@ export function setOffsetNodes( */ export function getFirstAndLastTokens( sourceCode: SourceCode, - node: ASTNode | AnyToken, + node: ASTNode | AnyToken | MaybeNode, borderOffset = 0, ): { firstToken: AST.Token; lastToken: AST.Token } { let firstToken = sourceCode.getFirstToken(node) @@ -133,3 +138,15 @@ export function getFirstAndLastTokens( return { firstToken, lastToken } } + +/** + * Check whether the given node or token is the beginning of a line. + */ +export function isBeginningOfLine( + sourceCode: SourceCode, + node: ASTNode | AnyToken | MaybeNode, +): boolean { + const prevToken = sourceCode.getTokenBefore(node, { includeComments: false }) + + return !prevToken || prevToken.loc.end.line < node.loc!.start.line +} diff --git a/src/rules/indent-helpers/es.ts b/src/rules/indent-helpers/es.ts index b6d291beb..49d2ef29a 100644 --- a/src/rules/indent-helpers/es.ts +++ b/src/rules/indent-helpers/es.ts @@ -972,7 +972,7 @@ export function defineVisitor(context: IndentContext): NodeListener & { if (isSemicolonToken(lastToken) && firstToken !== lastToken) { const next = sourceCode.getTokenAfter(lastToken) if (!next || lastToken.loc.start.line < next.loc.start.line) { - // Lone semicolons + // End of line semicolons setOffset(lastToken, 0, firstToken) } } diff --git a/src/rules/indent-helpers/index.ts b/src/rules/indent-helpers/index.ts index 5d686eb92..922f29f9e 100644 --- a/src/rules/indent-helpers/index.ts +++ b/src/rules/indent-helpers/index.ts @@ -3,16 +3,16 @@ import type * as ESTree from "estree" import type { ASTNode, RuleContext, RuleListener } from "../../types" import * as SV from "./svelte" import * as ES from "./es" +import * as TS from "./ts" import { isNotWhitespace } from "./ast" import { isCommentToken } from "eslint-utils" -import type { IndentOptions } from "./commons" +import type { AnyToken, IndentOptions } from "./commons" type IndentUserOptions = { indent?: number | "tab" switchCase?: number ignoredNodes?: string[] } -type AnyToken = AST.Token | AST.Comment /** * Normalize options. @@ -334,6 +334,7 @@ export function defineVisitor( const nodesVisitor = { ...ES.defineVisitor(indentContext), ...SV.defineVisitor(indentContext), + ...TS.defineVisitor(indentContext), } const knownNodes = new Set(Object.keys(nodesVisitor)) @@ -365,6 +366,8 @@ export function defineVisitor( "*:exit"(node: ASTNode) { // Ignore tokens of unknown nodes. if (!knownNodes.has(node.type)) { + debugger + console.log(node.type) ignore(node) } }, diff --git a/src/rules/indent-helpers/svelte.ts b/src/rules/indent-helpers/svelte.ts index dd5225aec..bfa62aee7 100644 --- a/src/rules/indent-helpers/svelte.ts +++ b/src/rules/indent-helpers/svelte.ts @@ -4,12 +4,12 @@ import { isNotWhitespace } from "./ast" import type { IndentContext } from "./commons" import { getFirstAndLastTokens } from "./commons" import { setOffsetNodes } from "./commons" -type NodeWithParent = Exclude< +type NodeWithoutES = Exclude< AST.SvelteNode, AST.SvelteProgram | AST.SvelteReactiveStatement > -type NodeListenerMap = { - [key in NodeWithParent["type"]]: T extends { type: key } ? T : never +type NodeListenerMap = { + [key in NodeWithoutES["type"]]: T extends { type: key } ? T : never } type NodeListener = { diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts new file mode 100644 index 000000000..bbb19d183 --- /dev/null +++ b/src/rules/indent-helpers/ts.ts @@ -0,0 +1,404 @@ +import type { TSESTree } from "@typescript-eslint/types" +import type * as ESTree from "estree" +import { + isClosingBracketToken, + isClosingParenToken, + isNotClosingParenToken, + isOpeningBracketToken, +} from "eslint-utils" +import type { AnyToken, IndentContext } from "./commons" +import { isBeginningOfLine } from "./commons" +import { setOffsetNodes } from "./commons" +import { getFirstAndLastTokens } from "./commons" + +type NodeWithoutES = Exclude +type NodeListenerMap = { + [key in NodeWithoutES["type"]]: T extends { type: key } ? T : never +} +type NodeListener = { + [T in keyof NodeListenerMap]: (node: NodeListenerMap[T]) => void +} + +/** + * 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 } = context + const visitor: NodeListener = { + TSTypeAnnotation(node: TSESTree.TSTypeAnnotation) { + // : Type + // => Type + const [colonOrArrowToken, secondToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + setOffset( + [colonOrArrowToken, secondToken], + 1, + sourceCode.getFirstToken(node.parent!), + ) + }, + TSAsExpression(node: TSESTree.TSAsExpression) { + // foo as T + const expressionTokens = getFirstAndLastTokens( + sourceCode, + node.expression as ESTree.Expression, + ) + const asToken = sourceCode.getTokenAfter(expressionTokens.lastToken)! + setOffset( + [ + asToken, + getFirstAndLastTokens(sourceCode, node.typeAnnotation).firstToken, + ], + 1, + expressionTokens.firstToken, + ) + }, + TSTypeReference(node: TSESTree.TSTypeReference) { + // T + if (node.typeParameters) { + const typeNameTokens = getFirstAndLastTokens(sourceCode, node.typeName) + setOffset( + sourceCode.getFirstToken(node.typeParameters), + 1, + typeNameTokens.firstToken, + ) + } + }, + TSTypeParameterInstantiation( + node: + | TSESTree.TSTypeParameterInstantiation + | TSESTree.TSTypeParameterDeclaration, + ) { + // + setOffsetNodes( + context, + node.params, + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + TSTypeParameterDeclaration(node: TSESTree.TSTypeParameterDeclaration) { + // + visitor.TSTypeParameterInstantiation(node) + }, + TSTypeAliasDeclaration(node: TSESTree.TSTypeAliasDeclaration) { + // type T = {} + const typeToken = sourceCode.getFirstToken(node) + const idToken = sourceCode.getFirstToken(node.id) + setOffset(idToken, 1, typeToken) + + let eqToken + if (node.typeParameters) { + setOffset(sourceCode.getFirstToken(node.typeParameters), 1, idToken) + eqToken = sourceCode.getTokenAfter(node.typeParameters)! + } else { + eqToken = sourceCode.getTokenAfter(node.id)! + } + + const initToken = sourceCode.getTokenAfter(eqToken) + + setOffset([eqToken, initToken], 1, idToken) + }, + TSFunctionType(node: TSESTree.TSFunctionType) { + const leftParenToken = sourceCode.getFirstToken(node) + const rightParenToken = sourceCode.getTokenAfter( + node.params[node.params.length - 1] || leftParenToken, + { filter: isClosingParenToken, includeComments: false }, + )! + setOffsetNodes(context, node.params, leftParenToken, rightParenToken, 1) + + const arrowToken = sourceCode.getTokenAfter(rightParenToken) + setOffset(arrowToken, 1, leftParenToken) + }, + TSTypeLiteral(node: TSESTree.TSTypeLiteral) { + // {foo:any} + setOffsetNodes( + context, + node.members, + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + TSPropertySignature(node: TSESTree.TSPropertySignature) { + // { target:any } + const firstToken = sourceCode.getFirstToken(node) + const keyTokens = getFirstAndLastTokens(sourceCode, node.key) + let keyLast + if (node.computed) { + const closeBracket = sourceCode.getTokenAfter(keyTokens.firstToken)! + setOffsetNodes(context, [node.key], firstToken, closeBracket, 1) + keyLast = closeBracket + } else { + keyLast = keyTokens.lastToken + } + if (node.typeAnnotation) { + const typeAnnotationToken = sourceCode.getFirstToken( + node.typeAnnotation, + ) + setOffset( + [ + ...sourceCode.getTokensBetween(keyLast, typeAnnotationToken), + typeAnnotationToken, + ], + 1, + firstToken, + ) + } else if (node.optional) { + const qToken = sourceCode.getLastToken(node) + setOffset(qToken, 1, firstToken) + } + }, + TSArrayType(node: TSESTree.TSArrayType) { + // T[] + const firstToken = sourceCode.getFirstToken(node) + setOffset( + sourceCode.getLastTokens(node, { count: 2, includeComments: false }), + 0, + firstToken, + ) + }, + TSQualifiedName(node: TSESTree.TSQualifiedName) { + // A.B + const objectToken = sourceCode.getFirstToken(node) + const dotToken = sourceCode.getTokenBefore(node.right)! + const propertyToken = sourceCode.getTokenAfter(dotToken) + + setOffset([dotToken, propertyToken], 1, objectToken) + }, + TSIndexedAccessType(node: TSESTree.TSIndexedAccessType) { + // A[B] + const objectToken = sourceCode.getFirstToken(node) + + const leftBracketToken = sourceCode.getTokenBefore(node.indexType, { + filter: isOpeningBracketToken, + includeComments: false, + })! + const rightBracketToken = sourceCode.getTokenAfter(node.indexType, { + filter: isClosingBracketToken, + includeComments: false, + }) + + setOffset(leftBracketToken, 1, objectToken) + setOffsetNodes( + context, + [node.indexType], + leftBracketToken, + rightBracketToken, + 1, + ) + }, + TSUnionType(node: TSESTree.TSUnionType | TSESTree.TSIntersectionType) { + // A | B + const firstToken = sourceCode.getFirstToken(node) + const types = [...node.types] + if ( + getFirstAndLastTokens(sourceCode, types[0]).firstToken === firstToken + ) { + types.shift() + } + setOffsetNodes( + context, + types, + firstToken, + null, + isBeginningOfLine(sourceCode, firstToken) ? 0 : 1, + ) + }, + TSIntersectionType(node: TSESTree.TSIntersectionType) { + // A & B + visitor.TSUnionType(node) + }, + TSParenthesizedType(node: TSESTree.TSParenthesizedType) { + // (T) + setOffsetNodes( + context, + [node.typeAnnotation], + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + TSMappedType(node: TSESTree.TSMappedType) { + // {[key in foo]: bar} + const leftBraceToken = sourceCode.getFirstToken(node) + + const leftBracketToken = sourceCode.getTokenBefore(node.typeParameter)! + const rightBracketToken = sourceCode.getTokenAfter( + node.nameType || node.typeParameter, + )! + setOffset( + [ + ...sourceCode.getTokensBetween(leftBraceToken, leftBracketToken), + leftBracketToken, + ], + 1, + leftBraceToken, + ) + setOffsetNodes( + context, + [node.typeParameter, node.nameType], + leftBracketToken, + rightBracketToken, + 1, + ) + + const rightBraceToken = sourceCode.getLastToken(node) + if (node.typeAnnotation) { + const typeAnnotationToken = sourceCode.getFirstToken( + node.typeAnnotation, + ) + setOffset( + [ + ...sourceCode.getTokensBetween( + rightBracketToken, + typeAnnotationToken, + ), + typeAnnotationToken, + ], + 1, + leftBraceToken, + ) + } else { + setOffset( + [...sourceCode.getTokensBetween(rightBracketToken, rightBraceToken)], + 1, + leftBraceToken, + ) + } + + setOffset(rightBraceToken, 0, leftBraceToken) + }, + TSTypeParameter(node: TSESTree.TSTypeParameter) { + // {[key in foo]: bar} + // ^^^^^^^^^^ + // type T + // ^^^^^^^^^^^^^^^ + const [firstToken, secondToken, ...afterTokens] = + sourceCode.getTokens(node) + setOffset(secondToken, 1, firstToken) + + for (const child of [node.constraint, node.default]) { + if (!child) { + continue + } + const [, ...removeTokens] = sourceCode.getTokens(child) + for (const token of removeTokens) { + const i = afterTokens.indexOf(token) + if (i >= 0) { + afterTokens.splice(i, 1) + } + } + } + + if (secondToken.value === "extends") { + let prevToken: AnyToken | null = null + let token = afterTokens.shift() + while (token) { + if (token.value === "=") { + break + } + setOffset(token, 1, secondToken) + prevToken = token + token = afterTokens.shift() + } + while (token) { + setOffset(token, 1, prevToken || secondToken) + token = afterTokens.shift() + } + } else { + setOffset(afterTokens, 1, firstToken) + } + }, + TSConditionalType(node: TSESTree.TSConditionalType) { + // T extends Foo ? T : U + const checkTypeToken = sourceCode.getFirstToken(node) + const extendsToken = sourceCode.getTokenAfter(node.checkType)! + const extendsTypeToken = sourceCode.getFirstToken(node.extendsType) + + setOffset(extendsToken, 1, checkTypeToken) + setOffset(extendsTypeToken, 1, extendsToken) + + const questionToken = sourceCode.getTokenAfter(node.extendsType, { + filter: isNotClosingParenToken, + includeComments: false, + })! + + const consequentToken = sourceCode.getTokenAfter(questionToken) + const colonToken = sourceCode.getTokenAfter(node.trueType, { + filter: isNotClosingParenToken, + includeComments: false, + })! + const alternateToken = sourceCode.getTokenAfter(colonToken) + + let baseNode = node + let parent = baseNode.parent + while ( + parent && + parent.type === "TSConditionalType" && + parent.falseType === baseNode + ) { + baseNode = parent + parent = baseNode.parent + } + const baseToken = sourceCode.getFirstToken(baseNode) + + setOffset([questionToken, colonToken], 1, baseToken) + setOffset(consequentToken, 1, questionToken) + setOffset(alternateToken, 1, colonToken) + }, + + // ---------------------------------------------------------------------- + // SINGLE TOKEN NODES + // ---------------------------------------------------------------------- + TSAnyKeyword() { + // noop + }, + TSBigIntKeyword() { + // noop + }, + TSBooleanKeyword() { + // noop + }, + TSNeverKeyword() { + // noop + }, + TSNullKeyword() { + // noop + }, + TSNumberKeyword() { + // noop + }, + TSObjectKeyword() { + // noop + }, + TSStringKeyword() { + // noop + }, + TSSymbolKeyword() { + // noop + }, + TSUndefinedKeyword() { + // noop + }, + TSUnknownKeyword() { + // noop + }, + TSVoidKeyword() { + // noop + }, + // ---------------------------------------------------------------------- + // WRAPPER NODES + // ---------------------------------------------------------------------- + TSLiteralType() { + // noop + }, + } + + return visitor +} diff --git a/src/types.ts b/src/types.ts index e108e4369..0c15f1261 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,8 +7,12 @@ import type { } from "eslint" import type { AST } from "svelte-eslint-parser" import type * as ESTree from "estree" +import type { TSESTree } from "@typescript-eslint/types" -export type ASTNode = AST.SvelteNode | ESTree.Node +export type ASTNode = + | AST.SvelteNode + | ESTree.Node + | Exclude type ASTNodeWithParent = | (Exclude & { parent: ASTNode }) | AST.SvelteProgram diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-errors.json new file mode 100644 index 000000000..d30558277 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-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 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 8 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 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 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 8 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": 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 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-input.svelte new file mode 100644 index 000000000..2b56525c7 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-input.svelte @@ -0,0 +1,33 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-output.svelte new file mode 100644 index 000000000..bba78d0bc --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation01-output.svelte @@ -0,0 +1,33 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-errors.json new file mode 100644 index 000000000..1f9c919c8 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-errors.json @@ -0,0 +1,92 @@ +[ + { + "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 8 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 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 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 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 4 spaces but found 0 spaces.", + "line": 19, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 20, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte new file mode 100644 index 000000000..49ec433b4 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte @@ -0,0 +1,23 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte new file mode 100644 index 000000000..a5b663de2 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte @@ -0,0 +1,23 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-types01-errors.json new file mode 100644 index 000000000..5a5edffea --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types01-errors.json @@ -0,0 +1,357 @@ +[ + { + "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 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 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 6 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 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 6 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 8 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 10 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 14 spaces but found 0 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 8 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 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 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 8 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 6 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 6 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 8 spaces but found 0 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 10 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 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 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 2 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 6 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 10 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 12 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 4 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 6 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 60, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 6 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 8 spaces but found 0 spaces.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 12 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 8 spaces but found 0 spaces.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 73, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 74, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types01-input.svelte new file mode 100644 index 000000000..282c588fb --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types01-input.svelte @@ -0,0 +1,77 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types01-output.svelte new file mode 100644 index 000000000..c747a6260 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types01-output.svelte @@ -0,0 +1,77 @@ + + + + diff --git a/tests/src/rules/indent.ts b/tests/src/rules/indent.ts index 5051b6ba2..f886a86de 100644 --- a/tests/src/rules/indent.ts +++ b/tests/src/rules/indent.ts @@ -6,6 +6,10 @@ const tester = new RuleTester({ parserOptions: { ecmaVersion: 2020, sourceType: "module", + parser: { + ts: "@typescript-eslint/parser", + js: "espree", + }, }, }) diff --git a/tests/utils/utils.ts b/tests/utils/utils.ts index f9716cf68..4c65f0239 100644 --- a/tests/utils/utils.ts +++ b/tests/utils/utils.ts @@ -183,6 +183,10 @@ function writeFixtures( parserOptions: { ecmaVersion: 2020, sourceType: "module", + parser: { + ts: "@typescript-eslint/parser", + js: "espree", + }, }, }, config.filename, From fc7373eb3e14a6e228d131801a09da57025a4b90 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 21 Jun 2021 13:09:09 +0900 Subject: [PATCH 02/11] update --- src/rules/indent-helpers/es.ts | 2 +- src/rules/indent-helpers/ts.ts | 139 ++++++++- .../invalid/ts/ts-interface01-errors.json | 277 ++++++++++++++++++ .../invalid/ts/ts-interface01-input.svelte | 61 ++++ .../invalid/ts/ts-interface01-output.svelte | 61 ++++ .../ts/ts-type-annotation02-input.svelte | 2 +- .../ts/ts-type-annotation02-output.svelte | 2 +- .../indent/invalid/ts/ts-types01-input.svelte | 2 +- .../invalid/ts/ts-types01-output.svelte | 2 +- .../indent/invalid/ts/ts-types02-errors.json | 37 +++ .../indent/invalid/ts/ts-types02-input.svelte | 12 + .../invalid/ts/ts-types02-output.svelte | 12 + 12 files changed, 603 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte diff --git a/src/rules/indent-helpers/es.ts b/src/rules/indent-helpers/es.ts index 49d2ef29a..e8dc5404d 100644 --- a/src/rules/indent-helpers/es.ts +++ b/src/rules/indent-helpers/es.ts @@ -250,7 +250,7 @@ export function defineVisitor(context: IndentContext): NodeListener & { setOffset(sourceCode.getFirstToken(node.id), 1, classToken) } if (node.superClass != null) { - const extendsToken = sourceCode.getTokenAfter(node.id || classToken)! + const extendsToken = sourceCode.getTokenBefore(node.superClass)! const superClassToken = sourceCode.getTokenAfter(extendsToken) setOffset(extendsToken, 1, classToken) setOffset(superClassToken, 1, extendsToken) diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts index bbb19d183..e9fbad3d4 100644 --- a/src/rules/indent-helpers/ts.ts +++ b/src/rules/indent-helpers/ts.ts @@ -163,6 +163,16 @@ export function defineVisitor(context: IndentContext): NodeListener { firstToken, ) }, + TSTupleType(node: TSESTree.TSTupleType) { + // [T, U] + setOffsetNodes( + context, + node.elementTypes, + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, TSQualifiedName(node: TSESTree.TSQualifiedName) { // A.B const objectToken = sourceCode.getFirstToken(node) @@ -352,7 +362,101 @@ export function defineVisitor(context: IndentContext): NodeListener { setOffset(consequentToken, 1, questionToken) setOffset(alternateToken, 1, colonToken) }, + TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration) { + // interface I {} + const interfaceToken = sourceCode.getFirstToken(node) + setOffset(sourceCode.getFirstToken(node.id), 1, interfaceToken) + if (node.typeParameters != null) { + setOffset( + sourceCode.getFirstToken(node.typeParameters), + 1, + sourceCode.getFirstToken(node.id), + ) + } + if (node.extends != null && node.extends.length) { + const extendsToken = sourceCode.getTokenBefore(node.extends[0])! + setOffset(extendsToken, 1, interfaceToken) + setOffsetNodes(context, node.extends, extendsToken, null, 1) + } + if (node.implements != null && node.implements.length) { + const implementsToken = sourceCode.getTokenBefore(node.implements[0])! + setOffset(implementsToken, 1, interfaceToken) + setOffsetNodes(context, node.implements, implementsToken, null, 1) + } + const bodyToken = sourceCode.getFirstToken(node.body) + setOffset(bodyToken, 0, interfaceToken) + }, + TSInterfaceBody(node: TSESTree.TSInterfaceBody) { + setOffsetNodes( + context, + node.body, + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + TSClassImplements( + node: TSESTree.TSClassImplements | TSESTree.TSInterfaceHeritage, + ) { + // class C implements T {} + // ^ + if (node.typeParameters) { + setOffset( + sourceCode.getFirstToken(node.typeParameters), + 1, + sourceCode.getFirstToken(node), + ) + } + }, + TSInterfaceHeritage(node: TSESTree.TSInterfaceHeritage) { + // interface I extends E implements T {} + // ^ ^ + visitor.TSClassImplements(node) + }, + + // ---------------------------------------------------------------------- + // NON-STANDARD NODES + // ---------------------------------------------------------------------- + ClassProperty(node: TSESTree.ClassProperty) { + 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 (node.value != null) { + const eqToken = sourceCode.getTokenAfter(lastKeyToken)! + const initToken = sourceCode.getTokenAfter(eqToken) + + setOffset([eqToken, initToken], 1, lastKeyToken) + } + }, // ---------------------------------------------------------------------- // SINGLE TOKEN NODES // ---------------------------------------------------------------------- @@ -400,5 +504,38 @@ export function defineVisitor(context: IndentContext): NodeListener { }, } - return visitor + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore + const extendsESVisitor: any = { + ["ClassDeclaration[implements], ClassDeclaration[typeParameters], ClassDeclaration[superTypeParameters]," + + "ClassExpression[implements], ClassExpression[typeParameters], ClassExpression[superTypeParameters]"]( + node: TSESTree.ClassDeclaration | TSESTree.ClassExpression, + ) { + if (node.typeParameters != null) { + setOffset( + sourceCode.getFirstToken(node.typeParameters), + 1, + sourceCode.getFirstToken(node.id || node), + ) + } + if (node.superTypeParameters != null && node.superClass != null) { + setOffset( + sourceCode.getFirstToken(node.superTypeParameters), + 1, + sourceCode.getFirstToken(node.superClass), + ) + } + if (node.implements != null && node.implements.length) { + const classToken = sourceCode.getFirstToken(node) + const implementsToken = sourceCode.getTokenBefore(node.implements[0])! + setOffset(implementsToken, 1, classToken) + + setOffsetNodes(context, node.implements, implementsToken, null, 1) + } + }, + } + + return { + ...visitor, + ...extendsESVisitor, + } } diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-interface01-errors.json new file mode 100644 index 000000000..e285112fc --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface01-errors.json @@ -0,0 +1,277 @@ +[ + { + "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 6 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 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 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 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 6 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 6 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 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 6 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 6 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": 39, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 6 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 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 6 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 4 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 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 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 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface01-input.svelte new file mode 100644 index 000000000..3df03712e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface01-input.svelte @@ -0,0 +1,61 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface01-output.svelte new file mode 100644 index 000000000..563065869 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface01-output.svelte @@ -0,0 +1,61 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte index 49ec433b4..66b2af1a6 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte @@ -20,4 +20,4 @@ A[ ] = [] - + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte index a5b663de2..53297ca63 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte @@ -20,4 +20,4 @@ ] = [] - + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types01-input.svelte index 282c588fb..a5e4fbf1b 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types01-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types01-input.svelte @@ -74,4 +74,4 @@ never } - + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types01-output.svelte index c747a6260..e338e7feb 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types01-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types01-output.svelte @@ -74,4 +74,4 @@ } - + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json new file mode 100644 index 000000000..bbc18dd4e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json @@ -0,0 +1,37 @@ +[ + { + "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 4 spaces but found 0 spaces.", + "line": 9, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte new file mode 100644 index 000000000..08d97d21e --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte @@ -0,0 +1,12 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte new file mode 100644 index 000000000..695ff858f --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte @@ -0,0 +1,12 @@ + + + + From c4bf9ec3f7abeb00d42393ed6022117e784cfadb Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 21 Jun 2021 15:17:46 +0900 Subject: [PATCH 03/11] update --- package.json | 2 +- src/rules/indent-helpers/es.ts | 12 +- src/rules/indent-helpers/index.ts | 2 +- src/rules/indent-helpers/ts.ts | 277 +- .../invalid/ts/ts-d-ts-eslint-errors.json | 3072 +++++++++++++++++ .../invalid/ts/ts-d-ts-eslint-input.svelte | 1019 ++++++ .../invalid/ts/ts-d-ts-eslint-output.svelte | 1019 ++++++ .../invalid/ts/ts-decorator01-errors.json | 932 +++++ .../invalid/ts/ts-decorator01-input.svelte | 207 ++ .../invalid/ts/ts-decorator01-output.svelte | 207 ++ .../indent/invalid/ts/ts-enum01-errors.json | 107 + .../indent/invalid/ts/ts-enum01-input.svelte | 27 + .../indent/invalid/ts/ts-enum01-output.svelte | 27 + .../invalid/ts/ts-function01-errors.json | 182 + .../invalid/ts/ts-function01-input.svelte | 43 + .../invalid/ts/ts-function01-output.svelte | 43 + .../invalid/ts/ts-interface02-errors.json | 182 + .../invalid/ts/ts-interface02-input.svelte | 43 + .../invalid/ts/ts-interface02-output.svelte | 43 + .../invalid/ts/ts-types01-input copy.svelte | 77 + .../indent/invalid/ts/ts-types02-errors.json | 60 + .../indent/invalid/ts/ts-types02-input.svelte | 14 + .../invalid/ts/ts-types02-output.svelte | 14 + 23 files changed, 7598 insertions(+), 13 deletions(-) create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-decorator01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-enum01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-enum01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-enum01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-function01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-function01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-function01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface02-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types01-input copy.svelte diff --git a/package.json b/package.json index b5aaea141..92cb27a57 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "pretest:base": "cross-env DEBUG=eslint-plugin-svelte*", "test": "mocha --require ts-node/register \"tests/src/**/*.ts\" --reporter dot --timeout 60000", "cover": "nyc --reporter=lcov npm run test", - "debug": "mocha --require ts-node/register/transpile-only \"tests/src/**/*.ts\" --reporter dot", + "debug": "mocha --require ts-node/register/transpile-only \"tests/src/**/*.ts\" --reporter dot --timeout 60000", "lint": "eslint .", "eslint-fix": "eslint . --fix", "update": "ts-node --transpile-only ./tools/update.ts && npm run eslint-fix && npm run test", diff --git a/src/rules/indent-helpers/es.ts b/src/rules/indent-helpers/es.ts index e8dc5404d..b0a25e282 100644 --- a/src/rules/indent-helpers/es.ts +++ b/src/rules/indent-helpers/es.ts @@ -1,5 +1,6 @@ import type { AST } from "svelte-eslint-parser" import type * as ESTree from "estree" +import type { TSESTree } from "@typescript-eslint/types" import type { ASTNode } from "../../types" import type { IndentContext } from "./commons" import { getFirstAndLastTokens } from "./commons" @@ -461,7 +462,7 @@ export function defineVisitor(context: IndentContext): NodeListener & { ) { const firstToken = sourceCode.getFirstToken(node) let leftParenToken, bodyBaseToken - if (isOpeningParenToken(firstToken)) { + if (firstToken.type === "Punctuator") { // method leftParenToken = firstToken bodyBaseToken = sourceCode.getFirstToken(getParent(node)!) @@ -490,6 +491,15 @@ export function defineVisitor(context: IndentContext): NodeListener & { bodyBaseToken = firstToken } + if ( + !isOpeningParenToken(leftParenToken) && + (node as TSESTree.FunctionExpression).typeParameters + ) { + leftParenToken = sourceCode.getTokenAfter( + (node as TSESTree.FunctionExpression).typeParameters!, + )! + } + const rightParenToken = sourceCode.getTokenAfter( node.params[node.params.length - 1] || leftParenToken, { filter: isClosingParenToken, includeComments: false }, diff --git a/src/rules/indent-helpers/index.ts b/src/rules/indent-helpers/index.ts index 922f29f9e..45cf2ef28 100644 --- a/src/rules/indent-helpers/index.ts +++ b/src/rules/indent-helpers/index.ts @@ -367,7 +367,7 @@ export function defineVisitor( // Ignore tokens of unknown nodes. if (!knownNodes.has(node.type)) { debugger - console.log(node.type) + console.log(node.type, node.loc!.start.line) ignore(node) } }, diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts index e9fbad3d4..2449c73ba 100644 --- a/src/rules/indent-helpers/ts.ts +++ b/src/rules/indent-helpers/ts.ts @@ -4,7 +4,9 @@ import { isClosingBracketToken, isClosingParenToken, isNotClosingParenToken, + isOpeningBraceToken, isOpeningBracketToken, + isOpeningParenToken, } from "eslint-utils" import type { AnyToken, IndentContext } from "./commons" import { isBeginningOfLine } from "./commons" @@ -16,7 +18,7 @@ type NodeListenerMap = { [key in NodeWithoutES["type"]]: T extends { type: key } ? T : never } type NodeListener = { - [T in keyof NodeListenerMap]: (node: NodeListenerMap[T]) => void + [T in keyof NodeListenerMap]?: (node: NodeListenerMap[T]) => void } /** @@ -27,7 +29,7 @@ type NodeListener = { */ export function defineVisitor(context: IndentContext): NodeListener { const { setOffset, sourceCode, copyOffset } = context - const visitor: NodeListener = { + const visitor = { TSTypeAnnotation(node: TSESTree.TSTypeAnnotation) { // : Type // => Type @@ -127,6 +129,7 @@ export function defineVisitor(context: IndentContext): NodeListener { }, TSPropertySignature(node: TSESTree.TSPropertySignature) { // { target:any } + // ^^^^^^^^^^ const firstToken = sourceCode.getFirstToken(node) const keyTokens = getFirstAndLastTokens(sourceCode, node.key) let keyLast @@ -154,6 +157,36 @@ export function defineVisitor(context: IndentContext): NodeListener { setOffset(qToken, 1, firstToken) } }, + TSIndexSignature(node: TSESTree.TSIndexSignature) { + // { [k: string ]: string[] }; + // ^^^^^^^^^^^^^^^^^^^^^^ + const leftBracketToken = sourceCode.getFirstToken(node) + const rightBracketToken = sourceCode.getTokenAfter( + node.parameters[node.parameters.length - 1] || leftBracketToken, + { filter: isClosingBracketToken, includeComments: false }, + )! + setOffsetNodes( + context, + node.parameters, + leftBracketToken, + rightBracketToken, + 1, + ) + const keyLast = rightBracketToken + if (node.typeAnnotation) { + const typeAnnotationToken = sourceCode.getFirstToken( + node.typeAnnotation, + ) + setOffset( + [ + ...sourceCode.getTokensBetween(keyLast, typeAnnotationToken), + typeAnnotationToken, + ], + 1, + leftBracketToken, + ) + } + }, TSArrayType(node: TSESTree.TSArrayType) { // T[] const firstToken = sourceCode.getFirstToken(node) @@ -289,9 +322,7 @@ export function defineVisitor(context: IndentContext): NodeListener { // ^^^^^^^^^^ // type T // ^^^^^^^^^^^^^^^ - const [firstToken, secondToken, ...afterTokens] = - sourceCode.getTokens(node) - setOffset(secondToken, 1, firstToken) + const [firstToken, ...afterTokens] = sourceCode.getTokens(node) for (const child of [node.constraint, node.default]) { if (!child) { @@ -305,6 +336,11 @@ export function defineVisitor(context: IndentContext): NodeListener { } } } + const secondToken = afterTokens.shift() + if (!secondToken) { + return + } + setOffset(secondToken, 1, firstToken) if (secondToken.value === "extends") { let prevToken: AnyToken | null = null @@ -386,7 +422,7 @@ export function defineVisitor(context: IndentContext): NodeListener { const bodyToken = sourceCode.getFirstToken(node.body) setOffset(bodyToken, 0, interfaceToken) }, - TSInterfaceBody(node: TSESTree.TSInterfaceBody) { + TSInterfaceBody(node: TSESTree.TSInterfaceBody | TSESTree.TSModuleBlock) { setOffsetNodes( context, node.body, @@ -413,13 +449,204 @@ export function defineVisitor(context: IndentContext): NodeListener { // ^ ^ visitor.TSClassImplements(node) }, + TSEnumDeclaration(node: TSESTree.TSEnumDeclaration) { + // enum E {} + const firstToken = sourceCode.getFirstToken(node) + const idTokens = getFirstAndLastTokens(sourceCode, node.id) + const prefixTokens = sourceCode.getTokensBetween( + firstToken, + idTokens.firstToken, + ) + setOffset(prefixTokens, 0, firstToken) + setOffset(idTokens.firstToken, 1, firstToken) + + const leftBraceToken = sourceCode.getTokenAfter(idTokens.lastToken)! + const rightBraceToken = sourceCode.getLastToken(node) + setOffset(leftBraceToken, 0, firstToken) + setOffsetNodes(context, node.members, leftBraceToken, rightBraceToken, 1) + }, + TSEnumMember(node: TSESTree.TSEnumMember) { + visitor.ClassProperty(node) + }, + TSModuleDeclaration(node: TSESTree.TSModuleDeclaration) { + const firstToken = sourceCode.getFirstToken(node) + const idTokens = getFirstAndLastTokens(sourceCode, node.id) + const prefixTokens = sourceCode.getTokensBetween( + firstToken, + idTokens.firstToken, + ) + setOffset(prefixTokens, 0, firstToken) + setOffset(idTokens.firstToken, 1, firstToken) + + if (node.body) { + const bodyFirstToken = sourceCode.getFirstToken(node.body) + setOffset( + bodyFirstToken, + isOpeningBraceToken(bodyFirstToken) ? 0 : 1, + firstToken, + ) + } + }, + TSModuleBlock(node: TSESTree.TSModuleBlock) { + visitor.TSInterfaceBody(node) + }, + TSMethodSignature(node: TSESTree.TSMethodSignature) { + // fn(arg: A): R | null; + const firstToken = sourceCode.getFirstToken(node) + const keyTokens = getFirstAndLastTokens(sourceCode, node.key) + let keyLast + if (node.computed) { + const closeBracket = sourceCode.getTokenAfter(keyTokens.firstToken)! + setOffsetNodes(context, [node.key], firstToken, closeBracket, 1) + keyLast = closeBracket + } else { + keyLast = keyTokens.lastToken + } + const leftParenToken = sourceCode.getTokenAfter(keyLast, { + filter: isOpeningParenToken, + includeComments: false, + })! + setOffset( + [ + ...sourceCode.getTokensBetween(keyLast, leftParenToken), + leftParenToken, + ], + 1, + firstToken, + ) + const rightParenToken = sourceCode.getTokenAfter( + node.params[node.params.length - 1] || leftParenToken, + { filter: isClosingParenToken, includeComments: false }, + )! + setOffsetNodes(context, node.params, leftParenToken, rightParenToken, 1) + if (node.returnType) { + const typeAnnotationToken = sourceCode.getFirstToken(node.returnType) + setOffset( + [ + ...sourceCode.getTokensBetween(keyLast, typeAnnotationToken), + typeAnnotationToken, + ], + 1, + firstToken, + ) + } + }, + TSCallSignatureDeclaration(node: TSESTree.TSCallSignatureDeclaration) { + // interface A { (e: E): R } + // ^^^^^^^^^^^^^ + const firstToken = sourceCode.getFirstToken(node) + let currToken = firstToken + if (node.typeParameters) { + currToken = sourceCode.getTokenAfter(node.typeParameters)! + setOffset(currToken, 1, firstToken) + } + const leftParenToken = currToken + const rightParenToken = sourceCode.getTokenAfter( + node.params[node.params.length - 1] || leftParenToken, + { filter: isClosingParenToken, includeComments: false }, + )! + setOffsetNodes(context, node.params, leftParenToken, rightParenToken, 1) + + if (node.returnType) { + const typeAnnotationToken = sourceCode.getFirstToken(node.returnType) + setOffset( + [ + ...sourceCode.getTokensBetween( + rightParenToken, + typeAnnotationToken, + ), + typeAnnotationToken, + ], + 1, + firstToken, + ) + } + }, + TSEmptyBodyFunctionExpression( + node: TSESTree.TSEmptyBodyFunctionExpression, + ) { + const firstToken = sourceCode.getFirstToken(node) + let leftParenToken, bodyBaseToken + if (firstToken.type === "Punctuator") { + // method + leftParenToken = firstToken + bodyBaseToken = sourceCode.getFirstToken(node.parent!) + } 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 + } + + if (!isOpeningParenToken(leftParenToken) && node.typeParameters) { + leftParenToken = sourceCode.getTokenAfter(node.typeParameters)! + } + + const rightParenToken = sourceCode.getTokenAfter( + node.params[node.params.length - 1] || leftParenToken, + { filter: isClosingParenToken, includeComments: false }, + )! + + setOffset(leftParenToken, 1, bodyBaseToken) + setOffsetNodes(context, node.params, leftParenToken, rightParenToken, 1) + }, + TSTypeOperator(node: TSESTree.TSTypeOperator | TSESTree.TSTypeQuery) { + // keyof T + const firstToken = sourceCode.getFirstToken(node) + const nextToken = sourceCode.getTokenAfter(firstToken) + + setOffset(nextToken, 1, firstToken) + }, + TSTypeQuery(node: TSESTree.TSTypeQuery) { + // type T = typeof a + visitor.TSTypeOperator(node) + }, + TSTypePredicate(node: TSESTree.TSTypePredicate) { + // v is T + const firstToken = sourceCode.getFirstToken(node) + const opToken = sourceCode.getTokenAfter(node.parameterName, { + filter: isNotClosingParenToken, + includeComments: false, + })! + const rightToken = + node.typeAnnotation && + getFirstAndLastTokens(sourceCode, node.typeAnnotation).firstToken + + setOffset( + [opToken, rightToken], + 1, + getFirstAndLastTokens(sourceCode, firstToken).firstToken, + ) + }, // ---------------------------------------------------------------------- // NON-STANDARD NODES // ---------------------------------------------------------------------- - ClassProperty(node: TSESTree.ClassProperty) { + ClassProperty(node: TSESTree.ClassProperty | TSESTree.TSEnumMember) { + const { keyNode, valueNode } = + node.type === "ClassProperty" + ? { keyNode: node.key, valueNode: node.value } + : { keyNode: node.id, valueNode: node.initializer } const firstToken = sourceCode.getFirstToken(node) - const keyTokens = getFirstAndLastTokens(sourceCode, node.key) + const keyTokens = getFirstAndLastTokens(sourceCode, keyNode) const prefixTokens = sourceCode.getTokensBetween( firstToken, keyTokens.firstToken, @@ -440,7 +667,7 @@ export function defineVisitor(context: IndentContext): NodeListener { setOffset(leftBracketToken, 0, firstToken) setOffsetNodes( context, - [node.key], + [keyNode], leftBracketToken, rightBracketToken, 1, @@ -450,13 +677,40 @@ export function defineVisitor(context: IndentContext): NodeListener { lastKeyToken = keyTokens.lastToken } - if (node.value != null) { + if (valueNode != null) { const eqToken = sourceCode.getTokenAfter(lastKeyToken)! const initToken = sourceCode.getTokenAfter(eqToken) setOffset([eqToken, initToken], 1, lastKeyToken) } }, + Decorator(node: TSESTree.Decorator) { + // @Decorator + const [atToken, secondToken] = sourceCode.getFirstTokens(node, { + count: 2, + includeComments: false, + }) + setOffset(secondToken, 0, atToken) + + const parent = node.parent! + const { decorators } = parent as { decorators?: TSESTree.Decorator[] } + if (!decorators || decorators.length === 0) { + return + } + if (decorators[0] === node) { + if (parent.range[0] === node.range[0]) { + const startParentToken = sourceCode.getTokenAfter( + decorators[decorators?.length - 1], + ) + setOffset(startParentToken, 0, atToken) + } else { + const startParentToken = sourceCode.getFirstToken(parent) + copyOffset(atToken, startParentToken) + } + } else { + setOffset(atToken, 0, sourceCode.getFirstToken(decorators[0])) + } + }, // ---------------------------------------------------------------------- // SINGLE TOKEN NODES // ---------------------------------------------------------------------- @@ -496,6 +750,9 @@ export function defineVisitor(context: IndentContext): NodeListener { TSVoidKeyword() { // noop }, + TSThisType() { + // noop + }, // ---------------------------------------------------------------------- // WRAPPER NODES // ---------------------------------------------------------------------- diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-errors.json new file mode 100644 index 000000000..10f6a94dd --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-errors.json @@ -0,0 +1,3072 @@ +[ + { + "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": 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": 19, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 24, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 27, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 30, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 33, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 40, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 41, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 47, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 49, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 50, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 52, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 56, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 59, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 69, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 73, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 74, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 75, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 76, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 77, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 78, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 79, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 80, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 81, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 82, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 83, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 84, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 85, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 86, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 90, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 91, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 92, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 93, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 97, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 98, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 99, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 100, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 101, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 103, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 105, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 107, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 109, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 111, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 115, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 116, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 117, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 118, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 119, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 14 spaces.", + "line": 120, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 14 spaces.", + "line": 121, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 14 spaces.", + "line": 122, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 10 spaces.", + "line": 123, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 124, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 14 spaces.", + "line": 125, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 14 spaces.", + "line": 126, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 14 spaces.", + "line": 127, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 10 spaces.", + "line": 128, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 129, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 130, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 133, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 135, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 137, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 202, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 205, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 206, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 214, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 216, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 218, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 219, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 220, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 221, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 222, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 228, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 232, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 233, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 234, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 235, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 236, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 237, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 238, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 239, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 240, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 241, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 242, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 243, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 244, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 245, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 246, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 247, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 248, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 249, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 250, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 251, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 252, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 253, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 254, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 255, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 256, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 257, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 258, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 259, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 260, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 264, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 265, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 266, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 267, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 268, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 269, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 270, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 271, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 272, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 273, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 274, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 275, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 276, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 277, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 278, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 279, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 280, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 281, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 282, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 283, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 284, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 285, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 286, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 287, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 288, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 289, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 290, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 291, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 292, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 296, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 297, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 298, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 299, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 300, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 301, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 302, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 303, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 304, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 305, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 306, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 307, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 308, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 309, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 310, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 311, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 312, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 313, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 314, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 315, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 316, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 317, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 318, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 319, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 320, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 321, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 322, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 323, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 324, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 328, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 329, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 330, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 331, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 332, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 333, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 334, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 335, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 336, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 337, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 338, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 339, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 340, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 341, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 342, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 343, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 344, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 345, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 346, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 347, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 348, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 349, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 350, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 351, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 352, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 353, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 354, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 355, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 356, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 360, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 361, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 362, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 363, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 364, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 365, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 366, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 367, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 368, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 369, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 370, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 371, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 372, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 373, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 374, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 375, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 376, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 377, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 378, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 379, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 380, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 381, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 382, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 383, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 384, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 385, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 386, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 387, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 388, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 389, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 390, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 391, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 392, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 396, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 397, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 398, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 399, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 400, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 401, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 402, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 403, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 404, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 405, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 406, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 407, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 408, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 409, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 410, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 411, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 412, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 413, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 414, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 415, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 416, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 417, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 418, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 419, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 420, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 421, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 422, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 423, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 424, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 425, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 16 spaces.", + "line": 426, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 427, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 428, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 430, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 432, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 434, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 436, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 437, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 442, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 443, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 444, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 445, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 446, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 447, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 448, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 449, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 450, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 451, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 452, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 453, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 454, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 455, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 456, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 457, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 458, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 459, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 460, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 461, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 462, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 463, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 464, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 465, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 466, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 467, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 468, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 469, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 470, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 471, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 472, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 473, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 474, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 475, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 476, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 477, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 478, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 479, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 480, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 481, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 482, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 483, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 484, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 485, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 486, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 487, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 488, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 489, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 490, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 491, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 492, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 493, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 494, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 495, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 496, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 497, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 498, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 499, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 500, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 501, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 502, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 503, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 504, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 505, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 506, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 507, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 508, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 509, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 513, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 518, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 520, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 522, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 524, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 526, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 528, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 529, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 530, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 531, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 532, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 533, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 534, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 538, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 539, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 540, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 541, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 542, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 543, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 544, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 545, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 549, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 550, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 551, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 552, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 556, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 557, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 558, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 559, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 560, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 561, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 562, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 563, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 564, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 565, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 566, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 567, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 568, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 569, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 570, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 571, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 572, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 576, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 577, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 578, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 579, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 580, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 581, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 583, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 585, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 587, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 589, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 591, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 593, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 595, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 597, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 601, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 603, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 610, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 616, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 617, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 620, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 622, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 624, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 626, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 628, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 630, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 632, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 634, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 638, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 639, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 641, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 643, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 645, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 667, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 669, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 678, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 682, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 686, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 687, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 688, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 689, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 690, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 691, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 692, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 693, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 694, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 695, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 696, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 697, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 701, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 702, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 707, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 708, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 712, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 713, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 714, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 715, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 716, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 717, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 718, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 719, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 720, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 721, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 725, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 726, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 727, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 728, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 729, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 730, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 731, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 735, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 736, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 737, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 741, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 742, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 743, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 744, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 745, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 746, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 747, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 748, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 749, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 750, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 751, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 752, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 753, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 754, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 758, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 762, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 763, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 764, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 768, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 14 spaces.", + "line": 769, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 10 spaces.", + "line": 770, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 771, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 14 spaces.", + "line": 772, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 10 spaces.", + "line": 773, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 776, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 777, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 778, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 779, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 783, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 784, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 789, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 790, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 791, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 793, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 795, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 799, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 817, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 819, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 821, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 822, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 823, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 824, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 825, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 826, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 827, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 829, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 830, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 831, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 832, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 833, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 834, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 835, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 836, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 837, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 838, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 840, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 841, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 842, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 844, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 845, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 846, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 847, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 851, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 852, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 853, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 854, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 855, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 856, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 857, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 858, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 859, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 863, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 864, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 865, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 869, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 870, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 874, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 879, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 881, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 886, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 912, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 914, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 915, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 917, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 918, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 919, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 920, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 921, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 922, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 923, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 924, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 925, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 926, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 927, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 928, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 929, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 930, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 931, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 932, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 933, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 934, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 935, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 936, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 937, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 938, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 939, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 940, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 941, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 942, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 950, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 951, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 952, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 953, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 954, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 955, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 961, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 963, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 967, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 971, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 972, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 973, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 974, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 12 spaces.", + "line": 975, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 976, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 978, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 980, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 982, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 983, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 984, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 985, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 986, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 987, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 988, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 992, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 993, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 994, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 995, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 999, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1000, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1004, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1005, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1006, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1007, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1008, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1009, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1010, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1011, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 8 spaces.", + "line": 1012, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 1014, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-input.svelte new file mode 100644 index 000000000..85ce0df82 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-input.svelte @@ -0,0 +1,1019 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-output.svelte new file mode 100644 index 000000000..6983c38a8 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-d-ts-eslint-output.svelte @@ -0,0 +1,1019 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json new file mode 100644 index 000000000..e0170baf8 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json @@ -0,0 +1,932 @@ +[ + { + "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 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 4 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 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 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 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 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 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 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 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 8 spaces but found 0 spaces.", + "line": 34, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 10 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 4 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 6 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 8 spaces but found 0 spaces.", + "line": 42, + "column": 1 + }, + { + "message": "Expected indentation of 8 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 2 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 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 6 spaces but found 0 spaces.", + "line": 53, + "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 8 spaces but found 0 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 10 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 4 spaces but found 0 spaces.", + "line": 61, + "column": 1 + }, + { + "message": "Expected indentation of 6 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 8 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 6 spaces but found 0 spaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 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 6 spaces but found 0 spaces.", + "line": 74, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 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 8 spaces but found 0 spaces.", + "line": 80, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 81, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 82, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 83, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 84, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 85, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 86, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 88, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 89, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 90, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 91, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 92, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 93, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 94, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 96, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 97, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 98, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 99, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 100, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 101, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 102, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 103, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 104, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 105, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 106, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 107, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 109, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 110, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 111, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 112, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 113, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 114, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 115, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 116, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 117, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 118, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 119, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 120, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 121, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 123, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 124, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 125, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 126, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 127, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 128, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 129, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 130, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 131, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 133, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 134, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 135, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 136, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 137, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 138, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 139, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 140, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 142, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 143, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 144, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 146, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 147, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 148, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 150, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 151, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 152, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 153, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 154, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 155, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 156, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 157, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 158, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 159, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 160, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 161, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 162, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 163, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 164, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 165, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 166, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 168, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 169, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 170, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 171, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 172, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 173, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 174, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 175, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 176, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 177, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 178, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 179, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 180, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 181, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 182, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 183, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 184, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 185, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 186, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 187, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 188, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 189, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 190, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 191, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 192, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 193, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 194, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 195, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 196, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 197, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 198, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 199, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 200, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 201, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 202, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 203, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 204, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-input.svelte new file mode 100644 index 000000000..11fe26aab --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-input.svelte @@ -0,0 +1,207 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte new file mode 100644 index 000000000..0a94b5993 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte @@ -0,0 +1,207 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-enum01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-enum01-errors.json new file mode 100644 index 000000000..46d84daab --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-enum01-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 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 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 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 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 4 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 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 6 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 24, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-enum01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-enum01-input.svelte new file mode 100644 index 000000000..ec5c894f2 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-enum01-input.svelte @@ -0,0 +1,27 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-enum01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-enum01-output.svelte new file mode 100644 index 000000000..d6cac4302 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-enum01-output.svelte @@ -0,0 +1,27 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-function01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-function01-errors.json new file mode 100644 index 000000000..a6aa81117 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-function01-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 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 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 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 10 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 6 spaces but found 0 spaces.", + "line": 15, + "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 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 10 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 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 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 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 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 4 spaces but found 0 spaces.", + "line": 39, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 40, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-function01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-function01-input.svelte new file mode 100644 index 000000000..7576a68df --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-function01-input.svelte @@ -0,0 +1,43 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-function01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-function01-output.svelte new file mode 100644 index 000000000..f5466b5c5 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-function01-output.svelte @@ -0,0 +1,43 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-errors.json new file mode 100644 index 000000000..47b70160f --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-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 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 8 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 8, + "column": 1 + }, + { + "message": "Expected indentation of 10 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 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": 13, + "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 6 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 8 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 6 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 6 spaces but found 0 spaces.", + "line": 28, + "column": 1 + }, + { + "message": "Expected indentation of 8 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 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 10 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 6 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 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte new file mode 100644 index 000000000..80570a1fc --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte @@ -0,0 +1,43 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte new file mode 100644 index 000000000..d13c25e61 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte @@ -0,0 +1,43 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types01-input copy.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types01-input copy.svelte new file mode 100644 index 000000000..a5e4fbf1b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types01-input copy.svelte @@ -0,0 +1,77 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json index bbc18dd4e..97fa918c8 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json @@ -33,5 +33,65 @@ "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": 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 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 6 spaces but found 0 spaces.", + "line": 18, + "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 4 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 23, + "column": 1 } ] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte index 08d97d21e..b8fda61e2 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte @@ -7,6 +7,20 @@ number , number ] + +type A += +keyof +T +type B += +typeof +C + +type D = (v) +=> +v is +number diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte index 695ff858f..78a2f33dc 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte @@ -7,6 +7,20 @@ , number ] + + type A + = + keyof + T + type B + = + typeof + C + + type D = (v) + => + v is + number From c39f4065c0b9e4a83027a3cabeeacd7c186e92bd Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 21 Jun 2021 15:21:26 +0900 Subject: [PATCH 04/11] fix --- src/rules/indent-helpers/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rules/indent-helpers/index.ts b/src/rules/indent-helpers/index.ts index 45cf2ef28..a26b045e0 100644 --- a/src/rules/indent-helpers/index.ts +++ b/src/rules/indent-helpers/index.ts @@ -366,8 +366,8 @@ export function defineVisitor( "*:exit"(node: ASTNode) { // Ignore tokens of unknown nodes. if (!knownNodes.has(node.type)) { - debugger - console.log(node.type, node.loc!.start.line) + // debugger + // console.log(node.type, node.loc!.start.line) ignore(node) } }, From e766dbe023445ac1c84cba8dc7a6d200bc127a95 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 21 Jun 2021 18:10:41 +0900 Subject: [PATCH 05/11] update --- .eslintignore | 1 + src/rules/indent-helpers/ts.ts | 396 +++++++++++++++++- .../indent/invalid/ts/ts-class01-errors.json | 202 +++++++++ .../indent/invalid/ts/ts-class01-input.svelte | 46 ++ .../invalid/ts/ts-class01-output.svelte | 46 ++ .../invalid/ts/ts-interface02-errors.json | 65 +++ .../invalid/ts/ts-interface02-input.svelte | 14 + .../invalid/ts/ts-interface02-output.svelte | 14 + .../indent/invalid/ts/ts-node01-errors.json | 57 +++ .../indent/invalid/ts/ts-node01-input.svelte | 16 + .../indent/invalid/ts/ts-node01-output.svelte | 16 + .../ts/ts-type-annotation02-errors.json | 85 ++++ .../ts/ts-type-annotation02-input.svelte | 20 + .../ts/ts-type-annotation02-output.svelte | 20 + .../ts/ts-type-annotation03-errors.json | 37 ++ .../ts/ts-type-annotation03-input.svelte | 12 + .../ts/ts-type-annotation03-output.svelte | 12 + .../indent/invalid/ts/ts-types02-errors.json | 240 +++++++++++ .../indent/invalid/ts/ts-types02-input.svelte | 50 +++ .../invalid/ts/ts-types02-output.svelte | 50 +++ .../indent/invalid/ts/ts-types03-errors.json | 162 +++++++ .../indent/invalid/ts/ts-types03-input.svelte | 41 ++ .../invalid/ts/ts-types03-output.svelte | 41 ++ 23 files changed, 1625 insertions(+), 18 deletions(-) create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-node01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-node01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-node01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types03-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types03-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types03-output.svelte diff --git a/.eslintignore b/.eslintignore index 6fd64068c..d55c57aca 100644 --- a/.eslintignore +++ b/.eslintignore @@ -7,3 +7,4 @@ !/.vscode !/.github /prettier-playground +/tests/fixtures/rules/indent/invalid/ts \ No newline at end of file diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts index 2449c73ba..25a4d9f66 100644 --- a/src/rules/indent-helpers/ts.ts +++ b/src/rules/indent-helpers/ts.ts @@ -106,8 +106,24 @@ export function defineVisitor(context: IndentContext): NodeListener { setOffset([eqToken, initToken], 1, idToken) }, - TSFunctionType(node: TSESTree.TSFunctionType) { - const leftParenToken = sourceCode.getFirstToken(node) + TSFunctionType(node: TSESTree.TSFunctionType | TSESTree.TSConstructorType) { + // ()=>void + const firstToken = sourceCode.getFirstToken(node) + // new or < or ( + let currToken = firstToken + if (node.type === "TSConstructorType") { + // currToken is new token + // < or ( + currToken = sourceCode.getTokenAfter(currToken)! + setOffset(currToken, 1, firstToken) + } + if (node.typeParameters) { + // currToken is < token + // ( + currToken = sourceCode.getTokenAfter(node.typeParameters)! + setOffset(currToken, 1, firstToken) + } + const leftParenToken = currToken const rightParenToken = sourceCode.getTokenAfter( node.params[node.params.length - 1] || leftParenToken, { filter: isClosingParenToken, includeComments: false }, @@ -117,6 +133,10 @@ export function defineVisitor(context: IndentContext): NodeListener { const arrowToken = sourceCode.getTokenAfter(rightParenToken) setOffset(arrowToken, 1, leftParenToken) }, + TSConstructorType(node: TSESTree.TSConstructorType) { + // new ()=>void + visitor.TSFunctionType(node) + }, TSTypeLiteral(node: TSESTree.TSTypeLiteral) { // {foo:any} setOffsetNodes( @@ -465,9 +485,6 @@ export function defineVisitor(context: IndentContext): NodeListener { setOffset(leftBraceToken, 0, firstToken) setOffsetNodes(context, node.members, leftBraceToken, rightBraceToken, 1) }, - TSEnumMember(node: TSESTree.TSEnumMember) { - visitor.ClassProperty(node) - }, TSModuleDeclaration(node: TSESTree.TSModuleDeclaration) { const firstToken = sourceCode.getFirstToken(node) const idTokens = getFirstAndLastTokens(sourceCode, node.id) @@ -531,12 +548,25 @@ export function defineVisitor(context: IndentContext): NodeListener { ) } }, - TSCallSignatureDeclaration(node: TSESTree.TSCallSignatureDeclaration) { + TSCallSignatureDeclaration( + node: + | TSESTree.TSCallSignatureDeclaration + | TSESTree.TSConstructSignatureDeclaration, + ) { // interface A { (e: E): R } // ^^^^^^^^^^^^^ const firstToken = sourceCode.getFirstToken(node) + // new or < or ( let currToken = firstToken + if (node.type === "TSConstructSignatureDeclaration") { + // currToken is new token + // < or ( + currToken = sourceCode.getTokenAfter(currToken)! + setOffset(currToken, 1, firstToken) + } if (node.typeParameters) { + // currToken is < token + // ( currToken = sourceCode.getTokenAfter(node.typeParameters)! setOffset(currToken, 1, firstToken) } @@ -562,8 +592,15 @@ export function defineVisitor(context: IndentContext): NodeListener { ) } }, + TSConstructSignatureDeclaration( + node: TSESTree.TSConstructSignatureDeclaration, + ) { + // interface A { new (e: E): R } + // ^^^^^^^^^^^^^^^^^ + visitor.TSCallSignatureDeclaration(node) + }, TSEmptyBodyFunctionExpression( - node: TSESTree.TSEmptyBodyFunctionExpression, + node: TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSDeclareFunction, ) { const firstToken = sourceCode.getFirstToken(node) let leftParenToken, bodyBaseToken @@ -608,7 +645,16 @@ export function defineVisitor(context: IndentContext): NodeListener { setOffset(leftParenToken, 1, bodyBaseToken) setOffsetNodes(context, node.params, leftParenToken, rightParenToken, 1) }, - TSTypeOperator(node: TSESTree.TSTypeOperator | TSESTree.TSTypeQuery) { + TSDeclareFunction(node: TSESTree.TSDeclareFunction) { + // function fn(): void; + visitor.TSEmptyBodyFunctionExpression(node) + }, + TSTypeOperator( + node: + | TSESTree.TSTypeOperator + | TSESTree.TSTypeQuery + | TSESTree.TSInferType, + ) { // keyof T const firstToken = sourceCode.getFirstToken(node) const nextToken = sourceCode.getTokenAfter(firstToken) @@ -619,6 +665,10 @@ export function defineVisitor(context: IndentContext): NodeListener { // type T = typeof a visitor.TSTypeOperator(node) }, + TSInferType(node: TSESTree.TSInferType) { + // infer U + visitor.TSTypeOperator(node) + }, TSTypePredicate(node: TSESTree.TSTypePredicate) { // v is T const firstToken = sourceCode.getFirstToken(node) @@ -636,15 +686,18 @@ export function defineVisitor(context: IndentContext): NodeListener { getFirstAndLastTokens(sourceCode, firstToken).firstToken, ) }, - - // ---------------------------------------------------------------------- - // NON-STANDARD NODES - // ---------------------------------------------------------------------- - ClassProperty(node: TSESTree.ClassProperty | TSESTree.TSEnumMember) { + TSAbstractMethodDefinition( + node: + | TSESTree.TSAbstractMethodDefinition + | TSESTree.TSAbstractClassProperty + | TSESTree.ClassProperty + | TSESTree.TSEnumMember, + ) { const { keyNode, valueNode } = - node.type === "ClassProperty" - ? { keyNode: node.key, valueNode: node.value } - : { keyNode: node.id, valueNode: node.initializer } + node.type === "TSEnumMember" + ? { keyNode: node.id, valueNode: node.initializer } + : { keyNode: node.key, valueNode: node.value } + const firstToken = sourceCode.getFirstToken(node) const keyTokens = getFirstAndLastTokens(sourceCode, keyNode) const prefixTokens = sourceCode.getTokensBetween( @@ -677,13 +730,161 @@ export function defineVisitor(context: IndentContext): NodeListener { lastKeyToken = keyTokens.lastToken } - if (valueNode != null) { + if ( + node.type === "TSAbstractMethodDefinition" + // || (node.type === "Property" && node.method === true) + ) { + 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) + } else if ( + (node.type === "TSAbstractClassProperty" || + node.type === "ClassProperty" || + node.type === "TSEnumMember") && + valueNode != null + ) { const eqToken = sourceCode.getTokenAfter(lastKeyToken)! const initToken = sourceCode.getTokenAfter(eqToken) setOffset([eqToken, initToken], 1, lastKeyToken) } }, + TSAbstractClassProperty(node: TSESTree.TSAbstractClassProperty) { + visitor.TSAbstractMethodDefinition(node) + }, + TSEnumMember(node: TSESTree.TSEnumMember) { + visitor.TSAbstractMethodDefinition(node) + }, + TSOptionalType( + node: TSESTree.TSOptionalType | TSESTree.TSNonNullExpression, + ) { + // [number?] + // ^^^^^^^ + setOffset( + sourceCode.getLastToken(node), + 1, + sourceCode.getFirstToken(node), + ) + }, + TSNonNullExpression(node: TSESTree.TSNonNullExpression) { + // v! + visitor.TSOptionalType(node) + }, + TSJSDocNonNullableType( + // @ts-expect-error -- Missing TSJSDocNonNullableType type + node: TSESTree.TSJSDocNonNullableType, + ) { + // T! + visitor.TSOptionalType(node) + }, + TSTypeAssertion(node: TSESTree.TSTypeAssertion) { + // + const firstToken = sourceCode.getFirstToken(node) + const expressionToken = getFirstAndLastTokens( + sourceCode, + node.expression, + ).firstToken + setOffsetNodes( + context, + [node.typeAnnotation], + firstToken, + sourceCode.getTokenBefore(expressionToken), + 1, + ) + setOffset(expressionToken, 1, firstToken) + }, + TSImportType(node: TSESTree.TSImportType) { + // import('foo').B + const firstToken = sourceCode.getFirstToken(node) + const leftParenToken = sourceCode.getTokenAfter(firstToken, { + filter: isOpeningParenToken, + includeComments: false, + })! + setOffset(leftParenToken, 1, firstToken) + const rightParenToken = sourceCode.getTokenAfter(node.parameter, { + filter: isClosingParenToken, + includeComments: false, + })! + setOffsetNodes( + context, + [node.parameter], + leftParenToken, + rightParenToken, + 1, + ) + if (node.qualifier) { + const dotToken = sourceCode.getTokenBefore(node.qualifier)! + const propertyToken = sourceCode.getTokenAfter(dotToken) + setOffset([dotToken, propertyToken], 1, firstToken) + } + if (node.typeParameters) { + setOffset(sourceCode.getFirstToken(node.typeParameters), 1, firstToken) + } + }, + TSParameterProperty(node: TSESTree.TSParameterProperty) { + // constructor(private a) + const firstToken = sourceCode.getFirstToken(node) + const parameterToken = sourceCode.getFirstToken(node.parameter) + setOffset( + [ + ...sourceCode.getTokensBetween(firstToken, parameterToken), + parameterToken, + ], + 1, + firstToken, + ) + }, + TSImportEqualsDeclaration(node: TSESTree.TSImportEqualsDeclaration) { + // import foo = require('foo') + const importToken = sourceCode.getFirstToken(node) + const idTokens = getFirstAndLastTokens(sourceCode, node.id) + setOffset(idTokens.firstToken, 1, importToken) + + const opToken = sourceCode.getTokenAfter(idTokens.lastToken) + + setOffset( + [opToken, sourceCode.getFirstToken(node.moduleReference)], + 1, + idTokens.lastToken, + ) + }, + TSExternalModuleReference(node: TSESTree.TSExternalModuleReference) { + // require('foo') + const requireToken = sourceCode.getFirstToken(node) + const leftParenToken = sourceCode.getTokenAfter(requireToken, { + filter: isOpeningParenToken, + includeComments: false, + })! + const rightParenToken = sourceCode.getLastToken(node) + + setOffset(leftParenToken, 1, requireToken) + setOffsetNodes( + context, + [node.expression], + leftParenToken, + rightParenToken, + 1, + ) + }, + TSExportAssignment(node: TSESTree.TSExportAssignment) { + // export = foo + const exportNode = sourceCode.getFirstToken(node) + const exprTokens = getFirstAndLastTokens(sourceCode, node.expression) + const opToken = sourceCode.getTokenBefore(exprTokens.firstToken) + + setOffset([opToken, exprTokens.firstToken], 1, exportNode) + }, + + // ---------------------------------------------------------------------- + // NON-STANDARD NODES + // ---------------------------------------------------------------------- + ClassProperty(node: TSESTree.ClassProperty) { + visitor.TSAbstractMethodDefinition(node) + }, Decorator(node: TSESTree.Decorator) { // @Decorator const [atToken, secondToken] = sourceCode.getFirstTokens(node, { @@ -714,6 +915,7 @@ export function defineVisitor(context: IndentContext): NodeListener { // ---------------------------------------------------------------------- // SINGLE TOKEN NODES // ---------------------------------------------------------------------- + // VALUES KEYWORD TSAnyKeyword() { // noop }, @@ -750,6 +952,39 @@ export function defineVisitor(context: IndentContext): NodeListener { TSVoidKeyword() { // noop }, + // MODIFIERS KEYWORD + TSAbstractKeyword() { + // noop + }, + TSAsyncKeyword() { + // noop + }, + TSPrivateKeyword() { + // noop + }, + TSProtectedKeyword() { + // noop + }, + TSPublicKeyword() { + // noop + }, + TSReadonlyKeyword() { + // noop + }, + TSStaticKeyword() { + // noop + }, + // OTHERS KEYWORD + TSDeclareKeyword() { + // noop + }, + TSExportKeyword() { + // noop + }, + TSIntrinsicKeyword() { + // noop + }, + // OTHERS TSThisType() { // noop }, @@ -759,8 +994,132 @@ export function defineVisitor(context: IndentContext): NodeListener { TSLiteralType() { // noop }, + // ---------------------------------------------------------------------- + // JSX + // ---------------------------------------------------------------------- + JSXElement(node: TSESTree.JSXElement) { + setOffsetNodes( + context, + node.children, + node.openingElement, + node.closingElement, + 1, + ) + }, + JSXFragment(node: TSESTree.JSXFragment) { + setOffsetNodes( + context, + node.children, + node.openingFragment, + node.closingFragment, + 1, + ) + }, + JSXOpeningElement(node: TSESTree.JSXOpeningElement) { + const openToken = sourceCode.getFirstToken(node) + const closeToken = sourceCode.getLastToken(node) + + const nameToken = sourceCode.getFirstToken(node.name) + setOffset(nameToken, 1, openToken) + if (node.typeParameters) { + setOffset(sourceCode.getFirstToken(node.typeParameters), 1, nameToken) + } + for (const attr of node.attributes) { + setOffset(sourceCode.getFirstToken(attr), 1, openToken) + } + if (node.selfClosing) { + const slash = sourceCode.getTokenBefore(closeToken)! + if (slash.value === "/") { + setOffset(slash, 0, openToken) + } + } + setOffset(closeToken, 0, openToken) + }, + JSXClosingElement(node: TSESTree.JSXClosingElement) { + const openToken = sourceCode.getFirstToken(node) + const slash = sourceCode.getTokenAfter(openToken)! + if (slash.value === "/") { + setOffset(slash, 0, openToken) + } + const closeToken = sourceCode.getLastToken(node) + const nameToken = sourceCode.getFirstToken(node.name) + setOffset(nameToken, 1, openToken) + setOffset(closeToken, 0, openToken) + }, + JSXOpeningFragment( + node: TSESTree.JSXOpeningFragment | TSESTree.JSXClosingFragment, + ) { + const [firstToken, ...tokens] = sourceCode.getTokens(node) + setOffset(tokens, 0, firstToken) + }, + JSXClosingFragment(node: TSESTree.JSXClosingFragment) { + visitor.JSXOpeningFragment(node) + }, + JSXAttribute(node: TSESTree.JSXAttribute) { + if (!node.value) { + return + } + const keyToken = sourceCode.getFirstToken(node) + const eqToken = sourceCode.getTokenAfter(node.name) + setOffset(eqToken, 1, keyToken) + setOffset(sourceCode.getFirstToken(node.value), 1, keyToken) + }, + JSXExpressionContainer(node: TSESTree.JSXExpressionContainer) { + setOffsetNodes( + context, + [node.expression], + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + JSXSpreadAttribute(node: TSESTree.JSXSpreadAttribute) { + setOffsetNodes( + context, + [node.argument], + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + JSXSpreadChild(node: TSESTree.JSXSpreadChild) { + setOffsetNodes( + context, + [node.expression], + sourceCode.getFirstToken(node), + sourceCode.getLastToken(node), + 1, + ) + }, + JSXMemberExpression(node: TSESTree.JSXMemberExpression) { + const objectToken = sourceCode.getFirstToken(node) + const dotToken = sourceCode.getTokenBefore(node.property)! + const propertyToken = sourceCode.getTokenAfter(dotToken) + + setOffset([dotToken, propertyToken], 1, objectToken) + }, + // ---------------------------------------------------------------------- + // JSX SINGLE TOKEN NODES + // ---------------------------------------------------------------------- + JSXEmptyExpression() { + // noop + }, + JSXIdentifier() { + // noop + }, + JSXNamespacedName() { + // noop + }, + JSXText() { + // noop + }, } + const o: { + [key in Exclude]: never + } = {} + // console.log(o) + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore const extendsESVisitor: any = { ["ClassDeclaration[implements], ClassDeclaration[typeParameters], ClassDeclaration[superTypeParameters]," + @@ -790,9 +1149,10 @@ export function defineVisitor(context: IndentContext): NodeListener { } }, } + const v: NodeListener = visitor return { - ...visitor, + ...v, ...extendsESVisitor, } } diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-class01-errors.json new file mode 100644 index 000000000..e93c4e48b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class01-errors.json @@ -0,0 +1,202 @@ +[ + { + "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 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 6 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 8 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 2 spaces but found 0 spaces.", + "line": 16, + "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 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 10 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 8 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 10 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 8 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 10 spaces but found 0 spaces.", + "line": 31, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 32, + "column": 1 + }, + { + "message": "Expected indentation of 10 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 10 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 37, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 10 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 4 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 2 spaces but found 0 spaces.", + "line": 43, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-class01-input.svelte new file mode 100644 index 000000000..6389b05e9 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class01-input.svelte @@ -0,0 +1,46 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-class01-output.svelte new file mode 100644 index 000000000..a6b923e49 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class01-output.svelte @@ -0,0 +1,46 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-errors.json index 47b70160f..69f14e820 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-errors.json @@ -178,5 +178,70 @@ "message": "Expected indentation of 2 spaces but found 0 spaces.", "line": 40, "column": 1 + }, + { + "message": "Expected indentation of 2 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 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 12 spaces but found 0 spaces.", + "line": 48, + "column": 1 + }, + { + "message": "Expected indentation of 12 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 6 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 4 spaces but found 0 spaces.", + "line": 53, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 54, + "column": 1 } ] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte index 80570a1fc..856cffa1c 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte @@ -38,6 +38,20 @@ E, R ; } + +interface D { +new +( +arg +: +readonly +string[ +] +) +: +void +; +} diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte index d13c25e61..d2fa58a74 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte @@ -38,6 +38,20 @@ R ; } + + interface D { + new + ( + arg + : + readonly + string[ + ] + ) + : + void + ; + } diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-node01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-node01-errors.json new file mode 100644 index 000000000..b1f0286e4 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-node01-errors.json @@ -0,0 +1,57 @@ +[ + { + "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 8 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 10 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": 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 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-node01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-node01-input.svelte new file mode 100644 index 000000000..7e67300cb --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-node01-input.svelte @@ -0,0 +1,16 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-node01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-node01-output.svelte new file mode 100644 index 000000000..d1271ab51 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-node01-output.svelte @@ -0,0 +1,16 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-errors.json index 1f9c919c8..48b8adc85 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-errors.json @@ -88,5 +88,90 @@ "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": 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 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 8 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": 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 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 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 2 spaces but found 0 spaces.", + "line": 40, + "column": 1 } ] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte index 66b2af1a6..c6c32b36b 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-input.svelte @@ -18,6 +18,26 @@ const o : A[ ] = [] + +const v += +b! + +let +x += +10 as +const +; + +let +x += +< +const +> +10 +; diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte index 53297ca63..038024d25 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation02-output.svelte @@ -18,6 +18,26 @@ : A[ ] = [] + + const v + = + b! + + let + x + = + 10 as + const + ; + + let + x + = + < + const + > + 10 + ; diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json new file mode 100644 index 000000000..b3bddd984 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json @@ -0,0 +1,37 @@ +[ + { + "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 2 spaces but found 0 spaces.", + "line": 9, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte new file mode 100644 index 000000000..8456ba989 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte @@ -0,0 +1,12 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte new file mode 100644 index 000000000..91e5fab23 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte @@ -0,0 +1,12 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json index 97fa918c8..9b3111be0 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-errors.json @@ -93,5 +93,245 @@ "message": "Expected indentation of 6 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 4 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 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 6 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 8 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 6 spaces but found 0 spaces.", + "line": 38, + "column": 1 + }, + { + "message": "Expected indentation of 6 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 6 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 4 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 4 spaces but found 0 spaces.", + "line": 46, + "column": 1 + }, + { + "message": "Expected indentation of 2 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 6 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 10 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 6 spaces but found 0 spaces.", + "line": 54, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 55, + "column": 1 + }, + { + "message": "Expected indentation of 8 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 8 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 10 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 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 6 spaces but found 0 spaces.", + "line": 63, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 64, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 65, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 66, + "column": 1 + }, + { + "message": "Expected indentation of 14 spaces but found 0 spaces.", + "line": 67, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 68, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 69, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 70, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 71, + "column": 1 + }, + { + "message": "Expected indentation of 8 spaces but found 0 spaces.", + "line": 72, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 73, + "column": 1 } ] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte index b8fda61e2..4c81e772d 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-input.svelte @@ -21,6 +21,56 @@ type D = (v) => v is number + +type E = [ +number, +string?, +boolean? +] +| +[ +{ +} +, +[ +number? +] +| +null +& +boolean[ +] +] +& +{ +} + +type F = +T extends +( +infer +U +)[ +] +? +U +: +T extends +infer +U +? +U +: +T extends +Promise< +infer +U +> +? +U +: +T +; diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte index 78a2f33dc..e546194ec 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types02-output.svelte @@ -21,6 +21,56 @@ => v is number + + type E = [ + number, + string?, + boolean? + ] + | + [ + { + } + , + [ + number? + ] + | + null + & + boolean[ + ] + ] + & + { + } + + type F = + T extends + ( + infer + U + )[ + ] + ? + U + : + T extends + infer + U + ? + U + : + T extends + Promise< + infer + U + > + ? + U + : + T + ; diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types03-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-types03-errors.json new file mode 100644 index 000000000..58c1e1f15 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types03-errors.json @@ -0,0 +1,162 @@ +[ + { + "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": 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 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 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 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 6 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 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": 27, + "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 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 10 spaces but found 0 spaces.", + "line": 35, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 36, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 37, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types03-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types03-input.svelte new file mode 100644 index 000000000..5ee79fd51 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types03-input.svelte @@ -0,0 +1,41 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types03-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types03-output.svelte new file mode 100644 index 000000000..f45994da1 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types03-output.svelte @@ -0,0 +1,41 @@ + + + + From fadd921dccd208dce0f4d383b4b874317880d0c5 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 21 Jun 2021 18:35:06 +0900 Subject: [PATCH 06/11] update --- src/rules/indent-helpers/ts.ts | 49 ++++- ...rs.json => ts-import-export01-errors.json} | 25 +++ .../ts/ts-import-export01-input.svelte | 23 +++ ...velte => ts-import-export01-output.svelte} | 9 +- .../indent/invalid/ts/ts-node01-input.svelte | 16 -- .../ts/ts-template-literal-type01-errors.json | 187 ++++++++++++++++++ .../ts-template-literal-type01-input.svelte | 43 ++++ .../ts-template-literal-type01-output.svelte | 43 ++++ .../ts/ts-type-annotation03-errors.json | 60 ++++++ .../ts/ts-type-annotation03-input.svelte | 13 ++ .../ts/ts-type-annotation03-output.svelte | 13 ++ 11 files changed, 459 insertions(+), 22 deletions(-) rename tests/fixtures/rules/indent/invalid/ts/{ts-node01-errors.json => ts-import-export01-errors.json} (68%) create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-import-export01-input.svelte rename tests/fixtures/rules/indent/invalid/ts/{ts-node01-output.svelte => ts-import-export01-output.svelte} (56%) delete mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-node01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-output.svelte diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts index 25a4d9f66..09008c5ef 100644 --- a/src/rules/indent-helpers/ts.ts +++ b/src/rules/indent-helpers/ts.ts @@ -878,6 +878,50 @@ export function defineVisitor(context: IndentContext): NodeListener { setOffset([opToken, exprTokens.firstToken], 1, exportNode) }, + TSNamedTupleMember(node: TSESTree.TSNamedTupleMember) { + // [a: string, ...b: string[]] + // ^^^^^^^^^ + const labelToken = sourceCode.getFirstToken(node) + const elementTokens = getFirstAndLastTokens(sourceCode, node.elementType) + setOffset( + [ + ...sourceCode.getTokensBetween(labelToken, elementTokens.firstToken), + elementTokens.firstToken, + ], + 1, + labelToken, + ) + }, + TSRestType(node: TSESTree.TSRestType) { + // [a: string, ...b: string[]] + // ^^^^^^^^^^^^^^ + const firstToken = sourceCode.getFirstToken(node) + const nextToken = sourceCode.getTokenAfter(firstToken) + + setOffset(nextToken, 1, firstToken) + }, + TSNamespaceExportDeclaration(node: TSESTree.TSNamespaceExportDeclaration) { + const firstToken = sourceCode.getFirstToken(node) + const idToken = sourceCode.getFirstToken(node.id) + + setOffset( + [...sourceCode.getTokensBetween(firstToken, idToken), idToken], + 1, + firstToken, + ) + }, + TSTemplateLiteralType(node: TSESTree.TSTemplateLiteralType) { + 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) + }, // ---------------------------------------------------------------------- // NON-STANDARD NODES @@ -1115,11 +1159,6 @@ export function defineVisitor(context: IndentContext): NodeListener { }, } - const o: { - [key in Exclude]: never - } = {} - // console.log(o) - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore const extendsESVisitor: any = { ["ClassDeclaration[implements], ClassDeclaration[typeParameters], ClassDeclaration[superTypeParameters]," + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-node01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-import-export01-errors.json similarity index 68% rename from tests/fixtures/rules/indent/invalid/ts/ts-node01-errors.json rename to tests/fixtures/rules/indent/invalid/ts/ts-import-export01-errors.json index b1f0286e4..9492154af 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-node01-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-import-export01-errors.json @@ -53,5 +53,30 @@ "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": 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 2 spaces but found 0 spaces.", + "line": 20, + "column": 1 } ] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-import-export01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-import-export01-input.svelte new file mode 100644 index 000000000..429f14b59 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-import-export01-input.svelte @@ -0,0 +1,23 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-node01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-import-export01-output.svelte similarity index 56% rename from tests/fixtures/rules/indent/invalid/ts/ts-node01-output.svelte rename to tests/fixtures/rules/indent/invalid/ts/ts-import-export01-output.svelte index d1271ab51..07805afac 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-node01-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-import-export01-output.svelte @@ -11,6 +11,13 @@ export = foo +; + + export + as + namespace + a + ; - + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-node01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-node01-input.svelte deleted file mode 100644 index 7e67300cb..000000000 --- a/tests/fixtures/rules/indent/invalid/ts/ts-node01-input.svelte +++ /dev/null @@ -1,16 +0,0 @@ - - - - diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-errors.json new file mode 100644 index 000000000..e703a0601 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-errors.json @@ -0,0 +1,187 @@ +[ + { + "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 2 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 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 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 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 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 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 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 8 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 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 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 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 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-input.svelte new file mode 100644 index 000000000..d5c44eb26 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-input.svelte @@ -0,0 +1,43 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-output.svelte new file mode 100644 index 000000000..92bfd5948 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-template-literal-type01-output.svelte @@ -0,0 +1,43 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json index b3bddd984..f9c29b9a6 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json @@ -33,5 +33,65 @@ "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 8 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 6 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 10 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 10 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 22, + "column": 1 } ] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte index 8456ba989..3ab45cdc9 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte @@ -7,6 +7,19 @@ new => void ; + +let y: +[ +a +: +string +, +... +b +: +number[ +] +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte index 91e5fab23..539ddb051 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte @@ -7,6 +7,19 @@ => void ; + + let y: + [ + a + : + string + , + ... + b + : + number[ + ] + ] From 449c34a192b16c70e9c68c778e73f045168c29c4 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 21 Jun 2021 18:39:48 +0900 Subject: [PATCH 07/11] update doc --- docs/rules/indent.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/indent.md b/docs/rules/indent.md index 400c424b2..b43540da3 100644 --- a/docs/rules/indent.md +++ b/docs/rules/indent.md @@ -17,7 +17,7 @@ since: "v0.3.0" 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 2021 syntaxes. It ignores unknown AST nodes, but it might be confused by non-standard syntaxes. +- In the expressions, this rule supports ECMAScript 2021 syntaxes and some TypeScript syntaxes. It ignores unknown AST nodes, but it might be confused by non-standard syntaxes. From f1cba6cfd2507f93a979fbb4a15bbd16aa7c6f1d Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Tue, 22 Jun 2021 15:34:31 +0900 Subject: [PATCH 08/11] update --- src/rules/indent-helpers/es.ts | 51 ++++---- src/rules/indent-helpers/ts.ts | 42 +++---- .../indent/invalid/ts/ts-class01-errors.json | 75 ++++++++++++ .../indent/invalid/ts/ts-class01-input.svelte | 16 +++ .../invalid/ts/ts-class01-output.svelte | 16 +++ .../ts/ts-type-annotation03-errors.json | 110 ++++++++++++++++++ .../ts/ts-type-annotation03-input.svelte | 25 ++++ .../ts/ts-type-annotation03-output.svelte | 25 ++++ 8 files changed, 302 insertions(+), 58 deletions(-) diff --git a/src/rules/indent-helpers/es.ts b/src/rules/indent-helpers/es.ts index b0a25e282..6e692d3d3 100644 --- a/src/rules/indent-helpers/es.ts +++ b/src/rules/indent-helpers/es.ts @@ -81,13 +81,12 @@ export function defineVisitor(context: IndentContext): NodeListener & { } }, ArrayExpression(node: ESTree.ArrayExpression | ESTree.ArrayPattern) { - setOffsetNodes( - context, - node.elements, - sourceCode.getFirstToken(node), - sourceCode.getLastToken(node), - 1, + const firstToken = sourceCode.getFirstToken(node) + const rightToken = sourceCode.getTokenAfter( + node.elements[node.elements.length - 1] || firstToken, + { filter: isClosingBracketToken, includeComments: false }, ) + setOffsetNodes(context, node.elements, firstToken, rightToken, 1) }, ArrayPattern(node: ESTree.ArrayPattern) { visitor.ArrayExpression(node) @@ -719,22 +718,13 @@ export function defineVisitor(context: IndentContext): NodeListener & { lastKeyToken = keyTokens.lastToken } - 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) { - const colonToken = sourceCode.getTokenAfter(lastKeyToken)! - 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) + if (node.value) { + const initToken = sourceCode.getFirstToken(node.value) + setOffset( + [...sourceCode.getTokensBetween(lastKeyToken, initToken), initToken], + 1, + lastKeyToken, + ) } }, Property(node: ESTree.Property) { @@ -763,13 +753,12 @@ export function defineVisitor(context: IndentContext): NodeListener & { } }, ObjectExpression(node: ESTree.ObjectExpression | ESTree.ObjectPattern) { - setOffsetNodes( - context, - node.properties, - sourceCode.getFirstToken(node), - sourceCode.getLastToken(node), - 1, + const firstToken = sourceCode.getFirstToken(node) + const rightToken = sourceCode.getTokenAfter( + node.properties[node.properties.length - 1] || firstToken, + { filter: isClosingBraceToken, includeComments: false }, ) + setOffsetNodes(context, node.properties, firstToken, rightToken, 1) }, ObjectPattern(node: ESTree.ObjectPattern) { visitor.ObjectExpression(node) @@ -939,9 +928,6 @@ export function defineVisitor(context: IndentContext): NodeListener & { DebuggerStatement() { // noop }, - EmptyStatement() { - // noop - }, Identifier() { // noop }, @@ -972,6 +958,9 @@ export function defineVisitor(context: IndentContext): NodeListener & { ChainExpression() { // noop }, + EmptyStatement() { + // noop + }, } return { diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts index 09008c5ef..9f7a839f9 100644 --- a/src/rules/indent-helpers/ts.ts +++ b/src/rules/indent-helpers/ts.ts @@ -18,7 +18,7 @@ type NodeListenerMap = { [key in NodeWithoutES["type"]]: T extends { type: key } ? T : never } type NodeListener = { - [T in keyof NodeListenerMap]?: (node: NodeListenerMap[T]) => void + [T in keyof NodeListenerMap]: (node: NodeListenerMap[T]) => void } /** @@ -37,11 +37,13 @@ export function defineVisitor(context: IndentContext): NodeListener { count: 2, includeComments: false, }) - setOffset( - [colonOrArrowToken, secondToken], - 1, - sourceCode.getFirstToken(node.parent!), - ) + const baseToken = sourceCode.getFirstToken(node.parent!) + setOffset([colonOrArrowToken, secondToken], 1, baseToken) + + const before = sourceCode.getTokenBefore(colonOrArrowToken) + if (before && before.value === "?") { + setOffset(before, 1, baseToken) + } }, TSAsExpression(node: TSESTree.TSAsExpression) { // foo as T @@ -730,27 +732,13 @@ export function defineVisitor(context: IndentContext): NodeListener { lastKeyToken = keyTokens.lastToken } - if ( - node.type === "TSAbstractMethodDefinition" - // || (node.type === "Property" && node.method === true) - ) { - 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) - } else if ( - (node.type === "TSAbstractClassProperty" || - node.type === "ClassProperty" || - node.type === "TSEnumMember") && - valueNode != null - ) { - const eqToken = sourceCode.getTokenAfter(lastKeyToken)! - const initToken = sourceCode.getTokenAfter(eqToken) - - setOffset([eqToken, initToken], 1, lastKeyToken) + if (valueNode != null) { + const initToken = sourceCode.getFirstToken(valueNode) + setOffset( + [...sourceCode.getTokensBetween(lastKeyToken, initToken), initToken], + 1, + lastKeyToken, + ) } }, TSAbstractClassProperty(node: TSESTree.TSAbstractClassProperty) { diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-class01-errors.json index e93c4e48b..05e3df5d5 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-class01-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class01-errors.json @@ -198,5 +198,80 @@ "message": "Expected indentation of 2 spaces but found 0 spaces.", "line": 43, "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 6 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 4 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 6 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 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 6 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 6 spaces but found 0 spaces.", + "line": 57, + "column": 1 + }, + { + "message": "Expected indentation of 6 spaces but found 0 spaces.", + "line": 58, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 59, + "column": 1 } ] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-class01-input.svelte index 6389b05e9..4de9a2cf4 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-class01-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class01-input.svelte @@ -41,6 +41,22 @@ false { } } + +class Foo { +prop +: +number; +opt +? +: +number; +opt2 +? +: +number += +42; +} diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-class01-output.svelte index a6b923e49..02970027d 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-class01-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class01-output.svelte @@ -41,6 +41,22 @@ { } } + + class Foo { + prop + : + number; + opt + ? + : + number; + opt2 + ? + : + number + = + 42; + } diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json index f9c29b9a6..b4fdf24b6 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-errors.json @@ -93,5 +93,115 @@ "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 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 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 6 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 6 spaces but found 0 spaces.", + "line": 33, + "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 6 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 4 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 10 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 6 spaces but found 0 spaces.", + "line": 47, + "column": 1 } ] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte index 3ab45cdc9..3c00d5074 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-input.svelte @@ -20,6 +20,31 @@ b number[ ] ] + +var +[ +foo +, +bar +] +: +any [ +] += arr + + +var +{ +foo +, +bar +} +: +{ +foo: +number +} += obj diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte index 539ddb051..ce4770881 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-type-annotation03-output.svelte @@ -20,6 +20,31 @@ number[ ] ] + + var + [ + foo + , + bar + ] + : + any [ + ] + = arr + + + var + { + foo + , + bar + } + : + { + foo: + number + } + = obj From 86916edbbd6ce995c7587bc16fb6d2b6b8c0c61a Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Tue, 22 Jun 2021 17:50:15 +0900 Subject: [PATCH 09/11] update --- src/rules/indent-helpers/es.ts | 56 +++--- src/rules/indent-helpers/ts.ts | 61 ++++--- .../script-yield-expression01-errors.json | 22 +++ .../script-yield-expression01-input.svelte | 9 + .../script-yield-expression01-output.svelte | 9 + .../indent/invalid/ts/ts-class02-errors.json | 167 ++++++++++++++++++ .../indent/invalid/ts/ts-class02-input.svelte | 38 ++++ .../invalid/ts/ts-class02-output.svelte | 38 ++++ .../invalid/ts/ts-decorator01-errors.json | 20 +++ .../invalid/ts/ts-decorator01-output.svelte | 8 +- .../invalid/ts/ts-function02-errors.json | 67 +++++++ .../invalid/ts/ts-function02-input.svelte | 18 ++ .../invalid/ts/ts-function02-output.svelte | 18 ++ 13 files changed, 478 insertions(+), 53 deletions(-) create mode 100644 tests/fixtures/rules/indent/invalid/script-yield-expression01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-yield-expression01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-yield-expression01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class02-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class02-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class02-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-function02-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-function02-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-function02-output.svelte diff --git a/src/rules/indent-helpers/es.ts b/src/rules/indent-helpers/es.ts index 6e692d3d3..9c2ee668d 100644 --- a/src/rules/indent-helpers/es.ts +++ b/src/rules/indent-helpers/es.ts @@ -36,10 +36,7 @@ type NodeListener = { * @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 -} { +export function defineVisitor(context: IndentContext): NodeListener { const { sourceCode, options, setOffsetBaseLine, setOffset } = context /** @@ -466,27 +463,24 @@ export function defineVisitor(context: IndentContext): NodeListener & { 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) + let nextToken = sourceCode.getTokenAfter(firstToken) + let nextTokenOffset = 0 + while ( + nextToken && + !isOpeningParenToken(nextToken) && + nextToken.value !== "<" + ) { + if ( + nextToken.value === "*" || + (node.id && nextToken.range[0] === node.id.range![0]) + ) { + nextTokenOffset = 1 + } + setOffset(nextToken, nextTokenOffset, firstToken) + nextToken = sourceCode.getTokenAfter(nextToken) } - leftParenToken = sourceCode.getTokenAfter( - idToken || starToken || functionToken, - )! + leftParenToken = nextToken! bodyBaseToken = firstToken } @@ -503,10 +497,10 @@ export function defineVisitor(context: IndentContext): NodeListener & { 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) + + const bodyToken = sourceCode.getFirstToken(node.body) setOffset(bodyToken, 0, bodyBaseToken) }, FunctionExpression(node: ESTree.FunctionExpression) { @@ -963,9 +957,9 @@ export function defineVisitor(context: IndentContext): NodeListener & { }, } - return { - ...visitor, - ":statement"(node: ESTree.Statement) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore + const commonVisitor: any = { + ":statement, PropertyDefinition"(node: ESTree.Statement) { const firstToken = sourceCode.getFirstToken(node) const lastToken = sourceCode.getLastToken(node) if (isSemicolonToken(lastToken) && firstToken !== lastToken) { @@ -997,6 +991,12 @@ export function defineVisitor(context: IndentContext): NodeListener & { } }, } + const v: NodeListener = visitor + + return { + ...v, + ...commonVisitor, + } } /** Get the parent node from the given node */ diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts index 9f7a839f9..5f5b7fc1b 100644 --- a/src/rules/indent-helpers/ts.ts +++ b/src/rules/indent-helpers/ts.ts @@ -7,6 +7,7 @@ import { isOpeningBraceToken, isOpeningBracketToken, isOpeningParenToken, + isSemicolonToken, } from "eslint-utils" import type { AnyToken, IndentContext } from "./commons" import { isBeginningOfLine } from "./commons" @@ -156,7 +157,7 @@ export function defineVisitor(context: IndentContext): NodeListener { const keyTokens = getFirstAndLastTokens(sourceCode, node.key) let keyLast if (node.computed) { - const closeBracket = sourceCode.getTokenAfter(keyTokens.firstToken)! + const closeBracket = sourceCode.getTokenAfter(keyTokens.lastToken)! setOffsetNodes(context, [node.key], firstToken, closeBracket, 1) keyLast = closeBracket } else { @@ -515,7 +516,7 @@ export function defineVisitor(context: IndentContext): NodeListener { const keyTokens = getFirstAndLastTokens(sourceCode, node.key) let keyLast if (node.computed) { - const closeBracket = sourceCode.getTokenAfter(keyTokens.firstToken)! + const closeBracket = sourceCode.getTokenAfter(keyTokens.lastToken)! setOffsetNodes(context, [node.key], firstToken, closeBracket, 1) keyLast = closeBracket } else { @@ -611,27 +612,24 @@ export function defineVisitor(context: IndentContext): NodeListener { leftParenToken = firstToken bodyBaseToken = sourceCode.getFirstToken(node.parent!) } 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) + let nextToken = sourceCode.getTokenAfter(firstToken) + let nextTokenOffset = 0 + while ( + nextToken && + !isOpeningParenToken(nextToken) && + nextToken.value !== "<" + ) { + if ( + nextToken.value === "*" || + (node.id && nextToken.range[0] === node.id.range[0]) + ) { + nextTokenOffset = 1 + } + setOffset(nextToken, nextTokenOffset, firstToken) + nextToken = sourceCode.getTokenAfter(nextToken) } - leftParenToken = sourceCode.getTokenAfter( - idToken || starToken || functionToken, - )! + leftParenToken = nextToken! bodyBaseToken = firstToken } @@ -1147,6 +1145,26 @@ export function defineVisitor(context: IndentContext): NodeListener { }, } + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore + const commonsVisitor: any = { + // Process semicolons. + ["TSTypeAliasDeclaration, TSCallSignatureDeclaration, TSConstructSignatureDeclaration, TSImportEqualsDeclaration," + + "TSAbstractMethodDefinition, TSAbstractClassProperty, TSEnumMember, ClassProperty," + + "TSPropertySignature, TSIndexSignature, TSMethodSignature"]( + node: ESTree.Node, + ) { + 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) { + // End of line semicolons + setOffset(lastToken, 0, firstToken) + } + } + }, + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore const extendsESVisitor: any = { ["ClassDeclaration[implements], ClassDeclaration[typeParameters], ClassDeclaration[superTypeParameters]," + @@ -1180,6 +1198,7 @@ export function defineVisitor(context: IndentContext): NodeListener { return { ...v, + ...commonsVisitor, ...extendsESVisitor, } } diff --git a/tests/fixtures/rules/indent/invalid/script-yield-expression01-errors.json b/tests/fixtures/rules/indent/invalid/script-yield-expression01-errors.json new file mode 100644 index 000000000..f0097feda --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-yield-expression01-errors.json @@ -0,0 +1,22 @@ +[ + { + "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 2 spaces but found 0 spaces.", + "line": 6, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-yield-expression01-input.svelte b/tests/fixtures/rules/indent/invalid/script-yield-expression01-input.svelte new file mode 100644 index 000000000..7bc1cdd14 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-yield-expression01-input.svelte @@ -0,0 +1,9 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-yield-expression01-output.svelte b/tests/fixtures/rules/indent/invalid/script-yield-expression01-output.svelte new file mode 100644 index 000000000..8a41e2c2c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-yield-expression01-output.svelte @@ -0,0 +1,9 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-class02-errors.json new file mode 100644 index 000000000..e40f468b6 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class02-errors.json @@ -0,0 +1,167 @@ +[ + { + "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 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 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 8 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 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 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 10 spaces but found 0 spaces.", + "line": 21, + "column": 1 + }, + { + "message": "Expected indentation of 12 spaces but found 0 spaces.", + "line": 22, + "column": 1 + }, + { + "message": "Expected indentation of 12 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 8 spaces but found 0 spaces.", + "line": 25, + "column": 1 + }, + { + "message": "Expected indentation of 10 spaces but found 0 spaces.", + "line": 26, + "column": 1 + }, + { + "message": "Expected indentation of 12 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 10 spaces but found 0 spaces.", + "line": 29, + "column": 1 + }, + { + "message": "Expected indentation of 8 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 6 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/ts/ts-class02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-class02-input.svelte new file mode 100644 index 000000000..f63162811 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class02-input.svelte @@ -0,0 +1,38 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-class02-output.svelte new file mode 100644 index 000000000..3230b9d28 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class02-output.svelte @@ -0,0 +1,38 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json index e0170baf8..ae897e19e 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json @@ -109,6 +109,11 @@ "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, @@ -124,6 +129,11 @@ "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": 32, @@ -229,6 +239,11 @@ "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, @@ -589,6 +604,11 @@ "line": 131, "column": 1 }, + { + "message": "Expected indentation of 4 spaces but found 0 spaces.", + "line": 132, + "column": 1 + }, { "message": "Expected indentation of 4 spaces but found 0 spaces.", "line": 133, diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte index 0a94b5993..2bb379973 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte @@ -23,11 +23,11 @@ type = "report" -; + ; title : string -; + ; constructor ( @@ -51,7 +51,7 @@ greeting : string -; + ; constructor ( message @@ -129,7 +129,7 @@ greeting : string -; + ; constructor(message: string) { this.greeting = message; } diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-function02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-function02-errors.json new file mode 100644 index 000000000..5ccb31a61 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-function02-errors.json @@ -0,0 +1,67 @@ +[ + { + "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 6 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 6 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 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-function02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-function02-input.svelte new file mode 100644 index 000000000..67c63dd7c --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-function02-input.svelte @@ -0,0 +1,18 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-function02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-function02-output.svelte new file mode 100644 index 000000000..1b89bbfef --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-function02-output.svelte @@ -0,0 +1,18 @@ + + + + From c77c0827e158b795eea30a1efcc5fb9110cd3cb2 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 23 Jun 2021 16:18:49 +0900 Subject: [PATCH 10/11] update --- src/rules/indent-helpers/ast.ts | 4 +- src/rules/indent-helpers/index.ts | 9 +- src/rules/indent-helpers/ts.ts | 150 +++--------------- .../invalid/script-methods01-errors.json | 102 ++++++++++++ .../invalid/script-methods01-input.svelte | 27 ++++ .../invalid/script-methods01-output.svelte | 27 ++++ .../ts/ts-conditional-type01-errors.json | 37 +++++ .../ts/ts-conditional-type01-input.svelte | 12 ++ .../ts/ts-conditional-type01-output.svelte | 12 ++ .../invalid/ts/ts-decorator01-errors.json | 12 +- .../invalid/ts/ts-decorator01-output.svelte | 10 +- .../invalid/ts/ts-interface02-input.svelte | 2 +- .../invalid/ts/ts-interface02-output.svelte | 2 +- .../invalid/ts/ts-interface03-errors.json | 27 ++++ .../invalid/ts/ts-interface03-input.svelte | 15 ++ .../invalid/ts/ts-interface03-output.svelte | 15 ++ .../invalid/ts/ts-types01-input copy.svelte | 77 --------- .../indent/invalid/ts/ts-types03-input.svelte | 2 +- .../invalid/ts/ts-types03-output.svelte | 2 +- 19 files changed, 325 insertions(+), 219 deletions(-) create mode 100644 tests/fixtures/rules/indent/invalid/script-methods01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/script-methods01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/script-methods01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface03-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface03-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-interface03-output.svelte delete mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-types01-input copy.svelte diff --git a/src/rules/indent-helpers/ast.ts b/src/rules/indent-helpers/ast.ts index 2cbcfc973..c6c6bcffa 100644 --- a/src/rules/indent-helpers/ast.ts +++ b/src/rules/indent-helpers/ast.ts @@ -17,6 +17,8 @@ export function isNotWhitespace( token: AnyToken | ESTree.Comment | null | undefined, ): boolean { return ( - token != null && (token.type !== "HTMLText" || Boolean(token.value.trim())) + token != null && + (token.type !== "HTMLText" || Boolean(token.value.trim())) && + (token.type !== "JSXText" || Boolean(token.value.trim())) ) } diff --git a/src/rules/indent-helpers/index.ts b/src/rules/indent-helpers/index.ts index a26b045e0..fd2ad6080 100644 --- a/src/rules/indent-helpers/index.ts +++ b/src/rules/indent-helpers/index.ts @@ -309,7 +309,14 @@ export function defineVisitor( saveExpectedIndent(tokens, actualIndent) return } - saveExpectedIndent(tokens, expectedIndent) + saveExpectedIndent( + tokens, + Math.min( + ...tokens + .map(getExpectedIndentFromToken) + .filter((i): i is number => i != null), + ), + ) let prev = prevToken if (prevComments.length) { diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts index 5f5b7fc1b..a15878440 100644 --- a/src/rules/indent-helpers/ts.ts +++ b/src/rules/indent-helpers/ts.ts @@ -14,7 +14,25 @@ import { isBeginningOfLine } from "./commons" import { setOffsetNodes } from "./commons" import { getFirstAndLastTokens } from "./commons" -type NodeWithoutES = Exclude +type NodeWithoutES = Exclude< + TSESTree.Node, + | { type: ESTree.Node["type"] } + | TSESTree.JSXAttribute + | TSESTree.JSXClosingElement + | TSESTree.JSXClosingFragment + | TSESTree.JSXElement + | TSESTree.JSXEmptyExpression + | TSESTree.JSXExpressionContainer + | TSESTree.JSXFragment + | TSESTree.JSXIdentifier + | TSESTree.JSXMemberExpression + | TSESTree.JSXNamespacedName + | TSESTree.JSXOpeningElement + | TSESTree.JSXOpeningFragment + | TSESTree.JSXSpreadAttribute + | TSESTree.JSXSpreadChild + | TSESTree.JSXText +> type NodeListenerMap = { [key in NodeWithoutES["type"]]: T extends { type: key } ? T : never } @@ -437,11 +455,12 @@ export function defineVisitor(context: IndentContext): NodeListener { setOffset(extendsToken, 1, interfaceToken) setOffsetNodes(context, node.extends, extendsToken, null, 1) } - if (node.implements != null && node.implements.length) { - const implementsToken = sourceCode.getTokenBefore(node.implements[0])! - setOffset(implementsToken, 1, interfaceToken) - setOffsetNodes(context, node.implements, implementsToken, null, 1) - } + // It may not calculate the correct location because the visitor key is not provided. + // if (node.implements != null && node.implements.length) { + // const implementsToken = sourceCode.getTokenBefore(node.implements[0])! + // setOffset(implementsToken, 1, interfaceToken) + // setOffsetNodes(context, node.implements, implementsToken, null, 1) + // } const bodyToken = sourceCode.getFirstToken(node.body) setOffset(bodyToken, 0, interfaceToken) }, @@ -1024,125 +1043,6 @@ export function defineVisitor(context: IndentContext): NodeListener { TSLiteralType() { // noop }, - // ---------------------------------------------------------------------- - // JSX - // ---------------------------------------------------------------------- - JSXElement(node: TSESTree.JSXElement) { - setOffsetNodes( - context, - node.children, - node.openingElement, - node.closingElement, - 1, - ) - }, - JSXFragment(node: TSESTree.JSXFragment) { - setOffsetNodes( - context, - node.children, - node.openingFragment, - node.closingFragment, - 1, - ) - }, - JSXOpeningElement(node: TSESTree.JSXOpeningElement) { - const openToken = sourceCode.getFirstToken(node) - const closeToken = sourceCode.getLastToken(node) - - const nameToken = sourceCode.getFirstToken(node.name) - setOffset(nameToken, 1, openToken) - if (node.typeParameters) { - setOffset(sourceCode.getFirstToken(node.typeParameters), 1, nameToken) - } - for (const attr of node.attributes) { - setOffset(sourceCode.getFirstToken(attr), 1, openToken) - } - if (node.selfClosing) { - const slash = sourceCode.getTokenBefore(closeToken)! - if (slash.value === "/") { - setOffset(slash, 0, openToken) - } - } - setOffset(closeToken, 0, openToken) - }, - JSXClosingElement(node: TSESTree.JSXClosingElement) { - const openToken = sourceCode.getFirstToken(node) - const slash = sourceCode.getTokenAfter(openToken)! - if (slash.value === "/") { - setOffset(slash, 0, openToken) - } - const closeToken = sourceCode.getLastToken(node) - const nameToken = sourceCode.getFirstToken(node.name) - setOffset(nameToken, 1, openToken) - setOffset(closeToken, 0, openToken) - }, - JSXOpeningFragment( - node: TSESTree.JSXOpeningFragment | TSESTree.JSXClosingFragment, - ) { - const [firstToken, ...tokens] = sourceCode.getTokens(node) - setOffset(tokens, 0, firstToken) - }, - JSXClosingFragment(node: TSESTree.JSXClosingFragment) { - visitor.JSXOpeningFragment(node) - }, - JSXAttribute(node: TSESTree.JSXAttribute) { - if (!node.value) { - return - } - const keyToken = sourceCode.getFirstToken(node) - const eqToken = sourceCode.getTokenAfter(node.name) - setOffset(eqToken, 1, keyToken) - setOffset(sourceCode.getFirstToken(node.value), 1, keyToken) - }, - JSXExpressionContainer(node: TSESTree.JSXExpressionContainer) { - setOffsetNodes( - context, - [node.expression], - sourceCode.getFirstToken(node), - sourceCode.getLastToken(node), - 1, - ) - }, - JSXSpreadAttribute(node: TSESTree.JSXSpreadAttribute) { - setOffsetNodes( - context, - [node.argument], - sourceCode.getFirstToken(node), - sourceCode.getLastToken(node), - 1, - ) - }, - JSXSpreadChild(node: TSESTree.JSXSpreadChild) { - setOffsetNodes( - context, - [node.expression], - sourceCode.getFirstToken(node), - sourceCode.getLastToken(node), - 1, - ) - }, - JSXMemberExpression(node: TSESTree.JSXMemberExpression) { - const objectToken = sourceCode.getFirstToken(node) - const dotToken = sourceCode.getTokenBefore(node.property)! - const propertyToken = sourceCode.getTokenAfter(dotToken) - - setOffset([dotToken, propertyToken], 1, objectToken) - }, - // ---------------------------------------------------------------------- - // JSX SINGLE TOKEN NODES - // ---------------------------------------------------------------------- - JSXEmptyExpression() { - // noop - }, - JSXIdentifier() { - // noop - }, - JSXNamespacedName() { - // noop - }, - JSXText() { - // noop - }, } // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore diff --git a/tests/fixtures/rules/indent/invalid/script-methods01-errors.json b/tests/fixtures/rules/indent/invalid/script-methods01-errors.json new file mode 100644 index 000000000..a659945f7 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-methods01-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 4 spaces but found 0 spaces.", + "line": 7, + "column": 1 + }, + { + "message": "Expected indentation of 4 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 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 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 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 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 4 spaces but found 0 spaces.", + "line": 23, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 24, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/script-methods01-input.svelte b/tests/fixtures/rules/indent/invalid/script-methods01-input.svelte new file mode 100644 index 000000000..f50ab07fa --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-methods01-input.svelte @@ -0,0 +1,27 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/script-methods01-output.svelte b/tests/fixtures/rules/indent/invalid/script-methods01-output.svelte new file mode 100644 index 000000000..9ffc8deb5 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/script-methods01-output.svelte @@ -0,0 +1,27 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-errors.json new file mode 100644 index 000000000..06f396c38 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-errors.json @@ -0,0 +1,37 @@ +[ + { + "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 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-input.svelte new file mode 100644 index 000000000..2426cbff6 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-input.svelte @@ -0,0 +1,12 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-output.svelte new file mode 100644 index 000000000..c52056a58 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-conditional-type01-output.svelte @@ -0,0 +1,12 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json index ae897e19e..28a3e1047 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-errors.json @@ -730,32 +730,32 @@ "column": 1 }, { - "message": "Expected indentation of 8 spaces but found 0 spaces.", + "message": "Expected indentation of 6 spaces but found 0 spaces.", "line": 160, "column": 1 }, { - "message": "Expected indentation of 10 spaces but found 0 spaces.", + "message": "Expected indentation of 8 spaces but found 0 spaces.", "line": 161, "column": 1 }, { - "message": "Expected indentation of 8 spaces but found 0 spaces.", + "message": "Expected indentation of 6 spaces but found 0 spaces.", "line": 162, "column": 1 }, { - "message": "Expected indentation of 10 spaces but found 0 spaces.", + "message": "Expected indentation of 8 spaces but found 0 spaces.", "line": 163, "column": 1 }, { - "message": "Expected indentation of 8 spaces but found 0 spaces.", + "message": "Expected indentation of 6 spaces but found 0 spaces.", "line": 164, "column": 1 }, { - "message": "Expected indentation of 6 spaces but found 0 spaces.", + "message": "Expected indentation of 4 spaces but found 0 spaces.", "line": 165, "column": 1 }, diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte index 2bb379973..2307a1d12 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator01-output.svelte @@ -157,12 +157,12 @@ : boolean ) { - if (verbose) { - return `type: ${this.type}\ntitle: ${this.title}`; - } else { - return this.title; - } + if (verbose) { + return `type: ${this.type}\ntitle: ${this.title}`; + } else { + return this.title; } + } } class Line { diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte index 856cffa1c..f982e6fc7 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-input.svelte @@ -54,4 +54,4 @@ void } - + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte index d2fa58a74..d668d7e76 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface02-output.svelte @@ -54,4 +54,4 @@ } - + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface03-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-interface03-errors.json new file mode 100644 index 000000000..92fb4cdeb --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface03-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 4 spaces but found 0 spaces.", + "line": 6, + "column": 1 + }, + { + "message": "Expected indentation of 2 spaces but found 0 spaces.", + "line": 12, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface03-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface03-input.svelte new file mode 100644 index 000000000..fac69709d --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface03-input.svelte @@ -0,0 +1,15 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-interface03-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-interface03-output.svelte new file mode 100644 index 000000000..78c950161 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-interface03-output.svelte @@ -0,0 +1,15 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types01-input copy.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types01-input copy.svelte deleted file mode 100644 index a5e4fbf1b..000000000 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types01-input copy.svelte +++ /dev/null @@ -1,77 +0,0 @@ - - - - diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types03-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types03-input.svelte index 5ee79fd51..c50d7feb2 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types03-input.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types03-input.svelte @@ -38,4 +38,4 @@ string[ ; - + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-types03-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-types03-output.svelte index f45994da1..4f0544df2 100644 --- a/tests/fixtures/rules/indent/invalid/ts/ts-types03-output.svelte +++ b/tests/fixtures/rules/indent/invalid/ts/ts-types03-output.svelte @@ -38,4 +38,4 @@ ; - + From d256986aa24f144158dcc52ae53a89d699badbee Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 23 Jun 2021 17:48:11 +0900 Subject: [PATCH 11/11] Fix decorator indent --- src/rules/indent-helpers/ts.ts | 9 ++- .../indent/invalid/ts/ts-class03-errors.json | 27 +++++++++ .../indent/invalid/ts/ts-class03-input.svelte | 11 ++++ .../invalid/ts/ts-class03-output.svelte | 11 ++++ .../invalid/ts/ts-decorator02-errors.json | 57 +++++++++++++++++++ .../invalid/ts/ts-decorator02-input.svelte | 16 ++++++ .../invalid/ts/ts-decorator02-output.svelte | 16 ++++++ 7 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class03-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class03-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-class03-output.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-decorator02-errors.json create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-decorator02-input.svelte create mode 100644 tests/fixtures/rules/indent/invalid/ts/ts-decorator02-output.svelte diff --git a/src/rules/indent-helpers/ts.ts b/src/rules/indent-helpers/ts.ts index a15878440..a534ca138 100644 --- a/src/rules/indent-helpers/ts.ts +++ b/src/rules/indent-helpers/ts.ts @@ -954,7 +954,14 @@ export function defineVisitor(context: IndentContext): NodeListener { ) setOffset(startParentToken, 0, atToken) } else { - const startParentToken = sourceCode.getFirstToken(parent) + const startParentToken = sourceCode.getFirstToken( + parent.parent && + (parent.parent.type === "ExportDefaultDeclaration" || + parent.parent.type === "ExportNamedDeclaration") && + node.range[0] < parent.parent.range[0] + ? parent.parent + : parent, + ) copyOffset(atToken, startParentToken) } } else { diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class03-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-class03-errors.json new file mode 100644 index 000000000..97a18ec4b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class03-errors.json @@ -0,0 +1,27 @@ +[ + { + "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": 5, + "column": 1 + }, + { + "message": "Expected indentation of 2 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 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class03-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-class03-input.svelte new file mode 100644 index 000000000..0d42eee69 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class03-input.svelte @@ -0,0 +1,11 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-class03-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-class03-output.svelte new file mode 100644 index 000000000..77e591a6b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-class03-output.svelte @@ -0,0 +1,11 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-errors.json b/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-errors.json new file mode 100644 index 000000000..fcf82eb90 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-errors.json @@ -0,0 +1,57 @@ +[ + { + "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 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 2 spaces but found 0 spaces.", + "line": 13, + "column": 1 + } +] diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-input.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-input.svelte new file mode 100644 index 000000000..a6c86134b --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-input.svelte @@ -0,0 +1,16 @@ + + + + diff --git a/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-output.svelte b/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-output.svelte new file mode 100644 index 000000000..6496d9e96 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/ts/ts-decorator02-output.svelte @@ -0,0 +1,16 @@ + + + +