From 32e28d59e872aa4602e2dc7a357cf17bb0b7e013 Mon Sep 17 00:00:00 2001 From: sniperc96 Date: Thu, 5 Jun 2025 19:24:49 +0800 Subject: [PATCH] api scan test Signed-off-by: sniperc96 --- ets2panda/linter/src/lib/CookBookMsg.ts | 1 + 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 | 26 +++++++++++++++++++ .../src/lib/utils/consts/ArkTS2Rules.ts | 3 ++- .../utils/consts/ArkuiDeprecatedInterfaces.ts | 23 ++++++++++++++++ 7 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 ets2panda/linter/src/lib/utils/consts/ArkuiDeprecatedInterfaces.ts diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index dc43661a29..624099fd63 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -368,6 +368,7 @@ cookBookTag[376] = 'Not supporting comparison between number type and bigint typ cookBookTag[377] = 'Non-decimal BigInt literals (0x/0o/0b) are not supported. Use decimal format instead (arkts-only-support-decimal-bigint-literal)'; cookBookTag[378] = 'Operator is not support (arkts-unsupport-operator)'; +cookBookTag[400] = 'Some UI interfaces are deprecated in ArkTS 1.2'; for (let i = 0; i <= cookBookTag.length; i++) { cookBookMsg[i] = ''; diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index 07f5587812..cf6ebfda64 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -264,3 +264,4 @@ faultsAttrs[FaultID.TsLikeCatchType] = new FaultAttributes(375); faultsAttrs[FaultID.NumericBigintCompare] = new FaultAttributes(376); faultsAttrs[FaultID.NondecimalBigint] = new FaultAttributes(377); faultsAttrs[FaultID.UnsupportOperator] = new FaultAttributes(378); +faultsAttrs[FaultID.UIInterfaceDeprecated] = new FaultAttributes(400); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index 49646a1965..e33c42dc76 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -252,3 +252,4 @@ faultDesc[FaultID.LocalStoragePropDecoratorNotSupported] = '"@LocalStorageProp" faultDesc[FaultID.PropFunctionNotSupported] = '"prop" function is not supported'; faultDesc[FaultID.SetAndPropFunctionNotSupported] = '"setAndProp" function is not supported'; faultDesc[FaultID.PropNeedCallMethodForDeepCopy] = 'Deep copy needs to call the specific method'; +faultDesc[FaultID.UIInterfaceDeprecated] = 'Some UI interfaces are deprecated'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index e9dd80975f..6081d1f6d8 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -253,6 +253,7 @@ export enum FaultID { PropFunctionNotSupported, SetAndPropFunctionNotSupported, PropNeedCallMethodForDeepCopy, + UIInterfaceDeprecated, // this should always be last enum LAST_ID } diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index b709829cf3..d04e8ed324 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -140,6 +140,7 @@ import { BaseTypeScriptLinter } from './BaseTypeScriptLinter'; import type { ArrayAccess, UncheckedIdentifier, CheckedIdentifier } from './utils/consts/RuntimeCheckAPI'; import { CheckResult } from './utils/consts/RuntimeCheckAPI'; import { NUMBER_LITERAL } from './utils/consts/RuntimeCheckAPI'; +import { arkuiDeprecatedInterfaces, interfaceFileName } from './utils/consts/ArkuiDeprecatedInterfaces'; interface InterfaceSymbolTypeResult { propNames: string[]; @@ -3752,6 +3753,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } this.handleInterfaceImport(node); + this.handleDeprecatedInterface(node); this.checkAsonSymbol(node); const tsIdentifier = node; this.handleTsInterop(tsIdentifier, () => { @@ -9356,4 +9358,28 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.incrementCounters(node, FaultID.NumericSemantics, autofix); } } + + private handleDeprecatedInterface(node: ts.Identifier): void { + if (!this.options.arkts2) { + return; + } + + const interfaceName = node.getText(); + if (!arkuiDeprecatedInterfaces.has(interfaceName)) { + return; + } + + const type = this.tsTypeChecker.getTypeAtLocation(node); + const symbol = type.getSymbol(); + const decl = TsUtils.getDeclaration(symbol); + const file = decl?.getSourceFile(); + const fileName = path.basename(file ? file.fileName : "undefined"); + console.log(`node: ${node.getText()}, fileName: ${fileName}`); + + if (!interfaceFileName.has(fileName)) { + return; + } + + this.incrementCounters(node, FaultID.UIInterfaceDeprecated); + } } diff --git a/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts b/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts index 2eaef243aa..2e2f6d041a 100644 --- a/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts +++ b/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts @@ -148,7 +148,8 @@ export const arkts2Rules: number[] = [ 375, 376, 377, - 378 + 378, + 400 ]; export const onlyArkts2SyntaxRules: Map = new Map([ diff --git a/ets2panda/linter/src/lib/utils/consts/ArkuiDeprecatedInterfaces.ts b/ets2panda/linter/src/lib/utils/consts/ArkuiDeprecatedInterfaces.ts new file mode 100644 index 0000000000..b105248b9b --- /dev/null +++ b/ets2panda/linter/src/lib/utils/consts/ArkuiDeprecatedInterfaces.ts @@ -0,0 +1,23 @@ +/* + * 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 const arkuiDeprecatedInterfaces: Set = new Set([ + "clip", + "WrappedBuilder" +]); + +export const interfaceFileName: Set = new Set([ + "common.d.ts" +]); \ No newline at end of file -- Gitee