diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 4caeea6c346d3da2bb85927717fbe2ebeea3288d..60b4c77b1f0341bc065587028a611472806e0dde 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -2166,7 +2166,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const processExpression = (expr: ts.Expression): void => { const symbol = this.tsUtils.trueSymbolAtLocation(expr); if (this.isJsFileSymbol(symbol) || this.isJsFileExpression(expr)) { - this.incrementCounters(expr, FaultID.InterOpImportJsDataCompare); + const autofix = this.autofixer?.fixInteropOperators(expr); + this.incrementCounters(expr, FaultID.InterOpImportJsDataCompare, autofix); } }; @@ -9119,8 +9120,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const processExpression = (expr: ts.Expression): void => { const symbol = this.tsUtils.trueSymbolAtLocation(expr); - if (this.isJsFileSymbol(symbol)) { - this.incrementCounters(expr, FaultID.BinaryOperations); + if (this.isJsFileSymbol(symbol) || this.isJsFileExpression(expr)) { + const autofix = this.autofixer?.fixInteropOperators(expr); + this.incrementCounters(expr, FaultID.BinaryOperations, autofix); } }; diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index dd1918fbf2ed3f7cbc154771a0063d72ebc2a637..dab13bd7d2f1e524d6bb7d8a166ada0b4d5c87db 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -4091,6 +4091,65 @@ export class Autofixer { ]; } + fixInteropOperators(expr: ts.Expression): Autofix[] | undefined { + if (ts.isPropertyAccessExpression(expr)) { + return this.fixPropertyAccessToNumber(expr); + } + + if (ts.isIdentifier(expr)) { + const symbol = this.utils.trueSymbolAtLocation(expr); + + if (this.utils.isJsImport(expr)) { + const toNumberCall = ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(expr, ts.factory.createIdentifier(TO_NUMBER)), + undefined, + [] + ); + + const replacementText = this.printer.printNode(ts.EmitHint.Unspecified, toNumberCall, expr.getSourceFile()); + + return [ + { + start: expr.getStart(), + end: expr.getEnd(), + replacementText + } + ]; + } + + const decl = symbol?.declarations?.find(ts.isVariableDeclaration); + if (decl?.initializer && ts.isPropertyAccessExpression(decl.initializer)) { + return this.fixPropertyAccessToNumber(decl.initializer); + } + } + + return undefined; + } + + private fixPropertyAccessToNumber(expr: ts.PropertyAccessExpression): Autofix[] { + const getPropCall = ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(expr.expression, ts.factory.createIdentifier(GET_PROPERTY_BY_NAME)), + undefined, + [ts.factory.createStringLiteral(expr.name.getText())] + ); + + const toNumberCall = ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(getPropCall, ts.factory.createIdentifier(TO_NUMBER)), + undefined, + [] + ); + + const replacementText = this.printer.printNode(ts.EmitHint.Unspecified, toNumberCall, expr.getSourceFile()); + + return [ + { + start: expr.getStart(), + end: expr.getEnd(), + replacementText + } + ]; + } + fixInteropArrayElementAccessExpression(express: ts.ElementAccessExpression): Autofix[] | undefined { const statements = ts.factory.createCallExpression( ts.factory.createPropertyAccessExpression(express.expression, ts.factory.createIdentifier(GET_PROPERTY_BY_INDEX)), diff --git a/ets2panda/linter/test/interop/binary_operation_js_obj.ets b/ets2panda/linter/test/interop/binary_operation_js_obj.ets index 44c53b80123ab33e89b506e175985c40428d14f0..472ad5669d75bba44ac209e2e148c3b4570a1a0e 100644 --- a/ets2panda/linter/test/interop/binary_operation_js_obj.ets +++ b/ets2panda/linter/test/interop/binary_operation_js_obj.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {foo} from "./binary_operation_js_obj_js" +import {foo,m,n} from "./binary_operation_js_obj_js" let a = foo.a let b = foo.b a + b @@ -20,4 +20,24 @@ a - b a * b a / b a % b -a ** b \ No newline at end of file +a ** b + +m + n +m % n +m ** n + +let x = 1, y = 2; +x + y; +x - y; +x % y; +x ** y; + +let bar = { a: 1, b: 2 }; + +let x2 = bar.a, y2 = bar.b; +x2 + y2; +x2 - y2; +x2 % y2; +x2 ** y2; + +foo.a + foo.b; \ No newline at end of file diff --git a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.arkts2.json b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.arkts2.json index e7eb94f512fe570331dcc2d0e6897415c8f2edb3..88784c2392e997667f1905cc123a601a9c260d2f 100644 --- a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.arkts2.json +++ b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.arkts2.json @@ -18,7 +18,7 @@ "line": 15, "column": 1, "endLine": 15, - "endColumn": 49, + "endColumn": 53, "problem": "InterOpImportJs", "suggest": "", "rule": "Importing directly from \"JS\" module is not supported (arkts-interop-js2s-import-js)", @@ -173,6 +173,206 @@ "suggest": "", "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", "severity": "ERROR" + }, + { + "line": 25, + "column": 1, + "endLine": 25, + "endColumn": 2, + "problem": "BinaryOperations", + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 5, + "endLine": 25, + "endColumn": 6, + "problem": "BinaryOperations", + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 1, + "endLine": 26, + "endColumn": 2, + "problem": "BinaryOperations", + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 5, + "endLine": 26, + "endColumn": 6, + "problem": "BinaryOperations", + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 1, + "endLine": 27, + "endColumn": 2, + "problem": "BinaryOperations", + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 6, + "endLine": 27, + "endColumn": 7, + "problem": "BinaryOperations", + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 3, + "endLine": 27, + "endColumn": 5, + "problem": "ExponentOp", + "suggest": "", + "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 5, + "endLine": 29, + "endColumn": 10, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 9, + "endLine": 29, + "endColumn": 10, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 12, + "endLine": 29, + "endColumn": 17, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 16, + "endLine": 29, + "endColumn": 17, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 3, + "endLine": 33, + "endColumn": 5, + "problem": "ExponentOp", + "suggest": "", + "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 11, + "endLine": 35, + "endColumn": 12, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 16, + "endLine": 35, + "endColumn": 17, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 22, + "endLine": 35, + "endColumn": 23, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 5, + "endLine": 37, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 17, + "endLine": 37, + "endColumn": 27, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 4, + "endLine": 41, + "endColumn": 6, + "problem": "ExponentOp", + "suggest": "", + "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 1, + "endLine": 43, + "endColumn": 6, + "problem": "BinaryOperations", + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 9, + "endLine": 43, + "endColumn": 14, + "problem": "BinaryOperations", + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.autofix.json b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.autofix.json index b67555d47569f24b1097dcdaf9800786be3e5683..02657b315262d64811922b09efbc6f62fb2f933a 100644 --- a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.autofix.json +++ b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.autofix.json @@ -13,31 +13,31 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [ +"result": [ { "line": 15, "column": 1, "endLine": 15, - "endColumn": 49, + "endColumn": 53, "problem": "InterOpImportJs", "autofix": [ { "start": 604, - "end": 652, + "end": 656, "replacementText": "", "line": 15, "column": 1, "endLine": 15, - "endColumn": 49 + "endColumn": 53 }, { - "start": 652, - "end": 652, - "replacementText": "let GeneratedImportVar_1 = ESValue.load('./binary_operation_js_obj_js');\nlet foo = GeneratedImportVar_1.getPropertyByName('foo');\n", + "start": 656, + "end": 656, + "replacementText": "let GeneratedImportVar_1 = ESValue.load('./binary_operation_js_obj_js');\nlet foo = GeneratedImportVar_1.getPropertyByName('foo');\nlet m = GeneratedImportVar_1.getPropertyByName('m');\nlet n = GeneratedImportVar_1.getPropertyByName('n');\n", "line": 15, "column": 1, "endLine": 15, - "endColumn": 49 + "endColumn": 53 } ], "suggest": "", @@ -52,8 +52,8 @@ "problem": "InteropObjectProperty", "autofix": [ { - "start": 661, - "end": 666, + "start": 665, + "end": 670, "replacementText": "foo.getPropertyByName(\"a\")", "line": 16, "column": 9, @@ -73,8 +73,8 @@ "problem": "InteropObjectProperty", "autofix": [ { - "start": 675, - "end": 680, + "start": 679, + "end": 684, "replacementText": "foo.getPropertyByName(\"b\")", "line": 17, "column": 9, @@ -92,6 +92,17 @@ "endLine": 18, "endColumn": 2, "problem": "BinaryOperations", + "autofix": [ + { + "start": 665, + "end": 670, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 18, + "column": 1, + "endLine": 18, + "endColumn": 2 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -102,6 +113,17 @@ "endLine": 18, "endColumn": 6, "problem": "BinaryOperations", + "autofix": [ + { + "start": 679, + "end": 684, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 18, + "column": 5, + "endLine": 18, + "endColumn": 6 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -112,6 +134,17 @@ "endLine": 19, "endColumn": 2, "problem": "BinaryOperations", + "autofix": [ + { + "start": 665, + "end": 670, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 2 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -122,6 +155,17 @@ "endLine": 19, "endColumn": 6, "problem": "BinaryOperations", + "autofix": [ + { + "start": 679, + "end": 684, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 19, + "column": 5, + "endLine": 19, + "endColumn": 6 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -132,6 +176,17 @@ "endLine": 20, "endColumn": 2, "problem": "BinaryOperations", + "autofix": [ + { + "start": 665, + "end": 670, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 2 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -142,6 +197,17 @@ "endLine": 20, "endColumn": 6, "problem": "BinaryOperations", + "autofix": [ + { + "start": 679, + "end": 684, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 20, + "column": 5, + "endLine": 20, + "endColumn": 6 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -152,6 +218,17 @@ "endLine": 21, "endColumn": 2, "problem": "BinaryOperations", + "autofix": [ + { + "start": 665, + "end": 670, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 21, + "column": 1, + "endLine": 21, + "endColumn": 2 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -162,6 +239,17 @@ "endLine": 21, "endColumn": 6, "problem": "BinaryOperations", + "autofix": [ + { + "start": 679, + "end": 684, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 21, + "column": 5, + "endLine": 21, + "endColumn": 6 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -172,6 +260,17 @@ "endLine": 22, "endColumn": 2, "problem": "BinaryOperations", + "autofix": [ + { + "start": 665, + "end": 670, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 22, + "column": 1, + "endLine": 22, + "endColumn": 2 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -182,6 +281,17 @@ "endLine": 22, "endColumn": 6, "problem": "BinaryOperations", + "autofix": [ + { + "start": 679, + "end": 684, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 22, + "column": 5, + "endLine": 22, + "endColumn": 6 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -192,6 +302,17 @@ "endLine": 23, "endColumn": 2, "problem": "BinaryOperations", + "autofix": [ + { + "start": 665, + "end": 670, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 23, + "column": 1, + "endLine": 23, + "endColumn": 2 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -202,6 +323,17 @@ "endLine": 23, "endColumn": 7, "problem": "BinaryOperations", + "autofix": [ + { + "start": 679, + "end": 684, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 23, + "column": 6, + "endLine": 23, + "endColumn": 7 + } + ], "suggest": "", "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", "severity": "ERROR" @@ -215,8 +347,8 @@ "autofix": [ { "replacementText": "Math.pow(a, b)", - "start": 711, - "end": 717, + "start": 715, + "end": 721, "line": 23, "column": 3, "endLine": 23, @@ -226,6 +358,435 @@ "suggest": "", "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", "severity": "ERROR" + }, + { + "line": 25, + "column": 1, + "endLine": 25, + "endColumn": 2, + "problem": "BinaryOperations", + "autofix": [ + { + "start": 723, + "end": 724, + "replacementText": "m.toNumber()", + "line": 25, + "column": 1, + "endLine": 25, + "endColumn": 2 + } + ], + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 5, + "endLine": 25, + "endColumn": 6, + "problem": "BinaryOperations", + "autofix": [ + { + "start": 727, + "end": 728, + "replacementText": "n.toNumber()", + "line": 25, + "column": 5, + "endLine": 25, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 1, + "endLine": 26, + "endColumn": 2, + "problem": "BinaryOperations", + "autofix": [ + { + "start": 729, + "end": 730, + "replacementText": "m.toNumber()", + "line": 26, + "column": 1, + "endLine": 26, + "endColumn": 2 + } + ], + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 5, + "endLine": 26, + "endColumn": 6, + "problem": "BinaryOperations", + "autofix": [ + { + "start": 733, + "end": 734, + "replacementText": "n.toNumber()", + "line": 26, + "column": 5, + "endLine": 26, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 1, + "endLine": 27, + "endColumn": 2, + "problem": "BinaryOperations", + "autofix": [ + { + "start": 735, + "end": 736, + "replacementText": "m.toNumber()", + "line": 27, + "column": 1, + "endLine": 27, + "endColumn": 2 + } + ], + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 6, + "endLine": 27, + "endColumn": 7, + "problem": "BinaryOperations", + "autofix": [ + { + "start": 740, + "end": 741, + "replacementText": "n.toNumber()", + "line": 27, + "column": 6, + "endLine": 27, + "endColumn": 7 + } + ], + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 3, + "endLine": 27, + "endColumn": 5, + "problem": "ExponentOp", + "autofix": [ + { + "replacementText": "Math.pow(m, n)", + "start": 735, + "end": 741, + "line": 27, + "column": 3, + "endLine": 27, + "endColumn": 5 + } + ], + "suggest": "", + "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 5, + "endLine": 29, + "endColumn": 10, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 747, + "end": 752, + "replacementText": "x: number = 1", + "line": 29, + "column": 5, + "endLine": 29, + "endColumn": 10 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 9, + "endLine": 29, + "endColumn": 10, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 751, + "end": 752, + "replacementText": "1.0", + "line": 29, + "column": 9, + "endLine": 29, + "endColumn": 10 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 12, + "endLine": 29, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 754, + "end": 759, + "replacementText": "y: number = 2", + "line": 29, + "column": 12, + "endLine": 29, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 16, + "endLine": 29, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 758, + "end": 759, + "replacementText": "2.0", + "line": 29, + "column": 16, + "endLine": 29, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 3, + "endLine": 33, + "endColumn": 5, + "problem": "ExponentOp", + "autofix": [ + { + "replacementText": "Math.pow(x, y)", + "start": 782, + "end": 788, + "line": 33, + "column": 3, + "endLine": 33, + "endColumn": 5 + } + ], + "suggest": "", + "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 11, + "endLine": 35, + "endColumn": 12, + "problem": "ObjectLiteralNoContextType", + "autofix": [ + { + "start": 791, + "end": 791, + "replacementText": "interface GeneratedObjectLiteralInterface_1 {\n a: number;\n b: number;\n}\n", + "line": 35, + "column": 11, + "endLine": 35, + "endColumn": 12 + }, + { + "start": 798, + "end": 798, + "replacementText": ": GeneratedObjectLiteralInterface_1", + "line": 35, + "column": 11, + "endLine": 35, + "endColumn": 12 + } + ], + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 16, + "endLine": 35, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 806, + "end": 807, + "replacementText": "1.0", + "line": 35, + "column": 16, + "endLine": 35, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 22, + "endLine": 35, + "endColumn": 23, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 812, + "end": 813, + "replacementText": "2.0", + "line": 35, + "column": 22, + "endLine": 35, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 5, + "endLine": 37, + "endColumn": 15, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 822, + "end": 832, + "replacementText": "x2: number = bar.a", + "line": 37, + "column": 5, + "endLine": 37, + "endColumn": 15 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 17, + "endLine": 37, + "endColumn": 27, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 834, + "end": 844, + "replacementText": "y2: number = bar.b", + "line": 37, + "column": 17, + "endLine": 37, + "endColumn": 27 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 4, + "endLine": 41, + "endColumn": 6, + "problem": "ExponentOp", + "autofix": [ + { + "replacementText": "Math.pow(x2, y2)", + "start": 873, + "end": 881, + "line": 41, + "column": 4, + "endLine": 41, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "exponent opartions \"**\" and \"**=\" are disabled (arkts-no-exponent-op)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 1, + "endLine": 43, + "endColumn": 6, + "problem": "BinaryOperations", + "autofix": [ + { + "start": 884, + "end": 889, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 43, + "column": 1, + "endLine": 43, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 9, + "endLine": 43, + "endColumn": 14, + "problem": "BinaryOperations", + "autofix": [ + { + "start": 892, + "end": 897, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 43, + "column": 9, + "endLine": 43, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Binary operations on js objects (arkts-interop-js2s-binary-op)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.json b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.json index ca88f857e960b437dcf767c0ac40be998c8f1236..e28baca176a2b17f328386775efec64717650b4b 100755 --- a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.json +++ b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.json @@ -13,5 +13,16 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [] + "result": [ + { + "line": 35, + "column": 11, + "endLine": 35, + "endColumn": 12, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + } + ] } \ No newline at end of file diff --git a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.migrate.ets b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.migrate.ets index 83e761ce7f324d71a40e25cf3bd1afca94a647c7..f29b91c27508799b1f7054d1ab2b622b82fe51cd 100644 --- a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.migrate.ets +++ b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.migrate.ets @@ -14,6 +14,8 @@ */ let GeneratedImportVar_1 = ESValue.load('./binary_operation_js_obj_js'); let foo = GeneratedImportVar_1.getPropertyByName('foo'); +let m = GeneratedImportVar_1.getPropertyByName('m'); +let n = GeneratedImportVar_1.getPropertyByName('n'); let a = foo.getPropertyByName("a") let b = foo.getPropertyByName("b") @@ -22,4 +24,28 @@ a - b a * b a / b a % b -Math.pow(a, b) \ No newline at end of file +Math.pow(a, b) + +m.toNumber() + n.toNumber() +m.toNumber() % n.toNumber() +Math.pow(m.toNumber(), n.toNumber()) + +let x: number = 1.0, y: number = 2.0; +x + y; +x - y; +x % y; +Math.pow(x, y); + +interface GeneratedObjectLiteralInterface_1 { + a: number; + b: number; +} +let bar: GeneratedObjectLiteralInterface_1 = { a: 1.0, b: 2.0 }; + +let x2: number = bar.a, y2: number = bar.b; +x2 + y2; +x2 - y2; +x2 % y2; +Math.pow(x2, y2); + +foo.getPropertyByName("a").toNumber() + foo.getPropertyByName("b").toNumber(); \ No newline at end of file diff --git a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.migrate.json b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.migrate.json index bf73aefbeb59779629eb972c93a678f72c4e7a49..817c2a94501ff9e7c7d318f8d8bacf6f388092a8 100644 --- a/ets2panda/linter/test/interop/binary_operation_js_obj.ets.migrate.json +++ b/ets2panda/linter/test/interop/binary_operation_js_obj.ets.migrate.json @@ -34,10 +34,30 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 17, + "column": 5, + "endLine": 17, + "endColumn": 52, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, { "line": 18, "column": 5, "endLine": 18, + "endColumn": 52, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 5, + "endLine": 20, "endColumn": 35, "problem": "AnyType", "suggest": "", @@ -45,9 +65,9 @@ "severity": "ERROR" }, { - "line": 19, + "line": 21, "column": 5, - "endLine": 19, + "endLine": 21, "endColumn": 35, "problem": "AnyType", "suggest": "", @@ -55,14 +75,44 @@ "severity": "ERROR" }, { - "line": 25, + "line": 27, + "column": 1, + "endLine": 27, + "endColumn": 15, + "problem": "MathPow", + "suggest": "", + "rule": "function \"Math.pow()\" behavior for ArkTS differs from Typescript version (arkts-math-pow-standard-diff)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 1, + "endLine": 31, + "endColumn": 37, + "problem": "MathPow", + "suggest": "", + "rule": "function \"Math.pow()\" behavior for ArkTS differs from Typescript version (arkts-math-pow-standard-diff)", + "severity": "ERROR" + }, + { + "line": 37, "column": 1, - "endLine": 25, + "endLine": 37, "endColumn": 15, "problem": "MathPow", "suggest": "", "rule": "function \"Math.pow()\" behavior for ArkTS differs from Typescript version (arkts-math-pow-standard-diff)", "severity": "ERROR" + }, + { + "line": 49, + "column": 1, + "endLine": 49, + "endColumn": 17, + "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 diff --git a/ets2panda/linter/test/interop/binary_operation_js_obj_js.js b/ets2panda/linter/test/interop/binary_operation_js_obj_js.js index aaf9c1dd4e9e4e7e46d0cf3efb92bb573817fde8..c8f9951bdacb9a6fd47ef3704d312293cb78ffd4 100755 --- a/ets2panda/linter/test/interop/binary_operation_js_obj_js.js +++ b/ets2panda/linter/test/interop/binary_operation_js_obj_js.js @@ -14,3 +14,5 @@ */ export let foo = {a: 1, b: 2} +export let m = 3 +export let n = 2 \ No newline at end of file diff --git a/ets2panda/linter/test/interop/interop_import_js_compare.ets.args.json b/ets2panda/linter/test/interop/interop_import_js_compare.ets.args.json index e2b903f0aa82e6ca4108ff67d5272bf49d6c2a5b..571ee6bb76b0cad72a9443db47c2f9d7db474bd0 100644 --- a/ets2panda/linter/test/interop/interop_import_js_compare.ets.args.json +++ b/ets2panda/linter/test/interop/interop_import_js_compare.ets.args.json @@ -1,5 +1,5 @@ { - "copyright": [ + "copyright": [ "Copyright (c) 2025 Huawei Device Co., Ltd.", "Licensed under the Apache License, Version 2.0 (the 'License');", "you may not use this file except in compliance with the License.", @@ -12,8 +12,10 @@ "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", "See the License for the specific language governing permissions and", "limitations under the License." - ], - "mode": { - "arkts2": "" - } - } \ No newline at end of file + ], + "mode": { + "arkts2": "", + "autofix": "--arkts-2", + "migrate": "--arkts-2" + } +} diff --git a/ets2panda/linter/test/interop/interop_import_js_compare.ets.autofix.json b/ets2panda/linter/test/interop/interop_import_js_compare.ets.autofix.json new file mode 100644 index 0000000000000000000000000000000000000000..8b8b4fe079c2d73f6205158b607ca2de110deb0d --- /dev/null +++ b/ets2panda/linter/test/interop/interop_import_js_compare.ets.autofix.json @@ -0,0 +1,582 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 57, + "problem": "InterOpImportJs", + "autofix": [ + { + "start": 607, + "end": 663, + "replacementText": "", + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 57 + }, + { + "start": 663, + "end": 663, + "replacementText": "let GeneratedImportVar_1 = ESValue.load('./interop_import_js_compare_js');\nlet foo = GeneratedImportVar_1.getPropertyByName('foo');\nlet m = GeneratedImportVar_1.getPropertyByName('m');\nlet n = GeneratedImportVar_1.getPropertyByName('n');\n", + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 57 + } + ], + "suggest": "", + "rule": "Importing directly from \"JS\" module is not supported (arkts-interop-js2s-import-js)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 9, + "endLine": 18, + "endColumn": 14, + "problem": "InteropObjectProperty", + "autofix": [ + { + "start": 672, + "end": 677, + "replacementText": "foo.getPropertyByName(\"a\")", + "line": 18, + "column": 9, + "endLine": 18, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Properties of interop objects can't be accessed directly (arkts-interop-js2s-access-js-prop)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 9, + "endLine": 19, + "endColumn": 14, + "problem": "InteropObjectProperty", + "autofix": [ + { + "start": 686, + "end": 691, + "replacementText": "foo.getPropertyByName(\"b\")", + "line": 19, + "column": 9, + "endLine": 19, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Properties of interop objects can't be accessed directly (arkts-interop-js2s-access-js-prop)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 2, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 672, + "end": 677, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 2 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 5, + "endLine": 20, + "endColumn": 6, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 686, + "end": 691, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 20, + "column": 5, + "endLine": 20, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 1, + "endLine": 21, + "endColumn": 2, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 672, + "end": 677, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 21, + "column": 1, + "endLine": 21, + "endColumn": 2 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 5, + "endLine": 21, + "endColumn": 6, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 686, + "end": 691, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 21, + "column": 5, + "endLine": 21, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 1, + "endLine": 22, + "endColumn": 2, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 672, + "end": 677, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 22, + "column": 1, + "endLine": 22, + "endColumn": 2 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 6, + "endLine": 22, + "endColumn": 7, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 686, + "end": 691, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 22, + "column": 6, + "endLine": 22, + "endColumn": 7 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 1, + "endLine": 23, + "endColumn": 2, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 672, + "end": 677, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 23, + "column": 1, + "endLine": 23, + "endColumn": 2 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 6, + "endLine": 23, + "endColumn": 7, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 686, + "end": 691, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 23, + "column": 6, + "endLine": 23, + "endColumn": 7 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 5, + "endLine": 24, + "endColumn": 6, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 722, + "end": 723, + "replacementText": "1.0", + "line": 24, + "column": 5, + "endLine": 24, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 1, + "endLine": 26, + "endColumn": 2, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 725, + "end": 726, + "replacementText": "m.toNumber()", + "line": 26, + "column": 1, + "endLine": 26, + "endColumn": 2 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 5, + "endLine": 26, + "endColumn": 6, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 729, + "end": 730, + "replacementText": "n.toNumber()", + "line": 26, + "column": 5, + "endLine": 26, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 5, + "endLine": 27, + "endColumn": 6, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 735, + "end": 736, + "replacementText": "1.0", + "line": 27, + "column": 5, + "endLine": 27, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 5, + "endLine": 29, + "endColumn": 10, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 742, + "end": 747, + "replacementText": "x: number = 1", + "line": 29, + "column": 5, + "endLine": 29, + "endColumn": 10 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 9, + "endLine": 29, + "endColumn": 10, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 746, + "end": 747, + "replacementText": "1.0", + "line": 29, + "column": 9, + "endLine": 29, + "endColumn": 10 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 12, + "endLine": 29, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 749, + "end": 754, + "replacementText": "y: number = 2", + "line": 29, + "column": 12, + "endLine": 29, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 16, + "endLine": 29, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 753, + "end": 754, + "replacementText": "2.0", + "line": 29, + "column": 16, + "endLine": 29, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 11, + "endLine": 35, + "endColumn": 12, + "problem": "ObjectLiteralNoContextType", + "autofix": [ + { + "start": 787, + "end": 787, + "replacementText": "interface GeneratedObjectLiteralInterface_1 {\n a: number;\n b: number;\n}\n", + "line": 35, + "column": 11, + "endLine": 35, + "endColumn": 12 + }, + { + "start": 794, + "end": 794, + "replacementText": ": GeneratedObjectLiteralInterface_1", + "line": 35, + "column": 11, + "endLine": 35, + "endColumn": 12 + } + ], + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 16, + "endLine": 35, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 802, + "end": 803, + "replacementText": "1.0", + "line": 35, + "column": 16, + "endLine": 35, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 22, + "endLine": 35, + "endColumn": 23, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 808, + "end": 809, + "replacementText": "2.0", + "line": 35, + "column": 22, + "endLine": 35, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 5, + "endLine": 37, + "endColumn": 15, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 818, + "end": 828, + "replacementText": "x2: number = bar.a", + "line": 37, + "column": 5, + "endLine": 37, + "endColumn": 15 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 17, + "endLine": 37, + "endColumn": 27, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 830, + "end": 840, + "replacementText": "y2: number = bar.b", + "line": 37, + "column": 17, + "endLine": 37, + "endColumn": 27 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 1, + "endLine": 43, + "endColumn": 6, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 881, + "end": 886, + "replacementText": "foo.getPropertyByName(\"a\").toNumber()", + "line": 43, + "column": 1, + "endLine": 43, + "endColumn": 6 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 9, + "endLine": 43, + "endColumn": 14, + "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 889, + "end": 894, + "replacementText": "foo.getPropertyByName(\"b\").toNumber()", + "line": 43, + "column": 9, + "endLine": 43, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/interop_import_js_compare.ets.migrate.ets b/ets2panda/linter/test/interop/interop_import_js_compare.ets.migrate.ets new file mode 100644 index 0000000000000000000000000000000000000000..76633c942c13423af8c35e3e8fc2b0ff3cf00257 --- /dev/null +++ b/ets2panda/linter/test/interop/interop_import_js_compare.ets.migrate.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +let GeneratedImportVar_1 = ESValue.load('./interop_import_js_compare_js'); +let foo = GeneratedImportVar_1.getPropertyByName('foo'); +let m = GeneratedImportVar_1.getPropertyByName('m'); +let n = GeneratedImportVar_1.getPropertyByName('n'); + +let a = foo.getPropertyByName("a") +let b = foo.getPropertyByName("b") +a > b +a < b +a >= b +a <= b +a = 1.0 + +m.toNumber() > n.toNumber() +m = 1.0 + +let x: number = 1.0, y: number = 2.0; +x > y; +x < y; +x >= y; +x <= y; + +interface GeneratedObjectLiteralInterface_1 { + a: number; + b: number; +} +let bar: GeneratedObjectLiteralInterface_1 = { a: 1.0, b: 2.0 }; + +let x2: number = bar.a, y2: number = bar.b; +x2 > y2; +x2 < y2; +x2 >= y2; +x2 <= y2; + +foo.getPropertyByName("a").toNumber() > foo.getPropertyByName("b").toNumber(); \ No newline at end of file diff --git a/ets2panda/linter/test/interop/interop_import_js_compare.ets.migrate.json b/ets2panda/linter/test/interop/interop_import_js_compare.ets.migrate.json new file mode 100644 index 0000000000000000000000000000000000000000..0ccdec1005fc3e20d0bdcd40db886bc6f12e3e3a --- /dev/null +++ b/ets2panda/linter/test/interop/interop_import_js_compare.ets.migrate.json @@ -0,0 +1,78 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 17, + "column": 5, + "endLine": 17, + "endColumn": 74, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 5, + "endLine": 18, + "endColumn": 56, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 5, + "endLine": 19, + "endColumn": 52, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 5, + "endLine": 20, + "endColumn": 52, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 5, + "endLine": 22, + "endColumn": 35, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 5, + "endLine": 23, + "endColumn": 35, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/interop_import_js_rules.ets.autofix.json b/ets2panda/linter/test/interop/interop_import_js_rules.ets.autofix.json index c7bff146b9dde4209c57f945f9d86dc001f28d69..f2721cbefe1fb33e295a058301113c62fd56977e 100644 --- a/ets2panda/linter/test/interop/interop_import_js_rules.ets.autofix.json +++ b/ets2panda/linter/test/interop/interop_import_js_rules.ets.autofix.json @@ -401,6 +401,17 @@ "endLine": 34, "endColumn": 11, "problem": "InterOpImportJsDataCompare", + "autofix": [ + { + "start": 1118, + "end": 1124, + "replacementText": "ff1.getPropertyByName(\"f1\").toNumber()", + "line": 34, + "column": 5, + "endLine": 34, + "endColumn": 11 + } + ], "suggest": "", "rule": "Importing data directly from the \"JS\" module for comparison is not supported (arkts-interop-js2s-compare-js-data)", "severity": "ERROR"