diff --git a/ets2panda/linter/package.json b/ets2panda/linter/package.json index c17b2cbeb3aef49fb06aa485044b7202c9e75c51..31e15aa31b81377cae976848680b77b9297b59a9 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 071430d2a9fd5ef5249b35e3aa3c149fe5fb5974..a6b6aab45225e89d5622f23b6b3aa76202706ea9 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 dbd43cdcec1ff844372b66f210715ff9365fa6f4..604307a2b1dd2e31eceb79cb0a989e66fba90af3 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 14d5afecdac6b4c20894e0505b84206f8e3b6e42..1228da6296b9df80fff4e3cb412cbb813207cce4 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 6413a4c2429cd6a1bbb9935e8d226399df16f985..fc6c2e2067827e21db80dd0855577d6510500ca2 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 5467025fde1b0ad44586634a510db764c39b2417..7c1ec684936d7199533cd44e31d6e847041ad271 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, @@ -102,7 +104,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[]; @@ -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); @@ -4107,6 +4111,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 +4248,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); @@ -5706,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/ArkTS2Rules.ts b/ets2panda/linter/src/lib/utils/consts/ArkTS2Rules.ts index 48ae3db9386bb8d8fac04b98fbb24a89a2eba7c8..bbb930f1c285aba3c16c2af26f9cddebf7050b42 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/ArkTSUtilsAPI.ts b/ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts new file mode 100644 index 0000000000000000000000000000000000000000..6dc6d3d6d6b5273b1411266ad55af70c329fdcb6 --- /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 0000000000000000000000000000000000000000..a7c1698e3ba00a285e16df6ee6b1c418f3832d4b --- /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/src/lib/utils/consts/ConcurrentAPI.ts b/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts index 61168c60e44f4ff0bc675bb5157a71855be9a31c..1e1270a602f16cfdff9d8c8b7fbeb5ea0db9235a 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 0000000000000000000000000000000000000000..1f7970802073582fa36b2341afda95f55e49d32c --- /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 0000000000000000000000000000000000000000..3ef4496a819a201892114d1c90f78ae32053c334 --- /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 0000000000000000000000000000000000000000..f33e9fbfec77fc33220a51f0c3b2ded2a0d1066c --- /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 0000000000000000000000000000000000000000..9f305c86d7ff705098b1e480818e125d5e6e3a4a --- /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": [] +} diff --git a/ets2panda/linter/test/main/arktsutils_module.ets b/ets2panda/linter/test/main/arktsutils_module.ets new file mode 100644 index 0000000000000000000000000000000000000000..3bfeec6005331e400a16972a240767cc9f567293 --- /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 0000000000000000000000000000000000000000..d8d3390ad9befeca9b595017d9eea0f5ada3d049 --- /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 0000000000000000000000000000000000000000..74272dd1b4c3d3e209c35eefd0b25cc69e7ec5c5 --- /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 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /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 0000000000000000000000000000000000000000..22421cb575b0915c990bbc0f4ea33af1fb5d93fb --- /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 0000000000000000000000000000000000000000..d8d3390ad9befeca9b595017d9eea0f5ada3d049 --- /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 0000000000000000000000000000000000000000..ffd36633b7f4b0d8800c061eaf06d43270da7155 --- /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 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /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 0000000000000000000000000000000000000000..f54a1fd4d6e9776e65d68aeb141b9e54d5163559 --- /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 0000000000000000000000000000000000000000..df9184137493b52f8f3387f4c5518985c9d24e5a --- /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 ed88cb6a2d9e247828708e561d02b06e512603ae..92d55b5c6e3fb8abf0dfb868afd2134d6e92be14 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 ee294d10703509acc8562f2a57d390e8d8ae4870..b2268a5804ecafdb4faaa5a07426c7d45351f80a 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,