From 5d84739aa438415d1f7bd808d5db67a8844b626c Mon Sep 17 00:00:00 2001 From: sefayilmazunal Date: Thu, 31 Jul 2025 13:29:57 +0300 Subject: [PATCH] arkts-concurrent-deprecated-apis impl Description: arkts-concurrent-deprecated-apis rule implemented Issue: ICNZN3 Signed-off-by: sefayilmazunal --- ets2panda/linter/rule-config.json | 1 + ets2panda/linter/src/lib/CookBookMsg.ts | 2 + ets2panda/linter/src/lib/FaultAttrs.ts | 1 + ets2panda/linter/src/lib/FaultDesc.ts | 1 + ets2panda/linter/src/lib/Problems.ts | 1 + ets2panda/linter/src/lib/TypeScriptLinter.ts | 58 +++++++----- .../src/lib/utils/consts/LimitedStdAPI.ts | 13 ++- .../concurrent_process_deprecated_apis.ets | 27 ++++++ ...rent_process_deprecated_apis.ets.args.json | 19 ++++ ...nt_process_deprecated_apis.ets.arkts2.json | 88 +++++++++++++++++++ ...oncurrent_process_deprecated_apis.ets.json | 17 ++++ .../test/main/oh_modules/@kit.ArkTS.d.ets | 3 +- .../test/main/oh_modules/@ohos.process.d.ets | 24 +++++ 13 files changed, 229 insertions(+), 26 deletions(-) create mode 100644 ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets create mode 100644 ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets.args.json create mode 100644 ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets.arkts2.json create mode 100644 ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets.json create mode 100644 ets2panda/linter/test/main/oh_modules/@ohos.process.d.ets diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 611a033828..346a6ee6fc 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -15,6 +15,7 @@ "arkts-limited-stdlib", "arkts-no-class-add-super-prop-with-readonly", "arkts-var-assignment-before-use", + "arkts-concurrent-deprecated-apis", "arkts-no-classes-as-obj", "arkts-obj-literal-props", "arkts-no-template-string-type", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index f0b8e41253..54b797cf89 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -296,6 +296,8 @@ cookBookTag[269] = cookBookTag[270] = 'ArkTS1.2 cannot catch a non Error instance thrown from JS code (arkts-interop-js2s-js-exception)'; cookBookTag[271] = 'After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)'; +cookBookTag[272] = + 'This API of process is obsolete in ArkTS 1.1. It\'s no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)'; cookBookTag[274] = 'The subclass constructor must call the parent class\'s parametered constructor (arkts-subclass-must-call-super-constructor-with-args)'; cookBookTag[275] = diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index 8ace468f16..197af41f90 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -202,6 +202,7 @@ faultsAttrs[FaultID.InteropJsObjectConditionJudgment] = new FaultAttributes(268) faultsAttrs[FaultID.InteropJsObjectExpandStaticInstance] = new FaultAttributes(269); faultsAttrs[FaultID.InteropJSFunctionInvoke] = new FaultAttributes(270); faultsAttrs[FaultID.VariableMissingInitializer] = new FaultAttributes(271); +faultsAttrs[FaultID.DeprecatedProcessApi] = new FaultAttributes(272); faultsAttrs[FaultID.MissingSuperCall] = new FaultAttributes(274); faultsAttrs[FaultID.CustomLayoutNeedAddDecorator] = new FaultAttributes(275); faultsAttrs[FaultID.InterfaceFieldNotImplemented] = new FaultAttributes(276); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index d812eab323..011b01a034 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -170,6 +170,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.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'; faultDesc[FaultID.AvoidUnionTypes] = 'Union types'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index dd700b4ed5..1497b09c7e 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -190,6 +190,7 @@ export enum FaultID { InteropTSFunctionInvoke, InteropJSFunctionInvoke, VariableMissingInitializer, + DeprecatedProcessApi, LimitedVoidTypeFromSdk, EntryAnnotation, SdkAbilityLifecycleMonitor, diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 1e0dd75815..6182e43d69 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -76,7 +76,9 @@ import { LIMITED_STD_REFLECT_API, MODULE_IMPORTS, ARKTSUTILS_MODULES, - ARKTSUTILS_LOCKS_MEMBER + ARKTSUTILS_LOCKS_MEMBER, + ARKTSUTILS_PROCESS_MEMBER, + PROCESS_DEPRECATED_INTERFACES } from './utils/consts/LimitedStdAPI'; import { SupportedStdCallApiChecker } from './utils/functions/SupportedStdCallAPI'; import { identiferUseInValueContext } from './utils/functions/identiferUseInValueContext'; @@ -3875,7 +3877,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { }) || false; const classType: ts.Type | undefined = this.getClassType(classDecl, isStatic); const allBaseTypes = classType && this.getAllBaseTypes(classType, classDecl, isStatic); - + if (!allBaseTypes || allBaseTypes.length === 0) { return; } @@ -4113,7 +4115,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { for (let i = 0; i < Math.min(derivedParams.length, baseParams.length); i++) { const baseParam = baseParams[i]; const derivedParam = derivedParams[i]; - + if (!baseParam.questionToken && derivedParam.questionToken) { this.incrementCounters(derivedParam, FaultID.MethodInheritRule); return; @@ -8169,7 +8171,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { res = true; }; if (symbol) { - this.checkSymbolAndExecute(symbol, identifier.text, SYSTEM_MODULES, cb); + this.checkSymbolAndExecute(symbol, [identifier.text], SYSTEM_MODULES, cb); } return res; } @@ -8505,50 +8507,58 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.incrementCounters(node, FaultID.NoNeedStdlibWorker); }; - this.checkSymbolAndExecute(symbol, WORKER_TEXT, WORKER_MODULES, cb); + 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) { const autofix = this.autofixer?.fixConcurrencyLock(parent); this.incrementCounters(node, FaultID.LimitedStdLibNoImportConcurrency, autofix); } + + if (PROCESS_DEPRECATED_INTERFACES.includes(parent.name.text)) { + this.incrementCounters(node, FaultID.DeprecatedProcessApi); + } }; - this.checkSymbolAndExecute(symbol, ARKTSUTILS_LOCKS_MEMBER, ARKTSUTILS_MODULES, cb); + this.checkSymbolAndExecute(symbol, [ARKTSUTILS_LOCKS_MEMBER, ARKTSUTILS_PROCESS_MEMBER], ARKTSUTILS_MODULES, cb); } - private checkSymbolAndExecute(symbol: ts.Symbol, symbolName: string, modules: string[], cb: () => void): void { + private checkSymbolAndExecute(symbol: ts.Symbol, symbolNames: string[], modules: string[], cb: () => void): void { void this; - if (symbol.name === symbolName) { - const decl = TsUtils.getDeclaration(symbol); - if (!decl) { - cb(); - return; - } + // Only execute if the provided list contains the symbol’s actual name + if (!symbolNames.includes(symbol.name)) { + return; + } - const fileName = TypeScriptLinter.getFileName(decl); + const decl = TsUtils.getDeclaration(symbol); + if (!decl) { + cb(); + return; + } - if ( - modules.some((moduleName) => { - return fileName.startsWith(moduleName); - }) - ) { - cb(); - } + const fileName = TypeScriptLinter.getFileName(decl); + if ( + modules.some((moduleName) => { + return fileName.startsWith(moduleName); + }) + ) { + cb(); } } private checkNodeForUsage(node: ts.Node, symbolName: string, modules: string[], cb: () => void): void { const symbol = this.tsUtils.trueSymbolAtLocation(node); if (symbol) { - this.checkSymbolAndExecute(symbol, symbolName, modules, cb); + this.checkSymbolAndExecute(symbol, [symbolName], modules, cb); return; } @@ -13551,8 +13561,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } if ( - (ts.isIdentifier(typeRef.typeName) && typeRef.typeName.text === ES_OBJECT) || - (ts.isQualifiedName(typeRef.typeName) && typeRef.typeName.right.text === ES_OBJECT) + ts.isIdentifier(typeRef.typeName) && typeRef.typeName.text === ES_OBJECT || + ts.isQualifiedName(typeRef.typeName) && typeRef.typeName.right.text === ES_OBJECT ) { this.incrementCounters(typeRef, FaultID.NoESObjectSupport); } diff --git a/ets2panda/linter/src/lib/utils/consts/LimitedStdAPI.ts b/ets2panda/linter/src/lib/utils/consts/LimitedStdAPI.ts index 3149a493a1..5051185d47 100644 --- a/ets2panda/linter/src/lib/utils/consts/LimitedStdAPI.ts +++ b/ets2panda/linter/src/lib/utils/consts/LimitedStdAPI.ts @@ -160,5 +160,16 @@ export const MODULE_IMPORTS: Record = { '@arkts.collections': ['collections'] }; -export const ARKTSUTILS_MODULES = ['@arkts.utils', '@kit.ArkTS']; +export const ARKTSUTILS_MODULES = ['@arkts.utils', '@ohos.process', '@kit.ArkTS']; export const ARKTSUTILS_LOCKS_MEMBER = 'locks'; +export const ARKTSUTILS_PROCESS_MEMBER = 'process'; + +export const PROCESS_DEPRECATED_INTERFACES = [ + 'isAppUid', + 'getUidForName', + 'getThreadPriority', + 'getSystemConfig', + 'getEnvironmentVar', + 'exit', + 'kill' +]; diff --git a/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets b/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets new file mode 100644 index 0000000000..c743b39bc2 --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets @@ -0,0 +1,27 @@ +/* + * 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 { process } from '../main/oh_modules/@kit.ArkTS'; + +// Deprecated APIs +process.isAppUid(12.0); // error +process.getUidForName('root'); // error +process.getThreadPriority(1.0); // error +process.getSystemConfig(1.0); // error +process.getEnvironmentVar('PATH'); // error +process.exit(0.0); // error +process.kill(6.0, 1.0); // error + +process.anyOtherMethod() // ok diff --git a/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets.args.json b/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets.args.json new file mode 100644 index 0000000000..bc4d2071da --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.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/concurrent/concurrent_process_deprecated_apis.ets.arkts2.json b/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets.arkts2.json new file mode 100644 index 0000000000..56cdb58228 --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.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": 19, + "column": 1, + "endLine": 19, + "endColumn": 8, + "problem": "DeprecatedProcessApi", + "suggest": "", + "rule": "This API of process is obsolete in ArkTS 1.1. It's no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 8, + "problem": "DeprecatedProcessApi", + "suggest": "", + "rule": "This API of process is obsolete in ArkTS 1.1. It's no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 1, + "endLine": 21, + "endColumn": 8, + "problem": "DeprecatedProcessApi", + "suggest": "", + "rule": "This API of process is obsolete in ArkTS 1.1. It's no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 1, + "endLine": 22, + "endColumn": 8, + "problem": "DeprecatedProcessApi", + "suggest": "", + "rule": "This API of process is obsolete in ArkTS 1.1. It's no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 1, + "endLine": 23, + "endColumn": 8, + "problem": "DeprecatedProcessApi", + "suggest": "", + "rule": "This API of process is obsolete in ArkTS 1.1. It's no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 1, + "endLine": 24, + "endColumn": 8, + "problem": "DeprecatedProcessApi", + "suggest": "", + "rule": "This API of process is obsolete in ArkTS 1.1. It's no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 1, + "endLine": 25, + "endColumn": 8, + "problem": "DeprecatedProcessApi", + "suggest": "", + "rule": "This API of process is obsolete in ArkTS 1.1. It's no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets.json b/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.ets.json new file mode 100644 index 0000000000..ca88f857e9 --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_process_deprecated_apis.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/main/oh_modules/@kit.ArkTS.d.ets b/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets index fdb4d44008..48d558071e 100644 --- a/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets +++ b/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets @@ -17,4 +17,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'; -export { ArkTSUtils } from '../oh_modules/@arkts.utils'; \ No newline at end of file +export { ArkTSUtils } from '../oh_modules/@arkts.utils'; +export { process } from '../oh_modules/@ohos.process'; diff --git a/ets2panda/linter/test/main/oh_modules/@ohos.process.d.ets b/ets2panda/linter/test/main/oh_modules/@ohos.process.d.ets new file mode 100644 index 0000000000..33507584b0 --- /dev/null +++ b/ets2panda/linter/test/main/oh_modules/@ohos.process.d.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. + */ + +export namespace process { + function isAppUid(v: number): boolean; + function getUidForName(v: string): number; + function getThreadPriority(v: number): number; + function getSystemConfig(name: number): number; + function getEnvironmentVar(name: string): string; + function exit(code: number): void; + function kill(signal: number, pid: number): boolean; +} -- Gitee