diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index 573acfd0c0c170b56c21e06cb42413699f03f647..59ab6532996c8d4f5b3367fb0323890f01c47852 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -298,5 +298,7 @@ faultDesc[FaultID.BuiltinDisableApi] = 'Disable Api'; faultDesc[FaultID.BuiltinIteratorResultValue] = 'IteratorResult.value is not supported'; faultDesc[FaultID.OptionalTupleType] = 'No optional tuple type'; faultDesc[FaultID.LargeNumericLiteral] = 'Numeric literal exceeds allowed range'; +faultDesc[FaultID.InstanceOfFunction] = 'instanceof with function type'; faultDesc[FaultID.unfixedTuple] = 'No unfixed tuple'; faultDesc[FaultID.EntryHasInvalidParams] = 'Entry has invalid parameters'; +faultDesc[FaultID.SuperInStaticContext] = '"super" in static context'; diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 37b2ec835e1be35227d21837b838f105193e8709..374e9466d480804a4fa255e3217b42688b42d99d 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -112,6 +112,13 @@ interface CreateClassPropertyForObjectLiteralParams { ctorInitProps: ts.PropertyAssignment[]; } +interface ConstructorBodyFixInfo { + pos: number; + needLeadingNewLine: boolean; + needTrailingNewLine: boolean; + indentLastLine: boolean; +} + export interface Autofix { replacementText: string; start: number; @@ -1592,75 +1599,35 @@ export class Autofixer { ctorDecl: ts.ConstructorDeclaration, paramTypes: ts.TypeNode[] | undefined ): Autofix[] | undefined { - if (paramTypes === undefined) { + if (paramTypes === undefined || !ctorDecl.body) { return undefined; } const fieldInitStmts: ts.Statement[] = []; const newFieldPos = ctorDecl.getStart(); const autofixes: Autofix[] = [{ start: newFieldPos, end: newFieldPos, replacementText: '' }]; + const indentStartPos = this.sourceFile.getLineAndCharacterOfPosition(ctorDecl.getStart()).character; for (let i = 0; i < ctorDecl.parameters.length; i++) { - this.fixCtorParameterPropertiesProcessParam(ctorDecl.parameters[i], paramTypes[i], fieldInitStmts, autofixes); - } - - // Note: Bodyless ctors can't have parameter properties. - if (ctorDecl.body) { - const beforeFieldStmts: ts.Statement[] = []; - const afterFieldStmts: ts.Statement[] = []; - const hasSuperExpressionStatement: boolean = this.hasSuperExpression( - ctorDecl.body, - beforeFieldStmts, - afterFieldStmts + this.fixCtorParameterPropertiesProcessParam( + ctorDecl.parameters[i], + paramTypes[i], + fieldInitStmts, + autofixes, + indentStartPos ); - let finalStmts: ts.Statement[] = []; - if (hasSuperExpressionStatement) { - finalStmts = beforeFieldStmts.concat(fieldInitStmts).concat(afterFieldStmts); - } else { - finalStmts = fieldInitStmts.concat(ctorDecl.body.statements); - } - const newBody = ts.factory.createBlock(finalStmts, true); - const newBodyText = this.printer.printNode(ts.EmitHint.Unspecified, newBody, ctorDecl.getSourceFile()); - autofixes.push({ start: ctorDecl.body.getStart(), end: ctorDecl.body.getEnd(), replacementText: newBodyText }); } + autofixes.push(this.fixCtorParameterPropertiesProcessBody(ctorDecl.body, fieldInitStmts, indentStartPos)); return autofixes; } - private hasSuperExpression( - body: ts.Block, - beforeFieldStmts: ts.Statement[], - afterFieldStmts: ts.Statement[] - ): boolean { - void this; - let hasSuperExpressionStatement = false; - ts.forEachChild(body, (node) => { - if (this.isSuperCallStmt(node as ts.Statement)) { - hasSuperExpressionStatement = true; - beforeFieldStmts.push(node as ts.Statement); - } else if (hasSuperExpressionStatement) { - afterFieldStmts.push(node as ts.Statement); - } else { - beforeFieldStmts.push(node as ts.Statement); - } - }); - return hasSuperExpressionStatement; - } - - private isSuperCallStmt(node: ts.Statement): boolean { - void this; - if (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)) { - const expr = node.expression.expression; - return expr.kind === ts.SyntaxKind.SuperKeyword; - } - return false; - } - private fixCtorParameterPropertiesProcessParam( param: ts.ParameterDeclaration, paramType: ts.TypeNode, fieldInitStmts: ts.Statement[], - autofixes: Autofix[] + autofixes: Autofix[], + indentStartPos: number ): void { // Parameter property can not be a destructuring parameter. if (!ts.isIdentifier(param.name)) { @@ -1673,7 +1640,6 @@ export class Autofixer { const paramModifiers = modifiers?.filter((x) => { return x.kind !== ts.SyntaxKind.OverrideKeyword; }); - const newFieldNode = ts.factory.createPropertyDeclaration( paramModifiers, propIdent, @@ -1683,7 +1649,7 @@ export class Autofixer { ); const newFieldText = this.printer.printNode(ts.EmitHint.Unspecified, newFieldNode, param.getSourceFile()) + this.getNewLine(); - autofixes[0].replacementText += newFieldText; + autofixes[0].replacementText += this.adjustIndentation(newFieldText, indentStartPos); const newParamDecl = ts.factory.createParameterDeclaration( undefined, @@ -1707,6 +1673,74 @@ export class Autofixer { } } + private fixCtorParameterPropertiesProcessBody( + ctorBody: ts.Block, + fieldInitStmts: ts.Statement[], + indentStartPos: number + ): Autofix { + let newStmtListText = this.printer.printList( + ts.ListFormat.MultiLine | ts.ListFormat.NoTrailingNewLine, + ts.factory.createNodeArray(fieldInitStmts), + ctorBody.getSourceFile() + ); + + const ctorBodyFixInfo = this.getParamPropertiesCtorBodyFixInfo(ctorBody); + + if (ctorBodyFixInfo.needLeadingNewLine) { + newStmtListText = this.getNewLine() + newStmtListText; + } + if (ctorBodyFixInfo.needTrailingNewLine) { + newStmtListText += this.getNewLine(); + } + newStmtListText = this.adjustIndentation(newStmtListText, indentStartPos, ctorBodyFixInfo.indentLastLine); + return { start: ctorBodyFixInfo.pos, end: ctorBodyFixInfo.pos, replacementText: newStmtListText }; + } + + getParamPropertiesCtorBodyFixInfo(ctorBody: ts.Block): ConstructorBodyFixInfo { + let pos: number; + let needLeadingNewLine = false; + let needTrailingNewLine = false; + let indentLastLine = false; + const statements = ctorBody.statements; + if (statements.length > 0) { + const superCallStmt = statements.find(TsUtils.isSuperCallStmt); + if (superCallStmt) { + // If there's a 'super()' call, then new statements are inserted after it. + const superCallIndex = statements.indexOf(superCallStmt); + if (superCallIndex === statements.length - 1) { + const superCallEndPosition = superCallStmt.getEnd(); + pos = TsUtils.getTrailingCommentRangesEnd(this.sourceFile, superCallEndPosition) ?? superCallEndPosition; + needLeadingNewLine = true; + } else { + pos = statements[superCallIndex + 1].getStart(); + needTrailingNewLine = true; + } + } else { + // If there's no 'super()' call, new statements are inserted at the beginning of ctor body. + needTrailingNewLine = true; + pos = statements[0].getStart(); + } + indentLastLine = true; + } else { + // Ctor body is empty, insert new statements after inner comments if any. + needLeadingNewLine = true; + const bracesOnSameLine = + this.sourceFile.getLineAndCharacterOfPosition(ctorBody.getStart()).line === + this.sourceFile.getLineAndCharacterOfPosition(ctorBody.getEnd()).line; + + if (bracesOnSameLine) { + pos = ctorBody.getEnd() - 1; /* The position of closing brace */ + needTrailingNewLine = true; + } else { + const leadingRangesPos = ctorBody.getStart() + 1; /* End position of opening brace */ + pos = TsUtils.getLeadingCommentRangesEnd(this.sourceFile, leadingRangesPos) ?? leadingRangesPos; + indentLastLine = true; + } + } + + return { pos, needLeadingNewLine, needTrailingNewLine, indentLastLine }; + } + fixPrivateIdentifier(node: ts.PrivateIdentifier): Autofix[] | undefined { const classMember = this.typeChecker.getSymbolAtLocation(node); if (!classMember || (classMember.getFlags() & ts.SymbolFlags.ClassMember) === 0 || !classMember.valueDeclaration) { @@ -3861,7 +3895,7 @@ export class Autofixer { return autofix; } - private adjustIndentation(text: string, startPos: number): string { + private adjustIndentation(text: string, startPos: number, indentLastLine = false): string { const lines = text.split(this.getNewLine()); if (lines.length <= 1) { return text; @@ -3879,7 +3913,7 @@ export class Autofixer { return line; }); - const lastLine = ' '.repeat(startPos) + lines[lines.length - 1]; + const lastLine = ' '.repeat(indentLastLine ? indentBase : startPos) + lines[lines.length - 1]; return [firstLine, ...middleLines, lastLine].join(this.getNewLine()); } diff --git a/ets2panda/linter/src/lib/utils/TsUtils.ts b/ets2panda/linter/src/lib/utils/TsUtils.ts index 3aa1893629cf4d0872461b648811448b079a9595..fc3f35fa269998502675cf3648def29d9ef19730 100644 --- a/ets2panda/linter/src/lib/utils/TsUtils.ts +++ b/ets2panda/linter/src/lib/utils/TsUtils.ts @@ -3951,4 +3951,22 @@ export class TsUtils { }) !== -1 ); } + + static getLeadingCommentRangesEnd(srcFile: ts.SourceFile, pos: number): number | undefined { + const leadingCommentRanges = ts.getLeadingCommentRanges(srcFile.text, pos); + return leadingCommentRanges ? leadingCommentRanges[leadingCommentRanges.length - 1].end : undefined; + } + + static getTrailingCommentRangesEnd(srcFile: ts.SourceFile, pos: number): number | undefined { + const trailingCommentRanges = ts.getTrailingCommentRanges(srcFile.text, pos); + return trailingCommentRanges ? trailingCommentRanges[trailingCommentRanges.length - 1].end : undefined; + } + + static isSuperCallStmt(node: ts.Statement): boolean { + if (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)) { + const expr = node.expression.expression; + return expr.kind === ts.SyntaxKind.SuperKeyword; + } + return false; + } } diff --git a/ets2panda/linter/test/main/parameter_properties.ets b/ets2panda/linter/test/main/parameter_properties.ets index 77065182777c657ac558b395830d55c605b8e9a4..0435b1a2771cb89a9d4c5b2598804a9353b65cf7 100644 --- a/ets2panda/linter/test/main/parameter_properties.ets +++ b/ets2panda/linter/test/main/parameter_properties.ets @@ -100,4 +100,52 @@ class G1 { class G2 { constructor(public a?: number, public b?: number) {} +} + +// empty body, braces on same line +class H1 { + constructor( + readonly x: number, + readonly y: number, + ) {} +} + +// empty body with comment, braces on same line +class H2 { + constructor( + readonly x: number, + readonly y: number, + ) { /* Comment */ } +} + +// empty body, braces on different lines +class H3 { + constructor( + readonly x: number, + readonly y: number, + ) { + } +} + +// empty body with comments on multiple lines +class H4 { + constructor( + readonly x: number, + readonly y: number, + ) { + // comment 1 + // comment 2 + } +} + +// body with statements and comments +class H5 { + constructor( + readonly x: number, + readonly y: number, + ) { + // comment at the beginning + console.log('hello'); + // comment at the end + } } \ No newline at end of file diff --git a/ets2panda/linter/test/main/parameter_properties.ets.arkts2.json b/ets2panda/linter/test/main/parameter_properties.ets.arkts2.json index 343ff611b84b1889fb0c175ee6dedf04fcd59b80..fec4a5a5a3889d1e906192376afba49ff5235ade 100644 --- a/ets2panda/linter/test/main/parameter_properties.ets.arkts2.json +++ b/ets2panda/linter/test/main/parameter_properties.ets.arkts2.json @@ -233,6 +233,106 @@ "suggest": "", "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", "severity": "ERROR" + }, + { + "line": 108, + "column": 5, + "endLine": 108, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 116, + "column": 5, + "endLine": 116, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 124, + "column": 5, + "endLine": 124, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 133, + "column": 5, + "endLine": 133, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 144, + "column": 5, + "endLine": 144, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/parameter_properties.ets.autofix.json b/ets2panda/linter/test/main/parameter_properties.ets.autofix.json index d6e77be9c67c9b6594e6c2c831c311639c2d620e..8109c3655ffa6128ae6c8a6c50b03be4e7ee5811 100644 --- a/ets2panda/linter/test/main/parameter_properties.ets.autofix.json +++ b/ets2panda/linter/test/main/parameter_properties.ets.autofix.json @@ -24,7 +24,7 @@ { "start": 622, "end": 622, - "replacementText": "public readonly x: number;\nprotected y: number;\nprivate z: number;\n", + "replacementText": "public readonly x: number;\n protected y: number;\n private z: number;\n ", "line": 20, "column": 5, "endLine": 20, @@ -58,9 +58,9 @@ "endColumn": 12 }, { - "start": 717, - "end": 719, - "replacementText": "{\n this.x = x;\n this.y = y;\n this.z = z;\n}", + "start": 718, + "end": 718, + "replacementText": "\n this.x = x;\n this.y = y;\n this.z = z;\n ", "line": 20, "column": 5, "endLine": 20, @@ -81,7 +81,7 @@ { "start": 622, "end": 622, - "replacementText": "public readonly x: number;\nprotected y: number;\nprivate z: number;\n", + "replacementText": "public readonly x: number;\n protected y: number;\n private z: number;\n ", "line": 20, "column": 5, "endLine": 20, @@ -115,9 +115,9 @@ "endColumn": 12 }, { - "start": 717, - "end": 719, - "replacementText": "{\n this.x = x;\n this.y = y;\n this.z = z;\n}", + "start": 718, + "end": 718, + "replacementText": "\n this.x = x;\n this.y = y;\n this.z = z;\n ", "line": 20, "column": 5, "endLine": 20, @@ -138,7 +138,7 @@ { "start": 622, "end": 622, - "replacementText": "public readonly x: number;\nprotected y: number;\nprivate z: number;\n", + "replacementText": "public readonly x: number;\n protected y: number;\n private z: number;\n ", "line": 20, "column": 5, "endLine": 20, @@ -172,9 +172,9 @@ "endColumn": 12 }, { - "start": 717, - "end": 719, - "replacementText": "{\n this.x = x;\n this.y = y;\n this.z = z;\n}", + "start": 718, + "end": 718, + "replacementText": "\n this.x = x;\n this.y = y;\n this.z = z;\n ", "line": 20, "column": 5, "endLine": 20, @@ -205,7 +205,7 @@ { "start": 870, "end": 870, - "replacementText": "public w: string;\nprivate readonly r: number[];\n", + "replacementText": "public w: string;\n private readonly r: number[];\n ", "line": 34, "column": 60, "endLine": 34, @@ -230,9 +230,9 @@ "endColumn": 67 }, { - "start": 969, - "end": 1021, - "replacementText": "{\n this.w = w;\n this.r = r;\n console.log(q, this.w, e, this.r, this.f);\n}", + "start": 975, + "end": 975, + "replacementText": "this.w = w;\n this.r = r;\n ", "line": 34, "column": 60, "endLine": 34, @@ -253,7 +253,7 @@ { "start": 870, "end": 870, - "replacementText": "public w: string;\nprivate readonly r: number[];\n", + "replacementText": "public w: string;\n private readonly r: number[];\n ", "line": 34, "column": 60, "endLine": 34, @@ -278,9 +278,9 @@ "endColumn": 67 }, { - "start": 969, - "end": 1021, - "replacementText": "{\n this.w = w;\n this.r = r;\n console.log(q, this.w, e, this.r, this.f);\n}", + "start": 975, + "end": 975, + "replacementText": "this.w = w;\n this.r = r;\n ", "line": 34, "column": 60, "endLine": 34, @@ -371,7 +371,7 @@ { "start": 1275, "end": 1275, - "replacementText": "readonly a: number;\n", + "replacementText": "readonly a: number;\n ", "line": 54, "column": 15, "endLine": 54, @@ -387,9 +387,9 @@ "endColumn": 33 }, { - "start": 1307, - "end": 1309, - "replacementText": "{\n this.a = a;\n}", + "start": 1308, + "end": 1308, + "replacementText": "\n this.a = a;\n ", "line": 54, "column": 15, "endLine": 54, @@ -410,7 +410,7 @@ { "start": 1335, "end": 1335, - "replacementText": "readonly aa: number;\nb: number;\npublic c: number;\n", + "replacementText": "readonly aa: number;\n b: number;\n public c: number;\n ", "line": 61, "column": 5, "endLine": 61, @@ -444,9 +444,9 @@ "endColumn": 11 }, { - "start": 1430, - "end": 1450, - "replacementText": "{\n super(aa);\n this.aa = aa;\n this.b = b;\n this.c = c;\n}", + "start": 1446, + "end": 1446, + "replacementText": "\n this.aa = aa;\n this.b = b;\n this.c = c;", "line": 61, "column": 5, "endLine": 61, @@ -467,7 +467,7 @@ { "start": 1335, "end": 1335, - "replacementText": "readonly aa: number;\nb: number;\npublic c: number;\n", + "replacementText": "readonly aa: number;\n b: number;\n public c: number;\n ", "line": 61, "column": 5, "endLine": 61, @@ -501,9 +501,9 @@ "endColumn": 11 }, { - "start": 1430, - "end": 1450, - "replacementText": "{\n super(aa);\n this.aa = aa;\n this.b = b;\n this.c = c;\n}", + "start": 1446, + "end": 1446, + "replacementText": "\n this.aa = aa;\n this.b = b;\n this.c = c;", "line": 61, "column": 5, "endLine": 61, @@ -524,7 +524,7 @@ { "start": 1335, "end": 1335, - "replacementText": "readonly aa: number;\nb: number;\npublic c: number;\n", + "replacementText": "readonly aa: number;\n b: number;\n public c: number;\n ", "line": 61, "column": 5, "endLine": 61, @@ -558,9 +558,9 @@ "endColumn": 11 }, { - "start": 1430, - "end": 1450, - "replacementText": "{\n super(aa);\n this.aa = aa;\n this.b = b;\n this.c = c;\n}", + "start": 1446, + "end": 1446, + "replacementText": "\n this.aa = aa;\n this.b = b;\n this.c = c;", "line": 61, "column": 5, "endLine": 61, @@ -581,7 +581,7 @@ { "start": 1477, "end": 1477, - "replacementText": "readonly aa: number;\n", + "replacementText": "readonly aa: number;\n ", "line": 68, "column": 15, "endLine": 68, @@ -597,9 +597,9 @@ "endColumn": 34 }, { - "start": 1510, - "end": 1594, - "replacementText": "{\n let f2: number = 1;\n console.log('before super() call');\n super(aa);\n this.aa = aa;\n}", + "start": 1590, + "end": 1590, + "replacementText": "\n this.aa = aa;", "line": 68, "column": 15, "endLine": 68, @@ -620,7 +620,7 @@ { "start": 1621, "end": 1621, - "replacementText": "readonly aa: number;\n", + "replacementText": "readonly aa: number;\n ", "line": 76, "column": 15, "endLine": 76, @@ -636,9 +636,9 @@ "endColumn": 34 }, { - "start": 1654, - "end": 1737, - "replacementText": "{\n super(aa);\n this.aa = aa;\n let f3: number = 1;\n console.log('after super() call');\n}", + "start": 1675, + "end": 1675, + "replacementText": "this.aa = aa;\n ", "line": 76, "column": 15, "endLine": 76, @@ -659,7 +659,7 @@ { "start": 1764, "end": 1764, - "replacementText": "readonly aa: number;\n", + "replacementText": "readonly aa: number;\n ", "line": 84, "column": 15, "endLine": 84, @@ -675,9 +675,9 @@ "endColumn": 34 }, { - "start": 1797, - "end": 1944, - "replacementText": "{\n let f4: number = 1;\n console.log('before super() call');\n super(aa);\n this.aa = aa;\n console.log('after super() call');\n let f5: number = 1;\n}", + "start": 1882, + "end": 1882, + "replacementText": "this.aa = aa;\n ", "line": 84, "column": 15, "endLine": 84, @@ -698,7 +698,7 @@ { "start": 2003, "end": 2003, - "replacementText": "public a?: number;\npublic b: number;\n", + "replacementText": "public a?: number;\n public b: number;\n ", "line": 98, "column": 34, "endLine": 98, @@ -723,9 +723,9 @@ "endColumn": 40 }, { - "start": 2052, - "end": 2054, - "replacementText": "{\n this.a = a;\n this.b = b;\n}", + "start": 2053, + "end": 2053, + "replacementText": "\n this.a = a;\n this.b = b;\n ", "line": 98, "column": 34, "endLine": 98, @@ -746,7 +746,7 @@ { "start": 2003, "end": 2003, - "replacementText": "public a?: number;\npublic b: number;\n", + "replacementText": "public a?: number;\n public b: number;\n ", "line": 98, "column": 34, "endLine": 98, @@ -771,9 +771,9 @@ "endColumn": 40 }, { - "start": 2052, - "end": 2054, - "replacementText": "{\n this.a = a;\n this.b = b;\n}", + "start": 2053, + "end": 2053, + "replacementText": "\n this.a = a;\n this.b = b;\n ", "line": 98, "column": 34, "endLine": 98, @@ -794,7 +794,7 @@ { "start": 2071, "end": 2071, - "replacementText": "public a?: number;\npublic b?: number;\n", + "replacementText": "public a?: number;\n public b?: number;\n ", "line": 102, "column": 34, "endLine": 102, @@ -819,9 +819,9 @@ "endColumn": 40 }, { - "start": 2121, - "end": 2123, - "replacementText": "{\n this.a = a;\n this.b = b;\n}", + "start": 2122, + "end": 2122, + "replacementText": "\n this.a = a;\n this.b = b;\n ", "line": 102, "column": 34, "endLine": 102, @@ -842,7 +842,7 @@ { "start": 2071, "end": 2071, - "replacementText": "public a?: number;\npublic b?: number;\n", + "replacementText": "public a?: number;\n public b?: number;\n ", "line": 102, "column": 34, "endLine": 102, @@ -867,9 +867,9 @@ "endColumn": 40 }, { - "start": 2121, - "end": 2123, - "replacementText": "{\n this.a = a;\n this.b = b;\n}", + "start": 2122, + "end": 2122, + "replacementText": "\n this.a = a;\n this.b = b;\n ", "line": 102, "column": 34, "endLine": 102, @@ -879,6 +879,486 @@ "suggest": "", "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", "severity": "ERROR" + }, + { + "line": 108, + "column": 5, + "endLine": 108, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2175, + "end": 2175, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23 + }, + { + "start": 2192, + "end": 2210, + "replacementText": "x: number", + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23 + }, + { + "start": 2216, + "end": 2234, + "replacementText": "y: number", + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23 + }, + { + "start": 2241, + "end": 2241, + "replacementText": "\n this.x = x;\n this.y = y;\n ", + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2175, + "end": 2175, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23 + }, + { + "start": 2192, + "end": 2210, + "replacementText": "x: number", + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23 + }, + { + "start": 2216, + "end": 2234, + "replacementText": "y: number", + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23 + }, + { + "start": 2241, + "end": 2241, + "replacementText": "\n this.x = x;\n this.y = y;\n ", + "line": 109, + "column": 5, + "endLine": 109, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 116, + "column": 5, + "endLine": 116, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2307, + "end": 2307, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23 + }, + { + "start": 2324, + "end": 2342, + "replacementText": "x: number", + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23 + }, + { + "start": 2348, + "end": 2366, + "replacementText": "y: number", + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23 + }, + { + "start": 2388, + "end": 2388, + "replacementText": "\n this.x = x;\n this.y = y;\n ", + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2307, + "end": 2307, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23 + }, + { + "start": 2324, + "end": 2342, + "replacementText": "x: number", + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23 + }, + { + "start": 2348, + "end": 2366, + "replacementText": "y: number", + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23 + }, + { + "start": 2388, + "end": 2388, + "replacementText": "\n this.x = x;\n this.y = y;\n ", + "line": 117, + "column": 5, + "endLine": 117, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 124, + "column": 5, + "endLine": 124, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2447, + "end": 2447, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23 + }, + { + "start": 2464, + "end": 2482, + "replacementText": "x: number", + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23 + }, + { + "start": 2488, + "end": 2506, + "replacementText": "y: number", + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23 + }, + { + "start": 2513, + "end": 2513, + "replacementText": "\n this.x = x;\n this.y = y;", + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2447, + "end": 2447, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23 + }, + { + "start": 2464, + "end": 2482, + "replacementText": "x: number", + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23 + }, + { + "start": 2488, + "end": 2506, + "replacementText": "y: number", + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23 + }, + { + "start": 2513, + "end": 2513, + "replacementText": "\n this.x = x;\n this.y = y;", + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 133, + "column": 5, + "endLine": 133, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2580, + "end": 2580, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23 + }, + { + "start": 2597, + "end": 2615, + "replacementText": "x: number", + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23 + }, + { + "start": 2621, + "end": 2639, + "replacementText": "y: number", + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23 + }, + { + "start": 2680, + "end": 2680, + "replacementText": "\n this.x = x;\n this.y = y;", + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2580, + "end": 2580, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23 + }, + { + "start": 2597, + "end": 2615, + "replacementText": "x: number", + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23 + }, + { + "start": 2621, + "end": 2639, + "replacementText": "y: number", + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23 + }, + { + "start": 2680, + "end": 2680, + "replacementText": "\n this.x = x;\n this.y = y;", + "line": 134, + "column": 5, + "endLine": 134, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 144, + "column": 5, + "endLine": 144, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2738, + "end": 2738, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23 + }, + { + "start": 2755, + "end": 2773, + "replacementText": "x: number", + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23 + }, + { + "start": 2779, + "end": 2797, + "replacementText": "y: number", + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23 + }, + { + "start": 2841, + "end": 2841, + "replacementText": "this.x = x;\n this.y = y;\n ", + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" + }, + { + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 2738, + "end": 2738, + "replacementText": "readonly x: number;\n readonly y: number;\n ", + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23 + }, + { + "start": 2755, + "end": 2773, + "replacementText": "x: number", + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23 + }, + { + "start": 2779, + "end": 2797, + "replacementText": "y: number", + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23 + }, + { + "start": 2841, + "end": 2841, + "replacementText": "this.x = x;\n this.y = y;\n ", + "line": 145, + "column": 5, + "endLine": 145, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/parameter_properties.ets.migrate.ets b/ets2panda/linter/test/main/parameter_properties.ets.migrate.ets index 6a79a113c46ed75c70c35b4dd9736eed54fd0979..458320d61e74499d90d4f63646333b3a6b16905e 100644 --- a/ets2panda/linter/test/main/parameter_properties.ets.migrate.ets +++ b/ets2panda/linter/test/main/parameter_properties.ets.migrate.ets @@ -15,9 +15,9 @@ class A { public readonly x: number; -protected y: number; -private z: number; -constructor( + protected y: number; + private z: number; + constructor( x: number, y: number, z: number @@ -25,7 +25,7 @@ constructor( this.x = x; this.y = y; this.z = z; -} + } foo(): void { console.log(this.x + this.y + this.z); @@ -39,12 +39,12 @@ class B { public f: number = 10; public w: string; -private readonly r: number[]; -constructor(q: number, w = 'default', e: boolean, r: number[] = [1, 2, 3]) { + private readonly r: number[]; + constructor(q: number, w = 'default', e: boolean, r: number[] = [1, 2, 3]) { this.w = w; this.r = r; console.log(q, this.w, e, this.r, this.f); -} + } } const b = new B(1, '2', true, []); @@ -59,11 +59,11 @@ interface GeneratedTypeLiteralInterface_1 { } class D { public a: number; -private b: GeneratedTypeLiteralInterface_1; -constructor(a: number, b: GeneratedTypeLiteralInterface_1) { + private b: GeneratedTypeLiteralInterface_1; + constructor(a: number, b: GeneratedTypeLiteralInterface_1) { this.a = a; this.b = b; -} // not fixable + } // not fixable } class E { @@ -71,16 +71,16 @@ class E { c: number = 0; readonly a: number; -constructor(a: number) { + constructor(a: number) { this.a = a; -} + } } class F extends E { readonly aa: number; -b: number; -public c: number; -constructor( + b: number; + public c: number; + constructor( aa: number, b: number, c: number @@ -89,39 +89,39 @@ constructor( this.aa = aa; this.b = b; this.c = c; -} + } } class F2 extends E { readonly aa: number; -constructor(aa: number) { + constructor(aa: number) { let f2: number = 1; console.log('before super() call'); super(aa); this.aa = aa; -} + } } class F3 extends E { readonly aa: number; -constructor(aa: number) { + constructor(aa: number) { super(aa); this.aa = aa; let f3: number = 1; console.log('after super() call'); -} + } } class F4 extends E { readonly aa: number; -constructor(aa: number) { + constructor(aa: number) { let f4: number = 1; console.log('before super() call'); super(aa); this.aa = aa; console.log('after super() call'); let f5: number = 1; -} + } } class G { @@ -130,18 +130,88 @@ class G { class G1 { public a?: number; -public b: number; -constructor(a?: number, b: number) { + public b: number; + constructor(a?: number, b: number) { this.a = a; this.b = b; -} + } } class G2 { public a?: number; -public b?: number; -constructor(a?: number, b?: number) { + public b?: number; + constructor(a?: number, b?: number) { this.a = a; this.b = b; + } +} + +// empty body, braces on same line +class H1 { + readonly x: number; + readonly y: number; + constructor( + x: number, + y: number, + ) { + this.x = x; + this.y = y; + } } + +// empty body with comment, braces on same line +class H2 { + readonly x: number; + readonly y: number; + constructor( + x: number, + y: number, + ) { /* Comment */ + this.x = x; + this.y = y; + } +} + +// empty body, braces on different lines +class H3 { + readonly x: number; + readonly y: number; + constructor( + x: number, + y: number, + ) { + this.x = x; + this.y = y; + } +} + +// empty body with comments on multiple lines +class H4 { + readonly x: number; + readonly y: number; + constructor( + x: number, + y: number, + ) { + // comment 1 + // comment 2 + this.x = x; + this.y = y; + } +} + +// body with statements and comments +class H5 { + readonly x: number; + readonly y: number; + constructor( + x: number, + y: number, + ) { + // comment at the beginning + this.x = x; + this.y = y; + console.log('hello'); + // comment at the end + } } \ No newline at end of file diff --git a/ets2panda/linter/test/main/parameter_properties.ets.migrate.json b/ets2panda/linter/test/main/parameter_properties.ets.migrate.json index f5bbbab5413b751bcc375dc9c7b788749e4839a7..7282b62c140152d133001ecf7465fe75c5152160 100644 --- a/ets2panda/linter/test/main/parameter_properties.ets.migrate.json +++ b/ets2panda/linter/test/main/parameter_properties.ets.migrate.json @@ -16,9 +16,9 @@ "result": [ { "line": 43, - "column": 24, + "column": 26, "endLine": 43, - "endColumn": 25, + "endColumn": 27, "problem": "DefaultArgsBehindRequiredArgs", "suggest": "", "rule": "Default parameters must be placed after mandatory parameters (arkts-default-args-behind-required-args)", diff --git a/ets2panda/linter/test/main/private_identifiers.ets.autofix.json b/ets2panda/linter/test/main/private_identifiers.ets.autofix.json index 60af364c0211f8b18ff023a347256482b9fa2217..a05c787677b2c1db11033cfb6e19e078d177610d 100644 --- a/ets2panda/linter/test/main/private_identifiers.ets.autofix.json +++ b/ets2panda/linter/test/main/private_identifiers.ets.autofix.json @@ -84,12 +84,20 @@ { "start": 617, "end": 628, - "replacementText": "private p: number;" + "replacementText": "private p: number;", + "line": 44, + "column": 22, + "endLine": 44, + "endColumn": 24 }, { "start": 1121, "end": 1123, - "replacementText": "p" + "replacementText": "p", + "line": 44, + "column": 22, + "endLine": 44, + "endColumn": 24 } ], "suggest": "", @@ -116,12 +124,20 @@ { "start": 677, "end": 689, - "replacementText": "private q?: string;" + "replacementText": "private q?: string;", + "line": 44, + "column": 43, + "endLine": 44, + "endColumn": 45 }, { "start": 1142, "end": 1144, - "replacementText": "q" + "replacementText": "q", + "line": 44, + "column": 43, + "endLine": 44, + "endColumn": 45 } ], "suggest": "", @@ -148,12 +164,20 @@ { "start": 692, "end": 704, - "replacementText": "private e!: string;" + "replacementText": "private e!: string;", + "line": 44, + "column": 53, + "endLine": 44, + "endColumn": 55 }, { "start": 1152, "end": 1154, - "replacementText": "e" + "replacementText": "e", + "line": 44, + "column": 53, + "endLine": 44, + "endColumn": 55 } ], "suggest": "", @@ -170,12 +194,20 @@ { "start": 707, "end": 721, - "replacementText": "private static s = 0;" + "replacementText": "private static s = 0;", + "line": 44, + "column": 60, + "endLine": 44, + "endColumn": 62 }, { "start": 1159, "end": 1161, - "replacementText": "s" + "replacementText": "s", + "line": 44, + "column": 60, + "endLine": 44, + "endColumn": 62 } ], "suggest": "", @@ -192,12 +224,20 @@ { "start": 724, "end": 741, - "replacementText": "private readonly r = 20;" + "replacementText": "private readonly r = 20;", + "line": 44, + "column": 70, + "endLine": 44, + "endColumn": 72 }, { "start": 1169, "end": 1171, - "replacementText": "r" + "replacementText": "r", + "line": 44, + "column": 70, + "endLine": 44, + "endColumn": 72 } ], "suggest": "", @@ -214,12 +254,20 @@ { "start": 744, "end": 768, - "replacementText": "private static readonly sr = 0;" + "replacementText": "private static readonly sr = 0;", + "line": 44, + "column": 77, + "endLine": 44, + "endColumn": 80 }, { "start": 1176, "end": 1179, - "replacementText": "sr" + "replacementText": "sr", + "line": 44, + "column": 77, + "endLine": 44, + "endColumn": 80 } ], "suggest": "", @@ -236,12 +284,20 @@ { "start": 771, "end": 801, - "replacementText": "private static readonly srq?: string;" + "replacementText": "private static readonly srq?: string;", + "line": 44, + "column": 85, + "endLine": 44, + "endColumn": 89 }, { "start": 1184, "end": 1188, - "replacementText": "srq" + "replacementText": "srq", + "line": 44, + "column": 85, + "endLine": 44, + "endColumn": 89 } ], "suggest": "", @@ -258,12 +314,20 @@ { "start": 805, "end": 827, - "replacementText": "private m(x: number): void { }" + "replacementText": "private m(x: number): void { }", + "line": 45, + "column": 10, + "endLine": 45, + "endColumn": 12 }, { "start": 1224, "end": 1226, - "replacementText": "m" + "replacementText": "m", + "line": 45, + "column": 10, + "endLine": 45, + "endColumn": 12 } ], "suggest": "", @@ -300,12 +364,20 @@ { "start": 955, "end": 987, - "replacementText": "private get g1(): number { return 10; }" + "replacementText": "private get g1(): number { return 10; }", + "line": 48, + "column": 18, + "endLine": 48, + "endColumn": 21 }, { "start": 1315, "end": 1318, - "replacementText": "g1" + "replacementText": "g1", + "line": 48, + "column": 18, + "endLine": 48, + "endColumn": 21 } ], "suggest": "", @@ -322,12 +394,20 @@ { "start": 990, "end": 1012, - "replacementText": "private set s1(x: number) { }" + "replacementText": "private set s1(x: number) { }", + "line": 49, + "column": 10, + "endLine": 49, + "endColumn": 13 }, { "start": 1329, "end": 1332, - "replacementText": "s1" + "replacementText": "s1", + "line": 49, + "column": 10, + "endLine": 49, + "endColumn": 13 } ], "suggest": "", @@ -344,12 +424,20 @@ { "start": 1016, "end": 1055, - "replacementText": "private static get g2(): number { return 10; }" + "replacementText": "private static get g2(): number { return 10; }", + "line": 50, + "column": 15, + "endLine": 50, + "endColumn": 18 }, { "start": 1352, "end": 1355, - "replacementText": "g2" + "replacementText": "g2", + "line": 50, + "column": 15, + "endLine": 50, + "endColumn": 18 } ], "suggest": "", @@ -366,12 +454,20 @@ { "start": 1058, "end": 1087, - "replacementText": "private static set s2(x: number) { }" + "replacementText": "private static set s2(x: number) { }", + "line": 51, + "column": 7, + "endLine": 51, + "endColumn": 10 }, { "start": 1363, "end": 1366, - "replacementText": "s2" + "replacementText": "s2", + "line": 51, + "column": 7, + "endLine": 51, + "endColumn": 10 } ], "suggest": "", @@ -388,12 +484,20 @@ { "start": 617, "end": 628, - "replacementText": "private p: number;" + "replacementText": "private p: number;", + "line": 44, + "column": 22, + "endLine": 44, + "endColumn": 24 }, { "start": 1121, "end": 1123, - "replacementText": "p" + "replacementText": "p", + "line": 44, + "column": 22, + "endLine": 44, + "endColumn": 24 } ], "suggest": "", @@ -420,12 +524,20 @@ { "start": 677, "end": 689, - "replacementText": "private q?: string;" + "replacementText": "private q?: string;", + "line": 44, + "column": 43, + "endLine": 44, + "endColumn": 45 }, { "start": 1142, "end": 1144, - "replacementText": "q" + "replacementText": "q", + "line": 44, + "column": 43, + "endLine": 44, + "endColumn": 45 } ], "suggest": "", @@ -442,12 +554,20 @@ { "start": 692, "end": 704, - "replacementText": "private e!: string;" + "replacementText": "private e!: string;", + "line": 44, + "column": 53, + "endLine": 44, + "endColumn": 55 }, { "start": 1152, "end": 1154, - "replacementText": "e" + "replacementText": "e", + "line": 44, + "column": 53, + "endLine": 44, + "endColumn": 55 } ], "suggest": "", @@ -464,12 +584,20 @@ { "start": 707, "end": 721, - "replacementText": "private static s = 0;" + "replacementText": "private static s = 0;", + "line": 44, + "column": 60, + "endLine": 44, + "endColumn": 62 }, { "start": 1159, "end": 1161, - "replacementText": "s" + "replacementText": "s", + "line": 44, + "column": 60, + "endLine": 44, + "endColumn": 62 } ], "suggest": "", @@ -486,12 +614,20 @@ { "start": 724, "end": 741, - "replacementText": "private readonly r = 20;" + "replacementText": "private readonly r = 20;", + "line": 44, + "column": 70, + "endLine": 44, + "endColumn": 72 }, { "start": 1169, "end": 1171, - "replacementText": "r" + "replacementText": "r", + "line": 44, + "column": 70, + "endLine": 44, + "endColumn": 72 } ], "suggest": "", @@ -508,12 +644,20 @@ { "start": 744, "end": 768, - "replacementText": "private static readonly sr = 0;" + "replacementText": "private static readonly sr = 0;", + "line": 44, + "column": 77, + "endLine": 44, + "endColumn": 80 }, { "start": 1176, "end": 1179, - "replacementText": "sr" + "replacementText": "sr", + "line": 44, + "column": 77, + "endLine": 44, + "endColumn": 80 } ], "suggest": "", @@ -530,12 +674,20 @@ { "start": 771, "end": 801, - "replacementText": "private static readonly srq?: string;" + "replacementText": "private static readonly srq?: string;", + "line": 44, + "column": 85, + "endLine": 44, + "endColumn": 89 }, { "start": 1184, "end": 1188, - "replacementText": "srq" + "replacementText": "srq", + "line": 44, + "column": 85, + "endLine": 44, + "endColumn": 89 } ], "suggest": "", @@ -552,12 +704,20 @@ { "start": 805, "end": 827, - "replacementText": "private m(x: number): void { }" + "replacementText": "private m(x: number): void { }", + "line": 45, + "column": 10, + "endLine": 45, + "endColumn": 12 }, { "start": 1224, "end": 1226, - "replacementText": "m" + "replacementText": "m", + "line": 45, + "column": 10, + "endLine": 45, + "endColumn": 12 } ], "suggest": "", @@ -594,12 +754,20 @@ { "start": 955, "end": 987, - "replacementText": "private get g1(): number { return 10; }" + "replacementText": "private get g1(): number { return 10; }", + "line": 48, + "column": 18, + "endLine": 48, + "endColumn": 21 }, { "start": 1315, "end": 1318, - "replacementText": "g1" + "replacementText": "g1", + "line": 48, + "column": 18, + "endLine": 48, + "endColumn": 21 } ], "suggest": "", @@ -616,12 +784,20 @@ { "start": 990, "end": 1012, - "replacementText": "private set s1(x: number) { }" + "replacementText": "private set s1(x: number) { }", + "line": 49, + "column": 10, + "endLine": 49, + "endColumn": 13 }, { "start": 1329, "end": 1332, - "replacementText": "s1" + "replacementText": "s1", + "line": 49, + "column": 10, + "endLine": 49, + "endColumn": 13 } ], "suggest": "", @@ -638,12 +814,20 @@ { "start": 1016, "end": 1055, - "replacementText": "private static get g2(): number { return 10; }" + "replacementText": "private static get g2(): number { return 10; }", + "line": 50, + "column": 15, + "endLine": 50, + "endColumn": 18 }, { "start": 1352, "end": 1355, - "replacementText": "g2" + "replacementText": "g2", + "line": 50, + "column": 15, + "endLine": 50, + "endColumn": 18 } ], "suggest": "", @@ -660,12 +844,20 @@ { "start": 1058, "end": 1087, - "replacementText": "private static set s2(x: number) { }" + "replacementText": "private static set s2(x: number) { }", + "line": 51, + "column": 7, + "endLine": 51, + "endColumn": 10 }, { "start": 1363, "end": 1366, - "replacementText": "s2" + "replacementText": "s2", + "line": 51, + "column": 7, + "endLine": 51, + "endColumn": 10 } ], "suggest": "", @@ -680,8 +872,7 @@ "problem": "DeclWithDuplicateName", "suggest": "", "rule": "Use unique names for types and namespaces. (arkts-unique-names)", - "severity": "ERROR", - "exclusive": "RT" + "severity": "ERROR" }, { "line": 59, @@ -691,8 +882,7 @@ "problem": "DeclWithDuplicateName", "suggest": "", "rule": "Use unique names for types and namespaces. (arkts-unique-names)", - "severity": "ERROR", - "exclusive": "RT" + "severity": "ERROR" }, { "line": 56, @@ -704,12 +894,20 @@ { "start": 1401, "end": 1412, - "replacementText": "private a: string;" + "replacementText": "private a: string;", + "line": 64, + "column": 32, + "endLine": 64, + "endColumn": 34 }, { "start": 1572, "end": 1574, - "replacementText": "a" + "replacementText": "a", + "line": 64, + "column": 32, + "endLine": 64, + "endColumn": 34 } ], "suggest": "", @@ -746,12 +944,20 @@ { "start": 1494, "end": 1526, - "replacementText": "private bar(): string { return 'baz'; }" + "replacementText": "private bar(): string { return 'baz'; }", + "line": 66, + "column": 18, + "endLine": 66, + "endColumn": 22 }, { "start": 1655, "end": 1659, - "replacementText": "bar" + "replacementText": "bar", + "line": 66, + "column": 18, + "endLine": 66, + "endColumn": 22 } ], "suggest": "", @@ -778,12 +984,20 @@ { "start": 1401, "end": 1412, - "replacementText": "private a: string;" + "replacementText": "private a: string;", + "line": 64, + "column": 32, + "endLine": 64, + "endColumn": 34 }, { "start": 1572, "end": 1574, - "replacementText": "a" + "replacementText": "a", + "line": 64, + "column": 32, + "endLine": 64, + "endColumn": 34 } ], "suggest": "", @@ -810,12 +1024,20 @@ { "start": 1494, "end": 1526, - "replacementText": "private bar(): string { return 'baz'; }" + "replacementText": "private bar(): string { return 'baz'; }", + "line": 66, + "column": 18, + "endLine": 66, + "endColumn": 22 }, { "start": 1655, "end": 1659, - "replacementText": "bar" + "replacementText": "bar", + "line": 66, + "column": 18, + "endLine": 66, + "endColumn": 22 } ], "suggest": "", @@ -830,8 +1052,7 @@ "problem": "DeclWithDuplicateName", "suggest": "", "rule": "Use unique names for types and namespaces. (arkts-unique-names)", - "severity": "ERROR", - "exclusive": "RT" + "severity": "ERROR" }, { "line": 71, @@ -843,7 +1064,11 @@ { "start": 1682, "end": 1693, - "replacementText": "private a: number;" + "replacementText": "private a: number;", + "line": 71, + "column": 3, + "endLine": 71, + "endColumn": 5 } ], "suggest": "", @@ -870,17 +1095,29 @@ { "start": 1726, "end": 1726, - "replacementText": "public b: number;\n" + "replacementText": "public b: number;\n ", + "line": 74, + "column": 15, + "endLine": 74, + "endColumn": 21 }, { "start": 1738, "end": 1754, - "replacementText": "b: number" + "replacementText": "b: number", + "line": 74, + "column": 15, + "endLine": 74, + "endColumn": 21 }, { - "start": 1756, - "end": 1758, - "replacementText": "{\n this.b = b;\n}" + "start": 1757, + "end": 1757, + "replacementText": "\n this.b = b;\n ", + "line": 74, + "column": 15, + "endLine": 74, + "endColumn": 21 } ], "suggest": "", diff --git a/ets2panda/linter/test/main/private_identifiers.ets.migrate.ets b/ets2panda/linter/test/main/private_identifiers.ets.migrate.ets index 001beccf210eebba407f1d00bc14b8846391f25f..2fa0c833d2872e591d671a0e988f5261c59b0794 100644 --- a/ets2panda/linter/test/main/private_identifiers.ets.migrate.ets +++ b/ets2panda/linter/test/main/private_identifiers.ets.migrate.ets @@ -72,7 +72,7 @@ class E { #b: string; // not fixable public b: number; -constructor(b: number) { + constructor(b: number) { this.b = b; -} + } } \ No newline at end of file diff --git a/ets2panda/linter/test/rules/rule25.ets.autofix.json b/ets2panda/linter/test/rules/rule25.ets.autofix.json index b69e79be0be31822b287c2c98c43a490696b1f68..f39859ea120fceddc3a09e5711b137defda78dc3 100644 --- a/ets2panda/linter/test/rules/rule25.ets.autofix.json +++ b/ets2panda/linter/test/rules/rule25.ets.autofix.json @@ -24,27 +24,47 @@ { "start": 624, "end": 624, - "replacementText": "protected ssn: string;\nprivate firstName: string;\nprivate lastName: string;\n" + "replacementText": "protected ssn: string;\n private firstName: string;\n private lastName: string;\n ", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 645, "end": 666, - "replacementText": "ssn: string" + "replacementText": "ssn: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 676, "end": 701, - "replacementText": "firstName: string" + "replacementText": "firstName: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 711, "end": 735, - "replacementText": "lastName: string" + "replacementText": "lastName: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { - "start": 742, - "end": 840, - "replacementText": "{\n this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n}" + "start": 752, + "end": 752, + "replacementText": "this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n ", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 } ], "suggest": "", @@ -61,27 +81,47 @@ { "start": 624, "end": 624, - "replacementText": "protected ssn: string;\nprivate firstName: string;\nprivate lastName: string;\n" + "replacementText": "protected ssn: string;\n private firstName: string;\n private lastName: string;\n ", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 645, "end": 666, - "replacementText": "ssn: string" + "replacementText": "ssn: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 676, "end": 701, - "replacementText": "firstName: string" + "replacementText": "firstName: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 711, "end": 735, - "replacementText": "lastName: string" + "replacementText": "lastName: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { - "start": 742, - "end": 840, - "replacementText": "{\n this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n}" + "start": 752, + "end": 752, + "replacementText": "this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n ", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 } ], "suggest": "", @@ -98,60 +138,52 @@ { "start": 624, "end": 624, - "replacementText": "protected ssn: string;\nprivate firstName: string;\nprivate lastName: string;\n" + "replacementText": "protected ssn: string;\n private firstName: string;\n private lastName: string;\n ", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 645, "end": 666, - "replacementText": "ssn: string" + "replacementText": "ssn: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 676, "end": 701, - "replacementText": "firstName: string" + "replacementText": "firstName: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { "start": 711, "end": 735, - "replacementText": "lastName: string" + "replacementText": "lastName: string", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 }, { - "start": 742, - "end": 840, - "replacementText": "{\n this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n}" + "start": 752, + "end": 752, + "replacementText": "this.ssn = ssn;\n this.firstName = firstName;\n this.lastName = lastName;\n ", + "line": 20, + "column": 9, + "endLine": 20, + "endColumn": 16 } ], "suggest": "", "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", "severity": "ERROR" - }, - { - "line": 49, - "column": 17, - "endLine": 49, - "endColumn": 30, - "problem": "ParameterProperties", - "autofix": [ - { - "start": 1301, - "end": 1301, - "replacementText": "readonly a: A;\n" - }, - { - "start": 1313, - "end": 1326, - "replacementText": "a: A" - }, - { - "start": 1328, - "end": 1353, - "replacementText": "{\n this.a = a;\n this.a = a;\n}" - } - ], - "suggest": "", - "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", - "severity": "ERROR", - "exclusive": "SDK" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/rules/rule25.ets.migrate.ets b/ets2panda/linter/test/rules/rule25.ets.migrate.ets index 51395c45d2fd17fb4b93446dd019fe53e7c5d985..94d37a9bf7c609f1408425ed8a5cefdf0e6eb049 100644 --- a/ets2panda/linter/test/rules/rule25.ets.migrate.ets +++ b/ets2panda/linter/test/rules/rule25.ets.migrate.ets @@ -15,20 +15,20 @@ class Person { protected ssn: string; -private firstName: string; -private lastName: string; -constructor( + private firstName: string; + private lastName: string; + constructor( ssn: string, firstName: string, lastName: string ) { - this.ssn = ssn; - this.firstName = firstName; - this.lastName = lastName; - this.ssn = ssn; - this.firstName = firstName; - this.lastName = lastName; -} + this.ssn = ssn; + this.firstName = firstName; + this.lastName = lastName; + this.ssn = ssn + this.firstName = firstName + this.lastName = lastName + } getFullName(): string { return this.firstName + " " + this.lastName