From 39aa62ae6dfbdc87edcca6b592602d756d84656d Mon Sep 17 00:00:00 2001 From: lizhonghan Date: Thu, 24 Apr 2025 09:55:38 +0800 Subject: [PATCH 1/2] Implement SharedArrayBuffer deprecated Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IC3HCX Test scenarios:new tests add to the linter Change-Id: I69446dc681e79974339e4ad01c2dcdbfee752438 Signed-off-by: lizhonghan --- ets2panda/linter/package.json | 2 +- 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 | 19 +++++- .../src/lib/utils/consts/ArkTS2Rules.ts | 3 +- .../src/lib/utils/consts/ConcurrentAPI.ts | 1 + .../builtin/concurrent_decorator_arkts2.ets | 22 ++++++ .../concurrent_decorator_arkts2.ets.args.json | 19 ++++++ ...oncurrent_decorator_arkts2.ets.arkts2.json | 68 +++++++++++++++++++ .../concurrent_decorator_arkts2.ets.json | 17 +++++ 12 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets create mode 100644 ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.args.json create mode 100644 ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.arkts2.json create mode 100644 ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.json diff --git a/ets2panda/linter/package.json b/ets2panda/linter/package.json index c17b2cbeb3..31e15aa31b 100644 --- a/ets2panda/linter/package.json +++ b/ets2panda/linter/package.json @@ -21,7 +21,7 @@ "pack:linter": "rimraf bundle && mkdir bundle && npm pack --pack-destination 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/ohmurl,test/interop,test/sdkwhite,test/concurrent", + "test_all": "npm run testrunner -- -d test/main,test/rules,test/regression,test/extended_features,test/ohmurl,test/interop,test/sdkwhite,test/concurrent,test/builtin", "test_main": "npm run testrunner -- -d test/main", "test_ohmurl": "npm run testrunner -- -d test/ohmurl", "test_interop": "npm run testrunner -- -d test/interop", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 071430d2a9..a6b6aab452 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -313,3 +313,4 @@ cookBookTag[341] = 'ArkTS directly instantiated JS objects is not supported (ark cookBookTag[342] = 'Calling methods of JS Object directly in interop is not allowed (arkts-no-call-class-method)'; cookBookTag[343] = 'Usage of "instanceof" operator is not allowed with interop objects (arkts-no-import-obj-type)'; cookBookTag[344] = 'Interop objects can\'t be incremented or decremented (arkts-no-js-obj-increases-decreases)'; +cookBookTag[349] = 'SharedArrayBuffer is not supported (arkts-no-support-sharedarraybuffer)'; diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index dbd43cdcec..604307a2b1 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -220,3 +220,4 @@ faultsAttrs[FaultID.InstantiatedJsOjbect] = new FaultAttributes(341); faultsAttrs[FaultID.InteropCallObjectMethods] = new FaultAttributes(342); faultsAttrs[FaultID.InteropJsInstanceof] = new FaultAttributes(343); faultsAttrs[FaultID.InteropIncrementDecrement] = new FaultAttributes(344); +faultsAttrs[FaultID.SharedArrayBufferDeprecated] = new FaultAttributes(349); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index 14d5afecda..1228da6296 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -208,3 +208,4 @@ faultDesc[FaultID.InteropCallObjectMethods] = 'Interop call methods in object'; faultDesc[FaultID.InteropJsInstanceof] = 'Instanceof operator with interop'; faultDesc[FaultID.InteropIncrementDecrement] = 'Interop increment or decrement'; faultDesc[FaultID.InteropObjectLiteralCompatibility] = 'Interop Object Literal incompatible'; +faultDesc[FaultID.SharedArrayBufferDeprecated] = 'SharedArrayBuffer is not supported'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index 6413a4c242..fc6c2e2067 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -209,6 +209,7 @@ export enum FaultID { InteropCallObjectMethods, InteropJsInstanceof, InteropIncrementDecrement, + SharedArrayBufferDeprecated, // 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 5467025fde..524286eba6 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -102,7 +102,7 @@ import { ARKTS_IGNORE_DIRS_OH_MODULES } from './utils/consts/ArktsIgnorePaths'; import type { ApiInfo, ApiListItem } from './utils/consts/SdkWhitelist'; import { ApiList, SdkProblem } from './utils/consts/SdkWhitelist'; import * as apiWhiteList from './data/SdkWhitelist.json'; -import { USE_SHARED, USE_CONCURRENT } from './utils/consts/ConcurrentAPI'; +import { USE_SHARED, USE_CONCURRENT, ESLIB_SHAREDMEMORY_FILENAME } from './utils/consts/ConcurrentAPI'; interface InterfaceSymbolTypeResult { propNames: string[]; @@ -4107,6 +4107,7 @@ export class TypeScriptLinter { private handleNewExpression(node: ts.Node): void { const tsNewExpr = node as ts.NewExpression; + this.handleSharedArrayBuffer(tsNewExpr); this.handleSdkDuplicateDeclName(tsNewExpr); if (this.options.advancedClassChecks || this.options.arkts2) { @@ -4243,9 +4244,25 @@ export class TypeScriptLinter { } } + private handleSharedArrayBuffer(node: ts.TypeReferenceNode | ts.NewExpression): void { + if (!this.options.arkts2) { + return; + } + const typeNameIdentifer = ts.isTypeReferenceNode(node) ? node.typeName : node.expression; + const decls = this.tsUtils.trueSymbolAtLocation(typeNameIdentifer)?.getDeclarations(); + const isSharedMemoryEsLib = decls?.some((decl) => { + const srcFileName = decl.getSourceFile().fileName; + return srcFileName.endsWith(ESLIB_SHAREDMEMORY_FILENAME); + }); + if (isSharedMemoryEsLib) { + this.incrementCounters(typeNameIdentifer, FaultID.SharedArrayBufferDeprecated); + } + } + private handleTypeReference(node: ts.Node): void { const typeRef = node as ts.TypeReferenceNode; + this.handleSharedArrayBuffer(typeRef); this.handleSdkDuplicateDeclName(typeRef); this.handleSdkConstructorIface(typeRef); diff --git a/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts b/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts index 48ae3db938..bbb930f1c2 100644 --- a/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts +++ b/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts @@ -102,5 +102,6 @@ export const arkts2Rules: number[] = [ 341, 342, 343, - 344 + 344, + 349 ]; diff --git a/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts b/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts index 61168c60e4..1e1270a602 100644 --- a/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts +++ b/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts @@ -15,3 +15,4 @@ export const USE_CONCURRENT = 'use concurrent'; export const USE_SHARED = 'use shared'; +export const ESLIB_SHAREDMEMORY_FILENAME = 'lib.es2017.sharedmemory.d.ts'; diff --git a/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets b/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets new file mode 100644 index 0000000000..1f79708020 --- /dev/null +++ b/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024-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. + */ + +let typeName: SharedArrayBuffer; // ERROR +let sab: SharedArrayBuffer = new SharedArrayBuffer(0) // 2 ERROR + +type NewTypeName = SharedArrayBuffer // ERROR +let newTypeName: NewTypeName +// disable use new NewTypeName() +let ntn: NewTypeName = new SharedArrayBuffer(0) // ERROR \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.args.json b/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.args.json new file mode 100644 index 0000000000..3ef4496a81 --- /dev/null +++ b/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.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/builtin/concurrent_decorator_arkts2.ets.arkts2.json b/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.arkts2.json new file mode 100644 index 0000000000..f33e9fbfec --- /dev/null +++ b/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.arkts2.json @@ -0,0 +1,68 @@ +{ + "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": 16, + "column": 15, + "endLine": 16, + "endColumn": 32, + "problem": "SharedArrayBufferDeprecated", + "suggest": "", + "rule": "SharedArrayBuffer is not supported (arkts-no-support-sharedarraybuffer)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 10, + "endLine": 17, + "endColumn": 27, + "problem": "SharedArrayBufferDeprecated", + "suggest": "", + "rule": "SharedArrayBuffer is not supported (arkts-no-support-sharedarraybuffer)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 34, + "endLine": 17, + "endColumn": 51, + "problem": "SharedArrayBufferDeprecated", + "suggest": "", + "rule": "SharedArrayBuffer is not supported (arkts-no-support-sharedarraybuffer)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 20, + "endLine": 19, + "endColumn": 37, + "problem": "SharedArrayBufferDeprecated", + "suggest": "", + "rule": "SharedArrayBuffer is not supported (arkts-no-support-sharedarraybuffer)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 28, + "endLine": 22, + "endColumn": 45, + "problem": "SharedArrayBufferDeprecated", + "suggest": "", + "rule": "SharedArrayBuffer is not supported (arkts-no-support-sharedarraybuffer)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.json b/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.ets.json new file mode 100644 index 0000000000..9f305c86d7 --- /dev/null +++ b/ets2panda/linter/test/builtin/concurrent_decorator_arkts2.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 From 8fadf4c43dc5424b0e168dbc1406dede0aa66a6e Mon Sep 17 00:00:00 2001 From: c30058867 Date: Wed, 23 Apr 2025 16:49:23 +0800 Subject: [PATCH 2/2] Fix import and call collections/ASON check Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IC3GKF Signed-off-by: caiy Change-Id: I36bf5969488106af4971cb32fe08e7af0b5aa217 --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 24 ++- .../src/lib/utils/consts/ArkTSUtilsAPI.ts | 17 ++ .../src/lib/utils/consts/CollectionsAPI.ts | 17 ++ .../linter/test/main/arktsutils_module.ets | 35 +++++ .../test/main/arktsutils_module.ets.args.json | 19 +++ .../main/arktsutils_module.ets.arkts2.json | 58 +++++++ .../test/main/arktsutils_module.ets.json | 17 ++ .../linter/test/main/collections_module.ets | 40 +++++ .../main/collections_module.ets.args.json | 19 +++ .../main/collections_module.ets.arkts2.json | 148 ++++++++++++++++++ .../test/main/collections_module.ets.json | 17 ++ .../main/oh_modules/@arkts.collections.d.ets | 28 ++++ .../test/main/oh_modules/@arkts.utils.d.ets | 22 +++ .../test/main/oh_modules/@kit.ArkTS.d.ets | 4 +- .../property_access_by_index.ets.arkts2.json | 20 +++ 15 files changed, 481 insertions(+), 4 deletions(-) create mode 100644 ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts create mode 100644 ets2panda/linter/src/lib/utils/consts/CollectionsAPI.ts create mode 100644 ets2panda/linter/test/main/arktsutils_module.ets create mode 100644 ets2panda/linter/test/main/arktsutils_module.ets.args.json create mode 100644 ets2panda/linter/test/main/arktsutils_module.ets.arkts2.json create mode 100644 ets2panda/linter/test/main/arktsutils_module.ets.json create mode 100644 ets2panda/linter/test/main/collections_module.ets create mode 100644 ets2panda/linter/test/main/collections_module.ets.args.json create mode 100644 ets2panda/linter/test/main/collections_module.ets.arkts2.json create mode 100644 ets2panda/linter/test/main/collections_module.ets.json create mode 100644 ets2panda/linter/test/main/oh_modules/@arkts.collections.d.ets create mode 100644 ets2panda/linter/test/main/oh_modules/@arkts.utils.d.ets diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 524286eba6..7c1ec68493 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -83,6 +83,8 @@ import { BUILTIN_GENERIC_CONSTRUCTORS } from './utils/consts/BuiltinGenericConst import { DEFAULT_DECORATOR_WHITE_LIST } from './utils/consts/DefaultDecoratorWhitelist'; import { INVALID_IDENTIFIER_KEYWORDS } from './utils/consts/InValidIndentifierKeywords'; import { WORKER_MODULES, WORKER_TEXT } from './utils/consts/WorkerAPI'; +import { COLLECTIONS_TEXT, COLLECTIONS_MODULES } from './utils/consts/CollectionsAPI'; +import { ARKTSUTILS_TEXT, ARKTSUTILS_MODULES } from './utils/consts/ArkTSUtilsAPI'; import { ETS_PART, PATH_SEPARATOR } from './utils/consts/OhmUrl'; import { DOUBLE_DOLLAR_IDENTIFIER, @@ -3092,6 +3094,8 @@ export class TypeScriptLinter { if (isArkTs2) { this.checkWorkerSymbol(tsIdentSym, node); + this.checkCollectionsSymbol(tsIdentSym, node); + this.checkArkTSUtilsSymbol(tsIdentSym, node); } if (isArkTs2 && tsIdentifier.text === LIKE_FUNCTION && isStdLibrarySymbol(tsIdentSym)) { this.incrementCounters(node, FaultID.ExplicitFunctionType); @@ -5723,21 +5727,35 @@ export class TypeScriptLinter { } } + private checkArkTSUtilsSymbol(symbol: ts.Symbol, node: ts.Node): void { + this.checkSymbol(symbol, node, ARKTSUTILS_TEXT, ARKTSUTILS_MODULES, FaultID.LimitedStdLibApi); + } + + private checkCollectionsSymbol(symbol: ts.Symbol, node: ts.Node): void { + this.checkSymbol(symbol, node, COLLECTIONS_TEXT, COLLECTIONS_MODULES, FaultID.LimitedStdLibApi); + } + private checkWorkerSymbol(symbol: ts.Symbol, node: ts.Node): void { - if (symbol.name === WORKER_TEXT) { + this.checkSymbol(symbol, node, WORKER_TEXT, WORKER_MODULES, FaultID.LimitedStdLibApi); + } + + private checkSymbol(symbol: ts.Symbol, node: ts.Node, symbolName: string, modules: string[], faultId: FaultID): void { + if (symbol.name === symbolName) { const decl = TsUtils.getDeclaration(symbol); if (!decl) { return; } + const sourceFile = decl.getSourceFile(); const fileName = path.basename(sourceFile.fileName); + if ( - WORKER_MODULES.some((moduleName) => { + modules.some((moduleName) => { return fileName.startsWith(moduleName); }) ) { - this.incrementCounters(node, FaultID.LimitedStdLibApi); + this.incrementCounters(node, faultId); } } } diff --git a/ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts b/ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts new file mode 100644 index 0000000000..6dc6d3d6d6 --- /dev/null +++ b/ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts @@ -0,0 +1,17 @@ +/* + * 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 ARKTSUTILS_TEXT = 'ASON'; +export const ARKTSUTILS_MODULES = ['@arkts.utils', '@kit.ArkTS']; diff --git a/ets2panda/linter/src/lib/utils/consts/CollectionsAPI.ts b/ets2panda/linter/src/lib/utils/consts/CollectionsAPI.ts new file mode 100644 index 0000000000..a7c1698e3b --- /dev/null +++ b/ets2panda/linter/src/lib/utils/consts/CollectionsAPI.ts @@ -0,0 +1,17 @@ +/* + * 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 COLLECTIONS_TEXT = 'collections'; +export const COLLECTIONS_MODULES = ['@arkts.collections', '@kit.ArkTS']; diff --git a/ets2panda/linter/test/main/arktsutils_module.ets b/ets2panda/linter/test/main/arktsutils_module.ets new file mode 100644 index 0000000000..3bfeec6005 --- /dev/null +++ b/ets2panda/linter/test/main/arktsutils_module.ets @@ -0,0 +1,35 @@ +/* + * 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 { utils } from './oh_modules/@arkts.utils'; + +import { utils as ArkTSUtilsAlias } from './oh_modules/@arkts.utils'; + +import { utils as kitArkTSUtils } from './oh_modules/@kit.ArkTS'; + +import { utils as definedArkTSUtils } from 'user_defined_worker'; //legal + +export { utils } from './oh_modules/@arkts.utils'; + +function tesCollectionsUsage() { + + const utils1: string = utils.ASON.stringify(1); + + const utils2 = ArkTSUtilsAlias.ASON.stringify(1); + + const utils3 = kitArkTSUtils.ASON.stringify(1); + + const utils4: string = ArkTSUtilsAlias.ASON.stringify(1); +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arktsutils_module.ets.args.json b/ets2panda/linter/test/main/arktsutils_module.ets.args.json new file mode 100644 index 0000000000..d8d3390ad9 --- /dev/null +++ b/ets2panda/linter/test/main/arktsutils_module.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": "" + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arktsutils_module.ets.arkts2.json b/ets2panda/linter/test/main/arktsutils_module.ets.arkts2.json new file mode 100644 index 0000000000..74272dd1b4 --- /dev/null +++ b/ets2panda/linter/test/main/arktsutils_module.ets.arkts2.json @@ -0,0 +1,58 @@ +{ + "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": 28, + "column": 32, + "endLine": 28, + "endColumn": 36, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 34, + "endLine": 30, + "endColumn": 38, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 32, + "endLine": 32, + "endColumn": 36, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 42, + "endLine": 34, + "endColumn": 46, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arktsutils_module.ets.json b/ets2panda/linter/test/main/arktsutils_module.ets.json new file mode 100644 index 0000000000..ca88f857e9 --- /dev/null +++ b/ets2panda/linter/test/main/arktsutils_module.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/collections_module.ets b/ets2panda/linter/test/main/collections_module.ets new file mode 100644 index 0000000000..22421cb575 --- /dev/null +++ b/ets2panda/linter/test/main/collections_module.ets @@ -0,0 +1,40 @@ +/* + * 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 { collections } from './oh_modules/@arkts.collections'; + +import { collections as collectionsAlias } from './oh_modules/@arkts.collections'; + +import { collections as kitCollections } from './oh_modules/@kit.ArkTS'; + +import { collections as definedCollections } from 'user_defined_worker'; //legal + +export { collections } from './oh_modules/@arkts.collections'; + +function tesCollectionsUsage() { + + const collections1: collections.Array = new collections.Array(); + + const collections2 = new collectionsAlias.Array(); + + const collections3 = new kitCollections.Array(); + + let collections4: collectionsAlias.Array; + + const collections5: collectionsAlias.Array = new collectionsAlias.Array(); + + let collections6: definedCollections.Array; // legal + +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/collections_module.ets.args.json b/ets2panda/linter/test/main/collections_module.ets.args.json new file mode 100644 index 0000000000..d8d3390ad9 --- /dev/null +++ b/ets2panda/linter/test/main/collections_module.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": "" + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/collections_module.ets.arkts2.json b/ets2panda/linter/test/main/collections_module.ets.arkts2.json new file mode 100644 index 0000000000..ffd36633b7 --- /dev/null +++ b/ets2panda/linter/test/main/collections_module.ets.arkts2.json @@ -0,0 +1,148 @@ +{ + "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": 16, + "column": 10, + "endLine": 16, + "endColumn": 21, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 10, + "endLine": 18, + "endColumn": 21, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 25, + "endLine": 18, + "endColumn": 41, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 10, + "endLine": 20, + "endColumn": 21, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 25, + "endLine": 20, + "endColumn": 39, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 10, + "endLine": 24, + "endColumn": 21, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 23, + "endLine": 28, + "endColumn": 34, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 55, + "endLine": 28, + "endColumn": 66, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 28, + "endLine": 30, + "endColumn": 44, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 28, + "endLine": 32, + "endColumn": 42, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 21, + "endLine": 34, + "endColumn": 37, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 23, + "endLine": 36, + "endColumn": 39, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 60, + "endLine": 36, + "endColumn": 76, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/collections_module.ets.json b/ets2panda/linter/test/main/collections_module.ets.json new file mode 100644 index 0000000000..ca88f857e9 --- /dev/null +++ b/ets2panda/linter/test/main/collections_module.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/@arkts.collections.d.ets b/ets2panda/linter/test/main/oh_modules/@arkts.collections.d.ets new file mode 100644 index 0000000000..f54a1fd4d6 --- /dev/null +++ b/ets2panda/linter/test/main/oh_modules/@arkts.collections.d.ets @@ -0,0 +1,28 @@ +/* + * 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 collections { + export class Array implements ConcatArray { + constructor(); + } + + export class Map { + constructor(entries?: readonly (readonly [K, V])[] | null); + } + + export interface ConcatArray { + + } +} \ 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 new file mode 100644 index 0000000000..df91841374 --- /dev/null +++ b/ets2panda/linter/test/main/oh_modules/@arkts.utils.d.ets @@ -0,0 +1,22 @@ +/* + * 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 utils { + namespace ASON { + function stringify(value: Object | null | undefined): string; + } +} + +export default utils; \ 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 ed88cb6a2d..92d55b5c6e 100644 --- a/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets +++ b/ets2panda/linter/test/main/oh_modules/@kit.ArkTS.d.ets @@ -13,4 +13,6 @@ * limitations under the License. */ -export { worker } from '../oh_modules/@ohos.worker'; \ No newline at end of file +export { worker } from '../oh_modules/@ohos.worker'; +export { collections } from '../oh_modules/@arkts.collections'; +export { utils } from '../oh_modules/@arkts.utils'; \ No newline at end of file diff --git a/ets2panda/linter/test/main/property_access_by_index.ets.arkts2.json b/ets2panda/linter/test/main/property_access_by_index.ets.arkts2.json index ee294d1070..b2268a5804 100644 --- a/ets2panda/linter/test/main/property_access_by_index.ets.arkts2.json +++ b/ets2panda/linter/test/main/property_access_by_index.ets.arkts2.json @@ -14,6 +14,16 @@ "limitations under the License." ], "result": [ + { + "line": 16, + "column": 10, + "endLine": 16, + "endColumn": 21, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, { "line": 22, "column": 3, @@ -254,6 +264,16 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", "severity": "ERROR" }, + { + "line": 177, + "column": 23, + "endLine": 177, + "endColumn": 34, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, { "line": 180, "column": 14, -- Gitee