From 64330a7cc069fe0180f379546795dea4c0df6340 Mon Sep 17 00:00:00 2001 From: beratagaca_9a91 Date: Fri, 20 Jun 2025 15:28:06 +0300 Subject: [PATCH] fix arkts-limited-stdlib-no-import-concurrency Description: ArkTSUtils.locks.AsyncLock handled Issue: #ICFVEQ Signed-off-by: beratagaca_9a91 --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 20 +++++++++- .../src/lib/utils/consts/LimitedStdAPI.ts | 4 ++ ... no_support_arktsutils_locks_asynclock.ets | 20 ++++++++++ ...arktsutils_locks_asynclock.ets.arkts2.json | 38 +++++++++++++++++++ ...rktsutils_locks_asynclock.ets.autofix.json | 38 +++++++++++++++++++ ...upport_arktsutils_locks_asynclock.ets.json | 17 +++++++++ ...arktsutils_locks_asynclock.ets.migrate.ets | 20 ++++++++++ ...rktsutils_locks_asynclock.ets.migrate.json | 38 +++++++++++++++++++ .../test/main/oh_modules/@arkts.utils.d.ets | 14 ++++++- .../test/main/oh_modules/@kit.ArkTS.d.ets | 3 +- 10 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets create mode 100644 ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.arkts2.json create mode 100644 ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.autofix.json create mode 100644 ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.json create mode 100644 ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.migrate.ets create mode 100644 ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.migrate.json diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 4b72c290e0..fcba4e1ebf 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -68,7 +68,10 @@ import { LIMITED_STD_OBJECT_API, LIMITED_STD_PROXYHANDLER_API, LIMITED_STD_REFLECT_API, - MODULE_IMPORTS + MODULE_IMPORTS, + ARKTSUTILS_TEXT, + ARKTSUTILS_MODULES, + ARKTSUTILS_LOCKS_MEMBER } from './utils/consts/LimitedStdAPI'; import { SupportedStdCallApiChecker } from './utils/functions/SupportedStdCallAPI'; import { identiferUseInValueContext } from './utils/functions/identiferUseInValueContext'; @@ -3866,6 +3869,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (isArkTs2) { this.checkWorkerSymbol(tsIdentSym, node); this.checkCollectionsSymbol(tsIdentSym, node); + this.checkConcurrencySymbol(tsIdentSym, node); } } @@ -7141,6 +7145,20 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.checkSymbolAndExecute(symbol, WORKER_TEXT, WORKER_MODULES, cb); } + private checkConcurrencySymbol(symbol: ts.Symbol, node: ts.Node): void { + const cb = (): void => { + const parent = node.parent; + if (!ts.isPropertyAccessExpression(parent)) { + return; + } + if (parent.name.text === ARKTSUTILS_LOCKS_MEMBER) { + this.incrementCounters(node, FaultID.LimitedStdLibNoImportConcurrency); + } + }; + + this.checkSymbolAndExecute(symbol, ARKTSUTILS_TEXT, ARKTSUTILS_MODULES, cb); + } + private checkSymbolAndExecute(symbol: ts.Symbol, symbolName: string, modules: string[], cb: () => void): void { void this; if (symbol.name === symbolName) { diff --git a/ets2panda/linter/src/lib/utils/consts/LimitedStdAPI.ts b/ets2panda/linter/src/lib/utils/consts/LimitedStdAPI.ts index ca9bdcd843..21007148eb 100644 --- a/ets2panda/linter/src/lib/utils/consts/LimitedStdAPI.ts +++ b/ets2panda/linter/src/lib/utils/consts/LimitedStdAPI.ts @@ -157,3 +157,7 @@ export const MODULE_IMPORTS: Record = { '@ohos.process': ['process'], '@ohos.taskpool': ['taskpool'] }; + +export const ARKTSUTILS_TEXT = 'ArkTSUtils'; +export const ARKTSUTILS_MODULES = ['@arkts.utils']; +export const ARKTSUTILS_LOCKS_MEMBER = 'locks'; diff --git a/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets new file mode 100644 index 0000000000..3ad92e0865 --- /dev/null +++ b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.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 { ArkTSUtils } from '../main/oh_modules/@kit.ArkTS'; + +let lock1 = new ArkTSUtils.locks.AsyncLock(); + +let lock2 = new ArkTSUtils.locks.AsyncLock(); \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.arkts2.json b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.arkts2.json new file mode 100644 index 0000000000..c38018cfbc --- /dev/null +++ b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.arkts2.json @@ -0,0 +1,38 @@ +{ + "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": 3, + "column": 17, + "endLine": 3, + "endColumn": 27, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 5, + "column": 17, + "endLine": 5, + "endColumn": 27, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.autofix.json b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.autofix.json new file mode 100644 index 0000000000..c38018cfbc --- /dev/null +++ b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.autofix.json @@ -0,0 +1,38 @@ +{ + "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": 3, + "column": 17, + "endLine": 3, + "endColumn": 27, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 5, + "column": 17, + "endLine": 5, + "endColumn": 27, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.json b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.json new file mode 100644 index 0000000000..ca88f857e9 --- /dev/null +++ b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.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": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.migrate.ets b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.migrate.ets new file mode 100644 index 0000000000..c8cd4f5b48 --- /dev/null +++ b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.migrate.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 { ArkTSUtils } from '../main/oh_modules/@kit.ArkTS'; + +let lock1 = new ArkTSUtils.locks.AsyncLock(); + +let lock2 = new ArkTSUtils.locks.AsyncLock(); \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.migrate.json b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.migrate.json new file mode 100644 index 0000000000..c38018cfbc --- /dev/null +++ b/ets2panda/linter/test/concurrent/ no_support_arktsutils_locks_asynclock.ets.migrate.json @@ -0,0 +1,38 @@ +{ + "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": 3, + "column": 17, + "endLine": 3, + "endColumn": 27, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 5, + "column": 17, + "endLine": 5, + "endColumn": 27, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/oh_modules/@arkts.utils.d.ets b/ets2panda/linter/test/main/oh_modules/@arkts.utils.d.ets index df91841374..0e5d4e1ba8 100644 --- a/ets2panda/linter/test/main/oh_modules/@arkts.utils.d.ets +++ b/ets2panda/linter/test/main/oh_modules/@arkts.utils.d.ets @@ -19,4 +19,16 @@ export namespace utils { } } -export default utils; \ No newline at end of file +export default utils; + +export namespace ArkTSUtils { + export namespace locks { + export class AsyncLock { + constructor(); + } + } + + export namespace safeModule { + export function foo(): void; + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets b/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets index dd994ead62..fdb4d44008 100644 --- a/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets +++ b/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets @@ -16,4 +16,5 @@ export { worker } from '../oh_modules/@ohos.worker'; export { collections } from '../oh_modules/@arkts.collections'; export { utils } from '../oh_modules/@arkts.utils'; -export { taskpool } from '../oh_modules/@ohos.taskpool'; \ No newline at end of file +export { taskpool } from '../oh_modules/@ohos.taskpool'; +export { ArkTSUtils } from '../oh_modules/@arkts.utils'; \ No newline at end of file -- Gitee