From 679ee5b3005882ec69fc48db5ecaea4690fe01fe Mon Sep 17 00:00:00 2001 From: Utku Enes GURSEL Date: Tue, 5 Aug 2025 15:52:44 +0300 Subject: [PATCH] not-support-tuple-generic-validation Issue: ICNZEN Description: Add arkts-not-support-tuple-generic-validation rule. Signed-off-by: Utku Enes GURSEL --- ets2panda/linter/package.json | 5 ++- ets2panda/linter/src/lib/CookBookMsg.ts | 3 +- ets2panda/linter/src/lib/FaultDesc.ts | 3 +- ets2panda/linter/src/lib/TypeScriptLinter.ts | 39 ++++++++++++++++++- ...t-tuple-generic-validation.ets.arkts2.json | 8 ++-- .../linter/test/taskpool/taskpool_execute.ets | 24 ++++++++++++ .../taskpool/taskpool_execute.ets.args.json | 19 +++++++++ .../taskpool/taskpool_execute.ets.arkts2.json | 28 +++++++++++++ .../test/taskpool/taskpool_execute.ets.json | 17 ++++++++ 9 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 ets2panda/linter/test/taskpool/taskpool_execute.ets create mode 100644 ets2panda/linter/test/taskpool/taskpool_execute.ets.args.json create mode 100644 ets2panda/linter/test/taskpool/taskpool_execute.ets.arkts2.json create mode 100644 ets2panda/linter/test/taskpool/taskpool_execute.ets.json diff --git a/ets2panda/linter/package.json b/ets2panda/linter/package.json index 0db61d9e69..929dd430b9 100644 --- a/ets2panda/linter/package.json +++ b/ets2panda/linter/package.json @@ -20,12 +20,13 @@ "pack:linter": "rimraf bundle && mkdir bundle && npm pack && mv panda-tslinter-*.tgz bundle", "pretest": " npm run fix", "test": "npm run test_all && npm run test_ts_import_ets", - "test_all": "npm run testrunner -- -d test/main,test/rules,test/regression,test/extended_features,test/migration,test/ohmurl,test/interop,test/sdkwhite,test/concurrent,test/builtin,test/deprecatedapi", + "test_all": "npm run testrunner -- -d test/main,test/rules,test/regression,test/extended_features,test/migration,test/ohmurl,test/interop,test/sdkwhite,test/concurrent,test/builtin,test/deprecatedapi, test/taskpool", "test_main": "npm run testrunner -- -d test/main", "test_ohmurl": "npm run testrunner -- -d test/ohmurl", "test_interop": "npm run testrunner -- -d test/interop", "test_sdk": "npm run testrunner -- -d test/sdkwhite", "test_deprecatedapi": "npm run testrunner -- -d test/deprecatedapi", + "test_taskpool": "npm run testrunner -- -d test/taskpool", "test_concurrent": "npm run testrunner -- -d test/concurrent", "test_rules": "npm run testrunner -- -d test/rules", "test_regression": "npm run testrunner -- -d test/regression", @@ -37,7 +38,7 @@ "test_ts_import_ets": "npm run testrunner -- -d test/ts_import_ets/ts --sdk --interop-mode", "test_migration": "npm run testrunner -- -d test/migration", "testrunner": "npm run compile && node build/testRunner/TestRunner.js", - "update-tests": "node scripts/update-test-results.mjs test/main test/rules test/regression test/extended_features test/ts_import_ets/ts test/migration test/ohmurl test/interop test/sdkwhite test/concurrent test/builtin test/deprecatedapi", + "update-tests": "node scripts/update-test-results.mjs test/main test/rules test/regression test/extended_features test/ts_import_ets/ts test/migration test/ohmurl test/interop test/sdkwhite test/concurrent test/builtin test/deprecatedapi test/taskpool", "eslint-check": "npx eslint .", "eslint-fix": "npm run eslint-check -- --fix", "prettier-fix": "npx prettier --write .", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 3aafa7ae52..bcaf3cf318 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -316,8 +316,7 @@ cookBookTag[284] = '"prop" function is not supported (arkui-no-prop-function)'; cookBookTag[285] = '"setAndProp" function is not supported (arkui-no-setandprop-function)'; cookBookTag[286] = 'Parameters decorated with "@Prop" need to call the specific method when receiving data to ensure deep copy of the data (arkui-prop-need-call-method-for-deep-copy)'; -cookBookTag[290] = - 'Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)'; +cookBookTag[290] = 'Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)'; cookBookTag[300] = 'The function type should be explicit (arkts-no-ts-like-function-call)'; cookBookTag[301] = 'Importing from "oh module" requires specifying full path (arkts-require-fullpath-name)'; cookBookTag[302] = diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index 5f0de591dd..644f93a730 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -174,8 +174,7 @@ faultDesc[FaultID.InteropJsObjectConditionJudgment] = 'Interop JS Object usage i faultDesc[FaultID.InteropJsObjectExpandStaticInstance] = 'Interop JS function usage'; faultDesc[FaultID.InteropJSFunctionInvoke] = 'Interop JS function invoke'; faultDesc[FaultID.VariableMissingInitializer] = 'Value must be assigned to variable'; -faultDesc[FaultID.NotSupportTupleGenericValidation] = - 'Tuple type cannot be used in generic type parameters of Promise static methods'; +faultDesc[FaultID.NotSupportTupleGenericValidation] = 'No Tuple type in Generic'; faultDesc[FaultID.DeprecatedProcessApi] = 'This process Api no longer supported in ArkTS 1.2'; faultDesc[FaultID.ExplicitFunctionType] = 'Not explicit function type'; faultDesc[FaultID.ClassstaticInitialization] = 'The static properties of a class need to have initial values'; diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 3f2e5be9d6..10c8041a23 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -19,7 +19,13 @@ import { FaultID } from './Problems'; import { TypeScriptLinterConfig } from './TypeScriptLinterConfig'; import type { Autofix } from './autofixes/Autofixer'; import { Autofixer } from './autofixes/Autofixer'; -import { PROMISE_METHODS, PROMISE_METHODS_WITH_NO_TUPLE_SUPPORT, SYMBOL, SYMBOL_CONSTRUCTOR, TsUtils } from './utils/TsUtils'; +import { + PROMISE_METHODS, + PROMISE_METHODS_WITH_NO_TUPLE_SUPPORT, + SYMBOL, + SYMBOL_CONSTRUCTOR, + TsUtils +} from './utils/TsUtils'; import { FUNCTION_HAS_NO_RETURN_ERROR_CODE } from './utils/consts/FunctionHasNoReturnErrorCode'; import { LIMITED_STANDARD_UTILITY_TYPES, @@ -5362,6 +5368,37 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleNoDeprecatedApi(tsCallExpr); this.handleFunctionReturnThisCall(tsCallExpr); this.handlePromiseTupleGeneric(tsCallExpr); + this.handleTupleGeneric(tsCallExpr); + } + + private handleTupleGeneric(callExpr: ts.CallExpression): void { + if (!this.options.arkts2) { + return; + } + if (!ts.isPropertyAccessExpression(callExpr.expression)) { + return; + } + const accessedProperty = callExpr.expression; + + if (!ts.isIdentifier(accessedProperty.expression)) { + return; + } + + if (accessedProperty.expression.text !== TASKPOOL) { + return; + } + + if (!callExpr.typeArguments) { + return; + } + + if (callExpr.parent) { + callExpr.typeArguments.forEach((node) => { + if (ts.isTupleTypeNode(node)) { + this.incrementCounters(node, FaultID.NotSupportTupleGenericValidation); + } + }); + } } private handleCallExpressionForUI(node: ts.CallExpression): void { diff --git a/ets2panda/linter/test/main/arkts-not-support-tuple-generic-validation.ets.arkts2.json b/ets2panda/linter/test/main/arkts-not-support-tuple-generic-validation.ets.arkts2.json index 52c316a716..e61aa4ff7a 100644 --- a/ets2panda/linter/test/main/arkts-not-support-tuple-generic-validation.ets.arkts2.json +++ b/ets2panda/linter/test/main/arkts-not-support-tuple-generic-validation.ets.arkts2.json @@ -41,7 +41,7 @@ "endColumn": 47, "problem": "NotSupportTupleGenericValidation", "suggest": "", - "rule": "Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", "severity": "ERROR" }, { @@ -51,7 +51,7 @@ "endColumn": 47, "problem": "NotSupportTupleGenericValidation", "suggest": "", - "rule": "Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", "severity": "ERROR" }, { @@ -61,7 +61,7 @@ "endColumn": 48, "problem": "NotSupportTupleGenericValidation", "suggest": "", - "rule": "Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", "severity": "ERROR" }, { @@ -71,7 +71,7 @@ "endColumn": 54, "problem": "NotSupportTupleGenericValidation", "suggest": "", - "rule": "Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", "severity": "ERROR" } ] diff --git a/ets2panda/linter/test/taskpool/taskpool_execute.ets b/ets2panda/linter/test/taskpool/taskpool_execute.ets new file mode 100644 index 0000000000..f50a174b03 --- /dev/null +++ b/ets2panda/linter/test/taskpool/taskpool_execute.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +function printArgs(args: number): number { + console.info(""printArgs: "" + args); + return args; +} + +taskpool.execute<[number], number>(printArgs, 100).then((value: number) => { + console.info(""taskpool result: "" + value); +}); + diff --git a/ets2panda/linter/test/taskpool/taskpool_execute.ets.args.json b/ets2panda/linter/test/taskpool/taskpool_execute.ets.args.json new file mode 100644 index 0000000000..bc4d2071da --- /dev/null +++ b/ets2panda/linter/test/taskpool/taskpool_execute.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/taskpool/taskpool_execute.ets.arkts2.json b/ets2panda/linter/test/taskpool/taskpool_execute.ets.arkts2.json new file mode 100644 index 0000000000..2b96bc02fd --- /dev/null +++ b/ets2panda/linter/test/taskpool/taskpool_execute.ets.arkts2.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": 21, + "column": 18, + "endLine": 21, + "endColumn": 26, + "problem": "NotSupportTupleGenericValidation", + "suggest": "", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/taskpool/taskpool_execute.ets.json b/ets2panda/linter/test/taskpool/taskpool_execute.ets.json new file mode 100644 index 0000000000..9f305c86d7 --- /dev/null +++ b/ets2panda/linter/test/taskpool/taskpool_execute.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": [] +} -- Gitee