From 975fe434b7997d6883d8c46734e06523aea4f259 Mon Sep 17 00:00:00 2001 From: beratagaca_9a91 Date: Tue, 3 Jun 2025 11:14:11 +0300 Subject: [PATCH] unary operation Autofix Description: autofix for unary operation usage Issue: #ICB8I1 Signed-off-by: beratagaca_9a91 --- .../test/interop/unary_operation_js_obj.ets | 20 +++ .../unary_operation_js_obj.ets.args.json | 21 +++ .../unary_operation_js_obj.ets.arkts2.json | 54 +++++++ .../unary_operation_js_obj.ets.autofix.json | 132 ++++++++++++++++++ .../interop/unary_operation_js_obj.ets.json | 3 + .../unary_operation_js_obj.ets.migrate.ets | 22 +++ .../unary_operation_js_obj.ets.migrate.json | 68 +++++++++ .../test/interop/unary_operation_js_obj_js.js | 16 +++ 8 files changed, 336 insertions(+) create mode 100644 ets2panda/linter/test/interop/unary_operation_js_obj.ets create mode 100644 ets2panda/linter/test/interop/unary_operation_js_obj.ets.args.json create mode 100644 ets2panda/linter/test/interop/unary_operation_js_obj.ets.arkts2.json create mode 100644 ets2panda/linter/test/interop/unary_operation_js_obj.ets.autofix.json create mode 100644 ets2panda/linter/test/interop/unary_operation_js_obj.ets.json create mode 100644 ets2panda/linter/test/interop/unary_operation_js_obj.ets.migrate.ets create mode 100644 ets2panda/linter/test/interop/unary_operation_js_obj.ets.migrate.json create mode 100644 ets2panda/linter/test/interop/unary_operation_js_obj_js.js diff --git a/ets2panda/linter/test/interop/unary_operation_js_obj.ets b/ets2panda/linter/test/interop/unary_operation_js_obj.ets new file mode 100644 index 0000000000..a6d66fee06 --- /dev/null +++ b/ets2panda/linter/test/interop/unary_operation_js_obj.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ +import {foo} from "./unary_operation_js_obj_js.js" + ++foo.num; +-foo.num; +!foo.num; +~foo.num; \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unary_operation_js_obj.ets.args.json b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.args.json new file mode 100644 index 0000000000..a89d885810 --- /dev/null +++ b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.args.json @@ -0,0 +1,21 @@ +{ + "copyright": [ + "Copyright (c) 2024-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." + ], + "mode": { + "arkts2": "", + "autofix": "--arkts-2", + "migrate": "--arkts-2" + } +} diff --git a/ets2panda/linter/test/interop/unary_operation_js_obj.ets.arkts2.json b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.arkts2.json new file mode 100644 index 0000000000..c935900b7d --- /dev/null +++ b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.arkts2.json @@ -0,0 +1,54 @@ +{ + "result": [ + { + "line": 15, + "column": 1, + "endLine": 15, + "endColumn": 51, + "problem": "InterOpImportJs", + "suggest": "", + "rule": "Importing directly from \"JS\" module is not supported (arkts-interop-js2s-import-js)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 9, + "problem": "InteropNoHaveNum", + "suggest": "", + "rule": "Interop object does not have property num (arkts-interop-js2s-unary-op)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 1, + "endLine": 18, + "endColumn": 9, + "problem": "InteropNoHaveNum", + "suggest": "", + "rule": "Interop object does not have property num (arkts-interop-js2s-unary-op)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 9, + "problem": "InteropNoHaveNum", + "suggest": "", + "rule": "Interop object does not have property num (arkts-interop-js2s-unary-op)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 9, + "problem": "InteropNoHaveNum", + "suggest": "", + "rule": "Interop object does not have property num (arkts-interop-js2s-unary-op)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unary_operation_js_obj.ets.autofix.json b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.autofix.json new file mode 100644 index 0000000000..f9cba0c863 --- /dev/null +++ b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.autofix.json @@ -0,0 +1,132 @@ +{ + "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": 15, + "column": 1, + "endLine": 15, + "endColumn": 51, + "problem": "InterOpImportJs", + "autofix": [ + { + "start": 604, + "end": 654, + "replacementText": "", + "line": 15, + "column": 1, + "endLine": 15, + "endColumn": 51 + }, + { + "start": 654, + "end": 654, + "replacementText": "let GeneratedImportVar_1 = ESValue.load('./unary_operation_js_obj_js.js');\nlet foo = GeneratedImportVar_1.getPropertyByName('foo');\n", + "line": 15, + "column": 1, + "endLine": 15, + "endColumn": 51 + } + ], + "suggest": "", + "rule": "Importing directly from \"JS\" module is not supported (arkts-interop-js2s-import-js)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 9, + "problem": "InteropNoHaveNum", + "autofix": [ + { + "start": 657, + "end": 664, + "replacementText": "foo.getPropertyByName(\"num\").toNumber()", + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 9 + } + ], + "suggest": "", + "rule": "Interop object does not have property num (arkts-interop-js2s-unary-op)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 1, + "endLine": 18, + "endColumn": 9, + "problem": "InteropNoHaveNum", + "autofix": [ + { + "start": 667, + "end": 674, + "replacementText": "foo.getPropertyByName(\"num\").toNumber()", + "line": 18, + "column": 1, + "endLine": 18, + "endColumn": 9 + } + ], + "suggest": "", + "rule": "Interop object does not have property num (arkts-interop-js2s-unary-op)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 9, + "problem": "InteropNoHaveNum", + "autofix": [ + { + "start": 677, + "end": 684, + "replacementText": "foo.getPropertyByName(\"num\").toNumber()", + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 9 + } + ], + "suggest": "", + "rule": "Interop object does not have property num (arkts-interop-js2s-unary-op)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 9, + "problem": "InteropNoHaveNum", + "autofix": [ + { + "start": 687, + "end": 694, + "replacementText": "foo.getPropertyByName(\"num\").toNumber()", + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 9 + } + ], + "suggest": "", + "rule": "Interop object does not have property num (arkts-interop-js2s-unary-op)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unary_operation_js_obj.ets.json b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.json new file mode 100644 index 0000000000..43cb4a27bc --- /dev/null +++ b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.json @@ -0,0 +1,3 @@ +{ + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unary_operation_js_obj.ets.migrate.ets b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.migrate.ets new file mode 100644 index 0000000000..5448d6f5f0 --- /dev/null +++ b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.migrate.ets @@ -0,0 +1,22 @@ +/* + * 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('./unary_operation_js_obj_js.js'); +let foo = GeneratedImportVar_1.getPropertyByName('foo'); + + ++foo.getPropertyByName("num").toNumber(); +-foo.getPropertyByName("num").toNumber(); +!foo.getPropertyByName("num").toNumber(); +~foo.getPropertyByName("num").toNumber(); \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unary_operation_js_obj.ets.migrate.json b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.migrate.json new file mode 100644 index 0000000000..4d448e180c --- /dev/null +++ b/ets2panda/linter/test/interop/unary_operation_js_obj.ets.migrate.json @@ -0,0 +1,68 @@ +{ + "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": 15, + "column": 5, + "endLine": 15, + "endColumn": 74, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 16, + "column": 5, + "endLine": 16, + "endColumn": 56, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 41, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 41, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 1, + "endLine": 22, + "endColumn": 41, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unary_operation_js_obj_js.js b/ets2panda/linter/test/interop/unary_operation_js_obj_js.js new file mode 100644 index 0000000000..6787c96784 --- /dev/null +++ b/ets2panda/linter/test/interop/unary_operation_js_obj_js.js @@ -0,0 +1,16 @@ +/* + * 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. + */ + +export let foo = {num: 0}; \ No newline at end of file -- Gitee