diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 8fec7929155ac0f77718d1d8be18ce7ddb29172c..c16bc57dab826132a090da4ab96c578c978de8e7 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -2757,15 +2757,12 @@ export class Autofixer { fixExponent(exponentNode: ts.Node): Autofix[] | undefined { let autofix: Autofix[] = []; let replaceText: Autofix = { replacementText: '', start: 0, end: 0 }; - - // ts.BinaryExpression let callArgs: ts.Expression[] | undefined; if (exponentNode.kind === ts.SyntaxKind.CallExpression) { callArgs = [...(exponentNode as ts.CallExpression).arguments]; } else if (exponentNode.kind === ts.SyntaxKind.BinaryExpression) { callArgs = [(exponentNode as ts.BinaryExpression).left, (exponentNode as ts.BinaryExpression).right]; } else { - // if we get here - it was an error! return undefined; } @@ -2784,13 +2781,21 @@ export class Autofixer { ) { const newAssignment = ts.factory.createAssignment((exponentNode as ts.BinaryExpression).left, newCall); replaceText = { - replacementText: this.printer.printNode(ts.EmitHint.Unspecified, newAssignment, exponentNode.getSourceFile()), + replacementText: this.nonCommentPrinter.printNode( + ts.EmitHint.Unspecified, + newAssignment, + exponentNode.getSourceFile() + ), start: exponentNode.getStart(), end: exponentNode.getEnd() }; } else { replaceText = { - replacementText: this.printer.printNode(ts.EmitHint.Unspecified, newCall, exponentNode.getSourceFile()), + replacementText: this.nonCommentPrinter.printNode( + ts.EmitHint.Unspecified, + newCall, + exponentNode.getSourceFile() + ), start: exponentNode.getStart(), end: exponentNode.getEnd() }; diff --git a/ets2panda/linter/test/main/comment_test.ets b/ets2panda/linter/test/main/comment_test.ets index 3731be6780b463c034d4600620956d2c92f5d13b..c2daf91be2c17e58f44e94d2d5b6c61dfb399668 100644 --- a/ets2panda/linter/test/main/comment_test.ets +++ b/ets2panda/linter/test/main/comment_test.ets @@ -21,3 +21,7 @@ class TestClass { // This is a comment. arr = [1, 0]; // This is a comment. } + +function fun(): number { + return 2 ** 5 // This is a comment. +} diff --git a/ets2panda/linter/test/main/comment_test.ets.arkts2.json b/ets2panda/linter/test/main/comment_test.ets.arkts2.json index 9f305c86d7ff705098b1e480818e125d5e6e3a4a..8fc563efed6f817c62a070de14c341bb526266ef 100644 --- a/ets2panda/linter/test/main/comment_test.ets.arkts2.json +++ b/ets2panda/linter/test/main/comment_test.ets.arkts2.json @@ -13,5 +13,16 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [] -} + "result": [ + { + "line": 26, + "column": 14, + "endLine": 26, + "endColumn": 16, + "problem": "ExponentOp", + "suggest": "", + "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/comment_test.ets.autofix.json b/ets2panda/linter/test/main/comment_test.ets.autofix.json index ca88f857e960b437dcf767c0ac40be998c8f1236..be4515ce337569028c57752e535981e502618d2b 100644 --- a/ets2panda/linter/test/main/comment_test.ets.autofix.json +++ b/ets2panda/linter/test/main/comment_test.ets.autofix.json @@ -13,5 +13,27 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [] + "result": [ + { + "line": 26, + "column": 14, + "endLine": 26, + "endColumn": 16, + "problem": "ExponentOp", + "autofix": [ + { + "replacementText": "Math.pow(2, 5)", + "start": 812, + "end": 818, + "line": 26, + "column": 14, + "endLine": 26, + "endColumn": 16 + } + ], + "suggest": "", + "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", + "severity": "ERROR" + } + ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/comment_test.ets.migrate.ets b/ets2panda/linter/test/main/comment_test.ets.migrate.ets index 3731be6780b463c034d4600620956d2c92f5d13b..580b08a736c3a73414231ef8faa9231369f2c5c1 100644 --- a/ets2panda/linter/test/main/comment_test.ets.migrate.ets +++ b/ets2panda/linter/test/main/comment_test.ets.migrate.ets @@ -21,3 +21,7 @@ class TestClass { // This is a comment. arr = [1, 0]; // This is a comment. } + +function fun(): number { + return Math.pow(2, 5) // This is a comment. +} diff --git a/ets2panda/linter/test/main/comment_test.ets.migrate.json b/ets2panda/linter/test/main/comment_test.ets.migrate.json index ca88f857e960b437dcf767c0ac40be998c8f1236..ea7862b453b6bdffcdd6b82356adbd5653b5cffe 100644 --- a/ets2panda/linter/test/main/comment_test.ets.migrate.json +++ b/ets2panda/linter/test/main/comment_test.ets.migrate.json @@ -13,5 +13,16 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [] + "result": [ + { + "line": 26, + "column": 12, + "endLine": 26, + "endColumn": 26, + "problem": "MathPow", + "suggest": "", + "rule": "function \"Math.pow()\" behavior for ArkTS differs from Typescript version (arkts-math-pow-standard-diff)", + "severity": "ERROR" + } + ] } \ No newline at end of file