diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 611a033828ee351a8d883852ab8fb3785bf19ed0..346a6ee6fcf395d9b7b69db94bc89be89dd84fbc 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 f0b8e41253982f18ac37463e1e3174e0224759f0..54b797cf89e3da74b1da3a1d4734c7154bc2aefe 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 8ace468f161fd5f32f2aac72700714920a6452b3..197af41f900356ac2f29827cd91d0558bb37ad29 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 d812eab32339364d3f430dad380008fcffea5ec2..011b01a0343bbc3e9e5880d592e8cc0fbccf831b 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 dd700b4ed503bf045a326a84be4b9149e4628771..1497b09c7e65f01dcd71bcf60cb19b75708a10d5 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 1e0dd75815109e868dd9b34384f35e41c0523c98..6182e43d69b1811276821e1359f6087abef17629 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 3149a493a1a8b608a3dafec14c6a44298cf12594..5051185d4718efcbccf592d3025f10ff630edf97 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 0000000000000000000000000000000000000000..c743b39bc25352fb3802ffe6937c8dd7898f9aa9 --- /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 0000000000000000000000000000000000000000..bc4d2071daf6e9354e711c3b74b6be2b56659066 --- /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 0000000000000000000000000000000000000000..56cdb58228917c703648debcf2e9aaf1ea3da96e --- /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 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /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 fdb4d4400856fb4f47dfe6e9bef5fabaa9cd492d..48d558071e75cded027b60394b4f0f0a53531920 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 0000000000000000000000000000000000000000..33507584b01a912e7c694ca35bfebd4c42f89aa7 --- /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; +}