diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index a15641503fd7aa6af889b0b1b95a5af54dd1809e..3bee2124dd9ccff7e64dc002e7622e3632a986fc 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -1374,7 +1374,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.checkDepricatedIsConcurrent(node as ts.PropertyAccessExpression); this.propertyAccessExpressionForBuiltin(node as ts.PropertyAccessExpression); this.checkConstrutorAccess(node as ts.PropertyAccessExpression); - + this.handleTaskPoolDeprecatedUsages(node as ts.PropertyAccessExpression); if (ts.isCallExpression(node.parent) && node === node.parent.expression) { return; } @@ -4581,7 +4581,6 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleInteropForCallJSExpression(tsCallExpr, calleeSym, callSignature); this.handleNoTsLikeFunctionCall(tsCallExpr); this.handleObjectLiteralInFunctionArgs(tsCallExpr); - this.handleTaskPoolDeprecatedUsages(tsCallExpr); this.handleSdkGlobalApi(tsCallExpr); this.handleObjectLiteralAssignmentToClass(tsCallExpr); this.checkRestrictedAPICall(tsCallExpr) @@ -8278,50 +8277,38 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return false; } - private handleTaskPoolDeprecatedUsages(node: ts.CallExpression): void { + private handleTaskPoolDeprecatedUsages(propertyAccess: ts.PropertyAccessExpression): void { if (!this.options.arkts2 || !this.useStatic) { return; } - - if (!ts.isPropertyAccessExpression(node.expression)) { - return; - } - - const propertyAccess = node.expression; - const objectExpr = propertyAccess.expression; - + const objectExpr = ts.isNewExpression(propertyAccess.expression) ? + propertyAccess.expression.expression : + propertyAccess.expression; // Step 1: Must be either setCloneList or setTransferList if (!TypeScriptLinter.isDeprecatedTaskPoolMethodCall(propertyAccess)) { return; } - - if (!ts.isIdentifier(objectExpr)) { + const variableDecl = TsUtils.getDeclaration(this.tsUtils.trueSymbolAtLocation(objectExpr)); + const isNoContinue = + !variableDecl || + !ts.isVariableDeclaration(variableDecl) || + !variableDecl?.initializer || + !ts.isNewExpression(variableDecl.initializer); + if (isNoContinue) { return; } - - // Step 2: Resolve declaration of task - const variableDecl = this.tsUtils.findVariableDeclaration(objectExpr); - if (!variableDecl?.initializer || !ts.isNewExpression(variableDecl.initializer)) { - return; - } - - // Step 3: Check new taskpool.Task() const taskpoolExpr = variableDecl.initializer.expression; - if (!TypeScriptLinter.isTaskPoolTaskCreation(taskpoolExpr)) { + if (!this.isTaskPoolTaskCreation(taskpoolExpr)) { return; } - const faultId = propertyAccess.name.text === DEPRECATED_TASKPOOL_METHOD_SETCLONELIST ? FaultID.SetCloneListDeprecated : FaultID.SetTransferListDeprecated; - this.incrementCounters(node.parent, faultId); + this.incrementCounters(propertyAccess.name, faultId); } private static isDeprecatedTaskPoolMethodCall(propertyAccess: ts.PropertyAccessExpression): boolean { - if (!ts.isIdentifier(propertyAccess.expression)) { - return false; - } const methodName = propertyAccess.name.text; return ( methodName === DEPRECATED_TASKPOOL_METHOD_SETCLONELIST || @@ -8329,13 +8316,64 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { ); } - private static isTaskPoolTaskCreation(taskpoolExpr: ts.Expression): boolean { - return ( - ts.isPropertyAccessExpression(taskpoolExpr) && - ts.isIdentifier(taskpoolExpr.expression) && - taskpoolExpr.expression.text === STDLIB_TASKPOOL_OBJECT_NAME && - taskpoolExpr.name.text === STDLIB_TASK_CLASS_NAME - ); + private isTaskPoolTaskCreation(taskpoolExpr: ts.Expression): boolean { + if ( + ts.isIdentifier(taskpoolExpr) || + ts.isPropertyAccessExpression(taskpoolExpr) && taskpoolExpr.name.text === STDLIB_TASK_CLASS_NAME + ) { + const objectExpr = ts.isIdentifier(taskpoolExpr) ? taskpoolExpr : taskpoolExpr.expression; + return this.isTaskPoolReferenceisTaskPoolImportForTaskPoolDeprecatedUsages(objectExpr); + } + return false; + } + + private isTaskPoolReferenceisTaskPoolImportForTaskPoolDeprecatedUsages(expr: ts.Expression): boolean { + if (ts.isIdentifier(expr)) { + const sym = this.tsTypeChecker.getSymbolAtLocation(expr); + const importChild = TsUtils.getDeclaration(sym); + if (!importChild) { + return false; + } + if (ts.isImportSpecifier(importChild)) { + return TypeScriptLinter.isTaskPoolImportForTaskPoolDeprecatedUsages(importChild); + } + if (ts.isImportClause(importChild) && importChild.name?.text === STDLIB_TASKPOOL_OBJECT_NAME) { + return TypeScriptLinter.checkModuleSpecifierForTaskPoolDeprecatedUsages(importChild.parent); + } + } + if (ts.isPropertyAccessExpression(expr)) { + return this.isTaskPoolReferenceOnPropertyAccessExpression(expr); + } + return false; + } + + private static checkModuleSpecifierForTaskPoolDeprecatedUsages(importDecl: ts.ImportDeclaration): boolean { + if (ts.isImportDeclaration(importDecl) && ts.isStringLiteral(importDecl.moduleSpecifier)) { + const moduleSpecifier = importDecl.moduleSpecifier; + return TASKPOOL_MODULES.includes(TsUtils.removeOrReplaceQuotes(moduleSpecifier.getText(), false)); + } + return false; + } + + private isTaskPoolReferenceOnPropertyAccessExpression(expr: ts.PropertyAccessExpression): boolean { + if (expr.name.text !== STDLIB_TASKPOOL_OBJECT_NAME || !ts.isIdentifier(expr.expression)) { + return false; + } + const sym = this.tsTypeChecker.getSymbolAtLocation(expr.expression); + const importChild = TsUtils.getDeclaration(sym); + if (importChild && ts.isNamespaceImport(importChild)) { + return TypeScriptLinter.checkModuleSpecifierForTaskPoolDeprecatedUsages(importChild.parent.parent); + } + return false; + } + + private static isTaskPoolImportForTaskPoolDeprecatedUsages(specifier: ts.ImportSpecifier): boolean { + const specifierName = specifier.propertyName ? specifier.propertyName : specifier.name; + if (STDLIB_TASKPOOL_OBJECT_NAME !== specifierName.text) { + return false; + } + const importDeclaration = specifier.parent.parent.parent; + return TypeScriptLinter.checkModuleSpecifierForTaskPoolDeprecatedUsages(importDeclaration); } private handleForOfJsArray(node: ts.ForOfStatement): void { diff --git a/ets2panda/linter/test/main/@ohos.taskpool.ets b/ets2panda/linter/test/main/@ohos.taskpool.ets new file mode 100755 index 0000000000000000000000000000000000000000..eef90ba56a6623ce649296e031f578a85adbab32 --- /dev/null +++ b/ets2panda/linter/test/main/@ohos.taskpool.ets @@ -0,0 +1,36 @@ +/* + * 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 namespace taskpool{ + export function isConcurrent(param:func):boolean { + return true + } + export class Task { + constructor(func: Function, ...args: Object[]){} + setTransferList(transfer?: ArrayBuffer[]): void{} + setCloneList(cloneList: Object[] | ArrayBuffer[]): void{} + } +} +export namespace otherTaskPool{ + export function isConcurrent(param:func):boolean { + return true + } + + export class Task { + constructor(func: Function, ...args: Object[]){} + setTransferList(transfer?: ArrayBuffer[]): void{} + setCloneList(cloneList: Object[] | ArrayBuffer[]): void{} + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/@ohos.taskpool.ets.args.json b/ets2panda/linter/test/main/@ohos.taskpool.ets.args.json new file mode 100755 index 0000000000000000000000000000000000000000..0adede204e309a92c8aac08d89f6af16d9c93f78 --- /dev/null +++ b/ets2panda/linter/test/main/@ohos.taskpool.ets.args.json @@ -0,0 +1,18 @@ +{ + "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." + ], + "mode": { + } +} diff --git a/ets2panda/linter/test/main/@ohos.taskpool.ets.json b/ets2panda/linter/test/main/@ohos.taskpool.ets.json new file mode 100755 index 0000000000000000000000000000000000000000..9f305c86d7ff705098b1e480818e125d5e6e3a4a --- /dev/null +++ b/ets2panda/linter/test/main/@ohos.taskpool.ets.json @@ -0,0 +1,17 @@ +{ + "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": [] +} diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages.ets b/ets2panda/linter/test/main/taskpool_deprecated_usages.ets index 05ec4e2f14809d6685c63f0ff9c89f60bb817001..8a089d224cfb8b9a91c97b0bb3968b59a2f42082 100644 --- a/ets2panda/linter/test/main/taskpool_deprecated_usages.ets +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages.ets @@ -13,10 +13,54 @@ * limitations under the License. */ 'use static' +import ArrayBuffer,{ taskpool,ArrayList } from '@kit.ArkTS' +import { taskpool as tp } from '@kit.ArkTS' +import * as arkts from '@kit.ArkTS'; +import { task as task7,Task } from './taskpool_deprecated_usages3'; let baseInstance1: BaseClass = new BaseClass(); -let array1 = new Array(); -array1.push(baseInstance1); +let array = new Array(); +array.push(baseInstance1); +let task = new taskpool.Task(testFunc, array, 10); +task.setCloneList(array); //error +task.setTransferList(array); //error + +function testFunc(){} +function test1():void {} + +const array1: number[] =[1] +const transfer: ArrayBuffer[] =[] let task1 = new taskpool.Task(testFunc, array1, 10); -task1.setCloneList(array1); -task1.setTransferList(array1); +task1.setCloneList(array1); //error +task1.setTransferList(transfer); //error + +let task2 = new tp.Task(test1) +task2.setCloneList([]) //error +task2.setCloneList(transfer) //error + +let test3 = new tp.Task(test1) +test3.setCloneList([]) //error +test3.setCloneList([transfer]) //error + +let task4 = new tp.Task(test1) +task4.setTransferList() //error +task4.setTransferList([]) //error +task4.setTransferList(transfer) //error + +let test5 = new tp.Task(test1) +test5.setTransferList() //error +test5.setTransferList([]) //error +test5.setTransferList(transfer) //error + +let task6 = new arkts.taskpool.Task(test1); +task6.setCloneList([]) //error +task6.setCloneList([transfer]) //error + +task7.setCloneList(array1) //error +task7.setTransferList(transfer) //error +new task7.setTransferList(transfer) //error +new task7.setCloneList(array1) //error +new Task(test1).setTransferList(transfer) +new Task(test1).setCloneList(array1) +const task8 = new Task(testFunc); +task8.setCloneList(array1) \ No newline at end of file diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.arkts2.json b/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.arkts2.json index 463c82314fe13513cae7fe2a912b6a62eb98b22b..5881b8079dec64adf90ac1344f90305a60f8fd98 100644 --- a/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.arkts2.json +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.arkts2.json @@ -14,10 +14,70 @@ "limitations under the License." ], "result": [ + { + "line": 16, + "column": 1, + "endLine": 16, + "endColumn": 60, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 16, + "column": 22, + "endLine": 16, + "endColumn": 30, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, { "line": 17, - "column": 36, + "column": 1, "endLine": 17, + "endColumn": 44, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 44, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 1, + "endLine": 18, + "endColumn": 37, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 68, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 36, + "endLine": 21, "endColumn": 45, "problem": "DynamicCtorCall", "suggest": "", @@ -25,9 +85,69 @@ "severity": "ERROR" }, { - "line": 20, + "line": 24, + "column": 5, + "endLine": 24, + "endColumn": 50, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 16, + "endLine": 24, + "endColumn": 29, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 47, + "endLine": 24, + "endColumn": 49, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 6, + "endLine": 25, + "endColumn": 18, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 6, + "endLine": 26, + "endColumn": 21, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 26, + "endLine": 31, + "endColumn": 27, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 33, "column": 5, - "endLine": 20, + "endLine": 33, "endColumn": 52, "problem": "AnyType", "suggest": "", @@ -35,9 +155,9 @@ "severity": "ERROR" }, { - "line": 20, + "line": 33, "column": 17, - "endLine": 20, + "endLine": 33, "endColumn": 30, "problem": "DynamicCtorCall", "suggest": "", @@ -45,9 +165,9 @@ "severity": "ERROR" }, { - "line": 20, + "line": 33, "column": 49, - "endLine": 20, + "endLine": 33, "endColumn": 51, "problem": "NumericSemantics", "suggest": "", @@ -55,24 +175,304 @@ "severity": "ERROR" }, { - "line": 21, - "column": 1, - "endLine": 21, - "endColumn": 28, + "line": 34, + "column": 7, + "endLine": 34, + "endColumn": 19, "problem": "SetCloneListDeprecated", "suggest": "", "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", "severity": "ERROR" }, { - "line": 22, - "column": 1, - "endLine": 22, + "line": 35, + "column": 7, + "endLine": 35, + "endColumn": 22, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 5, + "endLine": 37, + "endColumn": 31, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 17, + "endLine": 37, + "endColumn": 24, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 7, + "endLine": 38, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 7, + "endLine": 39, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 5, + "endLine": 41, + "endColumn": 31, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 17, + "endLine": 41, + "endColumn": 24, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 42, + "column": 7, + "endLine": 42, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 7, + "endLine": 43, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 5, + "endLine": 45, "endColumn": 31, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 17, + "endLine": 45, + "endColumn": 24, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 46, + "column": 7, + "endLine": 46, + "endColumn": 22, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 47, + "column": 7, + "endLine": 47, + "endColumn": 22, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 7, + "endLine": 48, + "endColumn": 22, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 5, + "endLine": 50, + "endColumn": 31, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 17, + "endLine": 50, + "endColumn": 24, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 51, + "column": 7, + "endLine": 51, + "endColumn": 22, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 7, + "endLine": 52, + "endColumn": 22, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 53, + "column": 7, + "endLine": 53, + "endColumn": 22, "problem": "SetTransferListDeprecated", "suggest": "", "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", "severity": "ERROR" + }, + { + "line": 55, + "column": 5, + "endLine": 55, + "endColumn": 43, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 17, + "endLine": 55, + "endColumn": 36, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 7, + "endLine": 56, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 7, + "endLine": 57, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 7, + "endLine": 59, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 7, + "endLine": 60, + "endColumn": 22, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 61, + "column": 5, + "endLine": 61, + "endColumn": 26, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 61, + "column": 11, + "endLine": 61, + "endColumn": 26, + "problem": "SetTransferListDeprecated", + "suggest": "", + "rule": "The taskpool setTransferList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setTransferList)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 5, + "endLine": 62, + "endColumn": 23, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 11, + "endLine": 62, + "endColumn": 23, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.json b/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.json index 1c17b59df7a1612ee61e9a9368eed3b136b9bcfc..619623e56042c24574b9b22c8c7871014101b08e 100644 --- a/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.json +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.json @@ -15,14 +15,114 @@ ], "result": [ { - "line": 20, + "line": 16, + "column": 1, + "endLine": 16, + "endColumn": 60, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 44, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 1, + "endLine": 18, + "endColumn": 37, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 68, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 24, "column": 5, - "endLine": 20, + "endLine": 24, + "endColumn": 50, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 5, + "endLine": 33, "endColumn": 52, "problem": "AnyType", "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" + }, + { + "line": 37, + "column": 5, + "endLine": 37, + "endColumn": 31, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 5, + "endLine": 41, + "endColumn": 31, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 5, + "endLine": 45, + "endColumn": 31, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 5, + "endLine": 50, + "endColumn": 31, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 5, + "endLine": 55, + "endColumn": 43, + "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/main/taskpool_deprecated_usages2.ets b/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets new file mode 100755 index 0000000000000000000000000000000000000000..f79e1e32cc64a6ffae5b07d437702edd7c6aece3 --- /dev/null +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets @@ -0,0 +1,33 @@ +/* + * 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 taskpool from '@ohos.taskpool'; +import { otherTaskPool as taskpool1 } from './@ohos.taskpool'; +import { taskpool as taskpool2 } from './@ohos.taskpool'; +function test1(){} +const array1: number[] =[1] +const transfer: ArrayBuffer[] =[] +let task = new taskpool1.Task(test1); +task.setCloneList(array1) +task.setTransferList(transfer) +new taskpool1.Task(test1).setTransferList(transfer); +function test(){ + const task3 = new taskpool2.Task(test1); + typeof task3.setTransferList(transfer); + return new taskpool2.Task(test1).setTransferList(); +} +let task4 = new taskpool.Task(test1); +task4.setCloneList([]) //error +task4.setCloneList(transfer) //error \ No newline at end of file diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.args.json b/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.args.json new file mode 100755 index 0000000000000000000000000000000000000000..3ef4496a819a201892114d1c90f78ae32053c334 --- /dev/null +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.args.json @@ -0,0 +1,19 @@ +{ + "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." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.arkts2.json b/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.arkts2.json new file mode 100755 index 0000000000000000000000000000000000000000..e4183cf1b5bb5b962d919e12ef452964584a4053 --- /dev/null +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.arkts2.json @@ -0,0 +1,88 @@ +{ + "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": 16, + "column": 1, + "endLine": 16, + "endColumn": 39, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 26, + "endLine": 20, + "endColumn": 27, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 10, + "endLine": 28, + "endColumn": 41, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 5, + "endLine": 31, + "endColumn": 37, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 17, + "endLine": 31, + "endColumn": 30, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 7, + "endLine": 32, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 7, + "endLine": 33, + "endColumn": 19, + "problem": "SetCloneListDeprecated", + "suggest": "", + "rule": "The taskpool setCloneList interface is deleted from ArkTS1.2 (arkts-limited-stdlib-no-setCloneList)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.json b/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.json new file mode 100755 index 0000000000000000000000000000000000000000..14da023dd0b347f06e79a6a58ed2a965ad18f232 --- /dev/null +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages2.ets.json @@ -0,0 +1,28 @@ +{ + "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": 31, + "column": 5, + "endLine": 31, + "endColumn": 37, + "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/main/taskpool_deprecated_usages3.ets b/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets new file mode 100755 index 0000000000000000000000000000000000000000..99eafb82960a351e05fd6a90c0cd45a937879983 --- /dev/null +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages3.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. + */ +import taskpool from '@ohos.taskpool'; +function test1(){} +export const task = new taskpool.Task(test1); +export class Task { + constructor(func: Function, ...args: Object[]){} + setTransferList(transfer?: ArrayBuffer[]): void{} + setCloneList(cloneList: Object[] | ArrayBuffer[]): void{} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.args.json b/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.args.json new file mode 100755 index 0000000000000000000000000000000000000000..3ef4496a819a201892114d1c90f78ae32053c334 --- /dev/null +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.args.json @@ -0,0 +1,19 @@ +{ + "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." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.arkts2.json b/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.arkts2.json new file mode 100755 index 0000000000000000000000000000000000000000..449be5d7945a1a914efc5ff077f0dbbc744de8ff --- /dev/null +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.arkts2.json @@ -0,0 +1,48 @@ +{ + "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": 39, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 15, + "endLine": 17, + "endColumn": 46, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 26, + "endLine": 17, + "endColumn": 39, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.json b/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.json new file mode 100755 index 0000000000000000000000000000000000000000..4fdd338ef26a4ff2a3ff6c93f48a14fd8c8c295d --- /dev/null +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages3.ets.json @@ -0,0 +1,28 @@ +{ + "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": 15, + "endLine": 17, + "endColumn": 46, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + } + ] +} \ No newline at end of file