diff --git a/ets2panda/linter/.eslintignore b/ets2panda/linter/.eslintignore index 4921dafdff623290a548b7d71f7006429fb2ea3d..4a1260f1df02b0d395bb2e90262cdca3c1fb5780 100644 --- a/ets2panda/linter/.eslintignore +++ b/ets2panda/linter/.eslintignore @@ -24,6 +24,8 @@ /test/** /test_extended_features/** /test_rules/** +/test_ts_import_ets/** +/arkTSTest/** /test_regression/** **.json **.js diff --git a/ets2panda/linter/.prettierignore b/ets2panda/linter/.prettierignore index 949e51dc38fe356c80fe3e93e5cc4882f1a0320b..5beb447e83b235494c6d8352224f29d2d73d1788 100644 --- a/ets2panda/linter/.prettierignore +++ b/ets2panda/linter/.prettierignore @@ -24,6 +24,8 @@ /test_extended_features/** /test_rules/** /test_regression/** +/test_ts_import_ets/** +/arkTSTest/** /third_party/** **.json **.js diff --git a/ets2panda/linter/arkTSTest/README.md b/ets2panda/linter/arkTSTest/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f017bc95eaee1a74a6836b934c3d22c2522996cb --- /dev/null +++ b/ets2panda/linter/arkTSTest/README.md @@ -0,0 +1,164 @@ +# ArkTS Syntax Constraint Rule Set Test Cases + +## Project Description + +This project aims to validate the constraint rules in [TypeScript to ArkTS Cookbook](https://gitee.com/openharmony/docs/blob/master/en/application-dev/quick-start/typescript-to-arkts-migration-guide.md) by script and output the test result report of the cases. + +The test cases are stored in the default directory called "testcase", and the results are stored in the "test_results" directory. + +## Project Requirements + +1. Provide a test case set for the ArkTS syntax constraint rule set. +2. The framework should be able to test the cases in the test case set and return the test results, including details of successful and failed cases. It should also support optional case blocking. +3. The test case set should cover all the ArkTS syntax rule sets, with at least 10 cases for each rule, including positive and negative examples. + +## Getting Started + +1. compile build typescript lib(pwd:third_party_typescript) + + ```shell + npm install + npm run build + npm run release + npm pack + ``` + + must run this step everytime if you change your code. + +2. Install project dependencies by running(pwd:third_party_typescript/tests/arkTSTest): + ```shell + rm -r ./node_modules/ ./package-lock.json # must run everytime + npm install # must run everytime + ``` +3. Place the test cases in the "testcase" folder. It is recommended to use the constraint name as the test case directory, such as "arkts-no-any-unknown". +4. Run the "run.js" script to perform the code testing. + + ```nodejs + node run.js -v1.0 + node run.js -v1.1 + ``` + + Run with a specified test case folder: + +```shell +node run.js -P:testcase/arkts-identifiers-as-prop-names // You can modify the test case to the specified directory in the current path +``` + +To get more details,you can use the command: + +```shell +node run.js --detail +``` + +Ignore a case directory or specific case: + +```shell +node run.js --ignore-list:testcase/arkts-identifiers-as-prop-names/case1.ets,testcase/arkts-no-any-unknown # Specify via --ignore-list or add to ignorecase.json +``` + +Example of `ignorecase.json`: + +```json +{ + "ignoreCase": ["testcase/arkts-identifiers-as-prop-names/xxxx.ets", "testcase/arkts-no-any-unknown"] +} +``` + +Generate test result files: + +```shell +node run.js -e +``` + +5. The generated test results are stored in the "test_results" directory, and basic test information is printed on the command line, such as: + +```plain +Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms +Failed test cases: +testcase/arkts-no-any-unknown/test2.ets +``` + +## Usage Instructions + +### Print details of failed test cases + +Support printing specific details of failed cases by using the `--detail` or `-D` command, such as: + +```shell +node run.js -D +``` + +Return details of failed cases: + +```plain +==> Expect the error in Line null The null character. Expect exception rules:null Actual error line 20 The 7character. Actual exception rules:Use explicit types instead of "any", "unknown" (arkts-no-any-unknown) Comparison Result:Fail! +Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms +Failed test cases: +testcase/arkts-no-any-unknown/test2.ets +``` + +### Block specific test cases + +1. Support blocking test case directories or specific cases by using the --ignore-list parameter, such as: + +```shell +# Ignore a single case +node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets +``` + +Return the test results: + +``` +Total number of test cases:44 Number of use cases passed:43 The number of use cases that failed:1 Total running time:6342ms +Ignored test cases: +testcase/arkts-no-any-unknown/test2.ets +``` + +2. Ignore multiple cases, separated by commas (support blocking directories): + +```shell +node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets,testcase/arkts-identifiers-as-prop-names +``` + +3. Support importing blocked cases through a configuration file: + Rename the "ignorecase.json.example" file in the root directory to "ignorecase.json" and configure the "ignoreCase" field for blocked cases, such as: + +```json +# ignorecase.json +{ +"ignoreCase":["testcase/arkts-no-any-unknown/test2.ets","testcase/arkts-identifiers-as-prop-names"] +} +``` + +Run the test case command: + +```shell +node run.js -D +``` + +Running results: + +```plain +// It can be observed that the configuration use case is properly masked +Total number of test cases:0 Number of use cases passed:0 The number of use cases that failed:0 Total running time:342ms +Ignored test cases: +testcase/arkts-no-any-unknown/test2.ets +testcase/arkts-identifiers-as-prop-names +``` + +#### Running Test Cases Script with Other Code + +Taking Python code as an example, refer to the file `run_test.py`: + +```python +import subprocess + +p = subprocess.Popen("node run.js --detail", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) +out, err = p.communicate() +print(out.decode('utf-8'), err.decode('utf-8')) + +return_code = p.returncode +print(return_code) +``` + +If there are any failed cases, an exception with the status code 1 will be thrown. If all cases pass, the correct status code 0 will be returned. diff --git a/ets2panda/linter/arkTSTest/README.zh-cn.md b/ets2panda/linter/arkTSTest/README.zh-cn.md new file mode 100644 index 0000000000000000000000000000000000000000..3573fc1c724b3e4099038dc4c75d7acb99a873d3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/README.zh-cn.md @@ -0,0 +1,166 @@ +# ArkTS语法约束规则集测试用例 + +## 项目说明 + +本项目旨在对[从TypeScript到ArkTS的适配规则](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/typescript-to-arkts-migration-guide.md)中的约束规则通过脚本方式进行验证并输出用例的测试结果报告。 + +其中测试用例默认存放在`testcase`目录,运行结果存放在`test_results`目录。 + +## 项目要求 + +1. 提供对ArkTS语法约束规则集的测试用例集 +2. 框架能对用例集中的用例进行测试,并返回测试结果,成功/失败用例详情。并支持可选屏蔽用例 +3. 用例集覆盖所有arkTS语法规则集,每条规则要有正例和反例覆盖,平均用例数不少于10个 + +## 快速开始 + +1. 编译构建typescript包(工作目录:third_party_typescript) + + ```shell + npm install + npm run build + npm run release + npm pack + ``` + + 每次修改代码必须执行以上步骤。 + +2. 安装项目依赖,执行(工作目录:third_party_typescript/tests/arkTSTest) + ```shell + rm -r ./node_modules/ ./package-lock.json # 每次必须执行 + npm install # 每次必须执行 + ``` +3. 将测试用例放至 testcase 文件夹,建议使用约束名称作为测试用例目录,如`arkts-no-any-unknown` +4. 运行`run.js`,进行代码测试 + + ```nodejs + node run.js -v1.0 + node run.js -v1.1 + ``` + + 指定测试用例文件夹运行: + + ```shell + node run.js -P:testcase/arkts-identifiers-as-prop-names // 可修改为当前路径下指定目录的测试用例 + ``` + + 打印详情: + + ```shell + node run.js --detail + ``` + + 屏蔽用例目录或具体用例: + + ```shell + node run.js --ignore-list:testcase/arkts-identifiers-as-prop-names/case1.ets,testcase/arkts-no-any-unknown # 通过--ignore-list指定或添加至 ignorecase.json + ``` + + `ignorecase.json`示例: + + ```json + { + "ignoreCase": ["testcase/arkts-identifiers-as-prop-names/xxxx.ets", "testcase/arkts-no-any-unknown"] + } + ``` + + 生成测试结果文件: + + ```shell + node run.js -e + ``` + +5. 生成的测试结果存放至 `test_results` 目录,命令行打印基本的测试信息,如: + + ```plain + Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms + Failed test cases: + testcase/arkts-no-any-unknown/test2.ets + ``` + +## 用法说明 + +### 打印失败测试用例详情 + +支持通过`--detail`或者`-D`指令打印具体失败用例细节,如运行指令: + +```shell +node run.js -D +``` + +返回未通过用例详情: + +```plain +==> Expect the error in Line null The null character. Expect exception rules:null Actual error line 20 The 7character. Actual exception rules:Use explicit types instead of "any", "unknown" (arkts-no-any-unknown) Comparison Result:Fail! +Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms +Failed test cases: +testcase/arkts-no-any-unknown/test2.ets +``` + +### 屏蔽指定测试用例 + +1. 支持使用 `--ignore-list` 参数传入屏蔽的用例目录或具体用例,如运行指令: + +```shell +# 忽略单个用例 +node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets +``` + +返回用例测试结果: + +``` +Total number of test cases:1 Number of use cases passed:1 The number of use cases that failed:0 Total running time:342ms +Ignored test cases: +testcase/arkts-no-any-unknown/test2.ets +``` + +2. 忽略多个用例,请使用`,`分割输入(支持屏蔽目录) + +```shell +node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets,testcase/arkts-identifiers-as-prop-names +``` + +3. 支持通过配置文件导入屏蔽用例: + +修改根目录下的`ignorecase.json.example`为`ignorecase.json`,配置`ignoreCase`字段为屏蔽用例字段,如: + +```json +# ignorecase.json +{ +"ignoreCase":["testcase/arkts-no-any-unknown/test2.ets","testcase/arkts-identifiers-as-prop-names"] +} +``` + +执行测试用例指令: + +```shell +node run.js -D +``` + +运行结果: + +```plain +// It can be observed that the configuration use case is properly masked +Total number of test cases:0 Number of use cases passed:0 The number of use cases that failed:0 Total running time:342ms +Ignored test cases: +testcase/arkts-no-any-unknown/test2.ets +testcase/arkts-identifiers-as-prop-names +``` + +### 使用其他代码运行测试用例脚本 + +以`Python`代码为例,参考文件`run_test.py`: + +```python +import subprocess + +p = subprocess.Popen("node run.js --detail", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) +out, err = p.communicate() +print(out.decode('utf-8'), err.decode('utf-8')) + +# 获取返回值 +return_code = p.returncode +print(return_code) +``` + +预期如果有用例不通过,则抛出异常状态码为`1`,如果用例全部通过,则返回正确状态码为`0`。 diff --git a/ets2panda/linter/arkTSTest/ignorecase.json b/ets2panda/linter/arkTSTest/ignorecase.json new file mode 100644 index 0000000000000000000000000000000000000000..9655b36851201e98f613abcd5c967229d2cb0dbb --- /dev/null +++ b/ets2panda/linter/arkTSTest/ignorecase.json @@ -0,0 +1,46 @@ +{ + "ignoreCase":["testcase/arkts-shared-module-exports/@arkts.lang.d.ets", + "testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.ts", + "testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.ts", + "testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.ts", + "testcase/arkts-limited-esobj/arkts-limited-esobj.d.ts", + "testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/case7.1.ts", + "testcase/arkts-no-import-assertions/path/module.ts", + "testcase/arkts-no-import-assertions/path/my-module.ts", + "testcase/arkts-no-misplaced-imports/path/module.ts", + "testcase/arkts-no-misplaced-imports/path/moduleName.ts", + "testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/math.ts", + "testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/utils.ts", + "testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/logger.ts", + "testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/case7.1.ts", + "testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/lib1-dependencie.ts", + "testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib1-dependencie.ts", + "testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib2-dependencie.ts", + "testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib3-dependencie.ts", + "testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib2-dependencie.ts", + "testcase/arkts-only-imported-variables/sendable_captured_variables_lib.d.ts", + "testcase/arkts-only-imported-variables/sendable_captured_variables_namespaceimport_lib.d.ts", + "testcase/arkts-no-ts-sendable-type-inheritance/@arkts.lang.d.ets", + "testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/@arkts.lang.d.ets", + "testcase/arkts-sendable-generic-types/@arkts.lang.d.ets", + "testcase/arkts-sendable-obj-init/@arkts.lang.d.ets", + "testcase/arkts-no-structural-typing/@arkts.lang.d.ets", + "testcase/common-lib/@arkts.lang.d.ets"], + "beta2":["testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.ets", + "testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.ets"], + "beta3":["testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.ets", + "testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-2-ok.ets", + "testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-1-ok.ets", + "testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-1-error.ets", + "testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-2-ok.ets", + "testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-1-error.ets", + "testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-2-ok.ets", + "testcase/arkts-sendable-function-decorator/arkts-sendable-function-decorator-1-error.ets", + "testcase/arkts-sendable-function-imported-variables/arkts-sendable-function-imported-variables-1-error.ets", + "testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-1-error.ets", + "testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-2-ok.ets", + "testcase/arkts-sendable-function-property/arkts-sendable-function-property-1-error.ets", + "testcase/arkts-sendable-typealias-declaration/arkts-sendable-typealias-declaration-1-error.ets", + "testcase/arkts-sendable-typealias-decorator/arkts-sendable-typealias-decorator-1-error.ets", + "testcase/arkts-shared-module-exports/shared-module.ets"] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/ignorecase.json.example b/ets2panda/linter/arkTSTest/ignorecase.json.example new file mode 100644 index 0000000000000000000000000000000000000000..51cd5d70ccd73712497ea59794b4dbb054a1566a --- /dev/null +++ b/ets2panda/linter/arkTSTest/ignorecase.json.example @@ -0,0 +1,3 @@ +{ + "ignoreCase":[] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/package.json b/ets2panda/linter/arkTSTest/package.json new file mode 100644 index 0000000000000000000000000000000000000000..9864569b036b55569913d37afa16578e0148383a --- /dev/null +++ b/ets2panda/linter/arkTSTest/package.json @@ -0,0 +1,14 @@ +{ + "name": "y", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "postinstall": "node scripts/install-ohos-typescript.mjs", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + } +} diff --git a/ets2panda/linter/arkTSTest/run.js b/ets2panda/linter/arkTSTest/run.js new file mode 100644 index 0000000000000000000000000000000000000000..e60589c57bc6d13e5d1d5ff6f60a8accad2d676b --- /dev/null +++ b/ets2panda/linter/arkTSTest/run.js @@ -0,0 +1,412 @@ +/* + * Copyright (c) 2023 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. + */ + + +const ts = require('typescript'); +const path = require('path'); +const fs = require('fs'); +const linter = require('./linterLib/linter_1_1/RunArkTSLinter'); +const TypeScriptLinter_1 = require("./lib/TypeScriptLinter"); +const InteropTypescriptLinter_1 = require("./lib/InteropTypescriptLinter"); +const Logger = require('./lib/Logger'); +const LoggerImpl = require('./src/LoggerImpl'); +Logger.Logger.init(new LoggerImpl.LoggerImpl()); + + +const ignoreCaseFilePath= path.join(__dirname, "ignorecase.json") +const compResults = {"detail":{}, 'failNum':0, "passedNum":0} +let consoleDetail = false; +let ignoreList = []; +let failTestCaseList = []; +let genResultFile = false; +let arktsVersion = '1.1'; +let enableBeta2 = false; +TypeScriptLinter_1.TypeScriptLinter.ideMode = true; +// TypeScriptLinter_1.TypeScriptLinter.testMode = true; +InteropTypescriptLinter_1.InteropTypescriptLinter.ideMode = true; +// InteropTypescriptLinter_1.InteropTypescriptLinter.testMode = true; +// Traverse the directory to find all test cases +function getAllETSFiles(filePath) { + let allFilePaths = []; + if (fs.existsSync(filePath)) { + const files = fs.readdirSync(filePath); + for (let i = 0; i < files.length; i++) { + let file = files[i]; // File name (excluding file path) + let currentFilePath = path.normalize(path.join(filePath, file)); + let stats = fs.lstatSync(currentFilePath); + if(ignoreList.includes(currentFilePath)){ + continue + } + if (stats.isDirectory()) { + allFilePaths = allFilePaths.concat(getAllETSFiles(currentFilePath)); + } else { + var index= currentFilePath.lastIndexOf("."); + var ext = currentFilePath.substring(index+1); + if (ext === 'ets' || ext === 'ts') { + allFilePaths.push(currentFilePath); + runComp(currentFilePath, file) + } + } + } + } else { + console.warn(`The specified directory ${filePath} Non-existent!`); + } + return allFilePaths; +} + +function runComp(currentFilePath, file){ + const result = runLinter(currentFilePath) + let jsonFile = currentFilePath.replace('.ets', '.json'); + jsonFile = jsonFile.replace('.ts', '.json'); + const checkfile = fs.existsSync(jsonFile); + if(checkfile){ + loadPares(jsonFile, result, currentFilePath, file) + }else{ + if (!currentFilePath.includes('-dependencie.ets') || ignoreList.includes(currentFilePath)) { + console.log(`Test cases ${currentFilePath} expected results are not added`) + } + } +} + +function forceUpdateExpected(expect, reality, jsonFile) { + let updateArray = []; + for (let i = 0; i < reality.length; i++) { + const realErrorItem = reality[i]; + const { line, character } = realErrorItem.file.getLineAndCharacterOfPosition(realErrorItem.start); + const realLine = { 'line': line + 1, 'character': character + 1 }; + const realMessageText = typeof (realErrorItem.messageText) === 'string' ? realErrorItem.messageText : realErrorItem.messageText.messageText; + let data = { + messageText: realMessageText, + expectLineAndCharacter: realLine + }; + updateArray.push(data); + } + if (arktsVersion === '1.0') { + expect.arktsVersion_1_0 = updateArray; + } else { + expect.arktsVersion_1_1 = updateArray; + } + let s = JSON.stringify(expect, null, 2); + fs.writeFileSync(jsonFile, s); +} + +// Compare the results with expectations and count the success and failure situations +function loadPares(jsonFile, result, currentFilePath, file){ + const dirName = path.dirname(currentFilePath) + let rules = "" + if (dirName.includes("\\")){ + rules = currentFilePath.split("\\")[currentFilePath.split("\\").length - 2] + }else{ + rules = currentFilePath.split("/")[currentFilePath.split("/").length - 2] + } + const testCaseFileName = file + dataStr = fs.readFileSync(jsonFile, "utf-8") + const expect = JSON.parse(dataStr) + // if need update expected files, insert forceUpdateExpected(expect, result, jsonFile) here. + let expectByVersion = arktsVersion === '1.0' ? expect.arktsVersion_1_0 : expect.arktsVersion_1_1; + if (expectByVersion === undefined) { + expectByVersion = []; + } + + const compResult = compareResult(expectByVersion, result); + compResult["testCaseName"] = testCaseFileName + if (Object.prototype.hasOwnProperty.call(compResults.detail, rules)) { + compResults["detail"][rules]["detail"].push(compResult) + compResults["detail"][rules]["testCaseNum"] += 1 + }else{ + compResults["detail"][rules] = {"detail":[compResult], "testCaseNum": 1, "failNum": 0, "passedNum": 0} + } + if(compResult.status){ + compResults["passedNum"] += 1 + compResults["detail"][rules]["passedNum"] += 1 + }else{ + failTestCaseList.push(currentFilePath) + if(consoleDetail){ + console.log(`Test cases ${currentFilePath} Failed!`) + for(let compDetail of compResult.detail){ + if(!compDetail.compResult){ + console.log(`==> Expect the error in Line ${compDetail.expectLineAndCharacter.line} The ${compDetail.expectLineAndCharacter.character} character. Expect exception rules:${compDetail.expectMessageText} Actual error line ${compDetail.realLineAndCharacter.line} The ${compDetail.realLineAndCharacter.character} character. Actual exception rules:${compDetail.realMessageText} Comparison Result:Fail!`) + } + } + } + compResults["failNum"] += 1 + compResults['detail'][rules]["failNum"] += 1 + } +} + + +// initial configuration +options = ts.readConfigFile('tsconfig.json', ts.sys.readFile).config.compilerOptions; +const allPath = ['*']; +Object.assign(options, { + 'emitNodeModulesFiles': true, + 'importsNotUsedAsValues': ts.ImportsNotUsedAsValues.Preserve, + 'module': ts.ModuleKind.ES2020, + 'moduleResolution': ts.ModuleResolutionKind.NodeJs, + 'noEmit': true, + 'target': ts.ScriptTarget.ES2021, + 'baseUrl': "/", + 'paths': { + '*': allPath + }, + 'lib': [ + 'lib.es2021.d.ts' + ], + 'types': [], + 'etsLoaderPath': 'null_sdkPath', + 'compatibleSdkVersion': 12, + 'compatibleSdkVersionStage': 'beta3' +}); + +// Calling the runlinter interface +function runLinter(rootName) { + nonStrictCheckParam = { + allowJS: true, + checkJs: false + }; + Object.assign(options, nonStrictCheckParam); + if (enableBeta2) { + beta2Param = { compatibleSdkVersionStage: 'beta2'}; + Object.assign(options, beta2Param); + } + builderProgram = ts.createIncrementalProgramForArkTs({ + rootNames: [path.join(process.cwd(), rootName)], + options: options, + }); + + let result = linter.runArkTSLinter(builderProgram); + return result; +} + +// Compare the difference between the expected value and the actual return value of the runlinter to determine if the test has passed +function compareResult(expect, reality){ + let isPass = true + const itemPassList = new Array() + if(reality.length == 0){ + if(expect.length == 0){ + // pass + isPass = true + }else{ + isPass = false + for(let expectInfo of expect){ + const compInfo = { + 'compResult':false, + 'realLineAndCharacter':{"line": null,"character": null}, + 'realMessageText':null, + 'expectLineAndCharacter':{"line": expectInfo.expectLineAndCharacter.line,"character": expectInfo.expectLineAndCharacter.character}, + 'expectMessageText':expectInfo.messageText, + } + itemPassList.push(compInfo) + } + } + }else{ + if(expect.length == 0){ + isPass = false + for(let realityInfo of reality){ + const { line, character } = realityInfo.file.getLineAndCharacterOfPosition(realityInfo.start) + const compInfo = { + 'compResult':false, + 'realLineAndCharacter':{"line": line + 1,"character": character + 1}, + 'realMessageText':realityInfo.messageText, + 'expectLineAndCharacter':{"line": null,"character": null}, + 'expectMessageText':null, + } + itemPassList.push(compInfo) + } + }else{ + if( reality.length > expect.length){ + isPass = false + for(let i=0; i path.normalize(x)); + + let filePathStats = fs.lstatSync(filePath) + if(!filePathStats.isDirectory()){ + runComp(filePath, path.basename(filePath)) + }else{ + getAllETSFiles(filePath) + } + endTime = process.uptime()*1000 + interval = (endTime - startTime); + const compReportDetail = {"compDetail": compResults, "compTime": interval, "failNum": compResults.failNum, "passedNum": compResults.passedNum} + const testCaseSum = compReportDetail.failNum + compReportDetail.passedNum + compReportDetail["testCaseSum"] = testCaseSum + console.log(`Total number of test cases:${testCaseSum} Number of use cases passed:${compResults.passedNum} The number of use cases that failed:${compResults.failNum} Total running time:${JSON.stringify(interval).split(".")[0]}ms. ArkTSVersion: ${arktsVersion}`) + if(genResultFile){ + writeResult(compReportDetail) + } + if (failTestCaseList.length > 0){ + console.log("Failed test cases:") + for(let testCase of failTestCaseList){ + console.log(testCase) + } + } + if(ignoreList.length>0){ + console.log("Ignored test cases:") + for(let ignoreCase of ignoreList){ + console.log(ignoreCase) + } + } + if(compReportDetail.failNum){ + process.exit(1) + } +} + +// get parameters +function getParam(){ + let pathArg = null + for(let key of process.argv){ + if(key.includes("-P:")){ + pathArg = key.replace("-P:", "") + } + if(key === "--detail" || key === "-D"){ + consoleDetail = true + } + if(key === "-e"){ + genResultFile = true + } + if(key.includes("--ignore-list:")){ + let ignoreStr = key.replace("--ignore-list:", "") + ignoreList = ignoreStr.split(",") + } + if (key === '-v1.0') { + arktsVersion = '1.0'; + } + if (key === '-v1.1') { + arktsVersion = '1.1'; + } + if (key === '-beta2') { + enableBeta2 = true; + } + } + return pathArg +} + +// execute +run() diff --git a/ets2panda/linter/arkTSTest/run_test.py b/ets2panda/linter/arkTSTest/run_test.py new file mode 100644 index 0000000000000000000000000000000000000000..887db074d73db0127673c3089e4149ea8350c309 --- /dev/null +++ b/ets2panda/linter/arkTSTest/run_test.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2023 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 subprocess + +p = subprocess.Popen("node run.js --detail", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) +out, err = p.communicate() +print(out.decode('utf-8'), err.decode('utf-8')) + +# Get return code +return_code = p.returncode +print(return_code) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3a18a537325233ec1cc96b83f0c9186b152cb2a4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-1-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use "as" for type conversion + +class Shape {} +class Circle extends Shape {x: number = 5} + +function createShape(): Shape { + return new Circle() +} + +let c = createShape() as Circle \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a994b4141a2f39eb9d52548134ad563471fae31 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-10-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Faulty type conversion + +const numberValue: any = 10; +const stringValue: string = numberValue; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..bd50c95aa266d944874e5802f6c6bb8fd4235f37 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-10-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 20 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 20 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 29 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..10f5f79cfb9c925d97ebb4a3a1c399460f9c1041 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-2-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use "" to transform Object Type + +class Shape {} +class Circle extends Shape {x: number = 5} + +function createShape(): Shape { + return new Circle() +} + +let c = createShape() + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e397fe02fcbfd051744ceaef38c0484c983941e4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 26, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 26, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e1e9bbd3d50909d380e111d4e5da116b3efa2ad6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-3-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use "new" to transform the reference type + +let e = (new Number(5.0)) instanceof Number + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1cf6cbbe4d2670a305b9e5403ef0d15cda7e6bb5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-4-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use "as" to convert reference types + +let e = (5.0 as Number) instanceof Number + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..093ec81d3d0f63396f7e252828930a0834b8136b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..53a4fda784ed2eeb808a8162ff4ad78055efb2b4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-5-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Uses "" transform string type + +const myValue: any = 42; +const myString: string = myValue; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..dc3a3b098357fd16bcc9a7f73162905773e1833c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 16 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 26 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 16 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e74c4f0be24d422a11518d4c7520de65762b873 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-6-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Converts a reference type to another reference type + +class Person { + name: string; + constructor(name: string) { + this.name = name; + } +} + +const person: Person = new Person("John"); +const personObj: object = person as object; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e229166332547c1500bc456513af3cb2ddbc4f55 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-7-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use "as" to convert native objects + +let date = new Date(); +let obj = date as object; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f031ef5d5912c8bc7b099d6c97806dad661b3182 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-8-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use a function to implement type conversion + +function toString(n: number): string { + return n.toString(); +} + +let str : string = toString(5); + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..19e4c3a73f9d0b2b76f988bf2fce9994d14f0582 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-9-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use the "new" type conversion + +const numberValue: number = 10; +const numberObject: Number = new Number(numberValue); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-as-casts/arkts-as-casts-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..99b58d9dc5e2ad05aa3c6456e03e5e65fccaecd7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-1-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The interface inherits the interface + +interface Control { + state: number +} + +interface SelectableControl extends Control { + select(): void +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba2af1004cbaed7cef2415977402d02bae0e5a6b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-10-ok.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The class implements multiple interfaces + +interface InterfaceA { + methodA(): void; +} + +class ClassA { + methodA(): void { + // ClassA method implementation + } +} + +class ClassB extends ClassA implements InterfaceA { + methodB(): void { + // InterfaceA method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f51000058e72485458b6c137ff18acd40296909c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-2-error.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Interface inheritance class + +class Control { + state: number = 0 +} + +interface SelectableControl extends Control { + select(): void +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..313c6709fefc3649c2b7eb677af2005225123d29 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interfaces cannot extend classes (arkts-extends-only-class)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interfaces cannot extend classes (arkts-extends-only-class)", + "expectLineAndCharacter": { + "line": 23, + "character": 37 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..08b9c69f0b93d1c44a59062cf9a9d0904755aa94 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-3-error.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Interface inheritance classes and interfaces + +class MyClass { + method(): void { + // Class method implementation + } +} + +interface InterfaceA extends MyClass, InterfaceB { + additionalMethod(): void; +} + +interface InterfaceB { + methodB(): void; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7e3d2a58f0aeb3e3f5b1087c0a7af767fcc4af71 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interfaces cannot extend classes (arkts-extends-only-class)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interfaces cannot extend classes (arkts-extends-only-class)", + "expectLineAndCharacter": { + "line": 25, + "character": 30 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6cf059b3837cfac66cbd88a1ccef85ed5d265142 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-4-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: An interface inherits multiple interfaces + +interface InterfaceA { + methodA(): void; +} + +interface InterfaceB { + methodB(): void; +} + +interface InterfaceC extends InterfaceA, InterfaceB { + methodC(): void; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c1f444accd40280510f6971aea8068192624712a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-5-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The interface inherits optional attributes + +interface InterfaceA { + propA?: number; +} + +interface InterfaceB extends InterfaceA { + propB?: string; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe9a5407d96c191c981a20b2f2dbcf5e60fe41e6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-6-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The interface inherits read-only attributes + +interface InterfaceA { + readonly propA: number; +} + +interface InterfaceB extends InterfaceA { + readonly propB: string; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..93ca920dfd0a46dbb341377fa0c6af3437a83d28 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-7-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The interface inherits the constructor. + +class MyClass { + constructor(x: number) { + // Class constructor implementation + } +} + +interface InterfaceA extends MyClass { + additionalMethod(): void; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7e3d2a58f0aeb3e3f5b1087c0a7af767fcc4af71 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interfaces cannot extend classes (arkts-extends-only-class)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interfaces cannot extend classes (arkts-extends-only-class)", + "expectLineAndCharacter": { + "line": 25, + "character": 30 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c37f6488bd1e9854dc08326040509ec4057b8ef0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-8-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Class implements the interface + +interface InterfaceA { + methodA(): void; +} + +class ClassA implements InterfaceA { + methodA(): void { + // InterfaceA method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e3a42071e4306e888315d6819b2c8086d9cf3a9d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-9-ok.ets @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The class implements multiple interfaces + +interface InterfaceA { + methodA(): void; +} + +interface InterfaceB { + methodB(): void; +} + +class ClassA implements InterfaceA, InterfaceB { + methodA(): void { + // InterfaceA method implementation + } + methodB(): void { + // InterfaceB method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-extends-only-class/arkts-extends-only-class-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d84c0e7dd80524ca323978282b21c4105dd289e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-1-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The basic data type is defined in the class +type: Positive example +*/ +class X { + public name: number = 0; +} +let x: X = { name: 1 }; +console.log(x.name); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..43f23d433e4ab8e36fcca28dcede455ef35c624f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-10-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +const animals: string[] = ["Dog", "Cat", "Lion", "Elephant"]; +// Use the find method to find the value +const foundAnimal: string | undefined = animals.find( + (animal) => animal === "Cat" +); +console.log(foundAnimal); // output: "Cat" or undefined (if not found) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b56747a5fc125cabbbb41d36e4aa541038ab770 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-11-error.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 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. + */ + +enum E1 { + str = '5' +} + +enum E2 { + num = 6 +} + +interface I { + one: string, + 2: string, // ERROR + '3': string, // OK + [E1.str]: string, // OK + [E2.num]: string // ERROR +} + +let vOne1: I = { + one: 'i1', + 2: 'i2', // ERROR + '3': 'i3', // OK + [E1.str]: 'e5', // OK + [E2.num]: 'e6' // ERROR +} + +let vOne2: I = { + one: 'i1', + 2: 'i2', // ERROR + '3': 'i3', // OK + '5': 'e5', // OK + 6: 'e6' // ERROR +} + + +class C { + public one?: string = 'c1'; + public 3?: string = 'c3'; // ERROR + public '4': string = 'c4'; // OK + public [E1.str]: string = 'e5'; // OK + public [E2.num]: string = 'e6'; // ERROR +} + +let vTwo1: C = { + one: 'c1', + 3: 'c3', // ERROR + '4': 'c4', // OK + [E1.str]: 'e5', // OK + [E2.num]: 'e6' // ERROR +} + +let vTwo2: C = { + one: 'c1', + 3: 'c3', // ERROR + '4': 'c4', // OK + '5': 'e5', // OK + 6: 'e6' // ERROR +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ec75554ade91317c62a232d39fb48785c93752ce --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-11-error.json @@ -0,0 +1,272 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 28, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 32, + "character": 16 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 35, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 36, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 37, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 40, + "character": 16 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 42, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 43, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 44, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 45, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 51, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 52, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 53, + "character": 10 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 54, + "character": 10 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 57, + "character": 16 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 59, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 60, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 61, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 62, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 65, + "character": 16 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 67, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 68, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 69, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 70, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 26, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 37, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 42, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 45, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 51, + "character": 10 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 54, + "character": 10 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 59, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 62, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 67, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 70, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..302387cfa623bab9c31af17bae8277054de1ff7a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-2-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:Gets the value by the attribute name +type: Positive example +*/ +class Person { + name: string; + age: number; + + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } +} + +const person = new Person("Alice", 30); + +console.log(person.name); // output : "Alice" diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe49283e31488ab01da44db9a410b4d35016396d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-3-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:Access array elements via numeric indexes +type: Positive example +*/ +const numbers: number[] = [1, 2, 3, 4, 5]; +const index: number = 2; +console.log(numbers[index]); // output: 3 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..70abed7ff4e4c077189954f91cc1e96c80d9ce23 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-4-ok.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:Access multidimensional array elements via numeric indexes +type: Positive example +*/ +const matrix: number[][] = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], +]; + +const row: number = 1; +const column: number = 2; +console.log(matrix[row][column]); // output: 6 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3eaaeac1edf9068b68a9a524f543a10ad2f5ba9c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-5-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:Access array elements via dynamic numeric indexing +type: Positive example +*/ +const fruits: string[] = ["Apple", "Banana", "Orange", "Grapes"]; +const dynamicIndex: number = 3; +console.log(fruits[dynamicIndex]); // output: "Grapes" diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e5f5bc52b8dbc462ccf8d7dfb2cbdc42b89f5e7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-6-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The object property is named Numeric +type: counterexample +*/ +class Obj { + 1: string = ""; + 2: string = ""; +} +let myObject: Obj = { + 1: "value1", + 2: "value2", +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a651a2a83c99d1cf8e2e9f54249c88273c6a07c5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-6-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 26, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 26, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e07f2a24114e2b8415dc70950546e8722d41c170 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-7-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The object property is named String +type: counterexample +*/ +class Obj { + "1": string = "123"; + "2": string = ""; +} +const o: Obj = { + "1": "12312", + "2": "ASDFA", +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..07cb573beaa5df969a8a51aea8569ed01ff8d550 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-7-error.json @@ -0,0 +1,40 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 16 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 26, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..51736706ecd1958abd2a453b3de29aa008c7c2a3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-8-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The object property name contains Symbol +type: counterexample +*/ +const firstName = Symbol("firstName"); +const lastName = Symbol("lastName"); +const person: any = { + [firstName]: "John", + [lastName]: "Doe", +}; + +console.log(person[firstName]); // output: John +console.log(person[lastName]); // output: Doe diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..02efcc179ab857da61703687441d8bde887e9788 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-8-error.json @@ -0,0 +1,76 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 21, + "character": 19 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 22, + "character": 18 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 15 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 21, + "character": 19 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 22, + "character": 18 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 15 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..03950b847cf69a45489a93e51e33c62f0493053f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-9-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The object property name contains Symbol.isConcatSpreadable +type: counterexample +*/ +class MyArray extends Array { + [Symbol.isConcatSpreadable] = true; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6f9411c88e643fe5f10b29ed9645760e3bc700e2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-identifiers-as-prop-names/arkts-identifiers-as-prop-names-9-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 22, + "character": 4 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 22, + "character": 4 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..02fc6391c928b88d817fff777c7dcd4a7781228a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-1-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The interface is implemented + +interface C { + foo(): void +} + +class C1 implements C { + foo() { } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ee1d888629969a17675b294ec1aa302cc72275c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-10-error.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: A class implements multiple class implements + +class MyClass1 { + // Class declaration +} + +interface MyClass2 { + // Class declaration +} + +class MyClass implements MyClass1, MyClass2 { + // Class implementation +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d91712ac8866a36d359e515ed6d78cf96cc74ef4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)", + "expectLineAndCharacter": { + "line": 27, + "character": 26 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)", + "expectLineAndCharacter": { + "line": 27, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..12a2c4f9607c8b34b54b88ff4291cddb4d7478d5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-2-error.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Classes are implemented + +class C { + foo(): void { } +} + +class C1 implements C { + foo() { } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6af722fa8294b4dc00db1fcbdea1899dd0e1bbd6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)", + "expectLineAndCharacter": { + "line": 23, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)", + "expectLineAndCharacter": { + "line": 23, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..12cd531b89ff087047070606015d21b62fc09346 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-3-error.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use both the "extends" and "implements" keywords in your class + +class MyBaseClass { + // Base class implementation +} + +class MyAnotherClass { + // Interface declaration +} + +class MyClass extends MyBaseClass implements MyAnotherClass { + // Class implementation +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..fb3a23b7c86e98d137be1755faabb37f0a9fbddd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)", + "expectLineAndCharacter": { + "line": 27, + "character": 46 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)", + "expectLineAndCharacter": { + "line": 27, + "character": 46 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5f75a19b411000cfb00fcf1244d474a0c6acb81 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-4-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use both the "extends" keyword in the interface + +interface MyBaseInterface { + // Base interface declaration +} + +interface MyOtherInterface { + // Interface declaration +} + +interface MyInterface extends MyBaseInterface, MyOtherInterface { + // Interface declaration +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..68ccfecd27949c196ba9a96ed2bd1d35b7c863d9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-5-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Create a class without any implements + +class MyClass { + //without implements +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..89b901f8d6e7412cada7e74d29e5cfeffe0db0eb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-6-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Create an interface without any implements + +interface MyInterface { + //without implements +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3b60e2a517d22cc092b3e19ec27a64e57fa359f2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-7-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The class implements a generic interface + +interface MyGenericInterface { + value: T; +} + +class MyClass implements MyGenericInterface { + value: string = 'abc'; +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7341192911ce8cd03da8b6f78465094bd58b23be --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-8-ok.ets @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The class implements multiple interface implements + +interface MyInterface1 { + // Interface declaration +} + +interface MyInterface2 { + // Interface declaration +} + +class MyClass implements MyInterface1, MyInterface2 { + // Class implementation +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e293810458f7cfe6fbe5228d9dbb35ff8b36405 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-9-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: A class implements an interface with methods + +interface MyMethodInterface { + // Interface declaration with a method + myMethod(): void; +} + +class MyClass implements MyMethodInterface { + // Class implementation + myMethod() { + // Method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-implements-only-iface/arkts-implements-only-iface-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4d03b0fed5114c7247a477445a38c53fe7484595 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +console.log(Object instanceof Array) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1438a843f57e3336e1cc9b731eb8dc3f8f9251e0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 20 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..02f487ca1ca3cf3c91d06ad6016f536b0d24bee8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +const strObj: String = new String("Hello, world"); +console.log(strObj instanceof String); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..21715094048d4d54680a613a917e4a1c1fa4e2fe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +class defined { + str:string = '666' +} +console.log(defined instanceof Array) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b8cdd6d8efcf06720d1ccad39005b1da55ab8f9f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b3058e1b8886a0114f7dd29fe5aac322d6984169 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +const numObj: Number = new Number(42); +console.log(numObj instanceof Number); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f563a5e217e02196c2bdee0faabcb2cde80ced94 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-3-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +const boolObj: Boolean = new Boolean(true); +console.log(boolObj instanceof Boolean); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..67fac3d36d40e3a473c3fb15e75b2177ebca62f2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-4-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +class ObjCreate { + num: number = 0 +} +const obj: ObjCreate = {num:1}; +console.log(obj instanceof Object); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2cfafb5ef0d7050ec0450becce2f82a00e253142 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-5-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +const arr: boolean[] = []; +console.log(arr instanceof Array); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e2c1a2f81505a5db353f03d5744d2d6e712cd10e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-6-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +const regex: RegExp = new RegExp('pattern'); +console.log(regex instanceof RegExp); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-instanceof-ref-types/arkts-instanceof-ref-types-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7bceba826c43ae89d2aaa4d76d6dcfb4bee4591 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: ESObject type for non local variables. +let responseData: ESObject = fetchDataFromExternalSource() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9d6a2baae1f4999ede92eb5fa656ef0185163640 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b029e33c53e8adef5b2f23165d78b1eab60554d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Explicitly annotate ESObject types. +function Fn() { + let f1: ESObject = foo() +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..92e6c192f7509dfcedc4a4dfac43663d5a594a16 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Initialize ESObject type variables using numerical values. +function Fn() { + let f2: ESObject = 1 +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3309e65b6d89ad32a469f840b8a1ee6312152ba3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1a8849b0408e19ec15a3e8e8a6eec4032faa73e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Using ESObject type assignment. +function Fn() { + let f1: ESObject = foo() + let f2 = f1 +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..cbf727b4ec57872323d97a1e57c1d816805fb76f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-2-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 20, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 20, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ebe695456f26342866f3b60f699eaa6c3fb940d4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Initialize ESObject type variables using objects. +function Fn() { + let f2: ESObject = {} +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3309e65b6d89ad32a469f840b8a1ee6312152ba3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d956d7d2e3c04d5d2fb8a6bb7bb6a76c1cbbcba4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: ESObject type variables passed to cross language calling functions. +function Fn() { + let f1: ESObject = foo() + bar(f1) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..aec14a932253257b39fd96cd227ace9e974dc7cf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-4-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Initializing ESObject type variables with arrays. +function Fn() { + let f2: ESObject = [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3309e65b6d89ad32a469f840b8a1ee6312152ba3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6c6a682e6dff3aa50da4cd33172cee7b8f0154c4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-5-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Initialize ESObject type variables with strings. +function Fn() { + let f2: ESObject = '' +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3309e65b6d89ad32a469f840b8a1ee6312152ba3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0708ba6e517b1c4aa439eb0c88ab7087a327dce4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-6-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Accessing properties of ESObject type variables. +function f() { + let f1: ESObject = [] + f1[1] +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..dd11bd159165d8d03ae60769470a4e85a1c4c683 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + }, + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + }, + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..61b90390c77c2dd1c70298b55047fe12c3f6b097 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-7-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Accessing properties of ESObject type variables. +function f() { + let f1: ESObject = {} + f1.prop +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..dd11bd159165d8d03ae60769470a4e85a1c4c683 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj-7-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + }, + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + }, + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj.d.ts b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f97e76369038d6bad4bc5db9877e8797dd017de2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-esobj/arkts-limited-esobj.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + +// Declaration used throughout the entire rule. +declare function foo(): any; +declare function bar(a: any): number; +declare function fetchDataFromExternalSource(): any; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..64d5f08285b8bbe4d1e3ab8d6802c47aa188bbf4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-1-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Object.getPrototypeOf + +class MyClass { + prop: string; + constructor() { + this.prop = 'Hello, World!'; + } +} + +const obj = new MyClass(); +const proto: Object = Object.getPrototypeOf(obj); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b163de6609281a356683a7e2e437bbc30001cd47 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 23 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 23 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a5a72fbc73fc93c0d85c6b12bbe1b1463e36c02 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-10-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Object.create + +interface P { + name: string +} + +const person: P = { + name: 'John' +}; + +console.log(Object.create(person).name); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..eea69bc5e47c88fe08fdd77a9e930a597aca999c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..777c729e4ad8ad3e7b727fcc7ed26324ae4a359f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-2-error.ets @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Object.hasOwnProperty + +interface O { + prop1?: string + prop2?: string +} + +const obj: O = { + prop1: 'value1', + prop2: 'value2' +}; + +if (obj.hasOwnProperty('prop1')) { + console.log('obj has prop1 Property。'); +} else { + console.log('obj doesn't has prop1 Property。'); +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3a58f6d99c98643577c0420b6266b5daea062198 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 29, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 29, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a627eb3c1775a750a69a35175b44bd955ee84ccd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-3-error.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Object.assign + +interface T1 { + a: number + b: number +} + +interface S1 { + b: number + c: number +} + +const target: T1 = { a: 1, b: 2 }; +const source: S1 = { b: 4, c: 5 }; + +const returnedTarget = Object.assign(target, source); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..199c0016c6fba2a4bd43c1ff4ff57fef174d5cd6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 32, + "character": 24 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 32, + "character": 24 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f46209a6242e471fc7cc61d41c8e85bd5ed007ee --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-4-ok.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Object.keys + +interface O { + a: string + b: number + c: boolean +} + +const obj: O = { + a: 'somestring', + b: 42, + c: false, +}; + +console.log(Object.keys(obj)); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d84c1d0c8ef6fa96b7d739603a3572ebf094d24b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-5-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Object.freeze + +interface O { + prop: number +} + +const obj: O = { + prop: 42, +}; + +Object.freeze(obj); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..868515a0f5a75b3813ccfc31fb68bb4133ddc3b9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba9348faed10cec77d7ed2825eff6b99ee11ee19 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-6-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Reflect.construct + +class Person { + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } +} + +const args = ['John', 25]; +const person: Object = Reflect.construct(Person, args); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e030c79e3b577bc00827b4b00c4a0fc0d0841937 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 24 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 27, + "character": 42 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 24 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 27, + "character": 42 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..db876ec88a97d49c30c283a68099370e3f2a8f6c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-7-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Reflect.has + +interface P { + name: string, + age: number +} + +const person: P = { + name: 'John', + age: 25 +}; + +console.log(Reflect.has(person, 'name')); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..57188f0732825fe93d8204918f39e4cc1a5c0e2a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-8-error.ets @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Object.seal + +interface O { + foo: string +} + +let obj: O = { + foo: 'bar' +}; + +Object.seal(obj); + +obj.foo = 'baz'; +console.log(obj.foo); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..868515a0f5a75b3813ccfc31fb68bb4133ddc3b9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..715e9e50731be1529409e07abdf03e94936c27f6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-9-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use Reflect.construct + +class Person { + name: string; + constructor(name: string) { + this.name = name; + } +} + +const obj = Reflect.construct(Person, ['John']); +console.log(obj instanceof Person); +console.log(obj.name); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..004ee4be0cb4c577b840f954b1295accf81c50f4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-stdlib/arkts-limited-stdlib-9-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 26, + "character": 13 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 26, + "character": 31 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 26, + "character": 13 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 26, + "character": 31 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a9c7090c355dc16fda18d948c319d9a2bfa662dd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Throw string. + +throw 'This is a string exception' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..75d1e341dffab692530bff3063486ade5d27e4f5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d8f18513a3806b4fce46f357635480b66b4bba63 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Throw an instance of the Error class. + +throw new Error('An error has occurred') \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..16cc6b5b5ea1b1cec18330b8c4f91fd29dcf1601 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Throw numbers. + +throw 42 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..75d1e341dffab692530bff3063486ade5d27e4f5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..484c95d02362d7e61f56cd9fea7a6aa6e9909372 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Throw custom error type. + +class CustomError extends Error { + constructor(message:string) { + super(message); + this.name = "CustomError"; + } +} + +throw new CustomError("Custom error information") \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7256eb660f33be7b6fc863dd4496f058cba961af --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Throw Boolean value. + +throw true diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..75d1e341dffab692530bff3063486ade5d27e4f5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9249a2cec9ba34892976e671a17f7a09a183438b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Throw custom error with error code. + +class CustomError extends Error { + constructor(code: number, message: string) { + super(message) + this.name = 'CustomError' + this.code = code // TS will report an error here + } +} + +throw new CustomError(500, 'Server error') diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5e8611a409bc455a94b5da64ff7c977124b26d5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Throw Object Literal. + +throw { message: "This is an object exception" } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c33112f320f80a35adcdc07bda93ad63968f3e93 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..359293440126aee4bba40902f224f77cf7ef0b70 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Throw type error. + +function multiply(a: number, b: string) { + if (typeof b !== 'number') { + throw new TypeError("The parameter 'b' must be a number") + } + return a * b +} + +multiply(5, 'abc') diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7a7baac596f8c015ac6bdd188738bd4f3e54b588 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Throw array. + +throw [1, 2, 3] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..75d1e341dffab692530bff3063486ade5d27e4f5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..74372732da60a012a13b7198356e0cf1af27c681 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Throwing a null pointer exception. + +function getValue(obj: any): string { + if (!obj) { + throw new Error('Object is empty') + } + return obj.value +} + +getValue(null) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..bd2459e47b93b492686bbb2c77497b9e8198b232 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-5-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 24 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 24 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1f31a0658e3ea0f16a9220a320701eb1d249701 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Throw function. + +throw function() { + console.log("This is a function exception"); +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..48bd4f936c5e701a745c946192aa06191d9447c7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 19, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fb2762db6e5e83d387d697628dd5af65ff21b92d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Throw Range Error. + +function divide(a: number, b: number): number { + if (b === 0) { + throw new RangeError("Divisor cannot be zero"); + } + return a / b; +} + +divide(10, 0) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-limited-throw/arkts-limited-throw-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..79849c5a4dc30b3689e4e98967331b122f9f3045 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-1-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 1. ArkTs does not allow accessing types in type through indexes +type point = {x: number, y: number} +type N = point['x'] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2236c8ece807639df34090d0198d5421a5693338 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..837b291ccb90ca350e651598f4793a3eb77375f3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-10-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 10. ArkTs does not allow accessing types in objects through indexes +let obj = { + x: number, + y: number +} +type N = obj['x'] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e2302ed0bc0d2d69d2698317e8245a10da99a49a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-10-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 11 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 11 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-11-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-11-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..48942d2d1c37efe11978c1b690b8568d44776ac9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-11-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 11. Types in objects can be accessed through dot operators +let obj = { + x: number, + y: number +} +type N = obj.x \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-11-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-11-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..aee1d5c724553bce159a99d5c5cffa023d064195 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-11-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b254f1efdae8d6700729a1992be2a0e4a86afa0c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-2-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 2. ArkTs allows access to types using dot operators +type point = {x: number, y: number} +type N = point.x \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..60d6c5a641aa45823893fcaac7c756ab8d39d5bf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-2-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..187bbbd09e5dbb24b3470e3397eee9f2eec51ae0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-3-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 3. ArkTs does not allow access to classes through indexes type +class point {x: number = 0, y: number = 0} +type N = point['x'] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c877bdaf9fb2f37d0a3d28e03307ecea8aa8236a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b411f05e832bbb8738f023c3ae8c43e19c254e2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-4-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 4. ArkTs allows access to types in a class through dot operators +class point {x: number = 0, y: number = 0} +type N = point.x \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc128f848acb6c1a5774f02368d32d521cdc685 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-5-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 5. ArkTs does not allow accessing the type of an instantiated object through an index +class point {x: number = 0, y: number = 0} +let p = new point() +type N = p['x'] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..156ef8ae4a8f743ec71dc842618e6a3691340413 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 20, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 20, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd949e4cb1c03f163f59bb5e64fac5ffde4b0c9c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-6-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 6. ArkTs allows access to types in instantiated objects through dot operators +class point {x: number = 0, y: number = 0} +let p = new point() +type N = p.x \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/arkts-no-aliases-by-index-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/arkts-no-aliases-by-index-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5d551b84cbd07f445c1d181927305e1a7cd672a6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/arkts-no-aliases-by-index-7-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 7. Even if the type in the ts file is introduced, ArkTs does not allow index access +import { point } from './case7.1' +type N = point['x'] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/arkts-no-aliases-by-index-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/arkts-no-aliases-by-index-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c877bdaf9fb2f37d0a3d28e03307ecea8aa8236a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/arkts-no-aliases-by-index-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/case7.1.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/case7.1.ts new file mode 100644 index 0000000000000000000000000000000000000000..ed415d84c70e7d736bc0a2049434a3b220af525c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-7-error/case7.1.ts @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + +type point = { x: number; y: number }; +export { point }; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c932800ef9047ae2c02b7d3a6cf909538d4093c1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-8-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 8. The types in the imported file can be accessed through the dot operator +import { point } from './case7.1' +type N = point.x diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..30160e8603dc6a48d6d0decacf5ac20e34a60469 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-9-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 9. ArkTs does not allow accessing types in arrays through indexes +let arr = [1,2,3] +type N = arr[0] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c877bdaf9fb2f37d0a3d28e03307ecea8aa8236a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-aliases-by-index/arkts-no-aliases-by-index-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..286cae28e948dd7dde67e4e4ef5e8b69a63f7790 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module "arkts-no-ambient-decls-utils" { + export function multiply(a: number, b: number): number; + } + + \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f289f00e2036ea70857c6513fecd7b735c78363a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7860dd7915161f5817bef86df8eb1340e9c4b95b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 { multiply } from 'arkts-no-ambient-decls-utils' +console.log(multiply(2, 3)); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c85995b94a4375e8f0943c293e8b80e02e95c22 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module 'arkts-no-ambient-decls-utils' { + export const version: string; +} + + \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f289f00e2036ea70857c6513fecd7b735c78363a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a22e2f1a43323b904f6253595cbd895d94fdde7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 { version } from 'arkts-no-ambient-decls-utils' +console.log(version); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a40b908698797f22ed937d5771d6453d322fc6fd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module 'arkts-no-ambient-decls-utils' { + export class MyClass { + constructor(name: string); + sayHello(): void; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f289f00e2036ea70857c6513fecd7b735c78363a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..74fb30057dee7421a60443608fb7e75e35e29640 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 { MyClass } from 'arkts-no-ambient-decls-utils'; + +let myInstance: string = new MyClass("John"); +myInstance.sayHello(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a2c04dfb2fcc7e2f9abde9f9aa5d6ace68058a5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module "arkts-no-ambient-decls-utils" { + export namespace MyNamespace { + function sayHello(name: string): void; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f289f00e2036ea70857c6513fecd7b735c78363a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..61128f24e10209011f65fa29e18210169de9a088 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 MyNamespace from 'arkts-no-ambient-decls-utils'; + +MyNamespace.sayHello("Alice"); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a07c3b8f942f5a4c6308f74a1afd4f13cc7dc27d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module 'arkts-no-ambient-decls-utils' { + export enum MyEnum { + Option1 = 1, + Option2 = 2, + Option3 = 3 + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f289f00e2036ea70857c6513fecd7b735c78363a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6c4a3c0725a70c754c0e6c4612fba5e8b53ca3da --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 { MyEnum } from 'arkts-no-ambient-decls-utils'; + +console.log(MyEnum.Option1); +console.log(MyEnum.Option2); +console.log(MyEnum.Option3); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-utils.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-utils.js new file mode 100644 index 0000000000000000000000000000000000000000..1b08220bfbb572fb52b50eb9e8f4ec9019162c6f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ambient-decls/arkts-no-ambient-decls-utils.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 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. + */ + + +function multiply(a, b) { + return a * b; +} + +const version = "@3.3.1"; + +class MyClass { + constructor(name) { + this.name = name; + } + + sayHello() { + console.log(`Hello, ${this.name}!`); + } +} + +let MyNamespace; +(function (MyNamespace) { + function sayHello(name) { + console.log(`Hello, ${name}!`); + } + MyNamespace.sayHello = sayHello; +})(MyNamespace || (MyNamespace = {})); + +("use strict"); +var MyEnum; +(function (MyEnum) { + MyEnum[(MyEnum["Option1"] = 1)] = "Option1"; + MyEnum[(MyEnum["Option2"] = 2)] = "Option2"; + MyEnum[(MyEnum["Option3"] = 3)] = "Option3"; +})(MyEnum || (MyEnum = {})); + +module.exports = { + version, + multiply: multiply, + MyClass, +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..534e8817b349549433d89022e8b5d84da7738459 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use any or unknown when defining variables. +let age: unknown = 30 +let aabc: any = 'xiaoming' + \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4ef8db3a288798e86b23e74db48c5dce64983b2d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1b6087b11c711e88ba662b4aa3d16f47cf58792 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: When defining variables, use specific types. If the type cannot be determined, use ESObject to avoid using ESObject. +let age: number = 30 +let aabc: string = 'xiaoming' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..019ff61660f351c5232d2d45a570f5e7efe5315d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-10-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Implicit Any Error. +function processInput(input) { + // Process input +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b439054a5bcd291aa09996f7b9ae32191304cb31 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 23 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 23 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a584573f112fa2010d9a39e6dd51158763a5ec1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-11-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Implicit Any Error. +let anyValue +let stringValue = anyValue diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cac2ff78e0983a4bd194d17ebfea07bc34e29fbd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-11-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..89869a4897caf03d77dec03c1a7cd3334e0c0740 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use any or unknown when defining the formal parameters of a function. +function greet(name: any ): void { + console.log(`${name},test`) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3f86c59b72d585358c2c583d55929920fddd1f1a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 22 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 22 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..007a66111494ab54cfe36974d3e7f8566d19a435 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Use specific types when defining formal parameters of functions +function greet(name: string ): void { + console.log(`${name},test`) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ce0f04f44edf9bd66526198d579c6993dbe9690 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use any or unknown when defining the return value of a function. +function add(x: number, y: number): any { + return x + y +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0534b5f049e18e501c3757a555d40621c72a2e78 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 37 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 37 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b3110333b4f7d6441c5b90094ab04e6a7c30b7a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Specify a specific type when defining the return value of a function. +function add(x: number, y: number): number { + return x + y +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e145f3e9c5a6024c8541894a60c3ab1fb199adfb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use any or unknown when defining the properties of an object. +const person:{name: any; age: unknown}={ + name:'xiaoming', + age:30 +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0bc2f48eccf33fda2b26454639be2553b53b2d69 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 21 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 31 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 40 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 21 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 31 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 40 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ecdfed94af8f0b35f531663f3812e0197b0f2d2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Specify a specific type when defining the properties of an object. +const person:{name: string; age: number}={ + name:'xiaoming', + age:30, +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..16620f351f363b6d74b4c51f7f562ab5e063e3b1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-4-ok.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 42 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 42 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..76fdddfe4e5c7ad0b26f8a6103b1bdd57992bdba --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use any or unknown when defining attributes in a class. +class Person { + name: any = 'xxx' +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..452cca04a329730aee490e9a2c0a415c3b3f816f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e4bf1f609b0f5c22deac8f6dc7a146a8dd2286c9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Specify specific types when defining attributes in a class. +class Person { + name: string = 'xxx' +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ddf5e44232e4e09f2b49ea5e72f4e3ad38d19a26 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use any or unknown when defining properties and methods in an interface. +interface Shape { + area(): any +} +class Circle implements Shape { + private radius: any + constructor(radius: any) {} + area(): any { + return Math.PI * this.radius * this.radius + } +} +const myCircle: Shape = new Circle(5) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8a21169a470c177c5a02ae07c74c7e1f40f85cec --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 19 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 23 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 24, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 19 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 23 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 24, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d20c3ff4130db98a056d624bee91b12419871bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Specify specific types when defining properties and methods in an interface. +interface Shape { + area(): number +} +class Circle implements Shape { + constructor(private radius: number) {} + area(): number { + return Math.PI * this.radius * this.radius + } +} +const myCircle: Shape = new Circle(5) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..834bfda0c6a70c0380f80db30ff66bb8454ad70d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-6-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 22, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 22, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1736cc5f088c05a4095fcba540a55eb59f5f4b2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Call to use any or unknown when defining generics. +function identity(arg: T): T { + return arg +} +const result: any = identity(42) +const message: unknown = identity('Test') diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3f811734a5e257b65dff9a20722f41bbb0f48a21 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 21, + "character": 15 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 16 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 21, + "character": 15 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 16 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e4bbe229ec06beedae874c3676c5fb3c04a7b3a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Generic call passing in specific types. +function identity(arg: T): T { + return arg +} +const result: number = identity(42) +const message: string = identity('Test') diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d8be6926185fa97d1112b5947cf684da10ad942 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-8-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Implicit Any Error. +class C { + a +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8a2ad4517b15eabcc0587b9b6dc5a8a51800a19c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b93844b94cb90a5d370f43760825f54c3f8b90b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-9-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Implicit Any Error. +let a diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4d84246d29de59f607bddf2416da1ab02f954628 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-any-unknown/arkts-no-any-unknown-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..249b354a0f2115339edd996a6d1cc0fcc5a40dfe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +const status = "success" as const; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a011ea214300184c7e963e17b0024c1b769ece7d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 17, + "character": 16 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 17, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0269adf149ea442697e2221768f3a863c661004 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-ok.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 status: string = "success" \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d8ed72630be84d9915c5730366ffcd0a99b5824e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +const count = 42 as const; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b8c4a0f5549f076645dbad8bc325e0ddd0c5d064 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 17, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1d2b2bb4d0c7e80d6d171c82e483077191c121c9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-ok.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +const count: number = 42 ; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..950da319a3cf5cef410f6491f1b207427b4ca098 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +const person = { + name: "John", + age: 30 +} as const; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..85321d88e4eda7216f3f7a5b00c8466792bc55a1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 17, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 16 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 16 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f41f5f50270e6870c7c61501538dfa42cf80d83a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonObj { + name: string = '' + age: number = 0 +} + +const person: PersonObj = { + name: "John", + age: 30 +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1c0b0611b66a543627cd1f462d63fa11acc040d7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +const numbers = [1, 2, 3] as const; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0de8440d0df122d493e0a013643365bc8b16879a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 17, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 17, + "character": 27 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5ec97905ac40c1eff457adfc98f6c027527fc090 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-ok.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +const numbersArray: number[] = [1, 2, 3] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..262e8c860a05f3c97ad5033c7d7e4ae531419d93 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +const config = { + theme: { + primaryColor: "blue", + secondaryColor: "green" + } +} as const; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..88c9630c583c8a53c131a28896394892f5da8a9a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 17, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"as const\" assertions are not supported (arkts-no-as-const)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..feb974d7a4af195ee124171297f726154e9d918f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +class ConfigAll { + theme: Theme = new Theme() +} + +class Theme { + primaryColor: string = '' + secondaryColor: string = '' +} + +const config: ConfigAll = { + theme: { + primaryColor: "blue", + secondaryColor: "green" + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-as-const/arkts-no-as-const-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1c9e44c6b0240cd2e2902a86958e784fc1a84a8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Declare a type that accepts two parameters and returns their sum. +interface MathOperation { + (x: number, y: number): number +} + +const add: MathOperation = (x, y) => x + y + +console.log(add(5, 3)) // Output: 8 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5a0a54fa95236bd03db42fd0a8df92e8b799683c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bba22d4b6448e5948207a59565d2d7cb5a98528a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using function types to replace calls in object types. +type MathOperation = (x: number, y: number) => number + +const add: MathOperation = (x, y) => { + return x + y +} + +console.log(add(5, 3)) // Output: 8 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b3f2105327832621feb84ebda4d95deba293dfa5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Declare a class type that accepts string parameters and returns their length. +interface LengthFunction { + (str: string): number +} + +const l: LengthFunction = (str) => str.length +console.log(l('Hello')) // Output: 5 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5a0a54fa95236bd03db42fd0a8df92e8b799683c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7c980011017a2f4fcfba937a564ba8128faaad5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using function types to replace calls in object types. +type LengthFunction1 = (str: string) => void + +const lengt: LengthFunction1 = (str) => { + return str.length +} + +console.log(lengt('Hello')) // Output: 5 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5abe0c73766d9f968700a27ec216c3a6027f246d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Declare a type that accepts a variable number of parameters and returns their sum. +interface SumFunction { + (...numbers: number[]): number +} + +const sum: SumFunction = (...numbers: number[]) => + numbers.reduce((sum, num) => sum + num, 0) +console.log(sum(1, 2, 3, 4)) // Output: 10 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5a0a54fa95236bd03db42fd0a8df92e8b799683c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6758a775f3da98de89fbec4abec2d685cedbde83 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using function types to replace calls in object types. +type SumFunction = (...numbers: number[]) => number + +const sum: SumFunction = (...numbers) => { + return numbers.reduce((a, b) => a + b, 0) +} + +console.log(sum(1,2,3,4)) // Output: 10 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..661eb470b4874651a18d9d6fce27fcc8ebb850c3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Declare a class type that accepts object parameters and returns the value of the specified property. +interface GetPropertyValueFunction { + (obj: object, key: string): string +} + +const getProperty: GetPropertyValueFunction = (obj, key) => obj[key] +console.log(getProperty({ name: 'John' }, 'name')) // Output: "John" diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a1bdcc828f45f5467be4e90a540c378e5f295c6f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 47 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 25 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 47 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 25 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c9b99467ee0598c667ab9e2bea78889e387d84eb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using function types to replace calls in object types. +type GetPropertyValueFunction1 = (obj: object, key: string) => string + +const getProperty1: GetPropertyValueFunction1 = (obj, key): string => { + return obj[key] +} + +class o { + name: string = '' +} +let n: o = { name: 'John' } + +console.log(getProperty1(n, 'name')) // Output: "John" diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..60e7877c3be9b5217f5e60dcf56799d3e4476528 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Declare a type that accepts callback functions as parameters. +interface CallbackFunction { + (callback: () => void): void +} + +const execute: CallbackFunction = (callback) => callback() +execute(() => console.log('Callback executed.')) // Output: "Callback executed." diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d1473bbfe5a48c8feca960f2170c79d5ad9b4d43 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c0c9cdafdabadde47e6665a8d6f0816e70318d13 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using function types to replace calls in object types. +type CallbackFunction = (callback: () => void) => void; + +class ExecuteCallback { + call(callback: () => void): void { + callback(); + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-call-signatures/arkts-no-call-signatures-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fda0e1a44ef326f0a252c13ac3cb2357b4ce5ca4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-1-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Explicitly declares a class + +class Oblong { + constructor(height: number, width: number) { + this.height = height + this.width = width + } + height: number + width: number +} + +let oblong = new Oblong(0.0, 0.0) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..64ffbe28aea00ffc84ec7f65ea595c50914767e1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-10-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Explicitly declares a class inside a function + + +function testClassExpressionInsideFunction() { + class MyClass { + // Declare a class + }; + + const instance = new MyClass(); +} + +testClassExpressionInsideFunction(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..cf63ce16d5761fb4fd520e2946a4382304d7472c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-2-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use a class expression to declare a class + +const Oblong = class { + constructor(height: number, width: number) { + this.height = height + this.width = width + } + height: number + width: number +} + +const oblong = new Oblong(0.0, 0.0) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..07347f4f8776acc4ae2837e5132fbfbbe9b64574 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Class literals are not supported (arkts-no-class-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 16 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Class literals are not supported (arkts-no-class-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 16 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..937874b1479f362414db1212d546a287b61d23e6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-3-ok.ets @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Explicitly declares multiple classes + +class Oblong { + constructor(height: number, width: number) { + this.height = height + this.width = width + } + height: number + width: number +} + +class Circle { + constructor(radius: number) { + this.radius = radius + } + radius: number +} + +class Semicircle { + constructor(radius: number) { + this.radius = radius + } + radius: number +} + +let oblong = new Oblong(0.0, 0.0) +let circle = new Circle(1.0) +let semicircle = new Semicircle(2.0) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..24153fdd7979373f6bb96841ee69f9155237f804 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-4-ok.ets @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use different types of class expressions + +class BaseClass { + baseMethod() { + console.log("Base method"); + } +} + +interface MyInterface { + interfaceMethod(): void; +} + +class DerivedClass extends BaseClass implements MyInterface { + interfaceMethod() { + console.log("Interface method"); + } +} + +const obj1 = new BaseClass(); +const obj2 = new DerivedClass(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9d3bbe4c33b8a9d1f1fb1811040b86b8dee48c9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-5-error.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use class expressions inside a class + +class MyClass { + // Explicitly declare a class +} + +function testClassExpression() { + + const myClass = class { + // Class expressions + }; + + const instance = new myClass(); +} + +testClassExpression(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4f02fad8fd84e05eeed056f6276330efe19de000 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Class literals are not supported (arkts-no-class-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Class literals are not supported (arkts-no-class-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..44664bb982c08a5429fb907541700669f3f5ee5e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-6-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use a declared class inside the class + +class MyClass { + // Explicitly declare a class +} + +function testUsingDeclaredClassInside() { + // Try to use a declared class within a class + const myInstance = new MyClass(); + console.log(myInstance); +} + +testUsingDeclaredClassInside(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ec42b90f438efd12f30df1c11e652fb60841c88c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-7-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use class expressions inside functions + +function testClassExpressionInsideFunction() { + // Use class expressions inside functions + const myClass = class { + // Class expressions + }; + const instance = new myClass(); +} + +testClassExpressionInsideFunction(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4ad87de873a2c845941813666c200c51c554e1ed --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Class literals are not supported (arkts-no-class-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Class literals are not supported (arkts-no-class-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..688ca530fca3937bcc8b9dc1cdb80b8cabaa6183 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-8-ok.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use display to declare a class in a conditional judgment + +const condition = true; + +if (condition) { + class MyClass { + // Class definition + } + + const myObject = new MyClass(); +} else { + class AnotherClass { + // Class definition + } + + const anotherObject = new AnotherClass(); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0cd54a128dd17e75498ee4f7f1840e35ea38e2d3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-9-error.ets @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use a class expression in an instance method of a class + +class MyClass { + testClassExpression() { + const classExpression = class { + // Class expression body + }; + + return new classExpression(); + } +} + +const instance = new MyClass(); +instance.testClassExpression(); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..bfa7831d068e105db16319f2f554a537b6830dcb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-class-literals/arkts-no-class-literals-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Class literals are not supported (arkts-no-class-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Class literals are not supported (arkts-no-class-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 29 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..38cae6a57fb44293f5089030f19d50686b19f712 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-error.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Assigning a class as a value to an object. +class Person { + name: string + + constructor(name: string) { + this.name = name + } + + sayHello() { + console.log(`Hello, my name is ${this.name}.`) + } +} + +const PersonClass: typeof Person = Person + +const person = new PersonClass('Xiaoming') +person.sayHello() // Output:Hello, my name is Xiaoming. diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..083c1be50731374f38141ad5b5e7e7e54a23a606 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 30, + "character": 20 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 30, + "character": 36 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 30, + "character": 20 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 30, + "character": 36 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..cfb119edc1e15b93f9d3a58db9a08910f34ab70f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-ok.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Assigning values to objects using instances of class. +class Person { + name: string = '' + + constructor(name: string) { + this.name = name + } +} + +type PersonPerson = () => Person + +class Menu { + person: PersonPerson = () => { + return new Person('Xiaoming') + } + createController() { + if (this.person) { + return this.person() + } + return null + } +} + +let p: Menu = new Menu() +console.log(p.createController()!.name) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..dc02e269bd675a1d4b4c463c003b4fbed08e57e7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Assigning a Class to a Variable. +class MathOperation { + static square(num: number): number { + return num * num + } +} + +const operation: typeof MathOperation = MathOperation +const result: number = operation.square(5) +console.log(result) // Output: 25 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d1815df64e7d40e00f4962ab96cd290493aa0034 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 24, + "character": 18 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 24, + "character": 41 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 24, + "character": 18 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 24, + "character": 41 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..10431145414cc2643c36be8cfd734363d73376e7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Assigning values to objects using instances of class. +class MathOperation { + square(num: number) { + return num * num + } +} + +const operation = new MathOperation() +const result = operation.square(5) +console.log(result) // Output: 25 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e25f077adcd31e41644af1eb1fde686383d6d314 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Assigning a Class to a Variable. +class Calculator { + static add(a: number, b: number): number { + return a + b + } +} + +function performOperation( + a: number, + b: number, + operation: (a: number, b: number) => number +): number { + return operation(a, b) +} + +const calculator: typeof Calculator = Calculator +const result: number = performOperation(2, 3, calculator.add) +console.log(result) // Output: 5 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a2adac9eae1e2680111a811a90614a2bf003d2f1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 32, + "character": 19 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 32, + "character": 39 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 32, + "character": 19 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 32, + "character": 39 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ae00f54b437ad5a7fac8ef55fd5124cf054fe9a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Assigning values to objects using instances of class. +class Logger { + log(message: string): void { + console.log(message) + } +} + +const loggerFn: (message: string) => void = new Logger().log +loggerFn('Hello, world!') // Output: "Hello, world!" diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..52bee1be7ae49c4794fd77e7b57f21306e9aa7de --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Pass the class as a parameter. +function classDecorator(constructor: Function) { + console.log('Target class: ', constructor) +} + +class MyClass { + constructor() { + console.log('123') + } +} + +classDecorator(MyClass) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..33207512a3fe2d89a069fb47de8e66a440e042bf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 28, + "character": 16 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 28, + "character": 16 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5cd577905d8ea9d2cc06745e87d699d36a968f2b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Assigning values to objects using instances of class. +class Calculator { + add(a: number, b: number): number { + return a + b + } +} + +function performOperation( + a: number, + b: number, + operation: (a: number, b: number) => number +) { + return operation(a, b) +} + +const calculator = new Calculator() +const result = performOperation(2, 3, calculator.add) +console.log(result) // Output:5 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..faf1b7af0e41b6dd3c0cc20694e2a49f1e402be0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Class as the value of an array. +class MyClass { + private value: number + + constructor(value: number) { + this.value = value + } + + getValue(): number { + return this.value + } +} + +const myArray: (any | number)[] = [MyClass, 2, 3] + +console.log(myArray[0]) // Output: [class MyClass] +console.log(myArray[1]) // Output: 2 +console.log(myArray[2]) // Output: 3 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..77da8161e578ec8e90904b8b67f576dfd21e525e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 30, + "character": 17 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 30, + "character": 36 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 30, + "character": 17 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 30, + "character": 36 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..609826617c69ea369e865f541607c8efcd6e14a5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Assigning values to objects using instances of class. +class Logger { + log(message: string): void { + console.log(message) + } +} + +const loggerFn: (message: string) => void = new Logger().log +loggerFn('Hello, world!') // Output: "Hello, world!" diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..30c363fa62e511bd2e6b1e0abda71f60c0cdd019 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-6-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Assigning values to objects using instances of class. +class Validator { + static validateEmail(email: string): boolean { + // Basic email validation logic + const emailRegex = new RegExp('^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$') + return emailRegex.test(email) + } +} + +type ValidationFunction = (value: string) => boolean +const emailValidator: ValidationFunction = Validator.validateEmail + +const isValidEmail = emailValidator('test@example.com') +console.log(isValidEmail) // Output: true diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4dde572a8e1dcb19491ea4b5fe1356f10f6c0ae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-7-ok.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Assigning values to objects using instances of class. +class Logger { + log(message: string) { + console.log(message) + } +} + +class Application { + logger: Logger + + constructor(logger: Logger) { + this.logger = logger + } + + run() { + this.logger.log('Application is running.') + } +} + +const logger = new Logger() +const app = new Application(logger) + +app.run() // Output:Application is running. diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-classes-as-obj/arkts-no-classes-as-obj-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7400b15bf5c6cb63d5ecd845b3909fab29917b8b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 bNum: number = 1; +let cNum: number = 2; +let acc: number = (bNum = 1, cNum = 2); + +console.log(acc); + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..bf8f6276f3f23e86d3ac003d1a6dadd2aeac908e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 19, + "character": 20 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 19, + "character": 20 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0504bb1696e0b4586eccc9e6abaaad5fcd765f2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +for (let i = 0, j = 0; i < 10; ++i, j += 2) { + console.log(i); + console.log(j); +} + +let numInit = 0; +++numInit; +numInit = numInit++; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5081cfd2e93156b34a30b0e8866dc7c02ac7583 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 aExample:number +let bExample:number + +aExample = 10,bExample=5 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f81e75e8cd7cc1ff628b04f742bcd92c971bd69c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..546e167450ac97f07414ecd8f8786f0bd4c03449 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +for (let i = 0; i < 3; i++) { + for (let j = 0, k = 0; j < 2; j++, k += 5) { + console.log(i, j, k); + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3318a38458eb9f86b73dd299333a0a841cecb4c3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-3-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 y:number = 0; +y = (y++, y++); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e8b8fe7223fc849cab2c74549d3af5b54d8847a7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 18, + "character": 6 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 18, + "character": 6 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..39e9481865cce0fc94d585040db0ade2d03fa8b1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-4-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 aOne:number = 5 +let bOne:number = 10; +let cOne =(aOne++, bOne--, aOne + bOne); +console.log(cOne) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..681f1881d5911c7de2c0f751a760ca00374dc704 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-4-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 19, + "character": 12 + } + }, + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 19, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 19, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d35342596136c1ca0e34e7952c251d2ce7ed6a1b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-5-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 x1 = 0, y1 = (x1++, x1 + 1); +console.log(y1); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c91289d14f619e4a811b4fe2a9aacc90e01cda66 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e8a6c736c80336c7d02c1aafa1af4f1eb840b96c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-6-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +function foo() { + return "World"; +} + +let result = (foo(), "Goodbye"); +console.log(result); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4aabcffacd936865a72d08985bde0217d092ae6b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 21, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 21, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..75f60f6573352fb959b2fd6d9a1e83843294ecbf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-7-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 xMail = 0, + yMail = 10; +while ((xMail++, yMail--)) { + console.log(xMail, yMail); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ba404cb2e977eb004b905374731b0d827f492e76 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 19, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 19, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6e61babf8c6aa801afcd43aec1b6aac3248ad03 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-8-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +for (let i = 0, j = 0; i < 10; ++i, j += 2) { + console.log(i); + console.log(j); +} + +let x = 0; +x = (++x, x++); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..586cadd4063fdbd1fc9830be08b5ccd3e86acdcc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-comma-outside-loops/arkts-no-comma-outside-loops-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 23, + "character": 6 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)", + "expectLineAndCharacter": { + "line": 23, + "character": 6 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a07755fcb434cb9a045642b1e07f0177f1e0f19 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-1-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: If the generic parameter T inherits from the number type, then return T itself, otherwise return the never type +type Hey = T extends string ? T: never + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..65364cf3d6c3dd5b39db8693ea10ee2f768d7a0d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fd519e5f1d05a619d7a9d65c7a4a63aab069b789 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-10-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Use Object type to define generic types +interface X2 { + value: T; + checkedBy: U; +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..64b14ea556fa8a2696e827ba7622a579751b140c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-2-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Provide number explicit constraint in type alias +type Hey1 = T + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d55b6324f1f58108b0390ef6f0ee61fbc27ee51 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-3-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Conditional type selection +type If = T extends true ? A : B; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8bb7ac4cfd304b7cea50fdc6b8122d73d85dede8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 36 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 36 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..85ce32ad6a1ca0709a20507e3263e839301667b6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-4-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Rewrite Logic with Object +type Ins = Object + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8dfafa0aa5a430ab393bd386650a17b31023d3d6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-5-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Conditional type selection +type CustomType = T extends number ? number : string; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..336bbe4edd56e5648a29ca856132a4be87ec7e9d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 22 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 22 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f4386d84759a982a020649ec4022774f7c77548 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-6-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Provide number or string explicit constraints in type aliases +type CustomType = T; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0c1b7401cc943bf49e46429cf013bb0837bc9c25 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-7-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Conditional type selection +type Diff = T extends U ? never : T; +type Filter = T extends U ? T : never; + +type Distribute = T extends infer U ? Filter : never; + +type MyUnion = string | number | boolean; +type MyType = Distribute; + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e86c7d5ef7fa395c302e2f7f2b2f81d06f246ea8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-7-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 19 + } + }, + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 21 + } + }, + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 22 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 19 + } + }, + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 21 + } + }, + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 22 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f87e4c860092d518df95d461ede0d59a6447891 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-8-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Replacing Array with object requires that Item must be used as a generic parameter +interface HeadObj { + first: Item; +} +class O { + id: string = '' +} +type Head, Item> = Item; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f489b28a2ce1fabbb8aa207d07e535e342e5d4d2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-9-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Implement Exclude type +type Excludes = T extends U ? never : T; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ffff1a5268ea6778debb83f373c28dad2ceeef9b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-conditional-types/arkts-no-conditional-types-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 23 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Conditional types are not supported (arkts-no-conditional-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 23 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9bcadbc211b15b32888f92defdd8fe0b13af6284 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-1-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using TypeScript parameter properties +class MyClass { + constructor(public myField: string) { + + this.myField = myField + + } +} + + \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ed352f7dfd8adce88a4fabb5fb4ec7a50d7c46a5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ffe03ec8fb40536f7166dcd358c8a1ee84d606bd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-10-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Declare class fields using access modifiers (private or protected) (declare these fields in class) +class MyClass { + private name: string; + constructor(name: string) { + this.name = name; + } +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d16f5628b17e44f2b7edb7c752e65ea90a378627 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-11-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Call other functions in the constructor to initialize fields +class Calculator { + constructor(private result: number) { + this.performCalculation(); + } + + private performCalculation() { + + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ed352f7dfd8adce88a4fabb5fb4ec7a50d7c46a5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-11-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-12-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-12-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..48f0674af6f1c7fe5b8a93faf9d249ca13d6031f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-12-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Declare class fields using static attributes (declare these fields in class) +class MyClass { + static myName: string; + constructor(name: string) { + MyClass.myName = name; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-12-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-12-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-12-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8bd2036ec8279690be579561590c7b4e7c96f13d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-2-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Use TypeScript's parameter properties (declare fields in these classes) +class MyClass { + public myField: string; + + constructor(myField: string) { + this.myField = myField; + } +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd3fdff69facb0156d9b46bfcbd0ff0f4199d566 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-3-error.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use of Classes +class MyClass { + private _myField: string; + + constructor(private myField: string = '') { + this._myField = myField; + } + + getMyField(): string { + return this.myField; + } + + setMyField(value: string) { + this.myField = value; + } +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b82d6f5144672df1b77008fc4f4cde49fd720430 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 21, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 21, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1195a36a29fb75e3019552578d263fc1d0581de7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-4-ok.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Using TypeScript accessors (declaring these fields in class) +class MyClass { + private _myField: string; + + constructor() { + this._myField = ''; + } + + get myField(): string { + return this._myField; + } + + set myField(value: string) { + this._myField = value; + } +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..788abcbd92fff97e7bc1bab467695c9d60377773 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-5-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using the readonly class attribute of TypeScript +class MyClass { + public myField: string; + constructor(public readonly myFieldValue: string) { + this.myField = myFieldValue; + } +} + +const myInstance = new MyClass('myValue'); +console.log(myInstance.myField); + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f005697967dc0e8aa70c309c1d39c7f2617e98ee --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 20, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 20, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a92c307871c072957171db8bec969376ef97eb5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-6-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Use the readonly class attribute of TypeScript (declare these fields in class) +class MyClass { + public readonly myField: string; + constructor() { + this.myField = 'myValue'; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..608111fb54513a919230b414255950414142405f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-7-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using TypeScript Class Properties +class MyClass { + constructor(public myField: string) { + this.myField = 'myValue'; + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ed352f7dfd8adce88a4fabb5fb4ec7a50d7c46a5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e399fd7444f658ed9110ca6427e57b7a3e88c56 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-8-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Using TypeScript class attributes (declaring these fields in class) +class MyClass { + public myField: string; + constructor() { + this.myField = 'myValue'; + } +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..44ea8819fee80cbac2bfb7cd4a462c75fd4f4cb8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-9-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Declare class fields using access modifiers (private or protected) +class MyClass { + constructor(private name: string) { + this.name = name; + } +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ed352f7dfd8adce88a4fabb5fb4ec7a50d7c46a5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-prop-decls/arkts-no-ctor-prop-decls-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6dccb0fc97727b09eb6d2b4719712917b3bc94ed --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Person { + constructor( + name: string, + age: number + ) {} +} +type PersonCtor = new (name: string, age: number) => Person + +function createPerson(Ctor: PersonCtor, name: string, age: number): Person +{ + return new Ctor(name, age) +} + +const person = createPerson(Person, 'John', 30) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..875109e6c2ee01d5e697861d431b4f8314bb4128 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 23, + "character": 19 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 30, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 23, + "character": 19 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 30, + "character": 29 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..636ada7f3541bcddd1a04d2eec67fb9677419d67 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Person { + constructor( + name: string, + age: number + ) {} +} +type PersonCtor = (n: string, a: number) => Person + +function createPerson(Ctor: PersonCtor, n: string, a: number): Person { + return Ctor(n, a) +} + +let Impersonizer: PersonCtor = (n: string, a: number): Person => { + return new Person(n, a) +} + +const person = createPerson(Impersonizer, 'John', 30) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..116b6f1062a6cdfcff71f3433928c0c05818bd6c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-error.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +We define a class named 'Car' and use the 'CarCtor' type to describe the constructor type. We then define a 'createCar' function that takes a constructor and the corresponding arguments and returns a 'Car' instance. Finally, we use the createCar function to create an instance of the Car, print out its property values, and call the startEngine method. +*/ + +class Car { + brand: string; + model: string; + year: number; + + constructor(brand: string, model: string, year: number) { + this.brand = brand; + this.model = model; + this.year = year; + } + + startEngine() { + console.log(`Starting the engine of ${this.brand} ${this.model}`); + } +} + +type CarCtor = new (brand: string, model: string, year: number) => Car; + +function createCar(Ctor: CarCtor, brand: string, model: string, year: number): Car { + return new Ctor(brand, model, year); +} + +const car = createCar(Car, "BYD", "han", 2022); +console.log(car.brand); // BYD +console.log(car.model); // han +console.log(car.year); // 2022 +car.startEngine(); // Starting the engine of BYD han diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1dc6b44fb26c5f8fe02df54729b0eb894482126d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 37, + "character": 16 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 43, + "character": 23 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 37, + "character": 16 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 43, + "character": 23 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1ebef83e9cd6aa4318c07aa9db0535ad9c74851c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-ok.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Car { + brand: string; + model: string; + year: number; + + constructor(brand: string, model: string, year: number) { + this.brand = brand; + this.model = model; + this.year = year; + } + + startEngine() { + console.log(`Starting the engine of ${this.brand} ${this.model}`); + } +} + +type CarCtor = (brand: string, model: string, year: number) => Car; + +function createCar(Ctor: CarCtor, brand: string, model: string, year: number): Car { + return Ctor(brand, model, year); +} + +const CarCreator: CarCtor = (brand: string, model: string, year: number): Car => { + return new Car(brand, model, year); +} + +const car = createCar(CarCreator, "BYD", "han", 2022); +console.log(car.brand); // BYD +console.log(car.model); // han +console.log(car.year); // 2022 +car.startEngine(); // Starting the engine of BYD han \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b2005afce644b7a588214703152af0e5a2c4175 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-error.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Person { + name: string; + age: number; + + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } +} + +// Define a PersonCtor type that represents the constructor type +type PersonCtor = new (name: string, age: number) => Person; + +// Define a createPerson function that takes a constructor and arguments and returns an instance of Person +function createPerson(Ctor: PersonCtor, name: string, age: number): Person { + return new Ctor(name, age); +} + +// create intrance of Person with createPerson function +const person = createPerson(Person, 'John', 30); +console.log(person.name); // John +console.log(person.age); // 30 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..990dc05412f4ea75e9bf7821fd06dbaca42cfe93 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 28, + "character": 19 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 36, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 28, + "character": 19 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 36, + "character": 29 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..83e19126e2d2357491ecbd6b791331fbcbbda8bd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-ok.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Person { + name: string; + age: number; + + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } +} + +// define a PersonCtor type that represents the constructor type +type PersonCtor = (name: string, age: number) => Person; + +// define a createPerson function that takes a constructor and arguments and returns an instance of Person +function createPerson(Ctor: PersonCtor, name: string, age: number): Person { + return Ctor(name, age); +} + +// define a Impersonizer type that represents the constructor type +let Impersonizer: PersonCtor = (name: string, age: number): Person => { + return new Person(name, age); +} + +// create intrance of Person with createPerson function +const person = createPerson(Impersonizer, 'John', 30); +console.log(person.name); // John +console.log(person.age); // 30 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ef746ef9687c5808fd82be5cfa259e3a2b217208 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-error.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Animal { + name: string; + + constructor(name: string) { + this.name = name; + } +} + +type AnimalCtor = new (name: string) => Animal; + +function createAnimal(Ctor: AnimalCtor, name: string): Animal { + return new Ctor(name); +} + +const animal = createAnimal(Animal, "Dog"); +console.log(animal.name); // Dog \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b82f8c1f2921acfac81dac8bd6d8d0b34eefbc88 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 25, + "character": 19 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 31, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 25, + "character": 19 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 31, + "character": 29 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b31dbdc1379f589a90ac7aa34aebd6f0b43d2eb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-ok.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Animal { + name: string; + + constructor(name: string) { + this.name = name; + } +} + +type AnimalCtor = (name: string) => Animal; + +function createAnimal(Ctor: AnimalCtor, name: string): Animal { + return Ctor(name); +} + +let AnimalCreator: AnimalCtor = (name: string): Animal => { + return new Animal(name); +} + +const animal = createAnimal(AnimalCreator, "Dog"); +console.log(animal.name); // Dog diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fc49f02825eedcf6dc0b34dcd0e685fcf670ffe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-error.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Product { + name: string; + price: number; + + constructor(name: string, price: number) { + this.name = name; + this.price = price; + } +} + +type ProductCtor = new (name: string, price: number) => Product; + +function createProduct(Ctor: ProductCtor, name: string, price: number): Product { + return new Ctor(name, price); +} + +const product = createProduct(Product, "Phone", 999); +console.log(product.name); // Phone +console.log(product.price); // 999 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cec28e58da063c64556331f42ae63b42c09ada1f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 27, + "character": 20 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 33, + "character": 31 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)", + "expectLineAndCharacter": { + "line": 27, + "character": 20 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 33, + "character": 31 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..998bbdbdcb6564bcb9cf5300930e5989928ea08f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-ok.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Product { + name: string; + price: number; + + constructor(name: string, price: number) { + this.name = name; + this.price = price; + } +} + +type ProductCtor = (name: string, price: number) => Product; + +function createProduct(Ctor: ProductCtor, name: string, price: number): Product { + return Ctor(name, price); +} + +const ProductCreator: ProductCtor = (name: string, price: number): Product => { + return new Product(name, price); +} + +const product = createProduct(ProductCreator, "Phone", 999); +console.log(product.name); // Phone +console.log(product.price); // 999 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-funcs/arkts-no-ctor-signatures-funcs-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..607bf6fdf2f80690bb042da24eb360fe10f83bdd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-1-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Defining a constructor signature in an interface +interface I { + new (s: number): I +} + +function fn(i: I) { + return new i(100) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c17f54c3217638f6c5c66550a7beb0c9410f353f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2c5e950339d7509bd61d073df0ce2adc190dc01b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-10-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Define a constructor type using a class type (use a function or method instead) +class Person { + public name: string; + + constructor(name: string) { + this.name = name; + } +} + +function createPerson(name: string) { + return new Person(name); +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-11-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-11-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2fd0a2ae5493d197189e01406c50fa2edbee8ec --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-11-ok.ets @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Define parameters using optional and parameter attributes (encapsulate with classes; use functions or methods instead) +class Person { + name: string; + age?: number; + + constructor(name: string, age?: number) { + this.name = name; + this.age = age; + } +} + +function createPerson(name: string, age?: number) { + return new Person(name, age); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-11-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-11-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-11-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..da2c421d0f7f739ea57157657e6223afc706fc1d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-2-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Using methods in interfaces +interface I { + create(s: number): I +} + +function fn(i: I) { + return i.create(100) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..afbfd803e507ba0a04db009ebd7b5db5d51e0b7b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-3-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Define constructor return value interface +interface PersonConstructor { + new(name: string): Person; +} + +interface Person { + name: string; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c17f54c3217638f6c5c66550a7beb0c9410f353f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..12d08071b09992a09adae188f01b1039f11c6932 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-4-ok.ets @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Define a constructor return value interface (use a function or method instead) +interface Person { + name: string; +} + +interface PersonCreator { + create(name: string): Person; +} + +class PersonImpl implements Person { + name: string; + + constructor(name: string) { + this.name = name; + } +} + +class PersonCreatorImpl implements PersonCreator { + + create(name: string) { + return new PersonImpl(name); + } +} + +const creator = new PersonCreatorImpl(); +const person = creator.create('John'); + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9edf584c94fd727d0650b2c8cce6b30f70192d4d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-5-error.ets @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using the new operator and function type definition to construct a signature +interface Person { + name: string; +} + +interface PersonConstructor { + new(name: string): Person; +} + +class Person { + public name: string; + + constructor(name: string) { + this.name = name; + } +} + +function createPerson(name: string): Person { + return new Person(name); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7ff326fee342a4ede3e0fb90cfae511a06c774bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-5-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 18, + "character": 11 + } + }, + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 26, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d713f15e099774e22a17486cc2c0f69da8fd4a4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-6-ok.ets @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Using the new operator and function type definition to construct a signature (using a function or method instead) +interface Person { + name: string; +} + +interface PersonCreator { + create(name: string): Person; +} + +class PersonImpl implements Person { + name: string; + + constructor(name: string) { + this.name = name; + } +} + +class PersonCreatorImpl implements PersonCreator { + create(name: string) { + return new PersonImpl(name); + } +} + +function createPerson(name: string): Person { + const creator = new PersonCreatorImpl(); + return creator.create(name); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..325b9c37cd200f41f06e12bbd807c8407dc9be3b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-7-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Define parameters using optional and parameter attributes +interface PersonConstructor { + new(name: string, age?: number): object; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c17f54c3217638f6c5c66550a7beb0c9410f353f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..128ca7b1b80be00a830e17467dad7be22157fcbe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-8-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Define parameters using optional and parameter attributes (use functions or methods instead) +interface Person { + name: string; + age?: number; +} + +function createPerson(name: string, age?: number): Person { + return { + name: name, + age: age + }; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8f13134c83c9e71dbbd99884316438d2c4d8fda6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-9-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using class types to define constructor types +class Person { + public name: string; + + constructor(name: string) { + this.name = name; + } +} + +interface PersonConstructor { + new(name: string): Person; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cc6acf616cf57013b1b935cb8adc74a132e8d4ff --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-iface/arkts-no-ctor-signatures-iface-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..94af70a16745a4f78007ccfccefee97533d2e7fa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-error.ets @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using construction signatures in objects. +interface Person { + name: string + age: number + sayHello(): void +} + +const Person1: { + new (name: string, age: number): Person +} = function (name: string, age: number) { + this.name = name + this.age = age +} + +Person1.prototype.sayHello = function () { + console.log(`Hello, my name is ${this.name}, and I am ${this.age} years old.`) +} + +const alice: Person = new Person1('Alice', 30) +alice.sayHello() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a35036e12cbc84251b02d32292a870c7d2f50f53 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-error.json @@ -0,0 +1,104 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 24, + "character": 16 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 31, + "character": 30 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 31, + "character": 30 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 24, + "character": 16 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 28, + "character": 3 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 31, + "character": 30 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 32, + "character": 36 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 32, + "character": 59 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2dd183fb7b1c35c3656855270a18490047d6f87a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-ok.ets @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using classes to represent the structure and behavior of objects. +class Person { + name: string + age: number + + constructor(name: string, age: number) { + this.name = name + this.age = age + } + + sayHello() { + console.log( + `Hello, my name is ${this.name}, and I am ${this.age} years old.` + ) + } +} + +const alice: Person = new Person('Alice', 30) +alice.sayHello() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..50cdd00748c7a6d403f125f6b8a2b21754aaa57d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Interface Literal Mode Constructor Signature. +class Person { + n: string = '' + a: number = 0 +} + +class Teacher { + n: string = '' + a: number = 0 +} + +const myClass: { new (n: string, a: number): Person } = Teacher diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..79a9c8091b7e3efb67d56d5b159009feb93c6e16 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 16 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 28, + "character": 18 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 28, + "character": 57 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 16 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 28, + "character": 18 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 28, + "character": 57 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..388b0b88a8f3631db770ea4e4302f534d554718a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-ok.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using classes to implement interfaces. +interface Shape { + area(): number +} + +class Circle implements Shape { + private radius: number = 0 + constructor(radius: number) {} + + area() { + return Math.PI * this.radius * this.radius + } +} + +const myCircle: Shape = new Circle(5) +console.log(`Area of the circle: ${myCircle.area()}`) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0da8dc7fd4c898c735a56d80f4613c01bcc1988c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-error.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Interface object literal constructor signature. +class Person { + n: string = '' + a: number = 0 +} + +function c(clazz: { new (name: string, age: number): Person }): Person { + return new clazz('xiaoming', 9) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2f3c2396bdc172beeb816afebbb6aaf0e306560c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 19 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 23, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 19 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 23, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b5e1e81937686b7f629b18727f58f0a1abd5bc2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-ok.ets @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using classes to implement interfaces. +interface PersonInterface { + name: string + age: number + sayHello(): void +} + +class Person implements PersonInterface { + public name = '' + public age = 0 + constructor(name: string, age: number) {} + + sayHello() { + console.log(`Hello, my name is ${this.name}`) + } +} + +let person = new Person('John', 30) +person.sayHello() // Hello, my name is John diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b529f2f4fe7cc3a3165c5eeb0c0ca4ce5fbed0d7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using construction signatures in objects. +class SomeObject {} + +type SomeConstructor = { + new (s: string): SomeObject +} + +function fn(ctor: SomeConstructor) { + return new ctor('hello') +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..15d2cbd064f26faef73fb160cb7b4681af3da275 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 24 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 24 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9329d642a167533d803cc2d968fa3a30c1a39738 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Replacing construction signatures in objects with classes. +class SomeObject { + public f: string + constructor (s: string) { + this.f = s + } +} + +function fn(s: string): SomeObject { + return new SomeObject(s) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f6ab1876e79d4d79adda56230de06fc095bebd7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-error.ets @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using construction signatures in classes. +class Controller { + value: number = 0 + + constructor(value: number) { + this.value = value + } +} + +type ControllerConstrucotr = { + new (value: number): Controller +} + +class Menu { + controller: ControllerConstrucotr = Controller + createController() { + if (this.controller) { + return new this.controller(123) + } + return null + } +} + +let t = new Menu() +console.log(t.createController()!.value) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b51b28b810483cde44aeb39c1a577721ef315519 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 30 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 31, + "character": 39 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 30 + } + }, + { + "messageText": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 31, + "character": 39 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f94ef050ef0759c8d58d70d84157462a8a250c3b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-ok.ets @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using Class Substitution to Construct a Signature. +class Controller { + value: number = 0 + + constructor(value: number) { + this.value = value + } +} + +type ControllerConstrucotr = () => Controller + +class Menu { + controller: ControllerConstrucotr = () => { + return new Controller(123) + } + + createController() { + if (this.controller) { + return this.controller() + } + return null + } +} + +let t: Menu = new Menu() +console.log(t.createController()!.value) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ctor-signatures-type/arkts-no-ctor-signatures-type-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..16ca99815b625f887660c58a5c281f7c990de8e8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-1-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Interface definition merging + +interface Document { + createElement(tagName: number): HTMLDivElement + createElement(tagName: boolean): HTMLSpanElement + createElement(tagName: string, value: number): HTMLCanvasElement + createElement(tagName: string): HTMLElement + createElement(tagName: Object): Element +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..adbe729db9631ed6751b5898eea345dc6f08b20c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-10-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Merge a class and a module + +class MyClass { + method(): void { + // Class method implementation + } +} + +module MyModule { + export function method(): void { + // Module method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6572a39994c864bcf3fe2137870b542a311c8d99 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-11-error.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Interface declarations are merged, and attributes with the same name are merged but of different types + +interface Device { + price: number; +} + +interface Device { + price: string; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1b6a76560eedaeaf22a9de7d0dcdb96ac543eaba --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-11-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-12-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-12-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6db5143563a42d153ede6622cfa07087ff42abf9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-12-error.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Merge the properties of interface functions + +interface Utils { + getData: () => string; +} + +interface Utils { + getData: () => number; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-12-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-12-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1b6a76560eedaeaf22a9de7d0dcdb96ac543eaba --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-12-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..67090537df9ba323e41183bfe5cd46dcc2d19590 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-2-error.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Multiple interfaces are merged + +interface Document { + createElement(tagName: string): Element +} + +interface Document { + createElement(tagName: string): HTMLElement +} + +interface Document { + createElement(tagName: number): HTMLDivElement + createElement(tagName: boolean): HTMLSpanElement + createElement(tagName: string, value: number): HTMLCanvasElement +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..53899401c1bb41d4406d94e965d36f10a42ba312 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-2-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + }, + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + }, + { + "messageText": "Declaration merging is not supported (arkts-no-decl-merging)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..65011ac85d4795e35e5966e27382fbc456eb752a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-3-ok.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Declare an interface and use it + +interface Person { + name: string; + age: number; + sayHello: () => void; +} + +const person: Person = { + name: 'John', + age: 25, + sayHello: () => { + console.log('Hello!'); + } +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a91729c155d6fd2b80bb2bcf09011cfd7b7c50b4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-4-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Merge two modules + +module MyModule { + export function methodA(): void { + // Module A method implementation + } +} + +module MyModule { + export function methodB(): void { + // Module B method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9bc2aacb727973ac26a438a6b4920c0323c80b40 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-5-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Merge an interface and a namespace + +interface InterfaceA { + method(): void; +} + +namespace MyNamespace { + function method(): void { + // Namespace method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3126b77a40c5919c647d78276cb34da844010325 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-6-ok.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Implement an interface with a class + +interface Animal { + name: string; + speak(): void; +} + +class Dog implements Animal { + name = "Buddy"; + + speak() { + console.log("Woof!"); + } +} + +const myDog = new Dog(); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ed0d03da20576294235117ce09db3c38413c2431 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-7-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Merge two namespaces + +namespace MyNamespaceA { + export function method(): void { + // Namespace A method implementation + } +} + +namespace MyNamespaceB { + export function method(): void { + // Namespace B method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..71b8ae656988faa63bf8cca153c42c5554b187ca --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-8-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Merge classes and namespaces + +class MyClass { + method(): void { + // Class method implementation + } +} + +namespace MyNamespace { + export function method(): void { + // Namespace method implementation + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1810c54ad5a00dda596400bc2dfda3a0137253c3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-9-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Merge a class and an interface + +class MyClass implements InterfaceA { + method(): void { + // Class method implementation + } +} + +interface InterfaceA { + method(): void; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decl-merging/arkts-no-decl-merging-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..87f5d0bcfbee57c7202181c2bdb3b733966dac80 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-error.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Class decorator. +*/ +function classDecorator(constructor: Function) { + console.log('Class decorator called') + console.log('Target class: ', constructor) +} + +@classDecorator +class MyClass { + constructor() { + console.log('MyClass instantiate') + } +} + +const myObject = new MyClass() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..32c0affd971755ea4527ad7f609c9ec401921841 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5d59aa372dc5db1eb2ed29c15db9464be2bee5e1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Implementing code without using decorators. +*/ +function classDecorator(constructor: Function) { + console.log('Class decorator called') + console.log('Target class: ', constructor) +} + +class MyClass { + constructor() { + console.log('MyClass instantiate') + } +} + +classDecorator(MyClass) + +const myObject = new MyClass() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..1501544bfdd5270a3f75a08056c2d0ab59433ee9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-1-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 31, + "character": 16 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 31, + "character": 16 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ffb831fb1a16a46ec31ad91d17713d9986396c7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-error.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Method Decorator. +*/ +function methodDecorator( + target: any, + key: string, + descriptor: PropertyDescriptor +) { + console.log('Method decorator called') + console.log('Target class: ', target) + console.log('Method name: ', key) + console.log('Method Descriptor: ', descriptor) +} + +class MyClass { + @methodDecorator + myMethod() { + console.log('Method called') + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1c51f4f2bde03fd7b24a7d4166f01feb4bd1d83b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 21, + "character": 11 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 32, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 21, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c9b9b6a94cd13a2eee5cd05bf4a10533a6a6dbd1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-ok.ets @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Implementing code without using decorators. +*/ +type MethodDecoratorType = ( + target: T, + key: string, + descriptor: TypedPropertyDescriptor<() => void> +) => void + +function methodDecorator( + target: T, + key: string, + descriptor: TypedPropertyDescriptor<() => void> +) { + console.log('Method decorator called') + console.log('Target class: ', target) + console.log('Method name: ', key) + console.log('Method Descriptor: ', descriptor) + + const originalMethod = descriptor.value + + descriptor.value = function () { + console.log('Method Decorator Logic') + originalMethod?.call(this) + } +} + +class MyClass { + myMethod() { + console.log('Method called') + } +} + +const myObj = new MyClass() +const methodDescriptor = Object.getOwnPropertyDescriptor( + MyClass.prototype, + 'myMethod' +) + +if (methodDescriptor && typeof methodDescriptor.value === 'function') { + methodDecorator(MyClass.prototype, 'myMethod', methodDescriptor) +} + +;(myObj.myMethod as () => void)() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..5980b69c6ebb635114035c739a9e526e17768cff --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-2-ok.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 38, + "character": 22 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 38, + "character": 22 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 40, + "character": 5 + } + }, + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 51, + "character": 26 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 52, + "character": 11 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 57, + "character": 27 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 38, + "character": 22 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 40, + "character": 26 + } + }, + { + "messageText": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", + "expectLineAndCharacter": { + "line": 40, + "character": 21 + } + }, + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 51, + "character": 26 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 52, + "character": 11 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 57, + "character": 27 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1d64124436ca7ca3fdcab7989370ae7b2d52871 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Attribute Decorator. +*/ +function propertyDecorator(target: any, key: string) { + console.log('Property decorator called') + console.log('Target class: ', target) + console.log('Property name: ', key) +} + +class MyClass { + @propertyDecorator + myProperty: string = '' +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cf8a644d3718de8b6ddfe7e10ee5c78835b7d53d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 20, + "character": 36 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 20, + "character": 36 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b616146299f844914a80d604073151709adf5eed --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-ok.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Implementing code without using decorators. +*/ +class MyClass { + myProperty: string = '' + + constructor() { + this.myProperty = '' + propertyDecorator(MyClass.prototype, 'myProperty') + } +} + +function propertyDecorator(target: any, key: string) { + console.log('Property decorator called') + console.log('Target class: ', target) + console.log('Property name: ', key) +} + +const myObject = new MyClass() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..b29ae41e47185a9ebb193b4274cd9af72ee84b25 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-3-ok.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 29, + "character": 36 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 29, + "character": 36 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a742283014130796a608ce5711984967ce6e9974 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Parameter decorator. +*/ +function parameterDecorator(target: any, key: string, index: number) { + console.log('Parameter decorator called') + console.log('Target class: ', target) + console.log('Method name: ', key) + console.log('index: ', index) +} + +class MyClass { + myMethod(@parameterDecorator param: string) { + console.log('Method called with parameters: ', param) + } +} + +const myObj = new MyClass() +myObj.myMethod('Hello, World!') diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..32299e7399c6aaddb14201f2b8cedfbfbd945e78 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 20, + "character": 37 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 28, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 20, + "character": 37 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f519e4a249c5e337b12cc16cf87236bc0fdca87 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-ok.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Implementing code without using decorators. +*/ +class MyClass { + myMethod(param: string) { + console.log('Method called with parameters: ', param) + } +} + +function parameterDecorator(target: any, key: string, index: number) { + console.log('Parameter decorator called') + console.log('Target class: ', target) + console.log('Method name: ', key) + console.log('index: ', index) + + const originalMethod = target[key] + + target[key] = function (...args: any[]) { + console.log('Parameter Decorator Logic') + console.log('Parameter values: ', args[index]) + return originalMethod.apply(this, args) + } +} + +const myObj = new MyClass() +myObj.myMethod('Hello, World!') diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..e105aa61ab5615f223980eafb8196c74d6ecd6a9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-decorators-except-arkui/arkts-no-decorators-except-arkui-4-ok.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 26, + "character": 37 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 32, + "character": 9 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 34, + "character": 17 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 34, + "character": 17 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 34, + "character": 17 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 34, + "character": 36 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 26, + "character": 37 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 32, + "character": 9 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 34, + "character": 17 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 37, + "character": 33 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 34, + "character": 17 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 34, + "character": 36 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c69521ef24da26005144facf2888a3a0a04beb16 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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 x!: number // initialize x first + +initialize() + +function initialize() { + x = 10 +} + +console.log('x = ' + x) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ec25b7aa332272a19d259b6d5064ece002768408 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bd75cec5356a79395563f1eea59979532d6e3ec1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +function initialize(): number { + return 10 +} + +let x: number = initialize() + +console.log('x = ' + x) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1286eb6982ccf424d925ea240c32dc5e09658127 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Use a deterministic assignment assertion to tell TypeScript that a variable will be assigned +let y!: number; + +// Use a deterministic assignment assertion in a conditional statement +if (Math.random() > 0.5) { + y = 10; +} else { + y = 20; +} + +y.toFixed(2); // There will be no compilation errors, because y will definitely be assigned \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e3a46eeee481cbf5101f3dc11af83f9e4856311f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..285859e2d314ccc01ac7dbc2c5d2d972b7f66504 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-ok.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +function foo(): number { + let y: number; + if (Math.random() > 0.5) { + y = 10; + } else { + y = 20; + } + return y; +} + +let y: number = foo(); + +y.toFixed(2); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6c3dff42287d3980d6bec602e153645349a6464 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 emp!: string +console.log(emp) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ec25b7aa332272a19d259b6d5064ece002768408 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..29c39e676f3298ac1c60c716c97fe1e972c71797 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 emp: string = 'developer' +console.log(emp) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..25753b7410a551a72052f59a96ce221600cca238 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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 numbers!: number[]; + +// Initialize the array +numbers = [1, 2, 3, 4, 5]; + +console.log(numbers.length); +console.log(numbers[0]); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ec25b7aa332272a19d259b6d5064ece002768408 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bc24f334f1c3f2953fe13f21381a168c2d7d4f7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// initialize the array +let numbers: number[] = [1, 2, 3, 4, 5]; + +console.log(numbers.length); +console.log(numbers[0]); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..2639222698ef3af26ad7827d80393e727c148d91 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +function greet(name?: string) { + let message!: string; + + if (name) { + message = `Hello, ${name}!`; + } else { + message = "Hello, stranger!"; + } + + console.log(message); +} + +greet(); +greet("John"); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2f8b6003002a2ff5ba78ae08d911ba0ac60fa063 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 18, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 18, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..db2e60a6646f47437561a38dd362446f7d8a1a20 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +function greet(name?: string) { + let message: string; + + // if not name, use default + if (name) { + message = `Hello, ${name}!`; + } else { + message = "Hello, stranger!"; + } + + console.log(message); +} + +greet(); // "Hello, stranger!" +greet("John"); // "Hello, John!" \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-definite-assignment/arkts-no-definite-assignment-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9c088b77c37e7adcce7863b5f67bf2fc344ed4ca --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-1-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:Deletes object attributes +type: counterexample +*/ +interface Obj { + a?: number; + b: number; +} + +const obj: Obj = { a: 1, b: 2 }; +delete obj.a; +console.log(obj); // output:{ b: 2 } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..012467a64a7fac5149f761ccb27ab012f40eafc0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4307b09dbd17d9a4567af359383a8167ffb109a8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-10-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Remove attributes from nested objects and replace delete with null +class P { + name: string | null = "Alice"; + age: number = 25; +} +class O { + person: P = { + name: "Alice", + age: 25, + }; +} + +const obj: O = { person: { name: "Alice", age: 25 } }; +obj.person.name = null; +console.log(obj); + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4924956f0c2ac02c0eda1c88c18a0b00575e59ad --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-2-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Foo { + bar?: number; + constructor() { + this.bar = 10; + } +} + +Foo.prototype.bar = 42; +const foo = new Foo(); +console.log(foo.bar); // output: 10 +delete foo.bar; // Returns true, removing the foo object's own attributes \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..398462d8f5c7e68e424eadafab692fc1d7dcfc9c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + }, + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + }, + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..62011e79c0eae9ee92836af4f370c9a499578cd0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-3-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Remove array values +const arr: number[] = [1, 2, 3]; +delete arr[1]; +console.log(arr); // output:[1, undefined, 3] + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d73326dbbd10cd11c81dd1c4a358942f9f82ca24 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..198e1e4f8399cf5d86b53267e4e472a372ff8189 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-4-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Delete the properties of a class +interface MyClass { + prop1?: string; + prop2: string; +} + +const obj: MyClass = { + prop1: "Property 1", + prop2: "Property 2", +}; + +delete obj.prop1; +console.log(obj.prop1); // output:undefined +console.log(obj.prop2); // output:Property 2 + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e80aab2a21f393d5b24e53904edcc0fbeeef458e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..872730c0b022bdb889623bffbf29ab6349c2df3d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-5-error.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Remove attributes from nested objects +interface P { + name?: string; + age: number; +} +class O { + person: P = { + name: "123", + age: 25, + }; +} + +const obj: O = { person: { name: "Alice", age: 25 } }; +delete obj.person.name; +console.log(obj); + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..46a5b61104912e3662063ffa041f6cc8877b1725 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"delete\" operator is not supported (arkts-no-delete)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..da463cb8efb3094756bc4160e42c0f4b504f0c03 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-6-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Delete the object property and replace delete with null +interface Obj { + a?: number | null; + b: number; +} + +const obj: Obj = { a: 1, b: 2 }; +obj.a = null; +console.log(obj); // output:{ b: 2 } + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a3e4b9f16c5f198581a37fa67e41f6357f7d23b3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-7-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Foo { + bar?: number; + constructor() { + this.bar = 10; + } +} + +const foo = new Foo(); +console.log(foo.bar); // output: 10 +foo.bar = undefined; +console.log(foo.bar); // output: 10 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..39b4ca47aee4596fbe1e480c4dfc8d6cdb238caa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-8-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Example: Array element with undefined instead of delete +let arr: (number | undefined)[] = [1, 2, 3]; +arr[1] = undefined; +console.log(arr); // output:[1, undefined, 3] + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c2c6c88bccd6bd6ec4213c04de808e80bc7b3387 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-9-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Remove the properties of the class and replace delete with null +class MyClass { + prop1: string | null = "Property 1"; + prop2: string = "Property 2"; +} + +const obj: MyClass = new MyClass(); +obj.prop1 = null; +console.log(obj.prop1); // output:undefined +console.log(obj.prop2); // output:Property 2 + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-delete/arkts-no-delete-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..69a23f99de4987ff8f0ffe203e32f59fa1d743cf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 [firstA, secondA] = [1, 2]; +[firstA, secondA] = [secondA, firstA]; +console.log(firstA); +console.log(secondA); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..48b76ae88bf479a67247c36f6ed2b86f092b3a6d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + }, + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + }, + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2cd8cdec120dc2da3586e51c8ccb1e8c5935ce9e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +const aArr: number[] = [1, 2]; +let firstB = aArr[0]; +let secondB = aArr[1]; +let tmp = firstB; +firstB = secondB; +secondB = tmp; + +console.log(firstB); // 2 +console.log(secondB); // 1 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab737142e27a3f1cbd766376983af0d7d9a7d1f1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 language1 governing permissions and + * limitations under the License. + */ + + +const numbersArr = [1, 2, 3]; +let aa: number, bb: number, cc: number; +[aa, bb, cc] = numbersArr; +console.log(aa); +console.log(bb); +console.log(cc); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6e8a8e9a6ed26cd2ba3b9950bdc47e9566f8effa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1918c81ff91c23ae8e186b4a1d89fc4ed65ce705 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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 numbersArr2: number[] = [1, 2, 3]; +let aa2 = numbersArr2[0] +let bb2 = numbersArr2[1] +let cc2 = numbersArr2[2] + +console.log(aa2); +console.log(bb2); +console.log(cc2); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab1c7495af531ab26cf88b9c38404bc7004d5b64 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +const numArray = [1, 2, 3]; +let second2: number; +[, second2] = numArray; +console.log(second2); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6e8a8e9a6ed26cd2ba3b9950bdc47e9566f8effa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c66208d96e4e2d56cd8649bed9ec1ffcb647df0e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 numArrayTrue: number[] = [1, 2, 3]; +let secondNum: number = numArrayTrue[1]; +console.log(secondNum); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..60a99d1ac60a7738220dd59e4367cf8f557fdfff --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +const numbersArray = [1]; +let var1: number, bar1: number; +[var1 = 0, bar1 = 2] = numbersArray; +console.log(var1); +console.log(bar1); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6e8a8e9a6ed26cd2ba3b9950bdc47e9566f8effa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d8645fa2964d92569605491163601119f94cff2f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 numbersArrayOne: number[] = [1]; +let varTwo: number = 0; +let barTwo: number = 2; +console.log(varTwo); +console.log(barTwo); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1c432311c0e9e997396071d93e45722295d08fba --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +const numsArr = [1, 2, 3, 4, 5]; +let varOne: number, barOne: number, restOne: number[]; +[varOne, barOne, ...restOne] = numsArr; +console.log(varOne); +console.log(barOne); +console.log(restOne); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6e8a8e9a6ed26cd2ba3b9950bdc47e9566f8effa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring assignment is not supported (arkts-no-destruct-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f94239db1308f3d904d51339a5b8308f562aa1f6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +const numArr:number[] = [1, 2, 3, 4, 5]; +let var2 = numArr[0]; +let bar2 = numArr[1]; +let rest2:number[] = []; +for (let index = 2; index < numArr.length; index++) { + rest2.push(numArr[index]); +} +// [var2, bar2, ...rest2] = numbersArr; +console.log(var2); +console.log(bar2); +console.log(rest2); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-assignment/arkts-no-destruct-assignment-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e88f4d27931754263d349018f1683c6655fa4259 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 numbers = [1, 2, 3, 4, 5]; +let [first, second, ...rest] = numbers; + +console.log(first); // 1 +console.log(second); // 2 +console.log(rest); // [3, 4, 5] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4ea97ea700046251dfef2ba5f400cfa069c0a691 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ce5356b1baf01522868509177e419d2c9d02b179 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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 numbers:number[] = [1, 2, 3, 4, 5]; +let first = numbers[0]; +let second = numbers[1]; +let rest:number[] = []; +for (let i = 2; i < numbers.length; i++) { + rest.push(numbers[i]); +} + +console.log(first); // 1 +console.log(second); // 2 +console.log(rest); // [3, 4, 5] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a2be2893eed072654c7a2748704e4cc7e4e5aa72 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonA { + myName: string = ""; + age: number = 0; + city?: string = ""; +} + +let person: PersonA = { myName: "John", age: 30 }; +let { myName, age, city = "New York" }: PersonA = person; +console.log(city); // New York diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..631fa74a50bc76227eb059f9c96aa651fd72903c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..77989872d4fe13f94fd660a12db2f6b45c41f113 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonA { + myName: string = ""; + age: number = 0; + city?: string = ""; +} + +let person: PersonA = { myName: "John", age: 30 }; +let myName = person.myName +let age = person.age +let city = "New York" +console.log(city) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..957658f7d3cbedd8bafb05a2de08ab4514a49c42 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +function getNumbers(): [number, number, number] { + return [1, 2, 3]; +} + +let [x, y, z]: [number, number, number] = getNumbers(); +console.log(x); // 1 +console.log(y); // 2 +console.log(z); // 3 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..775dffbefcdee64d27abbfbc6eb992e81603dccc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ade042d7c4e623096113c9665802c22d5012ed31 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +function getNumbers(): [number, number, number] { + return [1, 2, 3]; +} + +let xyz = getNumbers() +let x = xyz[0] +let y = xyz[1] +let z = xyz[2] +console.log(x) +console.log(y) +console.log(z) + + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4afab9306dedf789c68bb6de1803d4ced6fe6bd6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-error.ets @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 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. + */ + + +class AddressInfo { + cityName: string = ""; + country: string = ""; +} + +class PersonB { + yourName: string = ""; + age: number = 0; + address: AddressInfo = { + cityName: "", + country: "", + }; +} + +let people: PersonB = { + yourName: "John", + age: 30, + address: { + cityName: "New York", + country: "USA", + }, +}; + +let { + yourName, + address: { cityName, country }, +}: PersonB = people; +console.log(yourName); // John +console.log(cityName); // New York +console.log(country); // USA diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..afa05f05eed7e2db33b99559698343bdedf94931 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 40, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 40, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f248714a576bf947044e40d7dab2257de4c0d907 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-ok.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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. + */ + + +class AddressInfo { + cityName: string = ""; + country: string = ""; +} + +class PersonB { + yourName: string = ""; + age: number = 0; + address: AddressInfo = { + cityName: "", + country: "", + }; +} + +let people: PersonB = { + yourName: "John", + age: 30, + address: { + cityName: "New York", + country: "USA", + }, +}; + +let yourName = people.yourName +let cityName = people.address.cityName +let country = people.address.country + +console.log(yourName); // John +console.log(cityName); // New York +console.log(country); // USA + + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca3074bd9f8e9f23e6173b616e820e38f2d345b8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 numbersArr: number[] = [1, 2, 3, 4, 5]; +let [, , third]: number[] = numbersArr; +console.log(third); // 3 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4ea97ea700046251dfef2ba5f400cfa069c0a691 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4d64a5330ac514a8472849afc6174cad1ae2999 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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 numbersArr: number[] = [1, 2, 3, 4, 5]; + +let third = numbersArr[2] + +console.log(third); // 3 + + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0a11c788f0fdfee467ce81b0902cb02117d2924 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 numbersOne: number[] = [1, 2, 3, 4, 5]; +let [one, two, ...three]: number[] = numbersOne; +console.log(one); // 1 +console.log(two); // 2 +console.log(three); // [3, 4, 5] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4ea97ea700046251dfef2ba5f400cfa069c0a691 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..edd85bb203231dc3c6dbc0fb2991cc080ad22c83 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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 numbersOne: number[] = [1, 2, 3, 4, 5]; + +let one = numbersOne[0] +let two = numbersOne[1] +let three: number[] = [] +for (let i = 2; i < numbersOne.length; i++) { + three.push(numbersOne[i]) +} + +console.log(one); // 1 +console.log(two); // 2 +console.log(three); // [3, 4, 5] + + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..101ac05fb795916b8b981f852de444ab6aaa147a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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 languageInfo governing permissions and + * limitations under the License. + */ + + +class PersonInfo { + NameInfo: string = ""; + ageInfo: number = 0; + cityInfo: string = ""; +} + +let personInfo: PersonInfo = { + NameInfo: "John", + ageInfo: 30, + cityInfo: "New York", +}; +let { NameInfo, ageInfo, cityInfo }: PersonInfo = personInfo; +console.log(NameInfo); // John +console.log(ageInfo); // 30 +console.log(cityInfo); // New York diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..646738879fa645d62e72cc1db6cbc5c1ac731627 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 28, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 28, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..042752a30462f2a602567bf3664420e09e8cc5b5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-ok.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonInfo { + NameInfo: string = ""; + ageInfo: number = 0; + cityInfo: string = ""; +} + +let personInfo: PersonInfo = { + NameInfo: "John", + ageInfo: 30, + cityInfo: "New York", +}; + +let NameInfo = personInfo.NameInfo +let ageInfo = personInfo.ageInfo +let cityInfo = personInfo.cityInfo + +console.log(NameInfo); // John +console.log(ageInfo); // 30 +console.log(cityInfo); // New York + + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-decls/arkts-no-destruct-decls-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f67fadac0731e952f2a879651cdb8a2739a47c2e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +interface ABC { + a?: number + b?: number + c?: number +} + +function sum({ a = 0, b = 0, c = 0 }: ABC) { + console.log(a + b + c) +} + +sum({ a: 10, b: 3, c: 9 }) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0d87d993d51a74b3d683e689e6d1e36c55134f49 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 24, + "character": 14 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 24, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..70f6d07a903da7e73cba62fda42fc9bf94cdac61 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +function sum(a: number, b: number, c: number): void { + console.log(a + b + c) +} + +sum(10, 3, 9) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..fdebdb0488465ad93ad9b63345f42f74eb75656c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +interface ABC { + a: number + b: number + c: number +} + +function sum({ a, b, c }: ABC) { + console.log(a + b + c) +} + +sum({ a: 10, b: 3, c: 9 }) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0d87d993d51a74b3d683e689e6d1e36c55134f49 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 24, + "character": 14 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 24, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0df7fd1cc9531c9dbb72a90feab626a674b4eaff --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +interface ABC { + a: number + b: number + c: number +} + +class Calculator { + sum(obj: ABC): void { + console.log(obj.a + obj.b + obj.c) + } +} + +const calculator = new Calculator() +calculator.sum({ a: 10, b: 3, c: 9 }) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..38d93506cc542e62bb7a3fc076494116433fe1e6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +interface Cat { + name: string + age: number +} + +class CatHandler { + fn({ name, age }: Cat): void { + console.log(name, age) + } +} + +const catHandler = new CatHandler() +catHandler.fn({ name: 'Persian cat', age: 11 }) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ea781de30b2f0050a3c8a433c7fc131df5eb6870 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 24, + "character": 6 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 24, + "character": 6 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..13563f5281c52c19fc234aa57841eb24e7f41a43 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +interface Cat { + name: string + age: number +} + +class CatHandler { + fn(obj: Cat): void { + console.log(obj.name, obj.age) + } +} + +const catHandler = new CatHandler() +catHandler.fn({ name: 'Persian cat', age: 11 }) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d62798b6c6de9d754f4e07584dbc53765526862c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +function sum({ a = 0, b = 0, c = 0 }): boolean { + const num = a + b + c + const isEven = num % 2 === 0 + console.log(isEven) + return isEven +} + +sum({ a: 10, b: 3, c: 9 }) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..70ae22e8500cc0d1257ba540b8244bfa4eb6aa7d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd53fc08db8219a0584ffaa1562870cb54970d0a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +function sum(a = 0, b = 0, c = 0): boolean { + const num = a + b + c + const isEven = num % 2 === 0 + console.log(isEven) + return isEven +} + +sum(10, 3, 9) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f0a0220848cbb6b6ea53c4dbcd099580a3ce1e9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +interface ArraySumParams { + numbers: number[] +} + +class Calculator { + arraySum({ numbers }: ArraySumParams): number { + return numbers.reduce((acc, curr) => acc + curr, 0) + } +} + +const calculator = new Calculator() +const result = calculator.arraySum({ numbers: [1, 2, 3, 4, 5] }) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..af20154cdc08233e50363a2a9f325d746b3d7bbf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 23, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 23, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a99026c45b372e9a28d22f475af89b494b7e898 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +interface ArraySumParams { + numbers: number[] +} + +class Calculator { + arraySum(params: ArraySumParams): number { + return params.numbers.reduce((acc, curr) => acc + curr, 0) + } +} + +const calculator = new Calculator() +const result = calculator.arraySum({ numbers: [1, 2, 3, 4, 5] }) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e250bb63c5a6e812991172ecb233ee6a67aaf4b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +interface MyObject { + name: string + age: number +} + +interface PropertyParams { + obj: MyObject + prop: keyof MyObject +} + +function getProperty({ obj, prop }: PropertyParams): string { + return obj[prop] +} + +const obj: MyObject = { name: 'xiaoming', age: 30 } +const propertyValue: string = getProperty({ obj, prop: 'name' }) +console.log(propertyValue) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..33f82cb13cf9cd0ed68b890e5a3851043d1f8a1b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 28, + "character": 22 + } + }, + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 29, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 28, + "character": 22 + } + }, + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 29, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..72380827e26739fb9defba47ac72bdb43f0974b7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +interface MyObject { + name: string + age: number +} + +interface PropertyParams { + obj: MyObject + prop: keyof MyObject +} + +function getProperty(params: PropertyParams): string { + return params.obj[params.prop] +} + +const obj: MyObject = { name: 'xiaoming', age: 30 } +const propertyValue: string = getProperty({ obj, prop: 'name' }) +console.log(propertyValue) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..64c73438b3813e2bae61a11a4fa1f5a4a7be5c40 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-6-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 29, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 29, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5672db5fb3138b6dd26c5510c95129455c97e300 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +interface StringParams { + str: string +} + +function toUpperCase({ str }: StringParams): string { + return str.toUpperCase() +} + +const result: string = toUpperCase({ str: 'hello' }) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b3b1b8d2433618ab08d1f566333d665f3d9165c5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 22, + "character": 22 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 22, + "character": 22 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..80e2732ccc050dbb37055cf16d9eacb3c3501a09 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +interface StringParams { + str: string +} + +function toUpperCase(params: StringParams): string { + return params.str.toUpperCase() +} + +const result: string = toUpperCase({ str: 'hello' }) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..eab36a9c773321fbad2706e963bee6cab54e3bf1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +interface JoinArrayParams { + arr: string[] + separator: string +} + +function joinArray({ arr, separator }: JoinArrayParams): string { + return arr.join(separator) +} + +const array: string[] = ['Hello', 'world'] +const separator: string = '-' +const result: string = joinArray({ arr: array, separator: separator }) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..fd600904b3aabe13077e32637f50cd85c47e1878 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 23, + "character": 20 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 23, + "character": 20 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..99b1793df4be54a09ae74500d82b251d19356dbb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +interface JoinArrayParams { + arr: string[] + separator: string +} + +function joinArray(params: JoinArrayParams): string { + return params.arr.join(params.separator) +} + +const array: string[] = ['Hello', 'world'] +const separator: string = '-' +const result: string = joinArray({ arr: array, separator: separator }) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..532e7f49d1663c40e4d8e958f9640ccc85ed5c63 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Function declaration for parameter deconstruction. +interface YearParams { + year: number +} + +function isLeapYear({ year }: YearParams): boolean { + return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) +} + +const result: boolean = isLeapYear({ year: 2023 }) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ef40a7646ddb854cb7239015ff89633c31887455 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 22, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 22, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e807f04ab6c747860c6d546d20638f30c686df4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Pass arguments directly to the function. +interface YearParams { + year: number +} + +function isLeapYear(params: YearParams): boolean { + return ( + params.year % 4 === 0 && + (params.year % 100 !== 0 || params.year % 400 === 0) + ) +} + +const result: boolean = isLeapYear({ year: 2023 }) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-destruct-params/arkts-no-destruct-params-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9cd8ab36270cd5c91c71f1bd88d9ce52d8819441 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type +enum Color { + RED, + GREEN +} +enum Color { + YELLOW = 2 +} +enum Color { + BLACK = 3, + BLUE +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ed72c87098c0f5f2be1071a3d029e1baaac607c1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e0184f8e3f2071bd6e2427b0f3bed73514185eb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type,initialize as an enum type +enum Color { + RED, + GREEN, + YELLOW, + BLACK, + BLUE +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9cd5e203fccfdbf899c3209012f719d3b7f77fb1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-error.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type +enum Fruit { + Apple = 1, + Orange = 2, + Banana = 3, +} + +enum Fruit { + Cherry = 4, + Grape = 5, +} + +type Fruits = Fruit | Fruit; + +const fruit: Fruits = Fruit.Banana; +console.log(fruit); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..834734e034628ab2eac71299c5f89d4d583cf5df --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..389b9314587459d59172e82cefb4054abab2571c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-ok.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type with `|` +enum Fruit1 { + Apple = 1, + Orange = 2, + Banana = 3, +} + +enum Fruit2 { + Cherry = 4, + Grape = 5, +} + +type Fruits = Fruit1 | Fruit2; + +const fruit: Fruits = Fruit1.Banana; +console.log(fruit); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..151ba3ed9c9f3e01dd0648e6feb834f61457fb26 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type +enum Foo { + A, +} +enum Foo { + B = 1, +} +enum Foo { + C = 2, +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..463e1224e134c42b57ce2941c11aad8379fcabd7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..31b5ec1aaa087947a7bb88fe463746f79089a72d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type +enum Foo { + A, + B = 1, + C = 2 +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..baada36061e7e969263ddc99e83e5feb94ad6de0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type with same name +enum Abc { + A = 'a', + B = 'b', + C = 'c' +} + +enum Abc { + D = 'd', + E = 'e', + F = 'f' +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..834734e034628ab2eac71299c5f89d4d583cf5df --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e163b5e9583e2a41f6c63f4c421e692f01209f74 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type with different name +enum Abc { + A = 'a', + B = 'b', + C = 'c' +} + +enum Def { + D = 'd', + E = 'e', + F = 'f' +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b1fe3f22d71fe02f86bd0d61257cccb7f1f8948 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type +enum Color { + RED = 1, GREEN = 2, BLUE = 3 +} + +enum Color { + CIRCLE = 4, SQUARE = 5, TRIANGLE = 6 +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4e5f99f5ebda49828a505034b0b5801314afa2bd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7e85ea25842314ab871956d4270fbdedf867138 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-ok.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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. + */ + + +// example: try to merge enum type +enum Color { + RED = 1, GREEN = 2, BLUE = 3 +} + +enum Shape { + CIRCLE = 4, SQUARE = 5, TRIANGLE = 6 +} + +// Convert to interface for merging +interface ColorOrShape { + color: Color; + shape: Shape; +} + +const colorOrShapes: ColorOrShape[] = [ + { color: Color.RED, shape: Shape.CIRCLE }, + { color: Color.GREEN, shape: Shape.SQUARE }, +]; + +console.log(colorOrShapes) + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-merging/arkts-no-enum-merging-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3734b03d98cc2f16e4e807152248a527f8f1eb96 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +// enum initialize members of different types explicitly +enum E1 { + A = 0xa, + B = 0xb, + C = 0xc, + D = 'foo' +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a73d85820cba91071df8a7172387f32d4e943b95 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9cb1f3fe60180d2e1f608b086d8bc68c897e7ab2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +// enum initialize members of same types explicitly +enum E1 { + A = 0xa, + B = 0xb, + C = 0xc, + D = 0xd, + E // should be 0xe +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3cbf470591ebd34f19cad0133c5d65fff863c5f6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +// enum initialize members of different types explicitly +enum CN { + Z = 'a', + H = 'b', + M = 'c', + X = 56 +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a73d85820cba91071df8a7172387f32d4e943b95 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c54050e2f67eb43c1e94d0386dd0a0f93079619e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +// enum initialize members of same types explicitly +enum CN { + Z = 'Z', + H = 'H', + M = 'M', + X = 'X' +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d09cef100ed056f93d06a50ddebaf369411e1295 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// enum initialize members of different types explicitly +enum UserResponse { + No = 0, + Yes = '1', +} + +function respond(recipient: string, message: UserResponse): void { + // ... +} + +respond("Princess Caroline", UserResponse.Yes); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..55b56da4817904d867f8e39af02b8a801e7d816a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bee8d773aff00ef86b80b7bc6c853ff9cb8e32e1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// enum initialize members of same types explicitly +enum UserResponse { + No = 0, + Yes = 1, +} + +function respond(recipient: string, message: UserResponse): void { + // ... +} + +respond("Princess Caroline", UserResponse.Yes); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..53dadcde46525dabb6929fe1820b3bb6687b6475 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-error.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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. + */ + + +// enum initialize members of different types explicitly +enum Operator { + ADD = 1, + DIV = 'D', + MUL = 2, + SUB +} +function compute( + op:Operator, + a:number, + b:number +) { + switch (op) { + case Operator.ADD: + return a + b; + case Operator.DIV: + return a / b; + case Operator.MUL: + return a * b; + case Operator.SUB: + return a - b; + default: + throw new Error('wrong operator'); + } +} +compute(Operator.ADD, 1, 3) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..55b56da4817904d867f8e39af02b8a801e7d816a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..50144857c2f5840eafb1a9fa12ed61c9cf8ca484 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-ok.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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. + */ + + +// initialize enumerations Implicitly +enum Operator { + ADD, + DIV, + MUL, + SUB +} +function compute( + op:Operator, + a:number, + b:number +) { + switch (op) { + case Operator.ADD: + return a + b; + case Operator.DIV: + return a / b; + case Operator.MUL: + return a * b; + case Operator.SUB: + return a - b; + default: + throw new Error('wrong operator'); + } +} +compute(Operator.ADD, 1, 3) // 4 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b8b69965a45daf3f1948c455a0eb8628a2620a2f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// ArkTS does not support initializing enumeration members with expressions that can only be evaluated during runtime +enum FileAccess { + // constant members + None, + Read = 1 << 1, + Write = 1 << 2, + ReadWrite = Read | Write, + // computed member + G = "123".length, +} +// 3 +console.log(FileAccess.G) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..99297006e6981248d7afb1c308e506168ae5f036 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e0e70db8dc56246df07e052aef69b9840097741b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-ok.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Initializing an enumeration member does not use calculations +/* +Constant enumeration expressions are a subset of TypeScript expressions that can be fully evaluated at compile time. An expression is a constant enumeration expression if it is: + +Literal enumeration expressions (basically string literals or numeric literals) +A reference to a previously defined constant enumeration member (can be derived from a different enumeration) +Constant enumeration expressions with parentheses +One of the +、-、~ unary operators applied to a constant enumeration expression ++、-、*, /, %, <<, >>, >>>, &, |, ^ use a constant enumeration expression as a binary operator for operands +Evaluating a constant enumeration expression to NaN or Infinity is a compile-time error. + +In all other cases, enumerated members are considered computational. +*/ + +enum FileAccess { + // constant members + None, + Read = 1 << 1, + Write = 1 << 2, + ReadWrite = Read | Write, + G = 3, +} +// 3 +console.log(FileAccess.G) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-enum-mixed-types/arkts-no-enum-mixed-types-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f07c6f43192a3c250e3512f66999c32eaefb567 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-1-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 interface Person { + name: string +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..14993dd8bbc1c3010c478af1826d95ae408df213 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-10-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +enum Direction { + Up, + Down, + Left, + Right, +} +export = Direction diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e970883ca23600e7a52125edd67cb10240e5050d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..dc40e0246e0f9921dabbeef5fe886c4d6e9e8800 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-2-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 function add(x:number, y:number): number{ + return x + y +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c5a6d8da3e6d60f2e75cbfa68c979aabb626ac3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-3-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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 class Person { + name: string + constructor(name: string) { + this.name = name + } + sayhi(): void { + console.log(this.name) + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7cfebb0fd0411f5b27067d33bb3925859a5f656 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-4-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 class Point { + constructor(x: number, y: number) {} + static origin = new Point(0, 0) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1866aa1c12e86c8142f02a17d5a82a9da91e0f84 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-5-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 = Person + +interface Person { + name: string +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c7917040cb3cff508fdf81ded8b0b67989029004 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c29589cd00a823d9a1ddbd92fac401c4d593a8d8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-6-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 = Point + +class Point { + constructor(x: number, y: number) {} + static origin = new Point(0, 0) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c7917040cb3cff508fdf81ded8b0b67989029004 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c3b49e9079972012dfa7e0e790c090d5a1aa6677 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-7-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Person { + name: string + constructor(name: string) { + this.name = name + } + sayhi(): void { + console.log(this.name) + } +} +export = Person diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0df032ff255c05d9e3411945d5b4dd84930a0ff9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..141a34d90f3271186bbad87175b7fc6337cfa9b1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-8-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Math { + static multiply(x: number, y: number) { + return x * y + } +} +export { Math } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b9d9a6f53150315830e304771f4637628fc9609 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-9-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +function add(x:number, y:number): number{ + return x+ y +} + +export = add \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f4619364e3553e0e48cb16a8823f3258b3fefdd6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-export-assignment/arkts-no-export-assignment-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..223a7d8e2508d2e0000d1e708c6d6682c5eabace --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-1-ok.ets @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use union types to declare the return value type of the method + +class MoveStatus { + public speed: number + constructor() { + this.speed = 0 + } +} +interface Mover { + getMoveStatus(): MoveStatus +} + +class ShakeStatus { + public frequency: number + constructor() { + this.frequency = 0 + } +} +interface Shaker { + getShakeStatus(): ShakeStatus +} + +class MoveAndShakeStatus { + public speed: number + public frequency: number + constructor() { + this.speed = 0 + this.frequency = 0 + } +} + +class C implements Mover, Shaker { + private move_status: MoveStatus + private shake_status: ShakeStatus + + constructor() { + this.move_status = new MoveStatus() + this.shake_status = new ShakeStatus() + } + + public getMoveStatus(): MoveStatus { + return this.move_status + } + + public getShakeStatus(): ShakeStatus { + return this.shake_status + } + + public getStatus(): MoveAndShakeStatus { + return { + speed: this.move_status.speed, + frequency: this.shake_status.frequency + } + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4966b3a49ad831faaf8bf57060efe85bcd93b2a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-10-error.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: An interface inherits two interfaces with the same method, and the return value is of multiple types + +interface InterfaceA { + methodA(): string; +} + +interface InterfaceB { + methodA(): number; +} + +interface InterfaceC extends InterfaceA, InterfaceB { + methodA(): string | number | boolean; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e46cc4f7fbf6dc4b33e10a7dcf3ec3dd96e3691e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..95feb79c39d69c8315e4e396bb6cb9159509557a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-11-error.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: An interface inherits an interface with the same method and a different method + +interface InterfaceA { + methodA(): string; +} + +interface InterfaceB { + methodA(): number; + methodB(): boolean; +} + +interface InterfaceC extends InterfaceA, InterfaceB { + methodA(): string | number; + methodB(): boolean; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9a0e68efffeb55f497f011a782cba5ae09831996 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-11-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..764293bac05737f4d12667674d77a7aa6cf71e4a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-2-error.ets @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: An interface inherits from two interfaces with the same method + +interface M { + speed: number +} + +interface S { + frequency: number +} + +interface MS { + speed: number + frequency: number +} + + +interface Mover { + getStatus(): M +} +interface Shaker { + getStatus(): S +} + +interface MoverShaker extends Mover, Shaker { + getStatus(): MS +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..53e3424cf6b93c8fd1fa2d3d31ce5c7c7ba9bb56 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 40, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 40, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..11ff2f22afae348bdb15234993a2de87b0043aa9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-3-error.ets @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The return value type is different + +interface InterfaceA { + method(): number; +} + +interface InterfaceB { + method(): string; +} + +interface InterfaceC extends InterfaceA, InterfaceB { + method(): number | string; +} + +const obj: InterfaceC = { + method() { + return 42; + } +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..56ee76a5c4e292317cce624f5ea91eb42fcd895a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 31, + "character": 25 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 31, + "character": 25 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5d56ed55d7bf38df97bfa9880b2a23959a4396c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-4-error.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The interface inherits from the two interfaces and modifies the function return value type + +interface InterfaceA { + method(): number; +} + +interface InterfaceB { + method(): string; +} + +interface InterfaceC extends InterfaceA, InterfaceB { + method(): string | number { + return 'Hello'; +} +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e46cc4f7fbf6dc4b33e10a7dcf3ec3dd96e3691e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d937f3b768db4386664a423cb8b822e6756d89c0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-5-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: An interface inherits two interfaces with the same method, but does not declare an implementation of the method + +interface InterfaceA { + method(): number; +} + +interface InterfaceB { + method(): number; +} + +interface InterfaceC extends InterfaceA, InterfaceB { } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ab631647f7a7e2b50b64e4e5527ea7981c0150e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-6-ok.ets @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The interface inherits different methods and different return values + +interface InterfaceA { + methodA(): string; +} + +interface InterfaceB { + methodB(): number; +} + +interface InterfaceC extends InterfaceA, InterfaceB { + methodA(): string; + methodB(): number; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e0a37be8d713f1980f3ff8ae11309cdeb477926 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-7-error.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: An interface inherits two interfaces with different return values for the same method + +interface InterfaceA { + method(): number; +} + +interface InterfaceB { + method(): string; +} + +interface InterfaceC extends InterfaceA, InterfaceB { + method(): number | string +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e46cc4f7fbf6dc4b33e10a7dcf3ec3dd96e3691e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..988a369377f129de06e2177bf5d732d9d6c6b0d1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-8-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The interface inherits two interfaces, one with methods and one without methods + +interface InterfaceA { + method(): number; +} + +interface InterfaceB { + //... +} + +interface InterfaceC extends InterfaceA, InterfaceB { } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3235695c03e1792444bfa9ad1a3e79ee034de181 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-9-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: An interface inherits two interfaces with the same method, with the same method parameter type but different order + +interface InterfaceA { + method(x: number, y: string): string; +} + +interface InterfaceB { + method(y: string, x: number): string; +} + +interface InterfaceC extends InterfaceA, InterfaceB { } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-extend-same-prop/arkts-no-extend-same-prop-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4862b98beac515b009c8d0d172b90dc6bb492146 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-1-ok.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:Since in ArkTS the object layout is deterministic at compile time and cannot be changed at runtime, the use of for.. initerate over the properties of an object. For arrays, you can use a regular for loop. +*/ +interface Person { + name: string; + age: number; + city: string; +} +const person: Person = { + name: "John", + age: 30, + city: "New York", +}; + +const properties = Object.getOwnPropertyNames(person); +properties.forEach((key) => { + console.log(key) + // console.log(key, person[key as keyof Person]); +}); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..51e3cc5cf31e757f66cb60ce591341d52da5758b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-10-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface MyObject { + prop1: string; + prop2: string; +} + + +function printObjectProperties(obj: MyObject, a: number, b: string) { + for (const prop in arguments) { + console.log(prop, arguments[prop]); + } +} + +const myObject: MyObject = { + prop1: "value1", + prop2: "value2", +}; + +printObjectProperties(myObject, 1, "d"); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2b594436b8e27be5308c84cd3b55b85e6fd07e90 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-10-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + }, + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 25, + "character": 23 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 24, + "character": 19 + } + }, + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 25, + "character": 23 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e56529bb6fea6e601deab385e21b941c3a7c60fe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-2-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +const fruits: string[] = ["apple", "banana", "orange"]; + +fruits.map((item: string): void => console.log(item)); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..766cd7ebe551c963983a2c238f2fa03076e75571 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-3-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:Since in ArkTS the object layout is deterministic at compile time and cannot be changed at runtime, the use of for.. initerate over the properties of an object. For arrays, you can use a regular for loop. +*/ +// Use the map method to iterate over the array +let strArr: string[] = ["a", "b", "c"]; +strArr.map((i: string): void => console.log(i)); + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7b6067b70158fafa39619cd4688c213048bd9eef --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-4-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +const str = "Hello"; + +for (let i = 0; i < str.length; i++) { + console.log(str[i]); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..8f13258f66abe3df42094df976387262e748d717 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-4-ok.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 20, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..267da12e6f56191aae18875d9bfe28ae9e1632a4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-5-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface MyObject { + prop1: string; + prop2: string; +} + +function printObjectProperties(obj: MyObject, a: number, b: string) { + for (let i = 0; i < arguments.length; i++) { + console.log(arguments[i]); + } +} + +const myObject: MyObject = { + prop1: "value1", + prop2: "value2", +}; + +printObjectProperties(myObject, 1, "d"); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..c16f2f84e21e9b5a15dbaa2fe2fd5944d9be4cd4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-5-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 24, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 24, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..14495577262127b3d001a4cea1efa26967dc3714 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-6-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Person { + name: string; + age: number; + city: string; +} + +const person: Person = { + name: "John", + age: 30, + city: "New York", +}; + +for (const key in person) { + console.log(key + ": " + person[key as keyof Person]); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5e21be140fdf4a67878cdf0c38751884f32f06db --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 29, + "character": 1 + } + }, + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 30, + "character": 28 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 29, + "character": 16 + } + }, + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 30, + "character": 28 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7011183c3b612a8da1b268031bd2f2f220eae2e4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-7-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +const fruits: string = ["apple", "banana", "orange"]; + +for (const index in fruits) { + console.log(index + ": " + fruits[index]); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..62c10d2a0116be0885c8a18ba942afaea65bcf12 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 19, + "character": 18 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e98952d2c4e543cf51f8be70c6669c55cb2c0f82 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-8-error.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 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 { JSDOM } from "jsdom"; + +// Create a virtual browser environment +const dom: ESObject = new JSDOM(`
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
`); + +// Get div elements in a virtual browser environment +const nodeList: HTMLCollectionOf = + dom.window.document.getElementsByTagName("div"); + +// Traverse the nodeList and print its innerText +for (let key in nodeList) { + console.log(nodeList[key].textContent); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4f54ef96d0f6148432448346c6f817d35c663169 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-8-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 20, + "character": 7 + } + }, + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 33, + "character": 3 + } + }, + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 36, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 20, + "character": 7 + } + }, + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 33, + "character": 3 + } + }, + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 36, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c34956d1cb18be8f9513d0567f5c99525b46fc4b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-9-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +const str = "Hello"; + +for (const index in str as any) { + console.log(index + ": " + (str as any)[index]); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cbeb552551d46df2294d16cb56808b0f66158379 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-for-in/arkts-no-for-in-9-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 28 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 20, + "character": 38 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"for .. in\" is not supported (arkts-no-for-in)", + "expectLineAndCharacter": { + "line": 19, + "character": 18 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 28 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 20, + "character": 38 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..bfcf272f5f790190d3642c8cb432b6d3987b540a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function sumValues(a:number, b:number):number { + return a + b; +} + +const args: number[] = [2, 3]; +const result: number[] = sumValues.apply(null, args); +console.log(result); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e8769d024634dcd2df9e1c74811dd5646edcd39f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 22, + "character": 26 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", + "expectLineAndCharacter": { + "line": 22, + "character": 36 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9123bae6cfb58884c6155d47e8be95c822621e99 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function sumValues(a: number, b: number): number { + return a + b; +} + +const args: number[] = [2, 3]; +const result: number[] = sumValues(...Array.from(args)); +console.log(result); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5ac4d28148e36259e7db7c11772c0f9891c9a391 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-error.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class A { + value: number = 0 + foo: Function = () => {} +} + +class Test { + value: number = 1234 + obj: A = { + value: this.value, + foo: this.foo.bind(this) + } + + foo() { + console.log(this.value) + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2907e9970949acd06e9e5d991da3ff81afcb2e97 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 12 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 26, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "'Function.bind' is not supported (arkts-no-func-bind)", + "expectLineAndCharacter": { + "line": 26, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c33cfbf7961582ce9fb4fedebc612bc32875fcad --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-ok.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class A { + value: number = 0 + foo: Function = () => {} +} + +class Test { + value: number = 1234 + foo: () => void = () => { + console.log(this.value) + } + obj: A = { + value: this.value, + foo: this.foo + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..661d912abdecaf8e44e1fa1197fc7ebdba2a8e68 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-error.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class A { + value:number; + constructor (value:number) { + this.value = value + } + + foo() { + console.log(this.value) + } +} + +let a1 = new A(1) +let a2 = new A(2) + +a1.foo() +a1.foo.apply(a2) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6ce15e639dffa265dd20fbd05627ef4d89e0e527 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 32, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", + "expectLineAndCharacter": { + "line": 32, + "character": 8 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d1ad35963ed2ea6d131fdd51a3461a5f3aa5876f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-ok.ets @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class A { + value:number; + constructor (value:number) { + this.value = value + } + + foo() { + this.fooApply(this) + } + + fooApply(a: A) { + console.log(a.value) + } +} + +let a1 = new A(1) +let a2 = new A(2) + +a1.foo() +a1.fooApply(a2) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f646405ecadc19d08569586c8eebd6f4230b2ef --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-error.ets @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2023 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 arr: number[] = [1, 2, 3, 4] +let str = String.fromCharCode.apply(null, Array.from(arr)) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d08633a481b0b0fd3bebf7a895a0558fce31d45a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 18, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + }, + { + "messageText": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", + "expectLineAndCharacter": { + "line": 18, + "character": 49 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f0f12422b4cad2f2a3e6ecf2e3f420d7a7f1056d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-ok.ets @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2023 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 arr: number[] = [1, 2, 3, 4] +let str = String.fromCharCode(...Array.from(arr)) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d13152a76748e51f6224f95ed2e21c5fe8fa7339 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-error.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Example { + value: number = 10; + + constructor() { + this.printValue = this.printValue.bind(this); + } + + printValue() { + console.log(this.value); + } +} + +const example = new Example(); +const printFunc = example.printValue; +printFunc(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..805017ad8204de0780d5f36b294fa678522699dd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 21, + "character": 23 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + }, + { + "messageText": "'Function.bind' is not supported (arkts-no-func-bind)", + "expectLineAndCharacter": { + "line": 21, + "character": 39 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5cf73f10aae671453c2c1d50cc366b5fa8991dc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-ok.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Example { + value: number = 10; + + constructor() { + this.printValue = this.printValue; + + } + + printValue = (): void => { + console.log(this.value); + } +} + +const example = new Example(); +const printFunc = example.printValue; +printFunc(); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-apply-bind-call/arkts-no-func-apply-bind-call-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5447e62e9a9d9fd5304645e39ada404a4ae770c0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const add = function (a: number): number { + return a; +}; + +add(4396); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..60ea68995e513f67156724a570d0060ba4e8560e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7a573d7629c42da7ff7b66dfa2c8378c4e933bad --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const add_arrow = (a: number): number => { + return a; +}; + +add_arrow(4396); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d571eac899c74fc3632055bc5253032bc279ae7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const greetFunc = function (name: string = "World"): string { + return `Hello, ${name}!`; +}; + +greetFunc(); +greetFunc('Xi an'); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4f62d0d270b31c1cd727d5c8402286a0cf27f7d3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ae41b99f0d8e739e9f6a8cbf270282b116b1d0e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const greet_arrows = (name: string = "World"): string => { + return `Hello, ${name}!`; +}; + +greet_arrows(); +greet_arrows("Xi an"); + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..2c254b9e36d8979cbd82e40367a22667cdf5fca8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const createUser = function ( + id: number, + name: string +): { id: number; name: string } { + return { + id, + name, + }; +}; + +console.log(createUser(996, "openharmony")); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..bc67aa7287e4e312ecaaecb41bb3f81bfeabf5c9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 20 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 4 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 20 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 4 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bbc7b2b7784c586237ae8aef33b669f69d608f80 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-ok.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class C { + id:number = 0 + name:string = '' +} + +const createUser_arrow = ( + id: number, + name: string +): C => { + return { + id, + name, + }; +}; + +console.log(createUser_arrow(996, "openharmony")); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..70ccedbee6334d08f5f8adca88b75fbdfa5f5e66 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const multiply = function (a: number, b: number, c: number): number { + return a * b * c; +}; + +console.log(multiply(3, 6, 9)); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f772e6d2911fd36936821697d80903c3cee46134 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f71c7992d0407a5a0e71c066f27f25aecbdca799 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const multiply_arrow = (a: number, b: number, c: number): number => { + return a * b * c; +}; + +console.log(multiply_arrow(3, 6, 9)); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f7550ff5d448f6a25d6ca194513b0f0b68fcc83 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const sumArray = function (arr: number[]): number { + return arr.reduce((acc, val) => acc + val, 0); +}; + +console.log(sumArray([66,88,99])); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f772e6d2911fd36936821697d80903c3cee46134 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..52e1c900dfd4454504f62f33a641a91f59e2deed --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const sumArray_arrow = (arr: number[]): number => { + return arr.reduce((acc, val) => acc + val, 0); +}; + +console.log(sumArray_arrow([66, 88, 99])); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3116dd029e6b1a4f08b6549135159e199f44eef9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class A1 { + age: number = 0; + name: string = ""; +} + +let a1: A1 = { age: 42, name: "foo" }; + +const getProperty = function (obj: A1): number { + return obj.age; +}; + +console.log(getProperty(a1)); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2589bd189e5f7f8373bacfe381dab62186825e56 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 24, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 24, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..51d2bd2fc2ff8debd3334de97279b92e05a58749 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class B1 { + age: number = 0; + name: string = ""; +} + +let b1: B1 = { age: 42, name: "foo" }; + +const getProperty_arrow = (obj: B1): number => { + return obj.age; +}; + +console.log(getProperty_arrow(b1)); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-expressions/arkts-no-func-expressions-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e21952c5c2934839304b624cd7fb755465358af --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function foo(value: number): void { + console.log(value.toString()) +} + +foo.add = (left: number, right: number) => { + return left + right +} + +foo.sub = (left: number, right: number) => { + return left - right +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a7638aadee23d60622bf59babccc282f87416ac4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c34ca7a7dd181be8fc3fb40957c4abd2ffcd3cad --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Foo1 { + static foo1(value: number): void { + console.log(value.toString()) + } + + static add(left: number, right: number): number { + return left + right + } + + static sub(left: number, right: number): number { + return left - right + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d343699eb8d07e0cd6175b4c7043d2c5db6d0fc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function doo(value: number): void { + console.log(value.toString()) +} + +doo.multiply = (left: number, right: number) => { + return left * right +} + +doo.divided = (left: number, right: number) => { + return left / right +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a7638aadee23d60622bf59babccc282f87416ac4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c2c032f4450f38043c198858368d8f41366d7a34 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Doo1 { + static doo1(value: number): void { + console.log(value.toString()) + } + + static add(left: number, right: number): number { + return left + right + } + + static sub(left: number, right: number): number { + return left - right + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ec7defe122e57b0be6f16907e8ef5b235ac9697 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-error.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function calculateAverage(...numbers: number[]): number { + const sum = numbers.reduce((total, num) => total + num, 0); + return sum / numbers.length; +} + +calculateAverage.rounded = (precision: number) => { + return (num: number): number => { + const factor = 10 ** precision; + return Math.round(num * factor) / factor; + }; +} + +const average = calculateAverage(2, 4, 6, 8, 10); +console.log(`The average is ${average}.`); + +const roundedAverage = calculateAverage.rounded(2)(average); +console.log(`The rounded average is ${roundedAverage}.`); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..faa23c7f6a2b7f14a9d9215ce1aa366c966afa57 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..82cfb52e05fbdc5fa537f06d492e72f92a27356c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-ok.ets @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Calculate { + static calculateAverage(...numbers: number[]): number { + const sum = numbers.reduce((total, num) => total + num, 0); + return sum / numbers.length; + } + static rounded(precision: number) { + return (num: number): number => { + const factor = 10 ** precision; + return Math.round(num * factor) / factor; + }; + } +} + +const average1:number = Calculate.calculateAverage(2, 4, 6, 8, 10); +console.log(`The average1 is ${average1}.`); + +const roundedAverage1:number = Calculate.rounded(2)(average1); +console.log(`The rounded average1 is ${roundedAverage1}.`); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..723fbce3c1b1efb194d135c531906200244873bf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-error.ets @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function formatName(firstName: string, lastName: string): string { + return `${lastName}, ${firstName}`; +} + +formatName.fullName = (firstName: string, lastName: string): string => { + return `${firstName} ${lastName}`; +} + +formatName.getInitials = (firstName: string, lastName: string): string => { + const firstInitial = firstName.charAt(0).toUpperCase(); + const lastInitial = lastName.charAt(0).toUpperCase(); + return `${firstInitial}.${lastInitial}.`; +} + +const formattedName = formatName("John", "Doe"); +console.log(`Formatted name: ${formattedName}`); + +const fullName = formatName.fullName("John", "Doe"); +console.log(`Full name: ${fullName}`); + +const initials = formatName.getInitials("John", "Doe"); +console.log(`Initials: ${initials}`); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a7638aadee23d60622bf59babccc282f87416ac4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..cdfec6353d54e995afd29649ad201507a33a9ff3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-ok.ets @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Format { + static formatName(firstName: string, lastName: string): string { + return `${lastName}, ${firstName}`; + } + static fullName = (firstName: string, lastName: string): string => { + return `${firstName} ${lastName}`; + } + static getInitials = (firstName: string, lastName: string): string => { + const firstInitial = firstName.charAt(0).toUpperCase(); + const lastInitial = lastName.charAt(0).toUpperCase(); + return `${firstInitial}.${lastInitial}.`; + } + +} + +const formattedName1:string = Format.formatName("John", "Doe"); +console.log(`Formatted name: ${formattedName1}`); + +const fullName:string = Format.fullName1("John", "Doe"); +console.log(`Full name: ${fullName}`); + +const initials1:string = Format.getInitials("John", "Doe"); +console.log(`Initials1: ${initials1}`); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..fa6ce0fa1760c7604e06301570954aa0441beac0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-error.ets @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function calculateFactorial(number: number): number { + if (number === 0 || number === 1) { + return 1; + } + return number * calculateFactorial(number - 1); +} + +calculateFactorial.description = "This function calculates the factorial of a number."; + +calculateFactorial.isEven = (number: number): boolean => { + return number % 2 === 0; +} + +calculateFactorial.isOdd = (number: number): boolean => { + return number % 2 !== 0; +} + +const factorial = calculateFactorial(5); +console.log(`The factorial of 5 is ${factorial}.`); + +const isEven = calculateFactorial.isEven(6); +console.log(`Is 6 even? ${isEven}`); + +const isOdd = calculateFactorial.isOdd(7); +console.log(`Is 7 odd? ${isOdd}`); + +console.log(calculateFactorial.description); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e1a9f69a4c5d52b4fcb16d992855ef2c57b77aba --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d9aa0ae81d4d42e16b07396bae7b30c7e7dc51c5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-ok.ets @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class CalculateFactorial { + static calculateFactorial(number: number): number { + if (number === 0 || number === 1) { + return 1; + } + return number * CalculateFactorial.calculateFactorial(number - 1); + } + static isEven = (number: number): boolean => { + return number % 2 === 0; + } + static isOdd = (number: number): boolean => { + return number % 2 !== 0; + } +} + +const factorial1 = CalculateFactorial.calculateFactorial(5); +console.log(`The factorial1 of 5 is ${factorial1}.`); + +const isEven1 = CalculateFactorial.isEven(6); +console.log(`Is 6 even? ${isEven1}`); + +const isOdd1 = CalculateFactorial.isOdd(7); +console.log(`Is 7 odd? ${isOdd1}`); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-func-props/arkts-no-func-props-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..36f3fae16b5eae9974306b456a41828a7bbad275 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Generator function generates an integer sequence. + +function* numberGenerator(n: number): Generator { + for (let i = 1; i <= n; i++) { + yield i + } +} + +const generator: Generator = numberGenerator(5) + +for (const num of generator) { + console.log(num) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1a462bdb2e998de57a31944354cd8e4077e6b4cd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7986a3a5dededbdc66a6afcb8a5a801cfd154d96 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-ok.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Using async or await mechanisms for parallel task processing. + +async function complexnumberGenerator(n: number): Promise { + return n +} + +async function numberGenerator() { + for (let i = 1; i <= 5; i++) { + console.log(await complexnumberGenerator(i)) + } +} + +numberGenerator() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..717f4ebbdbaff06bb70376c55d2b5033eeb12cf4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Generating a Fibonacci sequence using generator functions. + +function* fibonacciGenerator() { + let prev = 0 + let curr = 1 + + while (true) { + yield curr + const temp = prev + curr + prev = curr + curr = temp + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4b1b2cd779d704772c4b0d45343ff3ac7a820a75 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e0376ceaa108dc0c7ef37c21c6a042fcce986bb2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-ok.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Using async or await mechanisms for parallel task processing. + +function delay(ms: number): Promise { + return new Promise((resolve) => setTimeout(resolve, ms)) +} + +class FibonacciGenerator implements IterableIterator { + private prev: number = 0 + private curr: number = 1 + + public [Symbol.iterator](): IterableIterator { + return this + } + + public next(): IteratorResult { + const temp = this.prev + this.curr + this.prev = this.curr + this.curr = temp + return { value: this.curr, done: false } + } +} + +async function printFibonacciNumbers(): Promise { + const generator: FibonacciGenerator = new FibonacciGenerator() + + let count: number = 0 + for await (const num: number of generator) { + console.log(num) + count++ + if (count === 10) { + break + } + } +} + +printFibonacciNumbers() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..2db1eb1c3c8f812f621d2342ccfc41ea84f6d065 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-2-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 28 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 20, + "character": 28 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..822eebf38e8ae756ad13c6ac169ea7a5f481ab75 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Using generator functions to generate a random sequence of integers. + +function* randomIntegerGenerator(): Generator { + while (true) { + yield Math.floor(Math.random() * 100) + 1 + } +} + +const generator: Generator = randomIntegerGenerator() + +for (let i = 0; i < 10; i++) { + console.log(generator.next().value) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1a462bdb2e998de57a31944354cd8e4077e6b4cd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d7fc4cb9f073ba322ae7debdcb9426a8c576b94 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Using async or await mechanisms for parallel task processing. + +async function randomIntegerGenerator(): Promise { + return Math.floor(Math.random() * 100) + 1 +} + +async function printRandomIntegers(): Promise { + for (let i = 0; i < 10; i++) { + const randomInteger: number = await randomIntegerGenerator() + console.log(randomInteger) + } +} + +printRandomIntegers() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a7c255d85a2439d97be2c4976dccf24712490d1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Generate a random integer sequence within a given range using a generator function. + +function* randomRangeGenerator(min: number, max: number): Generator { + while (true) { + yield Math.floor(Math.random() * (max - min + 1)) + min + } +} + +const generator: Generator = randomRangeGenerator(10, 20) + +for (let i = 0; i < 10; i++) { + console.log(generator.next().value) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1a462bdb2e998de57a31944354cd8e4077e6b4cd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e2670af0b0a610af37f9be44101c043bb1c20f92 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Using async or await mechanisms for parallel task processing. + +async function randomRangeGenerator(min: number, max: number): Promise { + return Math.floor(Math.random() * (max - min + 1)) + min +} + +async function printRandomNumbers(): Promise { + for (let i = 0; i < 10; i++) { + const randomNum: number = await randomRangeGenerator(10, 20) + console.log(randomNum) + } +} + +printRandomNumbers() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..bc90da7cd2fa8c05165ea9e36c95b9b92140fc41 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-5-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Generate a character sequence using generator functions. + +function* characterGenerator(str: string): Generator { + for (let i = 0; i < str.length; i++) { + yield str[i] + } +} + +const generator: Generator = characterGenerator('Hello') + +for (let i = 0; i < 5; i++) { + console.log(generator.next().value) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1a462bdb2e998de57a31944354cd8e4077e6b4cd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8fbb29a0d0c62102c26286363f416a1a48bf9d86 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-6-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Generate a sequence of integers in reverse order using the generator function. + +function* reverseNumberGenerator(n: number): Generator { + for (let i = n; i >= 1; i--) { + yield i + } +} + +const generator: Generator = reverseNumberGenerator(5) + +for (let i = 0; i < 5; i++) { + console.log(generator.next().value) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1a462bdb2e998de57a31944354cd8e4077e6b4cd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e0611999833d1bb21939d17d79246b7837007f50 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-7-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Generating a binary sequence using generator functions. + +function* binaryGenerator(length: number): Generator { + for (let i = 0; i < 2 ** length; i++) { + yield i.toString(2).padStart(length, '0') + } +} + +const generator: Generator = binaryGenerator(4) + +for (let i = 0; i < 10; i++) { + console.log(generator.next().value) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1a462bdb2e998de57a31944354cd8e4077e6b4cd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generators/arkts-no-generators-7-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..cfb824f05124dec60a24745415b087c2669ae266 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-error.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const identity = (arg: T): T => arg; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..93f11e05afbb42ea2b5bb89d119f8f804fd6d71d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..257e9551fd4e8f707223c4be7c8ecf08de4fb081 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function identity(arg: T): T { + return arg; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c9b117967c82b91ecf9220a1ab9aff663272998e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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 generic_arrow_func_number = (x: T) => { + return x; +}; + +generic_arrow_func_number(123); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f5b6521f1a53061bb3e2617c6aadf0ecbc079711 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)", + "expectLineAndCharacter": { + "line": 17, + "character": 33 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce5bd1472a544fab0e59c3bb081ebe3cc117ebf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function generic_func_number(x: T): T { + return x; +} + +generic_func_number(123); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e3e7fea28c9f7010fd030fbbf32a5d17c325a1db --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const getLength = (arg: T, defaultValue: number = 0): number => { + if (typeof arg === 'number') { + return arg; + } else { + return defaultValue; + } +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..71aa1a37fc300195cfc5f84993d27655536c0c1f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fdc15debbf708c36eb1099941937883934d71b8a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function getLength (arg: T, defaultValue: number = 0): number { + if (typeof arg === 'number') { + return arg; + } else { + return defaultValue; + } +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..40b0a7e4d8f016fcc053c14c7d33309fe0eab241 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const createArray = (length: number, value: T): T[] => { + return new Array(length).fill(value); +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..526615c1d27f7abfd8d6809d01d9873b8d21d99e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)", + "expectLineAndCharacter": { + "line": 17, + "character": 21 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..eaa85a4b4844b96433fde09611a968ea967e9e29 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function createArray (length: number, value: T): T[] { + return new Array(length).fill(value); +}; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5af7b337a46ccb7a7341bb8ddf9f527db069895f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-error.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const sum = (a: T, b: T): T => a + b; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9236fe926a4ee91f31ddcb06116c70fd93b08c4b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)", + "expectLineAndCharacter": { + "line": 17, + "character": 13 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4da89a2a07313878a26a1e30841490785a60645b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function sum (a: T, b: T): T { + a + b; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-generic-lambdas/arkts-no-generic-lambdas-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c4fdbff932b796f4cda3f4cd031039c990135d8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 x: number = globalThis.abc \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..556b1eb346e9e0c4deb29c1b18c922f2c264bc2d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 17, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 17, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.ts new file mode 100644 index 0000000000000000000000000000000000000000..dce5c5f6bb5fbedf99d8a928bf729524c1a3f799 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-error/arkts-no-globalthis-1-error.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 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 abc: number = 100; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..de9e8cb034997465a19d7cddebbab3c38aeffbdd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 * as M from 'arkts-no-globalthis-1-ok' + +let x: number = M.abc \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..581dd47c2d16cb845aaf7e1c8d95cf12bd9699b2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-1-ok/arkts-no-globalthis-1-ok.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 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 let abc: number = 100; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..082df9734b1579bc7bcce1d2fc9086513dcb777c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +console.log(globalThis.Math.PI) // use global module Math \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..21e881c88261047d771a3cec5816c8c4c43f8115 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 17, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 17, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad7f5a86664c7d47d4e6b4a6aa74b5346b9a8bbe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 PI from Math + +console.log(PI) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..91ee65792d99c1d21ae45da1eb61cb5c2f9a2cf7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 x: number[] = globalThis.abc \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..581bb3d6696c91bd33b9bcae5ffdc99e66ea3922 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.ts new file mode 100644 index 0000000000000000000000000000000000000000..983d69dd9255025de5954f4b5bd45d2aaa339a2f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-error/arkts-no-globalthis-3-error.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 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 abc: number[] = [1, 2, 3]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a2c8b6296de5b289bc08f7497b605f23b88931a9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 * as M from 'arkts-no-globalthis-1-ok' + +let x: number[] = M.abc \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..aa3c2f4e1abe395a4b95e4cc5052f43cee9024af --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-3-ok/arkts-no-globalthis-3-ok.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 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 let abc: number[] = [100]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff2ba78af419692c79d018840694e1a7de95818c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 x: string = globalThis.foo \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..556b1eb346e9e0c4deb29c1b18c922f2c264bc2d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 17, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 17, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.ts new file mode 100644 index 0000000000000000000000000000000000000000..b064e411bd996a6397c29bb59f2b99f70ccf14c0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-error/arkts-no-globalthis-4-error.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 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 foo: string = 'hello'; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f14e247bf0a3f5b3303d75fe4e174ca0be19e1f6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 * as M from 'arkts-no-globalthis-4-ok' + +let x: number = M.foo \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..51a7752e526e0a09984dd33d8dca65cc61c3e9fe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-4-ok/arkts-no-globalthis-4-ok.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 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 let foo: string = 'hello'; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9db71353c59b74da85ca320b0a8205eff4a2dff1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// in bowser +console.log(globalThis.document === document) // true + +// run in Node.js +console.log(globalThis.process === process) // true + +// run in Web Worker +console.log(globalThis.self === self) // true + +// run in share Web Worker +console.log(globalThis.sharedWorker === sharedWorker) // true \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..67ff0b88680c9118bbe936d6e1d2d47ae5abe09f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 18, + "character": 13 + } + }, + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + }, + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 24, + "character": 13 + } + }, + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 27, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 18, + "character": 13 + } + }, + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + }, + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 24, + "character": 13 + } + }, + { + "messageText": "\"globalThis\" is not supported (arkts-no-globalthis)", + "expectLineAndCharacter": { + "line": 27, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a9a402d411a0bd9458fe5a8c5c9089bff576db7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// in bowser +console.log(document === document) // true + +// run in Node.js +console.log(process === process) // true + +// run in Web Worker +console.log(self === self) // true + +// run in share Web Worker +console.log(sharedWorker === sharedWorker) // true \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-globalthis/arkts-no-globalthis-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..51219c66487bbb7de90e484bea161b80ab6893c9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Call the add function without significantly annotated return type. +function add(a: number, b: number) { + return a + b +} + +function callAddFunction(a: number, b: number) { + return add(a, b) +} + +console.log(callAddFunction(2, 3)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..68f135bfedade88069344e487cdf2be66cfbe7c6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..be044cd03f3a5d85644145dfb7c53fe7a4d99d86 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Call the add function with significantly annotated return types. +function add(a: number, b: number): number { + return a + b +} + +// The return data type can be omitted and will be inferred based on the return type of the add function +function callAddFunction(a: number, b: number) { + return add(a, b) +} + +console.log(callAddFunction(2, 3)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb80e073184194653049a5abe68981dfa982c30b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +function isPalindrome(str: string) { + const reversedStr = str.split('').reverse().join('') + return str === reversedStr +} + +function callIsPalindromeFunction(str: string) { + return isPalindrome(str) +} + +console.log(callIsPalindromeFunction('aaaa')) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..28cf4ccf63fcb33dfd0f56342f5c8c58ca2a63d7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..825d9fd1a86d723515394d1428674a980d119c11 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +function isPalindrome(str: string): boolean { + const reversedStr = str.split('').reverse().join('') + return str === reversedStr +} + +function callIsPalindromeFunction(str: string): boolean { + return isPalindrome(str) +} + +console.log(callIsPalindromeFunction('aaaa')) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..95e60efd4ee8319d1bfa2e9ff945eb8bbfcfd793 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +function multiply(a: number, b: number) { + return a * b +} + +function callMultiplyFunction(a: number, b: number) { + return multiply(a, b) +} + +console.log(callMultiplyFunction(2, 3)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..68f135bfedade88069344e487cdf2be66cfbe7c6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..af5d9665e002a554d72352e14ae74f54e151ee76 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +function multiply(a: number, b: number): number { + return a * b +} + +// The return type can be omitted, and it will be inferred based on the return type of the multiply function. +function callMultiplyFunction(a: number, b: number): number { + return multiply(a, b) +} + +console.log(callMultiplyFunction(2, 3)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..947ca6262b6fb09b51d741e8df797162f4d38620 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +function concatenateStrings(a: string, b: string) { + return a + b +} + +function callConcatenateStringsFunction(a: string, b: string) { + return concatenateStrings(a, b) +} + +console.log(callConcatenateStringsFunction('aa', 'bb')) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..68f135bfedade88069344e487cdf2be66cfbe7c6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c076620ec546023b78ff897ae77ac1a68c04053d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +function concatenateStrings(a: string, b: string): string { + return a + b +} + +function callConcatenateStringsFunction(a: string, b: string) { + return concatenateStrings(a, b) +} + +console.log(callConcatenateStringsFunction('aa', 'bb')) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f0d0cb3e139d83ee36459f04ed72a2b773f590e3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +function calculateAverage(numbers: number[]) { + const sum = numbers.reduce((acc, curr) => acc + curr, 0) + return sum / numbers.length +} + +function callCalculateAverageFunction(numbers: number[]) { + return calculateAverage(numbers) +} +console.log(callCalculateAverageFunction([1, 2, 3, 4, 5, 6, 7, 8, 9])) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..28cf4ccf63fcb33dfd0f56342f5c8c58ca2a63d7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..02a8147cc1a7b2a7a5f4300e903b9d768b2c26d3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +function calculateAverage(numbers: number[]): number { + const sum = numbers.reduce((acc, curr) => acc + curr, 0) + return sum / numbers.length +} + +function callCalculateAverageFunction(numbers: number[]): number { + return calculateAverage(numbers) +} +console.log(callCalculateAverageFunction([1, 2, 3, 4, 5, 6, 7, 8, 9])) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9fd578c0a8f42b011c48a9514eb7210879e3c7a6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +const now = new Date() +function formatDate(date: Date) { + const year = date.getFullYear() + const month = String(date.getMonth() + 1).padStart(2, '0') + const day = String(date.getDate()).padStart(2, '0') + const hours = String(date.getHours()).padStart(2, '0') + const minutes = String(date.getMinutes()).padStart(2, '0') + const seconds = String(date.getSeconds()).padStart(2, '0') + + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}` +} + +function callFormatDateFunction(date: Date) { + return formatDate(date) +} + +console.log(callFormatDateFunction(now)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3236d3ae4f1bc627c3f5f3a0d9d1cf2fc17d1076 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 30, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e6e00c0d9ac9cde998aa6a3f8dfa130526e6eae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +const now = new Date() +function formatDate(date: Date): string { + const year = date.getFullYear() + const month = String(date.getMonth() + 1).padStart(2, '0') + const day = String(date.getDate()).padStart(2, '0') + const hours = String(date.getHours()).padStart(2, '0') + const minutes = String(date.getMinutes()).padStart(2, '0') + const seconds = String(date.getSeconds()).padStart(2, '0') + + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}` +} + +function callFormatDateFunction(date: Date): string { + return formatDate(date) +} + +console.log(callFormatDateFunction(now)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..439cdeebe03281d8abdf818d4d9146444b5e5e40 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +function reverseString(str: string) { + return str.split('').reverse().join('') +} + +function callReverseStringFunction(str: string) { + return reverseString(str) +} + +console.log(callReverseStringFunction('abcd')) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..68f135bfedade88069344e487cdf2be66cfbe7c6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c7ac08c64a751ce6c1a2cf4557ffb0b937daf483 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +function reverseString(str: string): string { + return str.split('').reverse().join('') +} + +function callReverseStringFunction(str: string): string { + return reverseString(str) +} + +console.log(callReverseStringFunction('abcd')) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca10e5e770acfd2c5396758b88eb81c6cc0c8a3a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +function filterArray(numbers: number[], predicate: (num: number) => boolean) { + return numbers.filter(predicate) +} + +function isEven(num: number): boolean { + return num % 2 === 0 +} + +function callFilterArrayFunction(numbers: number[]) { + return filterArray(numbers, isEven) +} + +console.log(callFilterArrayFunction([1, 2, 3, 4])) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..bb13566785a43328f9af1a145bc97febc418896c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..dfab9051cd22489996c0a1be4c066a1c0af57902 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +function filterArray( + numbers: number[], + predicate: (num: number) => boolean +): number[] { + return numbers.filter(predicate) +} + +function isEven(num: number): boolean { + return num % 2 === 0 +} + +function callFilterArrayFunction(numbers: number[]): number[] { + return filterArray(numbers, isEven) +} + +console.log(callFilterArrayFunction([1, 2, 3, 4])) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a8248f8d74614ed03d657f94a63705b89f8f445d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +function calculateSum(numbers: number[]) { + return numbers.reduce((acc, curr) => acc + curr, 0) +} + +function callCalculateSumFunction(numbers: number[]) { + return calculateSum(numbers) +} + +console.log(callCalculateSumFunction([1, 2, 3, 4, 5])) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..68f135bfedade88069344e487cdf2be66cfbe7c6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f86942bad5d0651ab2df613e918197b504b873d6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +function calculateSum(numbers: number[]): number { + return numbers.reduce((acc, curr) => acc + curr, 0) +} + +function callCalculateSumFunction(numbers: number[]): number { + return calculateSum(numbers) +} + +console.log(callCalculateSumFunction([1, 2, 3, 4, 5])) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..22601c65306cde63c308cc163beeb5c9347c01d3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Calling a function without a return type. +function findMax(numbers: number[]) { + return Math.max(...numbers) +} + +function callFindMaxFunction(numbers: number[]) { + return findMax(numbers) +} + +console.log(callFindMaxFunction([1, 2, 3, 4, 5])) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..68f135bfedade88069344e487cdf2be66cfbe7c6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1c96e5f86b131357e3a8a8fd78650c9251f26bc0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Positive example: Calling functions with significantly annotated return types. +function findMax(numbers: number[]): number { + return Math.max(...numbers) +} + +function callFindMaxFunction(numbers: number[]): number { + return findMax(numbers) +} + +console.log(callFindMaxFunction([1, 2, 3, 4, 5])) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-implicit-return-types/arkts-no-implicit-return-types-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bc1d853c8acd8d9afba39e5270bdd6c9f9e195a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-1-error.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 { obj } from './path/something' assert { type: 'json' } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..082df707d6ea56f3db6c773ecf1ccace534ea154 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-1-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Import assertions are not supported (arkts-no-import-assertions)", + "expectLineAndCharacter": { + "line": 17, + "character": 40 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7084709fb295821867a6c939ffe23a60aa4470e4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-10-ok.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 testRule from './testExample/testRule' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b1b06e19323e92776413a2b17a73d6db2baacc2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-2-ok.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 { something } from './path/module' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9cab1bb9e162159427071e5a1469440413461ec5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-3-error.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 something from './path/something' assert { type: 'json' }; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f7b29189e6b62469725c86272baed16c17352b74 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-3-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Import assertions are not supported (arkts-no-import-assertions)", + "expectLineAndCharacter": { + "line": 17, + "character": 42 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..36a69be01cf981aa7830684173b332c7a4f91d57 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-4-ok.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 something from './path/something' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..2aee238e772df859c9332d548bc0db12ec028d9f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-5-error.ets @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2023 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 { MyModule } from './path/my-module' assert { type: 'custom' }; + \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d3e37551dd3c85fdf8f2b305d8288bb1e605d964 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-5-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Import assertions are not supported (arkts-no-import-assertions)", + "expectLineAndCharacter": { + "line": 17, + "character": 45 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b814c6357908bce9a502f4c9d38c85f9ce82e97 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-6-ok.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 { MyModule } from './path/my-module'; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4fd5fdc683dbad8a4691a3be3bb156a395f69cdb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-7-error.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 { addition } from './testExample/utilsOne' assert { type: 'js' } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..79fb95c8d98f53baa569116963593154e4d891dd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-7-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Import assertions are not supported (arkts-no-import-assertions)", + "expectLineAndCharacter": { + "line": 17, + "character": 51 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..389008d71c7b7b0ab347a572df84c73dfd74ca6a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-8-ok.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 { addition } from './testExample/utilsOne' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1be2c76439b61694333cf9092f4d9c0d4e59535 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-9-error.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 testRule from './testExample/testRule-dependencie' assert { type: 'ets' } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0416292560baca6ea5afe28734a2d6e1df97f334 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/arkts-no-import-assertions-9-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Import assertions are not supported (arkts-no-import-assertions)", + "expectLineAndCharacter": { + "line": 17, + "character": 59 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/module.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/module.ts new file mode 100644 index 0000000000000000000000000000000000000000..b7d83797841fd9d878b70ec14c05afcacc83268f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/module.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + +// module.ts +export default function greet(name: string) { + console.log(`Hello, ${name}!`); +} + +export function sum(a: number, b: number) { + return a + b; +} + +export const PI = 3.14; + +export const something = { + obj: { + name: 'John', + age: 30, + city: 'New York' + } +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/my-module.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/my-module.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3656247441c20750b759760227fbfbfac5b66c1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/my-module.ts @@ -0,0 +1,11 @@ +// my-module.ts + +interface MyModule { + type: 'custom'; + // other... +} + +export const MyModule: MyModule = { + type: 'custom' + // other... +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/something.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/something.json new file mode 100644 index 0000000000000000000000000000000000000000..db92326e3b726c45b6218fd9c6c78d35b9715834 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/something.json @@ -0,0 +1,7 @@ +{ + "obj": { + "name": "John", + "age": 30, + "city": "New York" + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/styles.css b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/styles.css new file mode 100644 index 0000000000000000000000000000000000000000..0fcea5d311ca3822663eb93e2fadd84369e9ca66 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/path/styles.css @@ -0,0 +1,13 @@ +body { + font-family: Arial, sans-serif; + background-color: #f2f2f2; +} + +h1 { + color: #333; +} + +p { + color: #666; + line-height: 1.5; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/testRule-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/testRule-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..5764ce98ff20ece9e7526df724f3f79d3a24fc87 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/testRule-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class Point { + constructor(x: number, y: number) {} + static origin = new Point(0, 0) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/testRule-dependencie.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/testRule-dependencie.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/testRule-dependencie.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/utilsOne.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/utilsOne.js new file mode 100644 index 0000000000000000000000000000000000000000..da781d44c314b6f4e69778ba4c6f033b83daa4c6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-assertions/testExample/utilsOne.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + +function addition(a, b) { + return a + b; + } + + function multiply(a, b) { + return a * b; + } + + module.exports = { + addition: addition, + multiply: multiply, + }; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/arkts-no-import-default-as-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/arkts-no-import-default-as-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0c97be8734107ce0cc2573d4a022a773eb0ec871 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/arkts-no-import-default-as-1-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Using import... from... + +import { fn } from 'lib1-dependencie' + +fn() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/arkts-no-import-default-as-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/arkts-no-import-default-as-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/arkts-no-import-default-as-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b18843e456b962867306e3e22e694a47fc33046 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-1-ok/lib1-dependencie.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function fn() { + // do something ... +} +export default { + fn +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/arkts-no-import-default-as-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/arkts-no-import-default-as-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7270f17889524a619b29ece47ca4dd83863f32f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/arkts-no-import-default-as-10-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Multiple file import modules + +import { module1 } from 'lib1-dependencie'; +import { module2 } from 'lib2-dependencie'; + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/arkts-no-import-default-as-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/arkts-no-import-default-as-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/arkts-no-import-default-as-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..939abb764d4b21f65b2f45e4ccc89d00e5a406ae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/lib1-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 let module1 = { + name : 'module1' +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/lib2-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/lib2-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..148e6fc7a750fd03f094bbe0dc955788b407a002 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-10-ok/lib2-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 let module2 = { + name : 'module2' +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/arkts-no-import-default-as-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/arkts-no-import-default-as-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f2c7d06c4f5b302f03814028f633d20a05aa486a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/arkts-no-import-default-as-2-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use import default as ... Import + +import { default as d } from 'lib1-dependencie' + +d.fn() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/arkts-no-import-default-as-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/arkts-no-import-default-as-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9cd7861616cdf54b1020c95e4d747bc62f99bde7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/arkts-no-import-default-as-2-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import default as ...\" is not supported (arkts-no-import-default-as)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bca878ea48445c1484f7b90bf175cd0c170cebc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-2-error/lib1-dependencie.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function fn() { + // do something ... +} +export default { + fn +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/arkts-no-import-default-as-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/arkts-no-import-default-as-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e190d13c67bd691216ad69a3ce0c4e1c9d1bb65 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/arkts-no-import-default-as-3-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import using import * as + +import * as d from 'lib1-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/arkts-no-import-default-as-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/arkts-no-import-default-as-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/arkts-no-import-default-as-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bca878ea48445c1484f7b90bf175cd0c170cebc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-3-ok/lib1-dependencie.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function fn() { + // do something ... +} +export default { + fn +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/arkts-no-import-default-as-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/arkts-no-import-default-as-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..915f08699ddc6a8baf27e4636179ca3869808054 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/arkts-no-import-default-as-4-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import a named exported module + +import { modules } from 'lib1-dependencie'; + +modules.module1.fn() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/arkts-no-import-default-as-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/arkts-no-import-default-as-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/arkts-no-import-default-as-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..0733fdabc6edb845bad592dff98a5e16743dad8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-4-ok/lib1-dependencie.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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 let modules = { + module1: { + name: 'module1', + fn() { + // do something ... + } + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/arkts-no-import-default-as-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/arkts-no-import-default-as-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f0219f95ea35a537424fdd8c925504bc29128805 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/arkts-no-import-default-as-5-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import multiple named exported modules + +import { module1, module2 } from 'lib1-dependencie'; + +module1.fn() +module2.fn() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/arkts-no-import-default-as-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/arkts-no-import-default-as-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/arkts-no-import-default-as-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..2bb88022832687045c1ad6cd76b5091952441aaf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-5-ok/lib1-dependencie.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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 let module1 = { + name: 'module1', + fn() { + // do something ... + } +} + +export let module2 = { + name: 'module2', + fn() { + // do something ... + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/arkts-no-import-default-as-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/arkts-no-import-default-as-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc4251de7f135d0b0eb34dff1b22fca616003c07 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/arkts-no-import-default-as-6-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import and rename the exported module with a name + +import { module1 as module3 } from 'lib1-dependencie'; + +module3.fn() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/arkts-no-import-default-as-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/arkts-no-import-default-as-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/arkts-no-import-default-as-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..2bb88022832687045c1ad6cd76b5091952441aaf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-6-ok/lib1-dependencie.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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 let module1 = { + name: 'module1', + fn() { + // do something ... + } +} + +export let module2 = { + name: 'module2', + fn() { + // do something ... + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/arkts-no-import-default-as-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/arkts-no-import-default-as-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c9d6d98a375d884d6c46e924ba1588b805a48993 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/arkts-no-import-default-as-7-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import all content + +import * as modules from 'lib1-dependencie'; + +modules.module1.fn() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/arkts-no-import-default-as-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/arkts-no-import-default-as-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/arkts-no-import-default-as-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..2bb88022832687045c1ad6cd76b5091952441aaf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-7-ok/lib1-dependencie.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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 let module1 = { + name: 'module1', + fn() { + // do something ... + } +} + +export let module2 = { + name: 'module2', + fn() { + // do something ... + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/arkts-no-import-default-as-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/arkts-no-import-default-as-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b035534eaa09e9cc98f48f8efbac7754dd0b956 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/arkts-no-import-default-as-8-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import empty content + +import { } from 'lib1-dependencie'; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/arkts-no-import-default-as-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/arkts-no-import-default-as-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/arkts-no-import-default-as-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..2bb88022832687045c1ad6cd76b5091952441aaf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-8-ok/lib1-dependencie.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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 let module1 = { + name: 'module1', + fn() { + // do something ... + } +} + +export let module2 = { + name: 'module2', + fn() { + // do something ... + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/arkts-no-import-default-as-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/arkts-no-import-default-as-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..abc42d08a0afcf5f6375d74c14ffb1c597b6664c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/arkts-no-import-default-as-9-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Multiple module import + +import { default as m } from 'lib1-dependencie'; + +console.log(m.name) + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/arkts-no-import-default-as-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/arkts-no-import-default-as-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9cd7861616cdf54b1020c95e4d747bc62f99bde7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/arkts-no-import-default-as-9-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import default as ...\" is not supported (arkts-no-import-default-as)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..e7348b95f086401510d501461d6eb5e4d7bd8458 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-import-default-as/arkts-no-import-default-as-9-error/lib1-dependencie.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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 modules = { + name: 'modules' +} + +export default modules diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..151751088cf68d91dc73566038ca09fac2a67633 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonOne { + name: string; + age: number; + + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } +} + +const personOne = new PersonOne("John", 25); + +console.log("name" in personOne); +console.log("gender" in personOne); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..897bd6b153db3aa959d89f5df1ac61e44bcea8bb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 29, + "character": 20 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 30, + "character": 22 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 29, + "character": 20 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 30, + "character": 22 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6641269a8d9547376a1d1f06c9f479a9cd55d522 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonRight { + name: string; + age: number; + + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } +} + +const personRight = new PersonRight("John", 25); + +console.log(personRight instanceof PersonRight); +console.log(personRight instanceof PersonRight); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e45eaa25f56c8e6ced3e0cb11600b38186347fd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-error.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonTwo { + name: string; + + constructor(name: string) { + this.name = name; + } + + greet() { + console.log(`Hello, my name is ${this.name}.`); + } +} + +const personTwo = new PersonTwo("John"); + +console.log("greet" in personTwo); +console.log("age" in personTwo); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7727b2d2c4d5d0a3124e1df5e748d51e7d433df2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 31, + "character": 21 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 32, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 31, + "character": 21 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 32, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..deccc387dcce2c1ac68f26039fc313b9b9c9e37e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-ok.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonTwoRight { + name: string; + + constructor(name: string) { + this.name = name; + } + + greet() { + console.log(`Hello, my name is ${this.name}.`); + } +} + +const personTwoRight = new PersonTwoRight("John"); + +console.log(personTwoRight instanceof PersonTwoRight); +console.log(personTwoRight instanceof PersonTwoRight); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..76aab08e040346b81cc9a2c19e7bc9d13ee543a1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonThree { + static species: string = "Homo sapiens"; +} + +const personThree = new PersonThree(); +console.log("species" in personThree); +console.log("name" in personThree); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..aa082bda60c61365bcf66be75ddd6d6ac6049425 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 22, + "character": 23 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 23, + "character": 20 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 22, + "character": 23 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 23, + "character": 20 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..13c84716506e5abfb41ab463563e2e11233fa4d2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonThreeRight { + static species: string = "Homo sapiens"; +} + +const personThreeRight = new PersonThreeRight(); +console.log(personThreeRight instanceof PersonThreeRight); +console.log(personThreeRight instanceof PersonThreeRight); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9ec6e211a250c31d63132eea18b7f8ae7959eb1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-error.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonFour { + name: string; + + constructor(name: string) { + this.name = name; + } + + greet() { + console.log(`Hello, my name is ${this.name}.`); + } +} + +const personFour = new PersonFour("John"); + +console.log("greet" in personFour); // true +console.log("toString" in personFour); // true diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..bfaa7bfffccd8d3971d8850dda47bf6f4ba2af12 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 31, + "character": 21 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 32, + "character": 24 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 31, + "character": 21 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 32, + "character": 24 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bf9846094fb4efecebe8fba8c8a5a01a081dbc9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-ok.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonFourRight { + name: string; + + constructor(name: string) { + this.name = name; + } + + greet() { + console.log(`Hello, my name is ${this.name}.`); + } +} + +const personFourRight = new PersonFourRight("John"); + +console.log(personFourRight instanceof PersonFourRight); // true +console.log(personFourRight instanceof PersonFourRight); // true diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b3e28c7ffdb2089c5135137ec0f48e31babfdb3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonFive { + name: string = ""; +} +let per = new PersonFive(); + +let bear = "name" in per; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9735c1e1afcecb7c05540d37b45f980f944a088c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 22, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 22, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..16343fe5c752b562436e8b1e4585625234c6f499 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PersonFiveRight { + name: string = ""; +} +let perch = new PersonFiveRight(); + +let berch = p instanceof PersonFiveRight; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-in/arkts-no-in-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..66c15ff5f23c25e2cf1484c9ea82f2a585aa2702 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Simulate dictionary objects and use string keys to access values. +interface Dictionary { + [key: string]: string +} +const dictionary: Dictionary = { word1: 'definition1', word2: 'definition2' } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..fd789fead30d06f6a8e7ea7d680247939407295c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 32 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 32 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..81dc312839d0af1a335a246807da9ad00051da96 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using an array to store a set of string key value pairs. +const dictionaryEntries: [string, string][] = [ + ['word1', 'definition1'], + ['word2', 'definition2'], +] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..28ae80a1edda8efc0c73065f8adc84261c6bc8e8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Register and access plugins in the application, using the string key as the plugin name. +interface PluginRegistry { + [pluginName: string]: () => void +} +const plugins: PluginRegistry = { pluginA: () => {}, pluginB: () => {} } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..44051cddc5a0058b94fac61423ce1df3b09a3274 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 33 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b45f2017c786c4c716b8ad2843e8f50a16304c7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-ok.ets @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using arrays to store plugin functions. +const plugins: (() => void)[] = [() => {}, () => {}] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..24a1b08d958d85933a951505a7a656a3555c40f2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: In multilingual applications, use different language keys to access translations. +interface TranslationMap { + [language: string]: { [key: string]: string } +} +const translations: TranslationMap = { + en: { hello: 'Hello', goodbye: 'Goodbye' }, + fr: { hello: 'Bonjour', goodbye: 'Au revoir' }, +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e6c14e1485228a9df25fa0a386f2231aa952540d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-error.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 23 + } + }, + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 25 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 38 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 7 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 23 + } + }, + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 25 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 38 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 7 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ccf11284654b2bcab22d33608093daf353691e1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using arrays to store form field information. +const formFields: [string, string | number | boolean][] = [ + ['username', 'user123'], + ['age', 25], +] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..657f2cd7a4a7f78ac28ff4cd4f4698f58c5fa3b3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Process dynamically generated form fields, using string keys to represent field names and value types. +interface FormFields { + [fieldName: string]: string | number | boolean +} +const formData: FormFields = { username: 'user123', age: 25 } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2094c470eff013a7f55237cfef5160f15adc6928 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 30 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 30 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8afad6b4a3df856d824572fe3a19af1e4a47a888 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using arrays to store collections of different data types. +const dataAggregations: [string, number[]][] = [ + ['temperature', [25, 30, 28]], + ['humidity', [50, 45, 55]], +] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..25a9737b8836f9c12766bc01619c283836324de6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Handle data aggregation or data conversion, using string keys to represent collections of different data types. +interface DataAggregator { + [dataType: string]: number[] +} +const data: DataAggregator = { + temperature: [25, 30, 28], + humidity: [50, 45, 55], +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2094c470eff013a7f55237cfef5160f15adc6928 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 30 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 30 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0261e3bcebd576611b1b31eb9a68360b6d846860 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using arrays to store object properties and values. +const dynamicProperties: [string, any][] = [ + ['name', 'John'], + ['age', 30], + ['isActive', true], +] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..ff237b63e56fe8ff39dcdd359c3bd1252c52d20c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-5-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 35 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 35 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..dc5bd96ae06f4f69d393dc731545cce24f2a3b49 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Handle dynamic object properties by using string keys to represent property names and types. +interface DynamicObject { + [propertyName: string]: any +} +const dynamicObject: DynamicObject = { name: 'John', age: 30, isActive: true } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..463ce9b72a4ea7a1799bf854a182eb10c3f354d3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 38 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 38 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c065f7aaef78d0bc4710eb94b4df0c6849039f8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using arrays to store attributes and values of custom data structures. +const customProperties: [string, any][] = [ + ['property1', 'value1'], + ['property2', 42], +] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..d53414835ae11ea2c853ce9b7ea987c79e656b09 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-6-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 34 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 34 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..699e33ae02a0ac18c3247a7d68f163d5009ddc80 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Handle key value pair data structures with dynamic keys and values. +interface KeyValueMap { + [key: string]: any +} +const config: KeyValueMap = { key1: 'value1', key2: 42 } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d49c33b7b918fe85f226609ae30550827d657a40 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 18 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed signatures are not supported (arkts-no-indexed-signatures)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 18 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 29 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7cc4d96195be4fbbff239e0b2ef1ccc4fd70b473 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Using an array to store a set of key value pairs of data. +const keyValuePairs: [string, any][] = [ + ['key1', 'value1'], + ['key2', 42], +] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..cd31aff30713d790f93288c624296135b5d303c1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-indexed-signatures/arkts-no-indexed-signatures-7-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 31 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 18, + "character": 31 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e075cbe7feb1890fd05d2bb28ea7bac2de44e84 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-1-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 1. When a specific type cannot be inferred, ArkTS does not allow omitting generic type arguments +function greet(): T { + return 'Hello' as T +} +let z = greet() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..81c5d1ff0f2e7cce710077108f5c70826626809a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + }, + { + "messageText": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "expectLineAndCharacter": { + "line": 21, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + }, + { + "messageText": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "expectLineAndCharacter": { + "line": 21, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..66a7a08b1e7eb7017756cfa483e6de2a3f839018 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-10-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 10. Need to explicitly annotate generic function type arguments +function choose(x: T, y: T): T { + return Math.random() < 0.5 ? x: y +} + +let x = choose(10, 20) +let y = choose('10', 20) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..568cc161e04cf9b595d22119a3a397b72cc96e3c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-2-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 2. When the specific type cannot be inferred, the template type needs to be marked +function greet(): T { + return 'Hello' as T +} +let z = greet() +let z = greet() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ce1ea091f323ed089310f751d3eee31db1991026 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-3-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 3. ArkTs stipulates that general template function calls should include template types +function foo(a:T){} +foo() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d1894934e0ff85a85caf9d5a6f5023610c717b28 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..24a345c9537b86af6671a1c30bbe6a6f736eb68e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-4-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 4. ArkTs stipulates that general template function calls should include template types +function foo(a:T){} +foo() +foo() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e18ada455bfe1dc08d0ff0ead14774e527e21b5d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-5-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 5. When a parameter is declared but not assigned a value, and the type cannot be inferred, an error will be reported when the function is called without adding a template type +function foo(a:T){} +let b +foo(b) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..417f672bd5538699524ad38c51470d61783330b7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..39976b537f9e10aaa48d0ec9d3108bb9de18a198 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-6-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 6. When a parameter is declared and assigned a value, the type can be inferred, and in this case, no template type can be added when calling the function +function foo(a:T){} +let b:number = 1 +let c:string = '111' +foo(b) +foo(c) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bc0e8d2dbbeaeca296ee87d40a580e4ca1e977c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-7-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 7. The API in the class is not an object, and even if a type is defined as a function parameter, it is not allowed by ArkTs +class B { + n: number = 0 + s: string = '' +} +function foo(a:T){} +foo(B.n) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-7-error.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e98b9074f592851f8e223f3b324c1253fe665cfd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-8-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 8. Add static before attributes in the class +class B { + static n: number = 0 + s: string = '' +} +function foo(a:T){} +foo(B.n) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..39e53309dc45cc816a833bf32f991c013f7d908d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-9-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 9. Make class new an instance object + +class B { + n: number = 0 + s: string = '' +} +let b = new B() +function foo(a:T){} +foo(b.n) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-inferred-generic-params/arkts-no-inferred-generic-params-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a70ac5841d2739e3ddec455e87bd8f16b6c3c07 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-1-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Crossing of object types: Two or more object types can be crossed to generate a new object type that contains all the properties and methods of the original type +interface Person { name: string; age: number}; +interface Employee { id: number; department: string}; + +type PersonEmployee = Person & Employee; + +const person: Person = {name:'John', age:25}; +const employee: Employee = { id: 1, department: "IT" }; +const personEmployee: PersonEmployee = { name: 'John', age: 25, id: 1, department: 'IT' }; +console.log(personEmployee.name); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cad5056eaa0be45e56dd22a7f4a57f635b5258d7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 23 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 40 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 23 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 40 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7258efa5f12786b8622c68a65615e9d99be35a9f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-10-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: When inheriting multiple layers of attributes, interface inheritance can be used +interface Animal { + name: string; +} + +interface Mammal extends Animal { + warmBlooded: boolean; +} + +interface Dog extends Mammal { + bark(): void; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ffa4ca2f0e12641594871771b285516eabbb88bb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-2-ok.ets @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Crossing of object types +interface Person { +name: string = ''; +age: number = 0; +} + +interface Employee { +id: number = 0; +department: string = ''; +} + +interface PersonEmployee extends Person, Employee {} + +const person: Person = { name: 'John', age: 25 }; +const employee: Employee = { id: 1, department: 'IT' }; +const personEmployee: PersonEmployee = { name: 'John', age: 25, id: 1, department: 'IT' }; +console.log(personEmployee.name); + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b62b55653ff99ef6e9763984c76428e67edf4204 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-3-error.ets @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Intersection of interfaces: Two or more interfaces can be intersected to generate a new interface that contains all the properties and methods of the original interface +interface Logger { + log: (msg: string = '') => msg; +} + +interface Person { + name: string; + age: number; +} + +type PersonLogger = Person & Logger; +// Create a new interface type that includes properties and methods for Perosn and Logger + +const jack: PersonLogger = { + name: "Jack", + age: 32, + log: (msg: string = '') => msg, +}; + +jack.log(`${jack.name} is ${jack.age} years old.`); // Jack is 32 years old. \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a43d63472591d9a3f332262632d1fb566f3e1979 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 27, + "character": 21 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 30, + "character": 28 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 27, + "character": 21 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 30, + "character": 28 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..030f6fb7038c25508ec03d2993a4647d57455e67 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-4-ok.ets @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Intersection of interfaces +interface Logger { + log: (msg: string) => string; +} + +interface Person { + name: string; + age: number; +} + +interface PersonLogger extends Person, Logger { } +const jack: PersonLogger = { + name: "Jack", + age: 32, + log: (msg: string) => msg, +}; + +jack.log(`${jack.name} is ${jack.age} years old.`); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d305c688920e141e4f143f1d9a85cc2ebd08a15 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-5-error.ets @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use the type of interface +type Persons = { + name: string; + age: number; +}; + +type Employee = { + company: string; + salary: number; +}; + +type PersonEmployee = Persons & Employee; + +const personEmployee: PersonEmployee = { + name: "John", + age: 30, + company: "ABC Inc.", + salary: 5000 +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..adcb1ee06bdbb33d965d8ce8b164981295102c6e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-5-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 16 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 23 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 30, + "character": 40 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 16 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 23 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 30, + "character": 40 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..57489e773a17ddd8e4a14073af44fb4a29151b76 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-6-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Merge Class Types: Using Class Inheritance to Merge Class Types +class A { + a: number = 0; +} + +class B { + b: string = ''; +} + +class C extends A { + c: boolean = true; +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a6f4ea7daa97fbcfb3530822779f7eafe70cea11 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-7-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Using cross types to merge methods from multiple interfaces into one interface +interface CanWalk { + walk(): void; +} + +interface CanSwim { + swim(): void; +} + +// Using Inheritance +type CanDoBoths = CanWalk & CanSwim \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b3678122115ee578741a127e3734b879cd182f9a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 27, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 27, + "character": 19 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..afd2339fb7a3ee8cdd363fcb004231b638e06951 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-8-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Merge methods from multiple interfaces into one interface using inheritance +interface CanWalk { + walk(): void; + } + + interface CanSwim { + swim(): void; + } + + // Using Inheritance + interface CanDoBoth extends CanWalk, CanSwim {} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..aba9cc7b59f5eba244684885df71cc675e5e7736 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-9-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Use type aliases to replace inheritance and define the relationship between the three interfaces +interface Animal { + name: string; +} + +type Mammals = Animal & { + warmBlooded: boolean; +} + +type Dogs = Mammals & { + bark(): void; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cf1026be68b0060626c07277ba7bee376e5a19f9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-intersection-types/arkts-no-intersection-types-9-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 16 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 25 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 13 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 23 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 16 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 25 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 13 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 23 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d52f62c1aae620c38091314adeeeb08ad047bde --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-1-ok.ets @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use as for type conversion + +class Foo { + foo: string = '' + common: string = '' +} + +class Bar { + bar: string = '' + common: string = '' +} + +function isFoo(arg: Object): boolean { + return arg instanceof Foo +} + +function doStuff(arg: Object): void { + if (isFoo(arg)) { + let fooArg = arg as Foo + console.log(fooArg.foo) + } else { + let barArg = arg as Bar + console.log(barArg.bar) + } +} + +function main(): void { + doStuff(new Foo()) + doStuff(new Bar()) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f0dbbfa73b9d7f6270c37433785b4190bcc90867 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-10-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use instanceof to check whether it is an array + +let arr: [number] = [1, 2, 3, 4] + +if (arr instanceof Array) { + //arr is array +} else { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..01aefd0b70c51bd315abfbaf29df14196d9f9c23 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-2-error.ets @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Uses the is operator + +class Foo { + foo: string = '' + common: string = '' +} + +class Bar { + bar: string = '' + common: string = '' +} + +function isFoo(arg: Foo | Bar): arg is Foo { + return arg.foo !== undefined +} + +function doStuff(arg: Foo | Bar) { + if (isFoo(arg)) { + console.log(arg.foo) // OK + } else { + console.log(arg.bar) // OK + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4601e8f724b9acacfca5e7ba8c55e505b5d0ec4a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)", + "expectLineAndCharacter": { + "line": 29, + "character": 33 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)", + "expectLineAndCharacter": { + "line": 29, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f7276c89444a8cf6678ca11cecaacb2555b6275 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-3-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Uses the instanceof operator + +class Animal {} +class Dog extends Animal {} + +let animal = new Animal(); +let dog = new Dog(); + +let isAnimal = dog instanceof Animal \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d59f4088aadef81a5bb5ce7cca8a96899a6fb227 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-4-error.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Uses the is operator + +interface Person { + name: string + age: number +} + +let isAProps = (props: Object): props is Person => + typeof props !== 'null' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b4136ac06a8c3b35cc79c3aacaf8b82993ddfd3a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)", + "expectLineAndCharacter": { + "line": 24, + "character": 33 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)", + "expectLineAndCharacter": { + "line": 24, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..68198ecd4eca2c916f25399b841e9020ff08e400 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-5-ok.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Does not use the is operator + +class Foo { + foo: string = '' + common: string = '' +} + +class Bar { + bar: string = '' + common: string = '' +} + +function isFoo(arg: Foo | Bar): Boolean { + return arg.foo !== undefined +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba5f506135c6d725a6bacfe65cbe0c5ef633c554 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-6-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use the instanceof function to determine the function + +let x: Function = () =>{ + // do something ... +} +if (x instanceof Function) { + let func = x as Function; + func(); +} else { + //do something else ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca76660400342a4b8176f3afef90dfdeec71771d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-7-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use instanceof to determine the instance of a class + +class MyClass { + // declare a class +} + +let obj: Object = new MyClass(); +if (obj instanceof MyClass) { + // obj is instance of MyClass +} else { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a904a8e8a1e88c2ce6b3efd998201a6dfcccfff4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-8-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use instanceof to check whether a variable is an object + +class O { + n: number = 0 + s: string = '' +} + +let obj: O = { n: 42, s: 'foo' } +if (obj instanceof Object) { + //obj is object +} else { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f14a92cd93f3e13f0bfda4d49584d4c7a01314d2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-9-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use instanceof to check whether a variable is an interface type + +interface MyInterface { + name: string +} + +let x: MyInterface = { name: 'MyInterface' } as MyInterface; +if (x instanceof MyInterface) { + //obj is instance of MyInterface +} else { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-is/arkts-no-is-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bd2dbcdcd9ddf9fd537771e3e57f72e3872818d2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-1-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Does not use JSX + +let message = "message" \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d52fb095deb072bbffe86125160b7ec8c5414cf2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-10-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Using Fragments in JSX + +const element = ( + <> +

Title

+

Paragraph

+ +); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..63fae71b3d57938a1035f06abd0bb400c191b55b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-10-error.json @@ -0,0 +1,55 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 15 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 18 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 4 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..79738694282c3b093d515748c1b31964f1153369 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-2-error.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: use JSX + +let message =
message
\ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..fdea7f14e6512352868419aaba409b0708c84d2f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 19, + "character": 15 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8f1a00396dae2827ae28e17e23b1dc85ea63e678 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-3-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: use JSX + +let showMessage = () =>{ + return
message
+} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1b9a00e5b08948ce1868ff1dd69cc60a51c2ac56 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-3-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 12 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 25 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..52690fec417d7adade1f175939399e161a964c7f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-4-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: JSX is used in conditional statements + +let condition = true + +if (condition) { + let element =
message
; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1d32b28d26afbce044b4dca6df4457d687cf0f77 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-4-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 30 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..27943bdcde132412d8a511e9e8f5e5cfcc44d42d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-5-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Expressions are used in JSX + +let name = "John"; +let element =

Hello, {name}!

; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..18745cb159ce2c491bd70f86401fffd63528a058 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-5-error.json @@ -0,0 +1,55 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 15 + } + }, + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 20, + "character": 26 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 33 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 34 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 15 + } + }, + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 20, + "character": 26 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9fc5d2862a7d36ce04b7a34ac4bbfff24466adfa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-6-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use JSX in a for loop + +let items = ["Apple", "Banana", "Orange"]; + +for (let item of items) { + let element =
{item}
; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f1721aece2b162e6932b3538835ea47f3509db6a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-6-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9eb393e2f91b6658693bcc689257e893e419a5b6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-7-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use JSX in conditions + +let isLoggedIn = true; +let element = ( +
+ {isLoggedIn ?

Welcome back!

:

Please log in.

} +
+); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9aefda61e49782972b7f3f8e09e026e18cc4e5ad --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-7-error.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 6 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 30 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 42 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 22, + "character": 56 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 60 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 4 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 6 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 30 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 42 + } + }, + { + "messageText": "\"in\" operator is not supported (arkts-no-in)", + "expectLineAndCharacter": { + "line": 22, + "character": 56 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..63064d730ed4da2c74a3982b5d75ca1e017f8e15 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-8-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use custom components in JSX + +function CustomComponent() { + return
Custom Component
; +} +const element = ; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c891e1e6386c3fdbb7e321c037efbbc4e45e055e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-8-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 10 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 32 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 34 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 20, + "character": 10 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..155de4d71e35b55d63170168b339ec296190b12c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-9-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Using event handlers in JSX + +let handleClick = (event) => { + console.log('Button clicked', event); +} +const element = ; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..be9bc124a3c3dd3a63321937676d1a050d00220d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-jsx/arkts-no-jsx-9-error.json @@ -0,0 +1,55 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 20 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + }, + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 22, + "character": 33 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 56 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 19, + "character": 20 + } + }, + { + "messageText": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + }, + { + "messageText": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", + "expectLineAndCharacter": { + "line": 22, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a137379ea51f08c367a0e5676359538a43943559 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-1-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface User { + name?: string; + location?: string; + age?: number; +} + +type User2 = Required; + +const user: User2 = { + name: 'pingan8787', + age: 18 +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..93f9e0fd8fae2993dce101a14b97115179dbce13 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-10-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +type MyPartial = { + [P in keyof T]?: T[P] | undefined; +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0afde201fa908b6cdbd6e8de34dfa4819d649e08 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-10-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 21 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 20 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 21 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 20 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..dc5661af0ee51874301127b918674848d8f30f99 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-2-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface User{ + name?: string; + location?: string; + age?: number; +} + +type User2 = Readonly; + +const user: User2 = { + name: 'pingan8787', + age: 18 +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e1b03473e391cdd1f5fcd1cb1aa95c9877fa0f0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-3-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface User { + name?: string; + location?: string; + age?: number; +} + +type User2 = Pick; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..fbcc9310560938aeed754db5665d79c665de2cec --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-3-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 14 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..90e3a4afdd9ed9e7fc6f17ec449709ce4c7e29f7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-4-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface User{ + name?: string; + location?: string; + age?: number; +}; + +type User2 = Omit; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..fbcc9310560938aeed754db5665d79c665de2cec --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-4-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 14 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..18fbe1041932e8fa6570969b629024d6a04e41ea --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-5-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface MyObject { + name: string; + age: number; + address: string; +} + +type PartialObject = Partial; +const obj: PartialObject = { + name: "Alice", +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..69e0c34a0950bf825c8ee2e42a10dd3a1d4e5e0c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-6-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +type MyRequired = { + [P in keyof T]-?: T[P]; +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5148b94bf5fce4212ededf1eae85aa1cb4ffb9fe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 22 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 22 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4963b5ea6ab9eda841379a01efe5fd538be40da --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-7-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +type MyReadonly = { + readonly [P in keyof T]: T[P]; +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..79dc696531b93507db0a7db51b9f975a36a943a3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-7-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 22 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 28 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 22 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 28 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d19dcad54f7d730ec49ae018badd0589dcda3e9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-8-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +type MyPick = { + [P in K]: T[P]; +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0c1766870f67213d96e70f7389b3fa77e603a20e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-8-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 37 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 37 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..af1ac3d450ff2ba1b8e2066e60b64178034c496b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-9-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +type Omit = { + [P in Exclude]: T[P]; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..21b053fdd5a64d6330a5258d8686c5295602674a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-mapped-types/arkts-no-mapped-types-9-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 43 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 9 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 31 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Mapped type expression is not supported (arkts-no-mapped-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 43 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 9 + } + }, + { + "messageText": "Indexed access types are not supported (arkts-no-aliases-by-index)", + "expectLineAndCharacter": { + "line": 18, + "character": 31 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..41bf748ffe0a90593e364f0e91812d685fa45f9f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-1-ok.ets @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: A method that does not modify an object + +class C { + foo() { + console.log('foo') + } +} + +class Derived extends C { + foo() { + console.log('Extra') + super.foo() + } +} + +function bar() { + console.log('bar') +} + +let c1 = new C() +let c2 = new C() +c1.foo() // foo +c2.foo() // foo + +let c3 = new Derived() +c3.foo() // Extra foo diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d9ea35966c4aeb1f2bd6dfd083b331ee899b3b78 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-10-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The public method of modifying an object + +class MyClass { + public method() { + console.log('Private method'); + } +} + +const obj = new MyClass(); +obj.method = () => { + console.log('Modified method') +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1404b655707ecc09009386635f0c0f0ebf12035a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b1cc807cdb24866f859e2ef71464154d3850d1e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-2-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The method for modifying an object + +class MyClass { + myMethod() { + console.log("Original method"); + } +} + +const obj = new MyClass(); +obj.myMethod = () => { + console.log("Modified method"); +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1404b655707ecc09009386635f0c0f0ebf12035a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..de0487724cf3ba950c40ebe4c7ec80e6c7e3339a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-3-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Two different objects of a class share the same method + +class MyClass { + myMethod() { + console.log("Shared method"); + } +} + +const obj1 = new MyClass(); +const obj2 = new MyClass(); + +obj1.myMethod(); +obj2.myMethod(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..bdb79cf50b24c7b4cf1ab043cad6aeb17c4ba38c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-4-error.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Modify object method by prototyping + +class MyClass { + method() { + console.log('Existing method'); + } +} + +const myObject = new MyClass(); + +MyClass.prototype.method = () => { + console.log('Modified method'); +}; + +myObject.method(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f7c572d2612c2d318a877471037b72a9eb94cc21 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 27, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 27, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e390bb1e113086a160729524006a7950ab68173 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-5-error.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The method for replacing modified objects + +class MyClass { + myMethod() { + console.log("Original method"); + } +} + +function modifiedMethod() { + console.log("Modified method"); +} + +const obj = new MyClass(); +obj.myMethod = modifiedMethod; + +obj.myMethod(); // log: "Modified method" diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..280c83a44f2b67cd87605a6fe551f99c4da4cc64 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5ac28a138583a2fd4c24d2f29857375d59e1e57d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-6-ok.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Added new methods through inheritance + +class ParentClass { + parentMethod() { + console.log("Parent method"); + } +} + +class ChildClass extends ParentClass { + childMethod() { + console.log("Child method"); + } +} + +const child = new ChildClass() +child.parentMethod() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8bf19431c3edb42859f65736bd6112f6769543f9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-7-ok.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Modify the layout of the object + +class ParentClass { + parentMethod() { + console.log("Parent method"); + } +} + +class ChildClass extends ParentClass { + parentMethod() { + console.log("Child method"); + } +} + +const obj = new ChildClass(); +obj.parentMethod(); // log: "Child method" \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..13ffd05b6ce0bc6611bda90d8d24a68a7c44c57b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-8-ok.ets @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Define an object method with an interface + +interface MyInterface { + method(): void; +} + +class MyClass implements MyInterface { + method() { + console.log('Implemented method'); + } +} + +const obj: MyInterface = new MyClass(); +obj.method(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c4f6c39150accdd443cdbd97b58bedd1e43b31d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-9-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Create an instance as an object extension method + +class Abilities { + eat(){} +} + +class Person { + abilities = new Abilities(); +} + +let person = new Person(); +person.abilities.eat(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-method-reassignment/arkts-no-method-reassignment-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..dbb6b9ae5b0257107ad517dd864294d74cc7e6e7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-1-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Import the module of the default export and merge it with the named export into one object (former) +// Generic functions +function reverse(array: T[]): T[] { + return array.reverse() +} + +let names: string[] = ['Alice', 'Bob', 'Charlie'] +let reversedNames = reverse(names) +console.log(reversedNames) +import moduleDefault, * as myModule from './path/module' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..856fb30c2e6cb3e14140aa00cf644d3c211fbe8d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..496737351e2f056b847faf4bad1ef17ff70ad061 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-10-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Example: All exports in the import module (back) + +import * as myModule from './path/module' +// Class definition and instantiation +class Car { + private brand: string + + constructor(brand: string) { + this.brand = brand + } + + startEngine(): void { + console.log(`Starting the engine of ${this.brand} car.`) + } +} + +let myCar = new Car('Toyota') +myCar.startEngine() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d9ebb0c6aab47dbfb79cd7ae59c3e8de201cdf23 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-11-error.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Importing Modules for Default Export and Named Export (former) +// Conditional statements and loops +let num: number = 10 + +if (num > 0) { + console.log('Positive number') +} else if (num < 0) { + console.log('Negative number') +} else { + console.log('Zero') +} + +for (let i = 0; i < 5; i++) { + console.log(i) +} +import moduleDefault, { namedExport1, namedExport2 } from './path/moduleName' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1018bd251e5e0f27a8c96cb3db5a43fe12d0b211 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-11-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 32, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 32, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-12-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-12-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f5475850d6b86cedf8e2f06b3b144aae135c708 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-12-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Example: Importing Modules for Default Export and Named Export (back) + +import moduleDefault, { namedExport1, namedExport2 } from './path/moduleName' +// Conditional statements and loops +let num: number = 10 + +if (num > 0) { + console.log('Positive number') +} else if (num < 0) { + console.log('Negative number') +} else { + console.log('Zero') +} + +for (let i = 0; i < 5; i++) { + console.log(i) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-12-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-12-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-12-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-13-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-13-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d73e58e91537d65e3a80f5d89fb070f855beb067 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-13-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Import and rename modules for default and named exports (former) +// Arrays and iterations +let numbers: number[] = [1, 2, 3, 4, 5] +for (let num of numbers) { + console.log(num) +} + +let doubledNumbers = numbers.map((num) => num * 2) +console.log(doubledNumbers) +import moduleDefault, { + namedExport1 as myExport1, + namedExport2 as myExport2, +} from './path/moduleName' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-13-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-13-error.json new file mode 100644 index 0000000000000000000000000000000000000000..856fb30c2e6cb3e14140aa00cf644d3c211fbe8d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-13-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-14-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-14-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1041941f9626424395a3a9364e73e69bd7f8b5a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-14-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Example: Import and rename modules for default and named exports (back) + +import moduleDefault, { + namedExport1 as myExport1, + namedExport2 as myExport2, +} from './path/moduleName' +// Arrays and iterations +let numbers: number[] = [1, 2, 3, 4, 5] +for (let num of numbers) { + console.log(num) +} + +let doubledNumbers = numbers.map((num) => num * 2) +console.log(doubledNumbers) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-14-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-14-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-14-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba93b43a8b6a9005ebb5e05a111bb623d7277920 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-2-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Example: Import the module of the default export and merge it with the named export into one object (back) + +import moduleDefault, * as myModule from './path/module' +// Generic functions +function reverse(array: T[]): T[] { + return array.reverse() +} + +let names: string[] = ['Alice', 'Bob', 'Charlie'] +let reversedNames = reverse(names) +console.log(reversedNames) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b70e8562b8c4cac71a55462fdf0b7d37f73eca73 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-3-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Importing the module exported by default (former) +// Declaring variables and type annotations +let message: string = 'Hello, TypeScript!' +console.log(message) +import moduleDefault from './path/module' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ab9ad27fdd14c860176a6a4658007c2293b82775 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..af4375288878fb547b7d9b132c6389dba077531c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-4-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Example: Importing the Default Exported Module (back) + +import moduleDefault from './path/module' +// Declaring variables and type annotations +let message: string = 'Hello, TypeScript!' +console.log(message) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5afd9cf7f85ab600ce8ae74d94e9863fd72c4214 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-5-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counter-example: Importing a named exported module (former) +// Function definitions and calls +function add(a: number, b: number): number { + return a + b +} + +let result = add(3, 5) +console.log(result) +import { namedExport1, namedExport2 } from './path/moduleName' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2bfb9b594a3d6c4a1b0605c45eb745b2fac9460f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..20190e51d8af124d23b970e23d232fd6582341ae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-6-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Example: Importing a Named Exported Module (back) + +import { namedExport1, namedExport2 } from './path/moduleName' +// Function definitions and calls +function add(a: number, b: number): number { + return a + b +} + +let result = add(3, 5) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe26f6fb2b05c6afe6fbb1bb976c47a5158d1dc1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-7-error.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Importing a Named Exported Module and Renaming it (former) +// Interface definition and object usage +interface Person { + name: string + age: number +} + +let person: Person = { + name: 'John', + age: 25, +} + +console.log(person.name, person.age) +import { + namedExport1 as myExport1, + namedExport2 as myExport2, +} from './path/moduleName' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..73bdea9cdb1eec3829b822e9ed91aca26c50b0bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f4b0fc526dc3939457d99c526d28afbe1d56fc9a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-8-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Example: Importing a Named Exported Module and Renaming it (back) + +import { + namedExport1 as myExport1, + namedExport2 as myExport2, +} from './path/moduleName' +// Interface definition and object usage +interface Person { + name: string + age: number +} + +let person: Person = { + name: 'John', + age: 25, +} + +console.log(person.name, person.age) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..de72aeb97901cbd6e8048b4a322c03edfa0a193d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-9-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: All exports in the import module (former) +// Class definition and instantiation +class Car { + private brand: string + + constructor(brand: string) { + this.brand = brand + } + + startEngine(): void { + console.log(`Starting the engine of ${this.brand} car.`) + } +} + +let myCar = new Car('Toyota') +myCar.startEngine() + +import * as myModule from './path/module' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ff65c0923e43870d7442472d53cae57b821e5cc7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/arkts-no-misplaced-imports-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 34, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 34, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/path/module.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/path/module.ts new file mode 100644 index 0000000000000000000000000000000000000000..bbfdfb050b17f9740b9443c9f30967bcc4c25324 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/path/module.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + +// module.ts +export default function greet(name: string) { + console.log(`Hello, ${name}!`); +} + +export function sum(a: number, b: number) { + return a + b; +} + +export const PI = 3.14; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/path/moduleName.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/path/moduleName.ts new file mode 100644 index 0000000000000000000000000000000000000000..cbe808e963a2c5af22ae0fd863e9063a34cd2c3e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-misplaced-imports/path/moduleName.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + +// module.ts +export function namedExport1() { + console.log('This is namedExport1'); +} + +export function namedExport2() { + console.log('This is namedExport2'); +} + +export default function defaultExport() { + console.log('This is the default export'); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1548ef863339f35547921ca7bc31466d205256b8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module '*!text' { + const content: string + export default content +} + +import content from 'foo!text' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..efadaee787a42ead4f57413f805a519db102601b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab570c30f2841c36d0ddc8969698e9f389345ce0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare namespace N { + function foo(x: number): number +} + +// use module +import * as m from 'module' +console.log('N.foo called: ', N.foo(42)) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..ebcabe89e44474dd4d30c890462d0b8c6a27c53e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-1-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..454f749ea4a3083de80a2c85e891c12685986ba4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-error.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module "*foo"{ + export function add(a: number, b: number): number { + return a + b; + } + + export function subtract(a: number, b: number): number { + return a - b; + } + + export function multiply(a: number, b: number): number { + return a * b; + } +} + +import * as math from "mathfoo"; + +console.log(math.add(2, 3)); // Output: 5 +console.log(math.subtract(5, 2)); // Output: 3 +console.log(math.multiply(4, 6)); // Output: 24 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..fff989a15c9cd443073837800a4cf24eb7c1fc0b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 31, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 31, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/arkts-no-module-wildcards-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/arkts-no-module-wildcards-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..89b1c392759584fd4880f477b26abb9e03aa5ce6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/arkts-no-module-wildcards-2-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 * as math from "math"; + +console.log(math.add(2, 3)); // Output: 5 +console.log(math.subtract(5, 2)); // Output: 3 +console.log(math.multiply(4, 6)); // Output: 24 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/arkts-no-module-wildcards-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/arkts-no-module-wildcards-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/arkts-no-module-wildcards-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/math.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/math.ts new file mode 100644 index 0000000000000000000000000000000000000000..cd30b2d7702a1978f0aeea8b7b320af92700f45e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-2-ok/math.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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 function add(a: number, b: number): number { + return a + b; +} + +export function subtract(a: number, b: number): number { + return a - b; +} + +export function multiply(a: number, b: number): number { + return a * b; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6551f1126cc5bd0e4ba2b00bbb020d639ef5fe17 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module 'example-library/*' { + export interface ExampleInterface { + // ... + } +} + +import { ExampleInterface } from 'example-library/*'; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c560121aa0a934772f6f06236a8b72823d1f682d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..84efa55ae11b1dc6fae01f1e6470865e9ba4694f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare namespace N { + function foo(x: number): number +} +import * as m from 'bar' +console.log('N.foo called: ', N.foo(42)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..59d020930c792fa5edd1c770f724a2ec749fc1b8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-3-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..aeacae87912417daa7e90536851a94c3f026a5c1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module 'utils*' { + export function capitalize(str: string): string { + return str.charAt(0).toUpperCase() + str.slice(1); + } + + export function reverse(str: string): string { + return str.split("").reverse().join(""); + } +} + +import * as utils from "utilsbaz"; + +console.log(utils.capitalize("hello")); // Output: Hello +console.log(utils.reverse("world")); // Output: dlrow \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0e6f1675a692d1e478733939b98599d35fb692fc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/arkts-no-module-wildcards-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/arkts-no-module-wildcards-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bcd0f09fdc356c880d1e319adc5806f28b1f5a71 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/arkts-no-module-wildcards-4-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 * as utils from utils; + +console.log(utils.capitalize("hello")); // Output: Hello +console.log(utils.reverse("world")); // Output: dlrow \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/arkts-no-module-wildcards-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/arkts-no-module-wildcards-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/arkts-no-module-wildcards-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/utils.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..fd492629648e0baafdf36969c7c76d31622affd4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-4-ok/utils.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 function capitalize(str: string): string { + return str.charAt(0).toUpperCase() + str.slice(1); +} + +export function reverse(str: string): string { + return str.split('').reverse().join(''); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..710b4a2ce9db9f90e9c5c11596d97ad3b52bd854 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare module '*bar*' { + export default function log*(message: string): void { + console.log(message); + } +} + +import * as logger from "foobarbaz"; + +logger.default("Hello, world!"); // Output: Hello, world! \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3f3fb5e7f6769ba47b24dacd48fa50716c78b1d2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-error.json @@ -0,0 +1,118 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 18, + "character": 30 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 18, + "character": 41 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 18, + "character": 50 + } + }, + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 55 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 18, + "character": 30 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 18, + "character": 41 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 18, + "character": 50 + } + }, + { + "messageText": "Ambient module declaration is not supported (arkts-no-ambient-decls)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Wildcards in module names are not supported (arkts-no-module-wildcards)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 18, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 55 + } + }, + { + "messageText": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/arkts-no-module-wildcards-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/arkts-no-module-wildcards-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..00cac5e1cc31fdb8002773e99e691ac07605b7bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/arkts-no-module-wildcards-5-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 * as logger from "logger"; + +logger.default("Hello, world!"); // Output: Hello, world! \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/arkts-no-module-wildcards-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/arkts-no-module-wildcards-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/arkts-no-module-wildcards-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/logger.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..d742cad21f39454d9ccc9bf575c782244771f4fb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-module-wildcards/arkts-no-module-wildcards-5-ok/logger.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 default function log(message: string): void { + console.log(message); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a14d0da601957233878a169b7df7f14133f7cd18 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-error.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Multiple static blocks in class. +class C { + static s: string + + static { + C.s = 'aa' + } + static { + C.s = C.s + 'bb' + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0d5df84e73cb6bb814aa28381bd7651f00688ca3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only one static block is supported (arkts-no-multiple-static-blocks)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only one static block is supported (arkts-no-multiple-static-blocks)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f525984f8592e29735dbf21bddcea4ab9c39d34f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Merge multiple static blocks into one in a class. +class C { + static s: string + + static { + C.s = 'aa' + C.s = C.s + 'bb' + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..cbdbf3cda386d8d1cbb06770b004beeee443198c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Multiple static blocks in class. +class MyClass { + static { + console.log('Static Block 1') + } + + static { + console.log('Static Block 2') + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f01c7971bda101b192aca3c2d74c18a127387002 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only one static block is supported (arkts-no-multiple-static-blocks)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only one static block is supported (arkts-no-multiple-static-blocks)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..77e691362ae5915cf4a3409c0297a6df4bfa34bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Ets file importing ts file. +import {C,A} from './arkts-no-multiple-static-blocks-2-ok' + +console.log(C.s) // Output:'aabb' +console.log(A.s) // Output:'aabb' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..8097f47f65989e3adb5de61d038b66416466f9df --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-2-ok/arkts-no-multiple-static-blocks-2-ok.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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 multiple static blocks and merged static blocks to ets for use. +export class C { + static s: string; + + static { + C.s = 'aa'; + } + static { + C.s = C.s + 'bb'; + } +} + +export class A { + static s: string; + + static { + A.s = 'aa'; + A.s = A.s + 'bb'; + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f5bf206633f56c1dd92c15d5a651fd4829d38b84 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Multiple static blocks in class. +class MyClass { + static { + console.log('Static block 1') + console.log('duplicated code') + } + + static { + console.log('Static block 2') + console.log('duplicated code') + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0d5df84e73cb6bb814aa28381bd7651f00688ca3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only one static block is supported (arkts-no-multiple-static-blocks)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only one static block is supported (arkts-no-multiple-static-blocks)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..739d57f371ad9df60f151db9b4b7f731caff0d18 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Ets file importing ts file. +import {MyClass} from './arkts-no-multiple-static-blocks-3-ok' + +console.log(MyClass.s1); // Output:Hello +console.log(MyClass.s2); // Output:42 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..c32b7d8bae2790c7d0a992e79dfb1aa01377c527 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-3-ok/arkts-no-multiple-static-blocks-3-ok.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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. + */ + +// Multiple static blocks for ets use. +export class MyClass { + static s1: string; + static s2: number; + + static { + MyClass.s1 = 'Hello'; + MyClass.s2 = 42; + console.log('First static block'); + } + + static { + console.log('Second static block'); + console.log(`s1: ${MyClass.s1}`); + console.log(`s2: ${MyClass.s2}`); + } + + static { + console.log('Third static block'); + if (MyClass.s2 === 42) { + console.log('s2 is 42'); + } + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..bca1426fdf9885e80994e454059be590b88041cb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-error.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Multiple static blocks in class. +let condition1 = true +let condition2 = false + +class MyClass { + static { + console.log('Static block 1') + if (condition1) { + console.log('Logic 1') + } + } + + static { + console.log('Static block 2') + if (condition2) { + console.log('Logic 2') + } + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cf39b583a7b0af255e1fe5c7df7056b6e3d54b75 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Only one static block is supported (arkts-no-multiple-static-blocks)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only one static block is supported (arkts-no-multiple-static-blocks)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5e6510034682b981f150307b404c7c29e9086bf9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Positive example: Ets file importing ts file +import {A} from './arkts-no-multiple-static-blocks-4-ok' + +console.log(A.s) // Output:'aabb' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..027c7e3907c46c19ac334e9f38f119592902772f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-multiple-static-blocks/arkts-no-multiple-static-blocks-4-ok/arkts-no-multiple-static-blocks-4-ok.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + +// Merge static blocks for ets use. +export class A { + static s: string; + + static { + A.s = 'aa'; + A.s = A.s + 'bb'; + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..bbd37bb6578a255dc0cdf92e0f1cba0ae8143eeb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Calculate the sum of two numbers. +*/ +function addNumbers(a: number, b: number): number { + function add(a: number, b: number): number { + return a + b + } + + return add(a, b) +} + +const result = addNumbers(5, 3) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..edf0c03bf84c0016f6aa332f52868084603d7f04 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Calculate the sum of two numbers. +*/ +const addNumbers = (a: number, b: number): number => { + const add = (a: number, b: number): number => a + b + return add(a, b) +} + +const result = addNumbers(5, 3) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f0950eb87d1ef5a6fc51f706b6e0fae2db611a8d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Calculate the nth term of Fibonacci. +*/ +function fibonacci(n: number): number { + function calculateFibonacci(n: number): number { + if (n === 0 || n === 1) { + return n + } else { + return calculateFibonacci(n - 1) + calculateFibonacci(n - 2) + } + } + + return calculateFibonacci(n) +} + +const result = fibonacci(9) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..75294780c2eb52c2a867b3969a1f2429aded9cc0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Calculate the nth term of Fibonacci. +*/ +function fibonacci(n: number): number { + const calculateFibonacci = (n: number): number => { + if (n === 0 || n === 1) { + return n + } else { + return calculateFibonacci(n - 1) + calculateFibonacci(n - 2) + } + } + + return calculateFibonacci(n) +} + +const result = fibonacci(9) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..27acda9740bae908ed2835fda025f3f699414322 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-error.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Determine whether a string is palindrome. +*/ +function isPalindrome(str: string): boolean { + hzt19970622. + + function reverseString(str: string): string { + return str.split('').reverse().join('') + } + + const reversedStr = reverseString(str) + return str === reversedStr +} + +const result = isPalindrome('racecar') +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b0cdebabaaaede79e205544e49f5cd941d10133b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9921308c789f65672158835e5c129eadef0a566c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Determine whether a string is palindrome. +*/ +function isPalindrome(str: string): boolean { + const reverseString = (str: string): string => + str.split('').reverse().join('') + const reversedStr = reverseString(str) + return str === reversedStr +} + +const inputString = 'racecar' +const isPalindromeResult = isPalindrome(inputString) +console.log(isPalindromeResult) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d093ba985c4de9311c909f560a142dac74efc1c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Calculate the average value of an array. +*/ +function computeAverage(numbers: number[]): number { + function sumArray(numbers: number[]): number { + return numbers.reduce((sum, num) => sum + num, 0) + } + + const sum = sumArray(numbers) + return sum / numbers.length +} + +const result = computeAverage([1, 2, 3, 4, 5]) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..32d5bd7dcbad1674d4d0aa71f8585698ee2d1f76 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Calculate the average value of an array. +*/ +function computeAverage(numbers: number[]): number { + const sumArray = (numbers: number[]): number => + numbers.reduce((sum, num) => sum + num, 0) + + const sum = sumArray(numbers) + return sum / numbers.length +} + +const result = computeAverage([1, 2, 3, 4, 5]) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..bd38ef9d13159454b2ca8ceb04c49a161fb470cf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Check if the value is even. +*/ +function isEven(num: number): boolean { + function divideByTwo(num: number): number { + return num / 2 + } + + return divideByTwo(num) % 2 === 0 +} + +const result = isEven(57) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4d5261a9db8b1a2f94e809a602219ab82c6eb4a6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Check if the value is even. +*/ +function isEven(num: number): boolean { + const divideByTwo = (num: number): number => num / 2 + + return divideByTwo(num) % 2 === 0 +} + +const result = isEven(57) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..be48532911a0fd826d3ecff19370cd08ff662c4b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Convert string to uppercase and add exclamation points. +*/ +function convertToUpperCase(str: string): string { + function addExclamation(str: string): string { + return str.toUpperCase() + '!' + } + + return addExclamation(str) +} + +const result = convertToUpperCase('hello') +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6495969034df5a7e09f05d10bf919cae0d1b440 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Convert string to uppercase and add exclamation points. +*/ +function convertToUpperCase(str: string): string { + const addExclamation = (str: string): string => str.toUpperCase() + '!' + + return addExclamation(str) +} + +const result = convertToUpperCase('hello') +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a0795dbedf35db3a56f0c5f3787f1c7a4ba330d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Calculate the maximum value of an array. +*/ +function findMaxValue(numbers: number[]): number { + function getMaxValue(numbers: number[]): number { + return Math.max(...numbers) + } + + return getMaxValue(numbers) +} + +const result = findMaxValue([1, 2, 3, 4, 5]) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..63979b872f6f6140a8fb6492dabe499b19fd6a58 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Calculate the maximum value of an array. +*/ +function findMaxValue(numbers: number[]): number { + const getMaxValue = (numbers: number[]): number => Math.max(...numbers) + + return getMaxValue(numbers) +} + +const result = findMaxValue([1, 2, 3, 4, 5]) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d81d5a137c8a55a18e7a2532b982f97abe090394 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + string reversal. +*/ +function reverseString(str: string): string { + function reverse(str: string): string { + return str.split('').reverse().join('') + } + + return reverse(str) +} + +const result = reverseString('abc') +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f5c7a02ce3c118ffc91c4ddebe6f76ccd5db89b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + string reversal. +*/ +function reverseString(str: string): string { + const reverse = (str: string): string => str.split('').reverse().join('') + + return reverse(str) +} + +const result = reverseString('abc') +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1ea7393961199271154909c1cd2ce2fb46e93447 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Get odd numbers in an array. +*/ +function getOddNumbers(numbers: number[]): number[] { + function isOdd(number: number): boolean { + return number % 2 !== 0 + } + + return numbers.filter(isOdd) +} + +const result = getOddNumbers([1, 2, 3, 4, 5]) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c4ccc4c72f46a5bb1bead7424477a7847016c723 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Get odd numbers in an array. +*/ +function getOddNumbers(numbers: number[]): number[] { + const isOdd = (number: number): boolean => number % 2 !== 0 + + return numbers.filter(isOdd) +} + +const result = getOddNumbers([1, 2, 3, 4, 5]) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d5b84bff89e2497f76efe53126933c8592274754 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Declaring a function within a function. + Calculate the product of two numbers. +*/ +function multiplyNumbers(a: number, b: number): number { + function multiply(a: number, b: number): number { + return a * b + } + + return multiply(a, b) +} + +const result = multiplyNumbers(3, 5) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c820046f97f5b53f3c4732e8f147e19bc3227d8e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Nested functions are not supported (arkts-no-nested-funcs)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9d69bf00bf4bc1a414c3d6eb858f8a7b47d1915 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using lambda functions instead of declaring functions. + Calculate the product of two numbers. +*/ +function multiplyNumbers(a: number, b: number): number { + const multiply = (a: number, b: number): number => a * b + + return multiply(a, b) +} + +const result = multiplyNumbers(3, 5) +console.log(result) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-nested-funcs/arkts-no-nested-funcs-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..305c07058f9678aaa2335105e346dd7a30793f8f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Foo { + constructor() { + if (!new.target) throw 'foo() must be called with new' + console.log('foo instantiated with new') + } +} + +new Foo() // logs "foo instantiated with new" diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..76822d1ebd5d8142d5a3f397a0ac62888a7a4d44 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + }, + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 22 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + }, + { + "messageText": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)", + "expectLineAndCharacter": { + "line": 19, + "character": 22 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..46115806cb054e23878f182921b95cadb6c7d353 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +class MyClass { + constructor() { + if (!(this instanceof MyClass)) { + throw new Error("MyClass must be instantiated using 'new'"); + } + } +} + +function myFactory() { + return new MyClass(); +} + +let instance = myFactory(); // excute ok +let inst = MyClass.call(instance); // raise except \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..367029d8fd573e667c4bc3eeb34914f5e320e427 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-1-ok.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 30, + "character": 5 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 30, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 30, + "character": 5 + } + }, + { + "messageText": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", + "expectLineAndCharacter": { + "line": 30, + "character": 20 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..13b7a2eb141a24e6b5573e29ad540218c4e6879f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-2-error.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 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. + */ + + +class A { + constructor() { + console.log(new.target.name); + } +} + +class B extends A { + constructor() { + super(); + } +} + +let a = new A(); // logs "A" +let b = new B(); // logs "B" + +class C { + constructor() { + console.log(new.target); + } +} +class D extends C { + constructor() { + super(); + } +} + +let c = new C(); // logs class C{constructor(){console.log(new.target);}} +let d = new D(); // logs class D extends C{constructor(){super();}} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..dc1a24a26c8d03755f0bdffd931f4ab914917ceb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 19, + "character": 17 + } + }, + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 34, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 19, + "character": 17 + } + }, + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 34, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6351280ff1de75ce16fae90a06dffa742b52910b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-3-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +function Animal(this: T, name: string) { + if (new.target !== undefined) { + this.name = name + } else { + throw new Error('must use new to create instance!') + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..63d86e1818eeb5ee6fbc730c08b2fae0ac6a0315 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-3-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 27 + } + }, + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 18, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 19, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 27 + } + }, + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 18, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e65f6af6ed361d4d1e09b73ead208eef22026f84 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-4-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Parent {} +class Child extends Parent { + constructor() { + super() + console.log(new.target === Child) + } +} + +new Child() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0f92caaad223b79218ed9d0e37db50f234aa7591 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 21, + "character": 17 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 21, + "character": 32 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 21, + "character": 17 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 21, + "character": 32 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b4814dd75171172192861297141188719a6369db --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-5-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +class MyRectangle { + constructor(length:number, width:number) { + console.log(new.target === MyRectangle); + console.log(length,width) + } +} + +class MySquare extends MyRectangle { + constructor(length:number, width:number) { + super(length, width); + } +} + +let obj = new MySquare(3,3); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e64bd593d570541649231b344e7ecd76157b3dd1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 19, + "character": 17 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 19, + "character": 32 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 19, + "character": 17 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 19, + "character": 32 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e9358f34a6dcf197559141ecd5f86aad8f218e4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-6-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +class MyClass { + constructor() { + if (new.target !== MyClass) { + throw new Error("MyClass must be instantiated using 'new'"); + } + } +} + +function myFactory() { + return new MyClass(); +} + +const instance = myFactory(); // run ok +const instance2 = MyClass.call(instance); // raise error diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..341ee02821403079fda06a99120938537dfe132d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-new-target/arkts-no-new-target-6-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 19, + "character": 9 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 19, + "character": 24 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 30, + "character": 7 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 30, + "character": 19 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"new.target\" is not supported (arkts-no-new-target)", + "expectLineAndCharacter": { + "line": 19, + "character": 9 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 19, + "character": 24 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 30, + "character": 7 + } + }, + { + "messageText": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", + "expectLineAndCharacter": { + "line": 30, + "character": 27 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..54faec704023c1978d51368ad72cd2553bc27d7d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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 a = [ + { n: 1, s: "1" }, + { n: 2, s: "2" }, +]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7644ab7bdea91678d8b828e2d7f79539a9351356 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 9 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 9 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..c138ab8f20a85cf6516f872ad649919ce1457c0e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +interface PersonOne { + name: string; + age: number; +} + +const peopleOne: PersonOne[] = [ + { name: "Alice", age: 25 }, + { name: "Bob", age: 30 }, + { name: "Charlie", age: 35 }, +]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..907ee9b133bb5c17a04e4307e8d686f988cda83d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-error.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const mixed = [1, "two", true, { name: "Alice" }]; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5fdf2bf3494f13fe5c40442e5d8afd8becd36c8f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 15 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 32 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 15 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 32 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..01bbed315d7250b1b88bae6d580b4d22ed16dbc0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class CC { + n: number = 0; + s: string = ""; +} +const arr4 = ["hello", { n: 1, s: "world" } as CC, 3.14 as number]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..466209651c881f98fae2c358d6bf0ea5649466f3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-3-ok.ets @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class PersonTwo { + public name: string; + public age: number; + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } +} + +const peopleList = [ + new PersonTwo("Alice", 25), + new PersonTwo("Bob", 30), + new PersonTwo("Charlie", 35), +]; // 类型推断为 PersonTwo[] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..57f6550b85a48848e974b47d37714407b6a5d336 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-4-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class PersonOther { + name: string = ""; + age: number = 0; +} +const peopleOther = [ + { name: "Alice", age: 25 } as PersonOther, + { name: "Bob", age: 30 } as PersonOther, + { name: "Charlie", age: 35 } as PersonOther, +]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f2154e01538539d6ef7d1f8c6c1ccf34ccd7797 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-5-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +interface Person { + name: string; + age: number; +} + +const peopleInter = new Array(); + +peopleInter.push({ name: "Alice", age: 25 }); +peopleInter.push({ name: "Bob", age: 30 }); +peopleInter.push({ name: "Charlie", age: 35 }); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8f7e2bc989880a2d470bce14c4158307cbed08a8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-6-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class NumAndStr { + n: number = 0; + s: string = ""; +} + +class StrAndBoo { + a: string = ""; + b: boolean = false; +} + +let a12 = [{ a: "hhh", b: true } as StrAndBoo, { n: 2, s: "2" } as NumAndStr]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1dad4a7f7587e8706d610c67123efa3dda1684e2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-7-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class student { + name: string = ""; + age: number = 0; + score: number[] = []; +} + +const studentList = [ + { name: "张三", age: 18, score: [90, 85, 92] } as student, + { name: "李四", age: 20, score: [78, 80, 88] } as student, + { name: "王五", age: 19, score: [95, 91, 89] } as student, +]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..00cdf959a8da900a3df5be90ccfff6c060c4f8ae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-8-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class animalsInfo { + type: string = ""; + age: number = 0; + hasHair: boolean = false; +} + +const zoo :animalsInfo[]= [ + { type: "lion", age: 5, hasHair: true }, + { type: "elephent", age: 10, hasHair: false }, + { type: "tiger", age: 3, hasHair: true } +]; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-noninferrable-arr-literals/arkts-no-noninferrable-arr-literals-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..47fccef127a2d050406e06cd128f0a6d77b93f7e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Namespaces cannot be used as objects +namespace MyNamespace { + export let x: number +} + +let m = MyNamespace +m.x = 2 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7e4d46303b3917fd6f91344d1b7d7c2e7833206e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 22, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 22, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad1fefc10d1f881438427741689b8517f767d880 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// ArkTS does not support namespaces as objects, classes or modules can be used as object +namespace MyNamespace { + export let x: number +} + +MyNamespace.x = 2 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..82f16f78ee28aa436615b84e968c10bc5f084b2e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace Person { + export let name: string; + export let age: number; + export function sayHello() { + console.log(`Hello`); + } +} + +let m = Person +m.name = 'Peter' +m.sayHello(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d019eecda5ce3299e6a71e45101b5aa8817dd996 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 25, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 25, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a13b49bb7b9b0b47d0ddb0824c55bad54509fee --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-ok.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +// ArkTS does not support namespaces as objects, classes or modules can be used as object +namespace MyNamespace { + export interface Person { + name: string; + age: number; + } + + export function sayHello(person: Person) { + console.log(`Hello, ${person.name}`); + } + +} + + +// use object of namespace +const person: MyNamespace.Person = { name: 'John', age: 25 }; +MyNamespace.sayHello(person); + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..30d79c846122f919fc21ed5ca70276100c2fa466 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Namespaces cannot be used as objects +namespace MyNamespace { + export function myFunction() { + console.log("Hello, world!"); + } +} + +let obj = MyNamespace; +obj.myFunction(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d6ec0f6522f44b9d5d16158e0038cb3d76218ccf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 24, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 24, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd2d5886d648fc03c42f1d84507dc279fed9321c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +// ArkTS does not support namespaces as objects, classes or modules can be used as object +namespace MyNamespace { + export function foo() { + console.log("Hello, world!"); + } +} + +MyNamespace.foo(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ef46e171268a2feef799043b988d4099dd5d5070 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Namespaces cannot be used as objects +namespace X { + export interface Y { z:number } + export class Z { } + } + +type X = string; + +let c: X.Y = {z:3}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..042d359726bdaf4d6b322bfa7dba3153d8c5459e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 23, + "character": 6 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 23, + "character": 6 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f2e10e6720be13f71246f5bd0c8767010451bee --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +// ArkTS does not support namespaces as objects, classes or modules can be used as object +namespace X { + export interface Y { z:number } + export class Z { } + } + +let c: X.Y = {z:3}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..78226ea3d97ef9b414dcdc681f197d5f699758d2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Namespaces cannot be used as objects +namespace MyNamespace { + export let x: number = 10; +} + +let obj = MyNamespace; +console.log(obj.x); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1fb8ba8f823d3f0632012b409534d41861169158 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 22, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)", + "expectLineAndCharacter": { + "line": 22, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a853307bc03e5634d8ab03c6b2631abce6481477 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-ok.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +// ArkTS does not support namespaces as objects, classes or modules can be used as object +namespace MyNamespace { + export let x: number; + export let y: string; + + export function getX(): number { + return x; + } + + export function setY(value: string): void { + y = value; + } +} + +MyNamespace.x = 2; +MyNamespace.setY("hello"); + +console.log(MyNamespace.getX()); // 2 +console.log(MyNamespace.y); // hello \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-as-obj/arkts-no-ns-as-obj-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..764eb676172c5db011d2703815a65bbee890d5ae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace A { + export let x: number + x = 1 +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cb7c651c9e4b34222438b3b69a23c3accf72cf73 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2220e51680b3ac9e095ec7129311f414ccc6f00f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace A { + export let x: number + + export function init() { + x = 1 + } +} + +// Call the initialization function to execute +A.init() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..852c5628dcc53c9720ea1fba3a490573e27edb7f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace Person { + export let name: string + export let age: number + name = 'Susan' + age = 23 +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8e863283bc6caae2e4285b6f341374187523a218 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..237bba3b96472192554a188f11cc71d12b42ed03 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace Person { + export let name: string + export let age: number + + export function personInit() { + name = 'Susan' + age = 23 + } +} + +// Call the initialization function to execute +Person.personInit() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..859e177f883b944b473a4f2d47f60c7ac2f14d51 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MyNamespace { + let sVar = 10 + console.log(sVar) + + function foo() { + console.log('Hello, world!') + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cb7c651c9e4b34222438b3b69a23c3accf72cf73 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..654788328024bf2299f0f11409988d3a7fff19f4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MyNamespace { + let bar = 10 + + function foo() { + console.log('Hello, world!') + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..68299f6edb4a5c6dc4d0db0099e561bde76d2999 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-error.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MyNamespace { + let message: string = 'Hello, TypeScript!' + + function displayMessage() { + console.log(message) + } + + class MyClass { + private name: string + + constructor(name: string) { + this.name = name + } + + sayHello() { + console.log(`Hello, ${this.name}!`) + } + } + + displayMessage() + + let myObject = new MyClass('John') + myObject.sayHello() +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..eba6bbf236e7df8e4f0b325f9a3e31fe02ab01e2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 36, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 36, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fcae7293b22cd03a9cdc65827d6236261e3c3299 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MyNamespace { + let message: string = 'Hello, TypeScript!' + + function displayMessage() { + console.log(message) + } + + class MyClass { + private name: string + + constructor(name: string) { + this.name = name + } + + sayHello() { + console.log(`Hello, ${this.name}!`) + } + } + + let myObject = new MyClass('Peter') +} + +MyNamespace.displayMessage() +myObject.sayHello() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d31d0281c381f85a7d59f1d7919b17363bb7ea5d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MathUtils { + export function add(a: number, b: number): number { + return a + b + } + + export function subtract(a: number, b: number): number { + return a - b + } + + let result1 = MathUtils.add(5, 3) + console.log(result1) // output: 8 + + let result2 = MathUtils.subtract(10, 4) + console.log(result2) // output: 6 +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9365380d722981608dbd9a1ea8426065689be8ff --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 30, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 30, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..157e803328311f0d9453b9cfaf496c51d19140f4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MathUtils { + export function add(a: number, b: number): number { + return a + b + } + + export function subtract(a: number, b: number): number { + return a - b + } +} + +let result1 = MathUtils.add(5, 3) +console.log(result1) // output: 8 + +let result2 = MathUtils.subtract(10, 4) +console.log(result2) // output: 6 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..764eb676172c5db011d2703815a65bbee890d5ae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace A { + export let x: number + x = 1 +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cb7c651c9e4b34222438b3b69a23c3accf72cf73 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2220e51680b3ac9e095ec7129311f414ccc6f00f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace A { + export let x: number + + export function init() { + x = 1 + } +} + +// Call the initialization function to execute +A.init() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..852c5628dcc53c9720ea1fba3a490573e27edb7f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace Person { + export let name: string + export let age: number + name = 'Susan' + age = 23 +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8e863283bc6caae2e4285b6f341374187523a218 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..237bba3b96472192554a188f11cc71d12b42ed03 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace Person { + export let name: string + export let age: number + + export function personInit() { + name = 'Susan' + age = 23 + } +} + +// Call the initialization function to execute +Person.personInit() \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..859e177f883b944b473a4f2d47f60c7ac2f14d51 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MyNamespace { + let sVar = 10 + console.log(sVar) + + function foo() { + console.log('Hello, world!') + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cb7c651c9e4b34222438b3b69a23c3accf72cf73 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..654788328024bf2299f0f11409988d3a7fff19f4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MyNamespace { + let bar = 10 + + function foo() { + console.log('Hello, world!') + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..68299f6edb4a5c6dc4d0db0099e561bde76d2999 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-error.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MyNamespace { + let message: string = 'Hello, TypeScript!' + + function displayMessage() { + console.log(message) + } + + class MyClass { + private name: string + + constructor(name: string) { + this.name = name + } + + sayHello() { + console.log(`Hello, ${this.name}!`) + } + } + + displayMessage() + + let myObject = new MyClass('John') + myObject.sayHello() +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..eba6bbf236e7df8e4f0b325f9a3e31fe02ab01e2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 36, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 36, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fcae7293b22cd03a9cdc65827d6236261e3c3299 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MyNamespace { + let message: string = 'Hello, TypeScript!' + + function displayMessage() { + console.log(message) + } + + class MyClass { + private name: string + + constructor(name: string) { + this.name = name + } + + sayHello() { + console.log(`Hello, ${this.name}!`) + } + } + + let myObject = new MyClass('Peter') +} + +MyNamespace.displayMessage() +myObject.sayHello() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d31d0281c381f85a7d59f1d7919b17363bb7ea5d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MathUtils { + export function add(a: number, b: number): number { + return a + b + } + + export function subtract(a: number, b: number): number { + return a - b + } + + let result1 = MathUtils.add(5, 3) + console.log(result1) // output: 8 + + let result2 = MathUtils.subtract(10, 4) + console.log(result2) // output: 6 +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9365380d722981608dbd9a1ea8426065689be8ff --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 30, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "expectLineAndCharacter": { + "line": 30, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..157e803328311f0d9453b9cfaf496c51d19140f4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace MathUtils { + export function add(a: number, b: number): number { + return a + b + } + + export function subtract(a: number, b: number): number { + return a - b + } +} + +let result1 = MathUtils.add(5, 3) +console.log(result1) // output: 8 + +let result2 = MathUtils.subtract(10, 4) +console.log(result2) // output: 6 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ns-statements/arkts-no-ns-statements/arkts-no-ns-statements-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b2f0997e096b44ddb20f5f88d0833c7f0fbe2fc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const personInfo: { name: string; age: number } = { + name: "John", + age: 25, +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4dd93940e37a1cd7a51168ce333021f6a4ff4142 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 51 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 51 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d3048c184705e48a84e7a1e5cf147a03f7e48d8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Person { + name: string = ""; + age: number = 0; +} + +const person: Person = new Person(); +person.name = "John"; +person.age = 25; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6230c66db22d9491a6358e5fde0856b124582340 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const mathOperations: { + add: (x: number, y: number) => number; + subtract: (x: number, y: number) => number; +} = { + add: (x, y) => x + y, + subtract: (x, y) => x - y, +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5810fe61953b9338f72b1d1ee5c2c52cc36ffa62 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 23 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 23 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..84ea0655e46be558851254b29a4f30c31d6f2e9f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +interface Person { + name: string; + age: number; +} + +const people: Person = { + name: "John", + age: 25, +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f2e76d67e9cfb000ecbc51cd8628416989c2096b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const shoppingList: { + items: string[]; + totalPrice: number; +} = { + items: ["Apple", "Banana", "Orange"], + totalPrice: 10.99, +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d7d605635eb9914cd606dbcd11c1f4a1db2b1d17 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 21 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 21 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2c1c07e36817abf6924062fb0bcb38437a7b36a0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Animal { + name: string = ""; +} + +class Dog extends Animal { + breed: string = ""; +} + +const dog: Dog = new Dog(); +dog.name = "Buddy"; +dog.breed = "Golden Retriever"; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..bbff10a57abcb130d2ea39d2c7f69af259bce943 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const user: { + name: string; + age?: number; +} = { + name: "Alice", +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c72327f0c3a8602246bce96b4b37a60a4ad3527b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 13 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 13 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bc8dd39e4842eb80992b9d2714e043666598626a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-ok.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +interface Animal { + name: string; +} + +interface Cat extends Animal { + breed: string; +} + +const cat: Cat = { + name: "teddy", + breed: "bigOrange", +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d8af7f3c828582c0be8def74919d062bc5d5fa56 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-5-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +const config: { + readonly apiKey: string; + readonly apiUrl: string; +} = { + apiKey: "abc123", + apiUrl: "https://baidu.com", +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..605e550de46c25d7fa4b61676db688f7ab6a92e4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-obj-literals-as-types/arkts-no-obj-literals-as-types-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 15 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 15 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a8e364414279f9694d19e502c3f8b43794c2c30 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-1-ok.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The unary operators +, -, and ~ are only available for numeric types used in classes for numeric types +type: Positive example +*/ +class NumberManipulator { + private num: number; + + constructor(num: number) { + this.num = num; + } + + applyUnaryPlus(): number { + return +this.num; + } + + applyUnaryMinus(): number { + return -this.num; + } + + applyBitwiseNot(): number { + return ~this.num; + } +} + +const manipulator = new NumberManipulator(5); +console.log(manipulator.applyUnaryPlus()); // output:5 +console.log(manipulator.applyUnaryMinus()); // output:-5 +console.log(manipulator.applyBitwiseNot()); // output:-6 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..482e71a182be8a63874a46d68acb54aa896dbe75 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-10-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: The date object is converted by default +const date: Date = new Date(); +const num: number = +date; +console.log(num); // output:A numeric value in the form of a timestamp + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cdf560bbba68ce05e46f9405a2852583f30877b1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 19, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 19, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..52164a8fc00e9ef8199df829a92efc8c44386212 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-2-ok.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The unary operators +, -, and ~ are only available for numeric types Use in a namespace +type: Positive example +*/ +namespace MathOperations { + export function negateNumber(num: number): number { + return -num; // Use unary operators - Negate numeric values + } + + export function bitwiseNot(num: number): number { + return ~num; // Use the unary operator ~ to perform bitwise negation of values + } +} + +// Use functions in the namespace +const num = 10; +const negNum = MathOperations.negateNumber(num); // Gets the opposite of the numeric value +const bitwiseNotNum = MathOperations.bitwiseNot(num); // Bitwise negation of values +console.log(negNum, bitwiseNotNum); + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f14a896d9fd1d4658c60b044b4c446e379861823 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-3-ok.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The unary operators +, -, and ~ are only available for numeric types Use in functions +type: Positive example +*/ +function applyUnaryPlus(num: number): number { + return +num; +} + +function applyUnaryMinus(num: number): number { + return -num; +} + +function applyBitwiseNot(num: number): number { + return ~num; +} + +console.log(applyUnaryPlus(5)); // output:5 +console.log(applyUnaryMinus(5)); // output:-5 +console.log(applyBitwiseNot(5)); // output:-6 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3dd5dd29489dda0e61d476413c06b10dd3c64dbb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-4-ok.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Use in constructors function +class NumberWrapper { + private value: number; + + constructor(num: number) { + this.value = num; + } + + applyUnaryPlus(): number { + return +this.value; + } + + applyUnaryMinus(): number { + return -this.value; + } + + applyBitwiseNot(): number { + return ~this.value; + } +} + +const wrapper = new NumberWrapper(5); +console.log(wrapper.applyUnaryPlus()); // output:5 +console.log(wrapper.applyUnaryMinus()); // output:-5 +console.log(wrapper.applyBitwiseNot()); // output:-6 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2507ed8de81d277c9a4620e9788656f94fca3426 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-5-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Use in type aliases +type NumberUnaryOperator = (num: number) => number; + +const applyUnaryPlus: NumberUnaryOperator = (num) => +num; +const applyUnaryMinus: NumberUnaryOperator = (num) => -num; +const applyBitwiseNot: NumberUnaryOperator = (num) => ~num; + +console.log(applyUnaryPlus(5)); // output:5 +console.log(applyUnaryMinus(5)); // output:-5 +console.log(applyBitwiseNot(5)); // output:-6 + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..769cb14332de73e3fd9a318473f936683ab0a34a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-6-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Convert a string to a numeric type +const stringValue: string = "5"; +const positiveString1: number = +stringValue; +const positiveString2: number = -stringValue; +const positiveString3: number = ~stringValue; +console.log(positiveString1, positiveString2, positiveString3); // 5 -5 -6 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..345c062b60bebcec1e96ef618fed25fdf3979dd6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-6-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 19, + "character": 33 + } + }, + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 20, + "character": 33 + } + }, + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 21, + "character": 33 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 19, + "character": 33 + } + }, + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 20, + "character": 33 + } + }, + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 21, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0dc1998fa73484549f76640403b4810f9e15dee --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-7-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Converts a Boolean value to a numeric type +const stringValue: boolean = false; +const positiveString1: number = +stringValue; +const positiveString2: number = -stringValue; +const positiveString3: number = ~stringValue; +console.log(positiveString1, positiveString2, positiveString3); // 0 -0 -1 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..345c062b60bebcec1e96ef618fed25fdf3979dd6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-7-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 19, + "character": 33 + } + }, + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 20, + "character": 33 + } + }, + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 21, + "character": 33 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 19, + "character": 33 + } + }, + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 20, + "character": 33 + } + }, + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 21, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..72f9076f6ddb558305dd706e49475949aba5d0b8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-8-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Convert an object by default +interface MyObj { + valueOf: () => number; +} + +const obj: MyObj = { valueOf: () => 10 }; +const num: number = +obj; +console.log(num); // output:10 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9a8bad97d8524feff36802ec0269fbcddb2cf272 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 23, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 23, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..72c16434fb61a677abffc783cdab1b190f9eb5a0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-9-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Arrays are converted by default +const arr: number[] = [5]; +const num: number = +arr; +console.log(num); // output:5 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cdf560bbba68ce05e46f9405a2852583f30877b1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-polymorphic-unops/arkts-no-polymorphic-unops-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 19, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)", + "expectLineAndCharacter": { + "line": 19, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..069291e0e1e8976a6b16e497a28b7497c01a4482 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-1-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Person { + #name: string; + constructor(name: string) { + this.#name = name; + } + greet() { + console.log(`Hello, my name is ${this.#name}`); + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d443bc202148f703ee4d150c2e3c583e59bc317d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-1-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 20, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 23, + "character": 43 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 20, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 23, + "character": 43 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-10-ok..ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-10-ok..ets new file mode 100644 index 0000000000000000000000000000000000000000..d0564e4f50a77d3e2b10eea54d2b8478297702e4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-10-ok..ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:ArkTS does not support private fields declared with the # symbol. Use the private keyword instead. For private fields and read-only attributes, # is replaced with private +type: Positive example +*/ +class Point { + private readonly x: number; + private readonly y: number; + constructor(x: number, y: number) { + this.x = x; + this.y = y; + } + get coordinates() { + return `(${this.x}, ${this.y})`; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-10-ok..json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-10-ok..json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-10-ok..json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a65906a0f8107f01f2d18278116d883bca123ea6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-2-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counter-example: Private field vs. accessor method +class Circle { + #radius: number; + constructor(radius: number) { + this.#radius = radius; + } + get area() { + return Math.PI * this.#radius * this.#radius; + } +} + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a87982cf5741ad34251b75c7b2aab17fb79146df --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-2-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 24, + "character": 27 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 24, + "character": 42 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 24, + "character": 27 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 24, + "character": 42 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c4667ea12c54207ea33b5c81d0e77705e4d2a70f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-3-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Private fields vs. static methods +class Counter { + static #count = 0; + static increment() { + Counter.#count++; + } + static getCount() { + return Counter.#count; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..adc1f42ff02a5f1e9ef0e209b14d5b144c4e736c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-3-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 24, + "character": 20 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 24, + "character": 20 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..cbdb6774196745905378cfc726cd31adb864aaa2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-4-error.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: A private field in inheritance +class Animal { + #name: string; + constructor(name: string) { + this.#name = name; + } + makeSound() { + console.log(`${this.#name} makes a sound`); + } +} + +class Dog extends Animal { + constructor(name: string) { + super(name); + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8fffb18e9086dbcde98e479c842429dfefa09c30 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-4-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 24, + "character": 25 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 24, + "character": 25 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..81cd9de5a427c3217862c8310dcbe3fc4129ba00 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-5-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexamples: Private fields and read-only properties +class Point { + readonly #x: number; + readonly #y: number; + constructor(x: number, y: number) { + this.#x = x; + this.#y = y; + } + get coordinates() { + return `(${this.#x}, ${this.#y})`; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..272f2282d02cee26e92c3266219a3cd3dfe1b30b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-5-error.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 19, + "character": 12 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 20, + "character": 12 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 26, + "character": 21 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 26, + "character": 33 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 19, + "character": 12 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 20, + "character": 12 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 26, + "character": 21 + } + }, + { + "messageText": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)", + "expectLineAndCharacter": { + "line": 26, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-6-ok..ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-6-ok..ets new file mode 100644 index 0000000000000000000000000000000000000000..0ba507b9882b54f28c1132e79a60e5397ea22d5d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-6-ok..ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:ArkTS does not support private fields declared with the # symbol. Use the private keyword instead. Basic private field, # in which is replaced with private +type: Positive example +*/ +class Person { + private name: string; + constructor(name: string) { + this.name = name; + } + greet() { + console.log(`Hello, my name is ${this.name}`); + } +} + +class C { + private foo: string = "STR"; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-6-ok..json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-6-ok..json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-6-ok..json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-7-ok..ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-7-ok..ets new file mode 100644 index 0000000000000000000000000000000000000000..9f1bbe77a533116ff6921877f77a9be9703c489a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-7-ok..ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:ArkTS does not support private fields declared with the # symbol. Use the private keyword instead. in the private field and accessor method is replaced with private +type: Positive example +*/ +class Circle { + private radius: number; + constructor(radius: number) { + this.radius = radius; + } + get area() { + return Math.PI * this.radius * this.radius; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-7-ok..json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-7-ok..json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-7-ok..json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-8-ok..ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-8-ok..ets new file mode 100644 index 0000000000000000000000000000000000000000..00d34f6acf364e85ae82f9a95e6eb7dab025afb9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-8-ok..ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:ArkTS does not support private fields declared with the # symbol. Use the private keyword instead. For private fields and static methods, # is replaced with private +type: Positive example +*/ +class Counter { + private static count = 0; + static increment() { + Counter.count++; + } + static getCount() { + return Counter.count; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-8-ok..json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-8-ok..json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-8-ok..json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-9-ok..ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-9-ok..ets new file mode 100644 index 0000000000000000000000000000000000000000..20e2ea2a3314a85e34ecc87dfe01bb50f9c9583b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-9-ok..ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:ArkTS does not support private fields declared with the # symbol. Use the private keyword instead. In the private field of inheritance, the # in the field is replaced with private +type: Positive example +*/ +class Animal { + private name: string; + constructor(name: string) { + this.name = name; + } + makeSound() { + console.log(`${this.name} makes a sound`); + } +} + +class Dog extends Animal { + constructor(name: string) { + super(name); + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-9-ok..json b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-9-ok..json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-private-identifiers/arkts-no-private-identifiers-9-ok..json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2c37587276720bf5890d2de084732250f77181bd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-1-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 1. ArkTs can access fields using dot operators +class Point { + x: number = 0 + y: number = 0 +} +let p: Point = {x: 1, y: 2} +console.log(p.x) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5ab9f4d5c78041399bd454597290ccdac173e2fc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-10-ok.ets @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 10. ArkTS can support dynamic declaration of fields +class Person { + name: string + age: number + email: string + phoneNumber: string + + constructor(name: string, age: number, email: string, + phoneNumber: string) { + this.name = name + this.age = age + this.email = email + this.phoneNumber = phoneNumber + } +} + +let person = new Person('John', 30, '***@example.com', '18*********') +person.sex = 'man' +console.log(person.sex) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..616c5119e759c918161dbeeac782e2d1a62ffd24 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-2-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 2. ArkTS supports accessing elements in arrays through indexes +let arr = [1,2,3] +console.log(arr[0]) + +let newarr = ['name','age','sex'] +console.log(newarr[0]) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f47e5dd0dcdce0effe9c4d47c00bafd5b0f35bf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-3-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 3. ArkTS supports accessing elements in TypedArray (such as Int32Array) through indexes +let arr = new Int32Array(1) +console.log(arr[0]) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ccffaf21c45475684c3c40c850dfda1122f8490 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-4-ok.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 4. ArkTS can only access fields that are already declared or inherited in a class (access declaration fields) +class Person { + name: string = '' + age: number = 0 + email: string = '' + phoneNumber: string = '' + constructor(name: string, age: number, email: string, + phoneNumber: string) { + this.name = name + this.age = age + this.email = email + this.phoneNumber = phoneNumber + } +} + +let p = new Person('John', 30, '***@example.com', '18*********') +console.log(p.name) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a819a2f66061c363c308d2a0d817083024b9dd0d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-5-ok.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 5. ArkTS can only access fields that are already declared or inherited in the class (accessing inherited fields) +class Person { + name: string = '' + age: number = 0 + email: string = '' + phoneNumber: string = '' + constructor(name: string, age: number, email: string, + phoneNumber: string) { + this.name = name + this.age = age + this.email = email + this.phoneNumber = phoneNumber + } +} + +let p = new Person('John', 30, '***@example.com', '18*********') +console.log(p.age) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d64c90ea640c220b63c2f4f44a5b0bc63918a24 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-6-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 6. ArkTs does not support indexed access fields (obj [field]) +class Point { + x: number = 0 + y: number = 0 +} +let p: Point = {x: 1, y: 2} +console.log(p['x']) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7d824869a2a56cab456128312cccee0adddde4be --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 23, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 23, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8164206dacd65deb9dab61dad2c2794eb62f54f3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-7-error.ets @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 7.Accessing other fields will cause compile time errors +class Person { + name: string + age: number + email: string + phoneNumber: string + + constructor(name: string, age: number, email: string, + phoneNumber: string) { + this.name = name + this.age = age + this.email = email + this.phoneNumber = phoneNumber + } +} + +let person = new Person('John', 30, '***@example.com', '18*********') +console.log(person['name']) +console.log(person.unknownProperty) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..53c27949fb72c31ef5605c98e40f9f407fddd121 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 34, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 34, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8593701017ec31ecb6ff7cd893787a55f6a4935b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-8-ok.ets @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 8. ArkTS can access undeclared fields +class Person { + name: string + age: number + email: string + phoneNumber: string + + constructor(name: string, age: number, email: string, + phoneNumber: string) { + this.name = name + this.age = age + this.email = email + this.phoneNumber = phoneNumber + } +} + +let person = new Person('John', 30, '***@example.com', '18*********') +console.log(person.unknownProperty) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5d3d508c86a9eb21b4a2dd054340335175cf89a9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-9-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 9. ArkTS does not support dynamic access to fields +let person = { + name: 'John', + age: 30 +} +const filedNmae = 'name' +console.log(person[filedNmae]) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..167a70a5201c1a98ea8233869ee9eddf235f6a4c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-props-by-index/arkts-no-props-by-index-9-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 23, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "expectLineAndCharacter": { + "line": 23, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..40d13195da84f15136d866a9de953b18b591dc23 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +type CInstance = { + p: string; + m(): void; + q(r: number): boolean; +}; + +function C(this: CInstance, p: string) { + this.p = p; +} + +C.prototype = Object.create({ + m(this: CInstance) { + console.log(this.p); + }, +}); + +const c = new (C as any)("test"); +c.m(); // "test" \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..836bebd13d622b033ab65d136b59ef7ba98491bd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-error.json @@ -0,0 +1,104 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 15 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 27, + "character": 29 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 33, + "character": 7 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 33, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 24, + "character": 3 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 27, + "character": 15 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 27, + "character": 29 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 33, + "character": 7 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 33, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b094c9f9b63d3586aef1f538f478ec76883f6957 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +class C { + p: number = 0; + m() { + console.log(this.p); + } + q(r: number) { + return this.p == r; + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..cf86e184931cb92cecb383d1da567fd01f85b94e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-error.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +We defined a Person class that has a name property and a greet method. We then assign an age property on Person.prototype and set it to 25. +After creating the person object, we can access and use the age property on the prototype via person.age. +*/ + +declare interface X { + age: number; +} + +class Person { + name: string; + + constructor(name: string) { + this.name = name; + } + + greet() { + console.log(`Hello, my name is ${this.name}`); + } +} + +Person.prototype.age = 25; + +const person = new Person("Alice"); +console.log(person.age); // 25 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..65527cf06bdcdd7c84859afd04c97dea21ecd7b6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 38, + "character": 8 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 38, + "character": 8 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..778fb806283ff27a5a62f2ecb06eaf602e4fcbf4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Person { + name: string; + age: number; + + constructor(name: string,age: number) { + this.name = name; + this.age = age; + } + + greet() { + console.log(`Hello, my name is ${this.name},i'm {this.age} years old.`); + } +} + + +const person = new Person("Alice",25); +console.log(person.age); // 25 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..833e3f14345dfea5e9063716bfa9ff6495b2a741 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-error.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Car { + startEngine(): void; +} + +class Car { + brand: string; + + constructor(brand: string) { + this.brand = brand; + } + + static honk() { + console.log("Honk honk!"); + } +} + +Car.prototype.startEngine = function() { + console.log(`Starting the ${this.brand} engine...`); +}; + +const myCar = new Car("BYD"); +myCar.startEngine(); // output: "Starting the BYD engine..." \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b3c1218eabe71fda9172b2e1732d1ff31f55c343 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-error.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 33, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 33, + "character": 5 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 33, + "character": 29 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 33, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 17, + "character": 11 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 7 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 33, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 33, + "character": 5 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 33, + "character": 29 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 34, + "character": 31 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2c60d2afc9b826a637dd593347e40cebc4e76a3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Car { + brand: string; + + constructor(brand: string) { + this.brand = brand; + } + + static honk() { + console.log("Honk honk!"); + } + + static startEngine() { + console.log(`Starting the engine...`); + } +} + +const myCar = new Car("BYD"); +Car.startEngine(); //Starting the engine... diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..dfae362a8e212f7e417b080d97814936e9affef5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-error.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Animal { + name: string; + + constructor(name: string) { + this.name = name; + } +} + +Object.defineProperty(Animal.prototype, "category", { + value: "unknown", + writable: true, + enumerable: true, + configurable: true +}); + +const cat = new Animal("Tom"); +console.log(cat); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8f57770e040d980eeb85a7bbe7cb11da9fb1b577 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 30 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 53 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of standard library is restricted (arkts-limited-stdlib)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 25, + "character": 30 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 53 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..01e53176feaf60e31e4f8b7db9c454a596c777b7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Animal { + name: string; + category: string; + + constructor(name: string, category: string) { + this.name = name; + this.category = category; + } +} + +const cat = new Animal("Jerry","animal"); +console.log(cat.category); // animal \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..02aa06c23104376b75b40bf5c3746eaaa9f16c0c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-error.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface MyRectangle { + logArea(): void; +} + +class MyRectangle { + private _width: number; + private _height: number; + + constructor(width: number, height: number) { + this._width = width; + this._height = height; + } + + get width() { + return this._width; + } + + set width(value: number) { + this._width = value; + } + + get height() { + return this._height; + } + + set height(value: number) { + this._height = value; + } + + get area() { + return this._width * this._height; + } +} + +MyRectangle.prototype.logArea = function() { + console.log(`The area is ${this.area}`); +}; + +const rectangle = new MyRectangle(10, 5); +rectangle.logArea(); // The area is 50 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0b1ad668b5cf6a15a99161ff1f47099b557e10e0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-error.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 51, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 51, + "character": 13 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 51, + "character": 33 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 51, + "character": 33 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 17, + "character": 11 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 7 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 51, + "character": 1 + } + }, + { + "messageText": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "expectLineAndCharacter": { + "line": 51, + "character": 13 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 51, + "character": 33 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 52, + "character": 30 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f30242fb3738f029ca9318ca0c3a991ef9c14942 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-ok.ets @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 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. + */ + + +class MyRectangle { + private _width: number; + private _height: number; + + constructor(width: number, height: number) { + this._width = width; + this._height = height; + } + + get width() { + return this._width; + } + + set width(value: number) { + this._width = value; + } + + get height() { + return this._height; + } + + set height(value: number) { + this._height = value; + } + + get area() { + return this._width * this._height; + } + + logArea(){ + console.log(`The area is ${this.area}`); + } + +} + +const rectangle = new MyRectangle(10, 5); +rectangle.logArea(); // The area is 50 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-prototype-assignment/arkts-no-prototype-assignment-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..867ef457f2552a32805e9b346b0fbb85a4918463 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-1-error.ets @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 1. ArkTS does not support regular literals when directly declaring regularity +let regex: RegExp = /bc*d/ \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7eaef5ba9dd8a993b5a63fa85f65102659b01030 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-1-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 21 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ef45510fe6fcb330334a2ef71563fcdd80a12adc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-2-ok.ets @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 2. When declaring a regular directly, use RegExp() to create a regular object +let regex: RegExp = new RegExp('bc*d') \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..35d51aae6e851d86ed1eca1724c4baecf8e4cb4b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-3-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 3. ArkTS does not support regular literals when declaring regularity in a class +class X { + regex: RegExp = /bc*d/ +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1fe5ac0d7d967c18216e1528af1221898ec8e759 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-3-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 21 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..16fb864092c5a47502fe01c55f68a6c27dc3955b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-4-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 4. When declaring a regular in a class, use RegExp() to create a regular object +class X { + regex: RegExp = new RegExp('bc*d') +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5207721051d4dc9ef58c6d7d88638d662aab60e5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-5-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 5. ArkTS does not support regular literals when declaring regularity in functions +function foo(): T { + let regex: RegExp = /bc*d/ +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d774413d73754b8ec032ab721afa84d55dc73ce2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-5-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 23 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..eccc8b2f69d5774adae582ceade31f640b483a26 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-6-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 6. When declaring a regular in a function, use RegExp() to create a regular object +function foo(): T { + let regex: RegExp = new RegExp('bc*d') +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/arkts-no-regexp-literals-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/arkts-no-regexp-literals-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7adf12d4c3732da4a207db7a73912656c4b0fb70 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/arkts-no-regexp-literals-7-ok.ets @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2023 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. +*/ + +// 7. Introducing regular literals from ts files +import { regex } from './case7.1' +let a: RegExp = regex \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/arkts-no-regexp-literals-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/arkts-no-regexp-literals-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/arkts-no-regexp-literals-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/case7.1.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/case7.1.ts new file mode 100644 index 0000000000000000000000000000000000000000..ad0c2fe3ccdb010b43deebb9a0cd7ba4f33e3e9f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-7-ok/case7.1.ts @@ -0,0 +1,2 @@ +let regex: RegExp = /bc*d/; +export { regex }; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e8b637feb38e3cc0f6f97d78991399f271dee762 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-8-error.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 8. ArkTS does not support regular literals when declaring regularity in constructors +class person { + constructor (name: string, age: number) { + let regex: RegExp = /bc*d/ + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f72ba42ad3297c6092e7b20b8b084190f82d0511 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-8-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 20, + "character": 29 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ebbf8356cd0fdac88c98dc61e770ffe546de532 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-9-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 9. When declaring a regular in the constructor, use RegExp() to create a regular object +class person { + constructor (name: string, age: number) { + let regex: RegExp = new RegExp('bc*d') + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-regexp-literals/arkts-no-regexp-literals-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1333af7b1ed80a079df1ce6ac4b6e017a8de9e32 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 fs = require('fs'); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..24202352ba93ffc5f61db02565c4143f70523822 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"require\" and \"import\" assignment are not supported (arkts-no-require)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"require\" and \"import\" assignment are not supported (arkts-no-require)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e8882aaba690c2e183649a4cd2d3a2a101208e5f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-ok.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 * as fs from 'fs'; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0c73945bac035a936f6f78d45b7894ba89a86212 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 myUtils = require('./myUtils'); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..24202352ba93ffc5f61db02565c4143f70523822 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"require\" and \"import\" assignment are not supported (arkts-no-require)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"require\" and \"import\" assignment are not supported (arkts-no-require)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..23c90b29b14a8403c5b62d748254288d5aa32805 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-ok.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 myUtils from './myUtils'; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b735c8cd7e35e0fcc05caec2504cad2db9ba5a3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 myUtils = require('./myUtils'); +import yourUtils = require('./myUtils'); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9bd922938e78db144a7ac7710cd80ea73bf2d208 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"require\" and \"import\" assignment are not supported (arkts-no-require)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"require\" and \"import\" assignment are not supported (arkts-no-require)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"require\" and \"import\" assignment are not supported (arkts-no-require)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "\"require\" and \"import\" assignment are not supported (arkts-no-require)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..feb550284fb1a8aae31a7991a39cad9161de4f2e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 myUtils from './myUtils'; +import yourUtils from './myUtils'; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/arkts-no-require-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-require/myUtils.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/myUtils.js new file mode 100644 index 0000000000000000000000000000000000000000..c2eeaa65e5399605dc0d39cd154e3e59b159ecba --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-require/myUtils.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +function addition(a, b) { + return a + b +} + +function multiply(a, b) { + return a * b +} + +module.exports = { + addition: addition, + multiply: multiply, +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/arkts-no-side-effects-imports-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/arkts-no-side-effects-imports-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e246a8aecf02933349d1e571acb7a85ead13637 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/arkts-no-side-effects-imports-1-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import module + +import 'lib1-dependencie' + +window.MY_GLOBAL_VAR = 'Hello, world!' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/arkts-no-side-effects-imports-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/arkts-no-side-effects-imports-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..86bf656aaa5d81d0f9e25938c40146968fc136cb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/arkts-no-side-effects-imports-1-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..e677fd6031f3abcf4df74ffe6107af6b63f8f82c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-1-error/lib1-dependencie.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 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 EXAMPLE_VALUE = 42 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..493062fe5d0573d87eb644f7268883b78a1fd6fe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-10-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Imported using the wrong directory + +import 'wrong_path/module' + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..86bf656aaa5d81d0f9e25938c40146968fc136cb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-10-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/arkts-no-side-effects-imports-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/arkts-no-side-effects-imports-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b0cf49aa645376c0b50b24eb70af660c6e4c3a5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/arkts-no-side-effects-imports-11-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 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. +*/ + + +// Description: shared module Import module + +import 'lib1-dependencie' +import * as exampleValue from 'lib1-dependencie'; +import { export1 } from 'lib1-dependencie'; +import { exampleValue1, exampleValue2 } from 'lib1-dependencie'; +import { exampleValue1 as value1, exampleValue2 as value2 } from 'lib1-dependencie'; +'use shared' + +window.MY_GLOBAL_VAR = 'Hello, world!' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/arkts-no-side-effects-imports-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/arkts-no-side-effects-imports-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..00d7c154ac7c60c8a434a268af3eb3865ae575da --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/arkts-no-side-effects-imports-11-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Importing a module for side-effects only is not supported in shared module (arkts-no-side-effects-imports)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..296f235c29830a412c65005f2b0ab8bf48b897fe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-11-error/lib1-dependencie.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024 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 exampleValue = 42 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/arkts-no-side-effects-imports-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/arkts-no-side-effects-imports-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3856d01a72ff46984b96f6f72bd1c816e823be0d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/arkts-no-side-effects-imports-2-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Retrieve the exported variable with the * syntax + +import * as ns from 'lib1-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/arkts-no-side-effects-imports-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/arkts-no-side-effects-imports-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/arkts-no-side-effects-imports-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..16e5b1ebd1af311c2295f2342212193be66e89e9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-2-ok/lib1-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class myClass { + name: string = 'myClass' +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/arkts-no-side-effects-imports-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/arkts-no-side-effects-imports-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..07baa508357703a4289e6d311624b75eed18e8de --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/arkts-no-side-effects-imports-3-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Description: Import catalogs + +import 'lib1-dependencie' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/arkts-no-side-effects-imports-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/arkts-no-side-effects-imports-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..86bf656aaa5d81d0f9e25938c40146968fc136cb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/arkts-no-side-effects-imports-3-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..16e5b1ebd1af311c2295f2342212193be66e89e9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-3-error/lib1-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class myClass { + name: string = 'myClass' +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/arkts-no-side-effects-imports-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/arkts-no-side-effects-imports-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..397a681fcb8f291792e2dc2d9be0aa3f23345c77 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/arkts-no-side-effects-imports-4-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Description: Invoke an unexported function + +import * as ns from 'lib1-dependencie' +ns.unexportedFn() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/arkts-no-side-effects-imports-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/arkts-no-side-effects-imports-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/arkts-no-side-effects-imports-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..ccd4512392942502b7da3efa7bc51e083190e19b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-4-ok/lib1-dependencie.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function unexportedFn(){ + console.log('This function is not exported') +} +export function fn() { + console.log('This function is exported') +} + \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/arkts-no-side-effects-imports-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/arkts-no-side-effects-imports-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4882794d806ea24dcb403d69ceff6a0078091760 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/arkts-no-side-effects-imports-5-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Description: Import a method and execute it + +import * as ns from 'lib1-dependencie' + +ns.moduleMethod() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/arkts-no-side-effects-imports-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/arkts-no-side-effects-imports-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/arkts-no-side-effects-imports-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..008fe77d20e237e56d829b136800a76d3a2e3d41 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-5-ok/lib1-dependencie.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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 class Point { + constructor(x: number, y: number) { } + static origin = new Point(0, 0) +} + +export let moduleMethod = () => { + // do something... +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/arkts-no-side-effects-imports-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/arkts-no-side-effects-imports-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..298fb1f60d1cd52d336035c1e5f0610a2ab40a24 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/arkts-no-side-effects-imports-6-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Description: Get all exported variables via "*" syntax + +import * as ns from 'lib1-dependencie' +console.log(ns) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/arkts-no-side-effects-imports-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/arkts-no-side-effects-imports-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/arkts-no-side-effects-imports-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..5cf43b92e3d32d8e5da794361fd5d4b1748c527c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-6-ok/lib1-dependencie.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 EXAMPLE_VALUE = 42 +export const ANOTHER_VALUE = 'another value' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/arkts-no-side-effects-imports-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/arkts-no-side-effects-imports-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f67be765b0402d023b1554aeb569066ec04d050e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/arkts-no-side-effects-imports-7-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Description: Variables that are imported and exported normally + +import { EXAMPLE_VALUE } from 'lib1-dependencie' +console.log(EXAMPLE_VALUE) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/arkts-no-side-effects-imports-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/arkts-no-side-effects-imports-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/arkts-no-side-effects-imports-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..394fe79dcb5ed2d81c917147aa9771dba772a442 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-7-ok/lib1-dependencie.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 EXAMPLE_VALUE = 42 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/arkts-no-side-effects-imports-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/arkts-no-side-effects-imports-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b45c0045cf143c06c0d217e7aeba170119c59d2a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/arkts-no-side-effects-imports-8-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Description: Modify the imported variables + +import { mutableValue } from 'lib1-dependencie' +mutableValue = 20 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/arkts-no-side-effects-imports-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/arkts-no-side-effects-imports-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/arkts-no-side-effects-imports-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..1922e8691a57992fbaee3a0dbab77d0d30e477ee --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-8-ok/lib1-dependencie.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 let mutableValue = 10 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/arkts-no-side-effects-imports-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/arkts-no-side-effects-imports-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fef6dd6f5e1e35e64ec502bb955cf824dfd966e5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/arkts-no-side-effects-imports-9-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Description: Use aliases when importing + +import { exampleValue as aliasValue } from 'lib1-dependencie' +console.log(aliasValue) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/arkts-no-side-effects-imports-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/arkts-no-side-effects-imports-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/arkts-no-side-effects-imports-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..16c17f4e9c30460f9463f2ab540930987c7057d1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/arkts-no-side-effects-imports-9-ok/lib1-dependencie.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 exampleValue = 42 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/asrts-no-side-effects-imports-12-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/asrts-no-side-effects-imports-12-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b4c1c54c2e7aa7df362ae66daec65faa45316b71 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/asrts-no-side-effects-imports-12-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2024 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. +*/ + + +// Description: shared module Import module + +import 'lib1-dependencie' + +window.MY_GLOBAL_VAR = 'Hello, world!' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/asrts-no-side-effects-imports-12-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/asrts-no-side-effects-imports-12-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..86bf656aaa5d81d0f9e25938c40146968fc136cb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/asrts-no-side-effects-imports-12-ok.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..296f235c29830a412c65005f2b0ab8bf48b897fe --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-12-ok/lib1-dependencie.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024 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 exampleValue = 42 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/asrts-no-side-effects-imports-13-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/asrts-no-side-effects-imports-13-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..dc1188f57de747f463e501073beebc09557b1cd3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/asrts-no-side-effects-imports-13-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 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. +*/ + + +// Description: shared module Import module + +import exampleValue1 from 'lib1-dependencie' +import * as exampleValue from 'lib1-dependencie'; +import { export1 } from 'lib1-dependencie'; +import { exampleValue1, exampleValue2 } from 'lib1-dependencie'; +import { exampleValue1 as value1, exampleValue2 as value2 } from 'lib1-dependencie'; +'use shared' + +window.MY_GLOBAL_VAR = 'Hello, world!' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/asrts-no-side-effects-imports-13-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/asrts-no-side-effects-imports-13-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/asrts-no-side-effects-imports-13-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..407d0a7720823ca8dc497ca9136585cb654b8610 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-side-effects-imports/asrts-no-side-effects-imports-13-ok/lib1-dependencie.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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 exampleValue1 = 42 +export const exampleValue2 = 22 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0dce5fafda178853807ef7629764dbfd7c17274a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-1-ok.ets @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Expands an array using the expansion operator + +class Point2D { + x: number = 0; y: number = 0 +} + +class Point3D { + x: number = 0; y: number = 0; z: number = 0 + constructor(p2d: Point2D, z: number) { + this.x = p2d.x + this.y = p2d.y + this.z = z + } +} + +let p3d = new Point3D({ x: 1, y: 2 } as Point2D, 3) +console.log(p3d.x, p3d.y, p3d.z) + +class DerivedFromArray extends Uint16Array { }; + +let arr1 = [1, 2, 3] +let arr2 = new Uint16Array([4, 5, 6]) +let arr3 = new DerivedFromArray([7, 8, 9]) +let arr4 = [...arr1, 10, ...arr2, 11, ...arr3] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f9bbbb27e5feaaf03167589624ed2a68457e29e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-10-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Pass multiple arrays to the remaining parameters + +const arr1 = [1, 2, 3]; +const arr2 = [4, 5, 6]; +const arr3 = [7, 8, 9]; + +function testRestParameter(...args: number[]) { + console.log(args); +} + +testRestParameter(...arr1, ...arr2, ...arr3); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ae7a83026261226d22cf08dc7bdb7fa2389520d6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-2-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Expands an array using the expansion operators + +function foo(x: number, y: number, z: number) { + console.log(x, y, z) +} + +let args: [number, number, number] = [0, 1, 2] +foo(...args) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2033da12cc9a5872ce50843756b17becc2b3cc00 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d1b5104ed7cb18e8006eefd10b8c9449dd7c620 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-3-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Expands an object using the expansion operator + +class Point { + x: number = 0; + y: number = 0; + z?: number = 0; +} + +let point2d: Point = { x: 1, y: 2 } +let point3d: Point = { ...point2d, z: 3 } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..595f4d2c1deeed6c5b9a300b0bba0f6ddd3a9c5b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 26, + "character": 24 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 26, + "character": 24 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5401a0b4c45e86606bd0c22acf9841d188b38e58 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-4-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Pass the array to the remaining parameters + +function test(a: number, ...arr: number[]) { + console.log(arr); +} + +const nums = [1, 2, 3]; +test(1, ...nums); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..59c031c5e380281a04ecbc5dc92b64d15fb18695 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-5-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use the unwrap operator when passing parameters + +function sumNumber(...numbers: number[]): number { + let res = 0 + for (let n of numbers) + res += n + return res +} +sumNumber(1, 2, 3) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4cad8e2d82156efb38afb3827fb0618da94b6b7a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-6-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Copy an array to an array literal + +const arr1 = [1, 2, 3]; +const arr2 = [...arr1]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..52b640fd572397232dffa701988a930f77812487 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-7-ok.ets @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Expand the subclass of Array + +class MyArray extends Array { } + +const arr1 = new MyArray(1, 2, 3); +const arr2 = [...arr1]; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a8902a8a5e8241a89046f6cdd95038ac161c4152 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-8-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use TypedArray to expand arrays + +const arr1 = new Int32Array([1, 2, 3]); +const arr2 = [...arr1]; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d1b516906d0cba57bad0ce4af6ec0b3b2c282b9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-9-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Expand using a different type of TypedArray + +const arr1 = new Float64Array([1.1, 2.2, 3.3]); +const arr2 = [...arr1]; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-spread/arkts-no-spread-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..39a7d009eeeef3538892893c5245d563898954b7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Using this in static methods of classes. +*/ +class MathUtils { + static multiply(a: number, b: number): number { + return this.formatResult(a * b) + } + + static formatResult(result: number): string { + return `The result is ${result}` + } +} + +console.log(MathUtils.multiply(2, 3)) // Output: The result is 6 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e45d1574ede63e35e0e0ee029dc847096e752c07 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 22, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..217db04ea01696ce007567e1df751439f745d344 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using this in class instance methods. +*/ +class MathUtils { + multiply(a: number, b: number): number { + return this.formatResult(a * b) + } + + formatResult(result: number): string { + return `The result is ${result}` + } +} + +const mathUtils = new MathUtils() +console.log(mathUtils.multiply(2, 3)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..747b442c579f9cdd1cafe4c772bbe0bfb0d99028 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Using this to call other static methods in a class's static methods. +*/ +class Logger { + static log(message: string): void { + console.log(this.formatMessage(message)) + } + + static formatMessage(message: string): string { + return `[${new Date().toISOString()}] ${message}` + } +} + +Logger.log('Hello, world!') diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ed234b863f661ef28cf4a6135329fcf0fd9ec759 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5cf1c7f675f7284f3434069510bf0c29e318ead1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using this in class instance methods. +*/ +class Logger { + log(message: string): void { + console.log(this.formatMessage(message)) + } + + formatMessage(message: string): string { + return `[${new Date().toISOString()}] ${message}` + } +} + +const logger = new Logger() +logger.log('Hello, world!') diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..84a759f972f1895426212b72e99dfcb98c15c898 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Using this in static methods of functions. +*/ +function StringUtils() {} + +StringUtils.capitalize = function (str: string): string { + return this.uppercaseFirstLetter(str) +} + +StringUtils.uppercaseFirstLetter = function (str: string): string { + return str.charAt(0).toUpperCase() + str.slice(1) +} + +console.log(StringUtils.capitalize('Hello word!')) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..07e71dd3e23689607072975e98e56a9deac0e917 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-error.json @@ -0,0 +1,104 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 22, + "character": 26 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 22, + "character": 26 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 26, + "character": 36 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 22, + "character": 26 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 26, + "character": 36 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c14d35b416a98d06e07d9242f7ad2679cf75937 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using this in class instance methods. +*/ +class StringUtils { + capitalize(str: string): string { + return this.uppercaseFirstLetter(str) + } + + uppercaseFirstLetter(str: string): string { + return str.charAt(0).toUpperCase() + str.slice(1) + } +} + +const stringUtils = new StringUtils() +console.log(stringUtils.capitalize('Hello world!')) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ceaa60e0a8f3f8b06d8e5ae43362f43394c33036 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Using this to call other static methods in the static method of a function. +*/ +function MathUtils() {} + +MathUtils.sum = function (a: number, b: number): number { + return this.add(a, b) +} + +MathUtils.add = function (a: number, b: number): number { + return a + b +} + +console.log(MathUtils.sum(2, 3)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0d158e4192f3fa13640a2998bd7c325ff3f0e918 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-error.json @@ -0,0 +1,104 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 26, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Reassigning object methods is not supported (arkts-no-method-reassignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Declaring properties on functions is not supported (arkts-no-func-props)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "expectLineAndCharacter": { + "line": 26, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9633b78642441a744cccaf5fd42149c96104b73 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using this in class instance methods. +*/ +class MathUtils { + sum(a: number, b: number): number { + return this.add(a, b) + } + + add(a: number, b: number): number { + return a + b + } +} + +const mathUtils = new MathUtils() +console.log(mathUtils.sum(2, 3)) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..587d7e19734d34a2f869877518086f2681351191 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Using this in a static method of a class to return an instance of the current class. +*/ +class Counter { + static count: number = 0 + + static getInstance(): Counter { + this.count++ + return new this() + } +} + +const counter1 = Counter.getInstance() +const counter2 = Counter.getInstance() + +console.log(counter1 instanceof Counter) // true +console.log(counter2 instanceof Counter) // true +console.log(Counter.count) // 2 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7f86231a4afac5f6cff16fddc7782681df679d75 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 25, + "character": 16 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c3f764e012c4921ac9cf015cdb3b9b369f6b7b5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using this in class instance methods. +*/ +class Counter { + count: number = 0 + + getInstance(): Counter { + this.count++ + return new Counter() + } +} + +const counter1 = new Counter().getInstance() +const counter2 = new Counter().getInstance() + +console.log(counter1 instanceof Counter) // true +console.log(counter2 instanceof Counter) // true +console.log(counter2.count) // 2 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d0f0f6cd282c9672000f771d7f22e9806baee0b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Use this in the static method of a class to obtain the name of the current class. +*/ +class MyClass { + static getClassName(): string { + return this.name + } +} + +console.log(MyClass.getClassName()) // MyClass diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e45d1574ede63e35e0e0ee029dc847096e752c07 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 22, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5e511a215b6dbeb90e446428b1ecded2705ef611 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using this in class instance methods. +*/ +class MyClass { + getClassName(): string { + return this.constructor.name + } +} + +const myInstance = new MyClass() +console.log(myInstance.getClassName()) // MyClass diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1599fcc6ab054946dc1d9018a293deb39c8077aa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-error.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Using this as a parameter to pass to other functions in static methods of a class. +*/ +class StringUtils { + static reverse(str: string): string { + return this.reverseString(str) + } + + static reverseString(str: string): string { + return str.split('').reverse().join('') + } +} + +function printReversedString(reverseFn: (str: string) => string): void { + const reversed = reverseFn('hello') + console.log(reversed) +} + +printReversedString(StringUtils.reverse) // Output: olleh diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e45d1574ede63e35e0e0ee029dc847096e752c07 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 22, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe7cb8d124a53fc90421a17a409bda10a037b4cc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-ok.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using this in class instance methods. +*/ +class StringUtils { + reverse(str: string): string { + return this.reverseString(str) + } + + reverseString(str: string): string { + return str.split('').reverse().join('') + } +} + +function printReversedString(reverseFn: (str: string) => string): void { + const reversed = reverseFn('hello') + console.log(reversed) +} + +const stringUtils = new StringUtils() +printReversedString(stringUtils.reverse.bind(stringUtils)) // olleh diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..786a20ad5d047b47685d92c916df2191359f750a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-7-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 36, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "'Function.bind' is not supported (arkts-no-func-bind)", + "expectLineAndCharacter": { + "line": 36, + "character": 41 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8117719c2840b46479aa95ab51735f7137be66db --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-error.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Using this as the context in a callback function in a static method of a class +*/ +class Timer { + static delay(callback: () => void, milliseconds: number): void { + setTimeout(callback.bind(this), milliseconds) + } +} + +class MyClass { + static logMessage(): void { + console.log('Delayed message') + } + + static start(): void { + Timer.delay(this.logMessage, 2000) + } +} + +MyClass.start() // Output after 2 seconds: Delayed message diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2a686105d509f7e483a6b1468ead10d25bc6e83e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 22, + "character": 16 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 31, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 22, + "character": 30 + } + }, + { + "messageText": "'Function.bind' is not supported (arkts-no-func-bind)", + "expectLineAndCharacter": { + "line": 22, + "character": 25 + } + }, + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 32, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..63f2ffd984d44a8e8473c73b6ffdae31325a3c72 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-ok.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Using this in class instance methods. +*/ +class Timer { + delay(callback: () => void, milliseconds: number): void { + setTimeout(callback.bind(this), milliseconds) + } +} + +class MyClass { + logMessage(): void { + console.log('Delayed message') + } + + start(): void { + const timer = new Timer() + timer.delay(this.logMessage.bind(this), 2000) + } +} + +const myClass = new MyClass() +myClass.start() // Output after 2 seconds: Delayed message diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..e4df37b12b16e6bb90e07f2793fe6b921e12d99c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-standalone-this/arkts-no-standalone-this-8-ok.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 22, + "character": 16 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 33, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "'Function.bind' is not supported (arkts-no-func-bind)", + "expectLineAndCharacter": { + "line": 22, + "character": 25 + } + }, + { + "messageText": "'Function.bind' is not supported (arkts-no-func-bind)", + "expectLineAndCharacter": { + "line": 33, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/@arkts.lang.d.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/@arkts.lang.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..c47866c59e9c8b254d719a14375de40728160dd0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/@arkts.lang.d.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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. + */ + +declare namespace lang { + interface ISendable {} +} + +export { lang }; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d702238121f3f5b95b7da37a17485a2e14f6385f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-1-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 1.When entering parameters as a function, ArkTs specifies that the input parameter classes must be consistent +class X { + n: number = 0 + s: string = '' +} +class Y { + a: number = 0 + b: string = '' +} +function foo (x: X) { + console.log(x.n, x.s) +} +foo(new X()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e3f206d8112bda1eaab24bf915950751c872b2c1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-10-ok.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 10.New inherits direct assignment of class relationships, while ArkTs allows for assigning children to parents +class B { + n: number = 0 + s: string = '' +} + +// D is the inheritance class of B, which constructs the relationship between subtypes and supertypes +class D extends B { + constructor() { + super() + } +} + +let b = new B() +let d = new D() +b = d // Legal assignment because B is the parent class of D \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a9e46d1495dc29088c51fe715edb9d72d788ad56 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-11-error.ets @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SC1 {}; +class NC1 {}; +@Sendable +class SC2 {}; +class NC2 {}; +@Sendable +class SCT1 {}; +class NCT1 {}; +@Sendable +class SCT2 {}; +class NCT2 {}; + +const sc1:SC1 = new SC1(); +const nc1:NC1 = new NC1(); +const sc2:SC2 = new SC2(); +const nc2:NC2 = new NC2(); +const sct1:SCT1 = new SCT1(); +const nct1:NCT1 = new NCT1(); +const sct2:SCT2 = new SCT2(); +const nct2:NCT2 = new NCT2(); + +type TSS = SCT1 | SCT2; +type TSN = SCT1 | NCT1; + +let a1: SC1 = new NC1(); // ERROR +a1 = new NC1();// ERROR +function handle(p: SC1):void {}; +handle(new NC1());// ERROR +class Main1 { + constructor(param:SC1) {}; +} +new Main1(new NC1());// ERROR +interface IProxy {map: SC1;}; +const proxy: IProxy = {map: new NC1()};// ERROR +const proxies: IProxy[] = [{map: new NC1()}];// ERROR + + + +let b1: SC1 = new SC1(); // OK +let b2: SC1 = new NC1(); // ERROR +let b3: SCT1 = new SCT1(); // OK +let b4: SCT1 = new NCT1(); // ERROR +let b5: SC1 | NC1 = new SC1(); // OK +let b6: SC1 | NC1 = new SC2(); // ERROR +let b7: SC1 | NC1 = new NC1(); // OK +let b8: SC1 | NC1 = new NC2(); // ERROR +let b9: SC1 | NC1 = 1 ? new SC1() : new NC1(); // OK +let b10: SC1 | NC1 = 1 ? new SC1() : new NC2(); // ERROR +let b11: SC1 | NC1 = 1 ? new SC2() : new NC1(); // ERROR +let b12: SC1 | NC1 = 1 ? new SC2() : new NC2(); // ERROR +let b13: TSS = new SCT1(); // OK +let b14: TSS = new SCT2(); // OK +let b15: TSS = new NCT1(); // ERROR +let b16: TSS = new NCT2(); // ERROR +let b17: TSS = 1 ? new SCT1() : new NCT1(); // ERROR +let b18: TSS = 1 ? new SCT1() : new NCT2(); // ERROR +let b19: TSS = 1 ? new SCT2() : new NCT1(); // ERROR +let b20: TSS = 1 ? new SCT2() : new NCT2(); // ERROR +// For compatibility, if both sendable, no strict check +let b21: SCT1 = new SCT2();// OK +let b22: TSN = new SCT1(); // OK +let b23: TSN = new SCT2(); // OK +let b24: TSN = new NCT1(); // OK +let b25: TSN = new NCT2(); // OK +let b26: TSN = 1 ? new SCT1() : new NCT1(); // OK +let b27: TSN = 1 ? new SCT1() : new NCT2(); // OK +let b28: TSN = 1 ? new SCT2() : new NCT1(); // OK +let b29: TSN = 1 ? new SCT2() : new NCT2(); // OK + + + +// add check in PropertyDeclaration +class Main { + public p1: SC1 = new SC1(); // OK + public p2: SC1 = new NC1(); // ERROR + public p3: SCT1 = new SCT1(); // OK + public p4: SCT1 = new NCT1(); // ERROR + public p5: SC1 | NC1 = new SC1(); // OK + public p6: SC1 | NC1 = new SC2(); // OK + public p7: SC1 | NC1 = new NC1(); // OK + public p8: SC1 | NC1 = new NC2(); // OK + public p9: SC1 | NC1 = 1 ? new SC1() : new NC1(); // OK + public p10: SC1 | NC1 = 1 ? new SC1() : new NC2(); // OK + public p11: SC1 | NC1 = 1 ? new SC2() : new NC1(); // OK + public p12: SC1 | NC1 = 1 ? new SC2() : new NC2(); // OK + public p13: TSS = new SCT1(); // OK + public p14: TSS = new SCT2(); // OK + public p15: TSS = new NCT1(); // ERROR + public p16: TSS = new NCT2(); // ERROR + public p17: TSS = 1 ? new SCT1() : new NCT1(); // ERROR + public p18: TSS = 1 ? new SCT1() : new NCT2(); // ERROR + public p19: TSS = 1 ? new SCT2() : new NCT1(); // ERROR + public p20: TSS = 1 ? new SCT2() : new NCT2(); // ERROR +} + +// add check in ArrayLiteralExpression +const l1: [SC1] = [sc1]; // OK +const l2: [SC1] = [nc1]; // ERROR +const l3: SC1[] = [sc1]; // OK +const l4: SC1[] = [nc1]; // ERROR +const l5: SCT1[] = [sct1]; // OK +const l6: SCT1[] = [nct1]; // ERROR +const l7: (SC1 | NC1)[] = [ + sc1, // OK + sc2, // OK + nc1, // OK + nc2, // OK + 1 ? sc1 : nc1, // OK + 1 ? sc1 : nc2, // OK + 1 ? sc2 : nc1, // OK + 1 ? sc2 : nc2 // OK +]; +const l8: TSS[] = [ + sct1, // OK + sct2, // OK + nct1, // ERROR + nct2, // ERROR + 1 ? sct1 : nct1, // ERROR + 1 ? sct1 : nct2, // ERROR + 1 ? sct2 : nct1, // ERROR + 1 ? sct2 : nct2 // ERROR +]; + +// add check in ReturnStatement +function f1(): SC1 { + if (1) { + return new NC1(); // ERROR + } + return new SC1(); // OK +} + +function f2(): SCT1 { + if (1) { + return new NCT1(); // ERROR + } + return new SCT1(); // OK +} + +function f3():(SC1 | NC1) { + if (1) { + return new SC1(); // OK + } + if (1) { + return new SC2(); // OK + } + if (1) { + return new NC1(); // OK + } + if (1) { + return new NC2(); // OK + } + if (1) { + return 1 ? new SC1() : new NC1(); // OK + } + if (1) { + return 1 ? new SC1() : new NC2(); // OK + } + if (1) { + return 1 ? new SC2() : new NC1(); // OK + } + if (1) { + return 1 ? new SC2() : new NC2(); // OK + } + return new SC1(); // OK +} + + +function f4():(TSS) { + if (1) { + return new SCT1(); // OK + } + if (1) { + return new SCT2(); // OK + } + if (1) { + return new NCT1(); // ERROR + } + if (1) { + return new NCT2(); // ERROR + } + if (1) { + return 1 ? new SCT1() : new NCT1(); // ERROR + } + if (1) { + return 1 ? new SCT1() : new NCT2(); // ERROR + } + if (1) { + return 1 ? new SCT2() : new NCT1(); // ERROR + } + if (1) { + return 1 ? new SCT2() : new NCT2(); // ERROR + } + return new SCT1(); // OK +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..51961b86b67135b13c476130a10c3c2c4388d887 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-11-error.json @@ -0,0 +1,405 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 41, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 42, + "character": 1 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 44, + "character": 8 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 48, + "character": 11 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 50, + "character": 23 + } + }, + { + "messageText": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)", + "expectLineAndCharacter": { + "line": 51, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 51, + "character": 28 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 56, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 41, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 42, + "character": 1 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 44, + "character": 8 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 48, + "character": 11 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 50, + "character": 23 + } + }, + { + "messageText": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)", + "expectLineAndCharacter": { + "line": 51, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 51, + "character": 28 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 56, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 58, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 60, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 62, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 64, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 65, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 66, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 69, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 70, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 71, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 72, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 73, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 74, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 91, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 93, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 104, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 105, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 106, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 107, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 108, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 109, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 114, + "character": 20 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 116, + "character": 20 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 118, + "character": 29 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 132, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 133, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 134, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 135, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 136, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 137, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 143, + "character": 9 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 150, + "character": 9 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 192, + "character": 9 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 195, + "character": 9 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 198, + "character": 9 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 201, + "character": 9 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 204, + "character": 9 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 207, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d6ade958f5deea894c4f0d7e72164a5ef3afccd1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-2-error.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 2. If class X is specified as a function parameter in ArkTs, it is not allowed to pass in other classes +class X { + n: number = 0 + s: string = '' +} +class Y { + a: number = 0 + b: string = '' +} +function foo (x: X) { + console.log(x.n, x.s) +} +foo(new Y()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..33b1d0c99027969280b9cac4c7acb27206af6e4d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 29, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 29, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5aed055b5f1603dacb68b293cb3bb503ee55ff1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-3-error.ets @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 3. When used as a function parameter, even classes with the same API are not allowed as arguments by ArkTs +class X { + n: number = 0 + s: string = '' +} +class Y { + n: number = 0 + s: string = '' +} +let x = new X() +let y = new Y() +function foo (x: X) { + console.log(x.n, x.s) +} +foo(new Y()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e4ddbc76708d9958d18710533c6972ec55c13616 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 31, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 31, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c0b386f3980018bf2c7f8f5fddccfdeaf2a6532 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-4-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 4. If class X is specified as a function parameter, ArkTs allows all classes that inherit from X to be arguments to the function +class X { + n: number = 0 + s: string = '' +} +class Y extends X { + name: string = '', + age: number = 0 +} +function foo (x: X) { + console.log(x.n, x.s) +} +foo(new Y()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..daacd2c59298babee3fcc3fc9025211e447a6a1a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-5-error.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 5. Even if inherited from the same class, it is not supported +class X { + n: number = 0 + s: string = '' +} +class Y extends X { +} +class Z extends X {} +function foo (y: Y) { + console.log(y.n, y.s) +} +foo(new Z()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3b5bf8e3843ab916031783422013d526e057b34d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 28, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 28, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6cb1cabe268435d44dd37cba1eb939745e2b6587 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-6-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 6. Can use type aliases +class X { + n: number = 0 + s: string = '' +} +type Y = X +function foo (x: X) { + console.log(x.n, x.s) +} +foo(new Y()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bd0ca124613fd9faf82f77b45927d393556a33f5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-7-ok.ets @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2023 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 {lang} from '@arkts.lang'; + +// 7. Interface implementations can be used +interface Z { + n: number + s: string +} +class X implements Z { + n: number = 0 + s: string = '' +} +class Y implements Z { + n: number = 0 + s: string = '' +} +function foo(c: Z): void { + console.log(c.n, c.s) +} +foo(new X()) +foo(new Y()) + +// Sendable can be thought of as implement ISendable +@Sendable +class SendableClass { + public n: number = 0; +} +function foo(s: lang.ISendable) { +} +foo(new SendableClass()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..2fd55a7b1dd2d499b0162ce9a61e2cd4ba75d599 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-7-ok.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 37, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..91837fefe4fb2391bb13a31e01243c7abe13a863 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-8-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 8. You can use type assertions as +class X { + n: number = 0 + s: string = '' +} +const Y = {} as X +function foo (x: X) { + console.log(x.n, x.s) +} +foo(new Y()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..19aea83b368d08254a8f626cf74b30787a9f2a31 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-9-error.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// 9.The direct assignment of a new inheritance class relationship, assigning a parent to a child, is not allowed by ArkTs +class B { + n: number = 0 + s: string = '' +} + +// D is the inheritance class of B, which constructs the relationship between subtypes and supertypes +class D extends B { + constructor() { + super() + } +} + +let b = new B() +let d = new D() +d = b // Assigning b to d will cause compile time errors \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..fce612e1a4e1c2272ee32843f90da58e461e563a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-structural-typing/arkts-no-structural-typing-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 32, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 32, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..be4bab7e88ac187129836cb6107fecfafbe5de06 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-1-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Array iteration uses symbol.iterator +const arr: number[] = [1, 2, 3]; +const iterator = arr[Symbol.iterator](); +let iteration = iterator.next(); + + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..cecbc63b7c04badd8e90fc35486378284f4f8527 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-10-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +class CustomMatcher { + [Symbol.match](value: string): RegExpMatchArray | null { + const matches = value.match(/Hello/g); + return matches; + } +} + +const testString = "Hello, Hello!"; +const customObj = new CustomMatcher(); +const result = testString.match(customObj); +console.log(result); // output: [ 'Hello', 'Hello' ] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e2985e0834e0212026fca0a06bf5b98dd9e2491a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-10-error.json @@ -0,0 +1,41 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 18, + "character": 4 + } + }, + { + "messageText": "RegExp literals are not supported (arkts-no-regexp-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 33 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 18, + "character": 4 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..95783a6302186fd39c6fd4de26552a6cf2e791bb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-2-ok.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 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. + */ + + +// The class contains iterations of the generators function +interface IterableIteratort extends Iterator { + [Symbol.iterator](): IterableIteratort; +} + +class MyIterable { + arr: number[]; + + constructor(arr: number[]) { + this.arr = arr; + } + + *[Symbol.iterator](): IterableIteratort { + for (let i = 0; i < this.arr.length; i++) { + yield this.arr[i]; + } + } +} + +const iterable = new MyIterable([1, 2, 3]); + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..e565973dc73b0276b9f1bc127556f21a89907596 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-2-ok.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 31, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + }, + { + "messageText": "Generator functions are not supported (arkts-no-generators)", + "expectLineAndCharacter": { + "line": 31, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ef9cae229fb2f07742480778da0045dbdf5ef756 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-3-ok.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 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. + */ + + +// There are no iterations of the generators function in class +class Classroom implements Iterable { + private students: string[] + constructor(students: string[]) { + this.students = students + } + // Implement iterators + [Symbol.iterator](): Iterator { + let index: number = 0 + return { + next: (): IteratorResult => { + if (index < this.students.length) { + return { done: false, value: this.students[index++] } + } else { + return { done: true, value: undefined } + } + }, + } + } +} +const classroom = new Classroom([ + 'student1', + 'student2', + 'student3', + 'student4', + 'student5', +]) + +for (const student of classroom) { + console.log(student) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..d644eac9114e8c417409c323eae729ec946c5b5b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-3-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 26, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 26, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4df8cb8f78a113715817f3924affc1b1ab405748 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-4-ok.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 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. + */ + + +type CustomIterable = { + [Symbol.iterator](): Iterator; +}; + +// Use the custom type CustomIterable +function printValues(iterable: CustomIterable): void { + for (const item of iterable) { + console.log(item); + } +} + +// An implementation of an array +const arrayIterable: CustomIterable = { + [Symbol.iterator](): Iterator { + const data = [1, 2, 3]; + let index = 0; + + return { + next(): IteratorResult { + return { + value: data[index++], + done: index > data.length, + }; + }, + }; + }, +}; + +printValues(arrayIterable); // output: 1, 2, 3 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..961a41a55f825f1f62e8ed7b6f524b2d729ab473 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-4-ok.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 26 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 29, + "character": 47 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 34, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 26 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 29, + "character": 47 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 34, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5a33a2bbec4c3b84fa749e6cc19b7f8e8499f79 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-5-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +const uniqueID = Symbol("userID"); +const user = { + [uniqueID]: "abc123", + name: "Alice", +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1f42e596215014867fd087e62b9c3bb1e589192f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-5-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 17, + "character": 18 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 14 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c4ce09a154ea2c0aea8449dc770852b76596e480 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-6-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +class MyArray extends Array { + [Symbol.isConcatSpreadable] = true; +} + +const array1 = [1, 2, 3]; +const array2 = new MyArray(); +array2.push(4, 5, 6); + +const result = array1.concat(array2); + +console.log(result); // output: [1, 2, 3, 4, 5, 6] diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5e447eccbdd3b021184e246c21bb8a3c76dc5615 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 18, + "character": 4 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 18, + "character": 3 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 18, + "character": 4 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..993cf15a8e5d8af83fb52abaa6aeacf8788dc693 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-7-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The Symbol() API in TypeScript is used to generate unique property names at runtime. Since the common use cases of this API do not make sense in statically typed languages, ArkTS does not support the Symbol() API. In ArkTS, the object layout is determined at compile time and cannot be changed at runtime. +type: Positive example +*/ +class EvenNumber { + static [Symbol.hasInstance](instance: number) { + return typeof instance === "number" && instance % 2 === 0; + } +} + +const number1 = 10; +const number2 = 7; + +// console.log(number1 instanceof EvenNumber); +// console.log(number2 instanceof EvenNumber); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5d21c87b25208b2bcfb29e9d25344c67682a429d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-7-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 22, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 22, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..65d5a4639896959332b5f952cdc386a620382cfa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-8-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 s1 = Symbol.for("foo"); +let s2 = Symbol.keyFor(s1); +console.log(s2); //foo + +let s3 = Symbol("foo"); +let s4 = Symbol.keyFor(s3); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..021d5007088ee72758cb7feb652f21059e5fadd8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-8-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 17, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 17, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..243ede07e574b32a76c72461100c7d94fb57b899 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-9-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 s4 = Symbol.for("123"); +let s5 = Symbol.for("123"); +console.log(s4 == s5); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..42d221af510e8461d0615913538a269ed7060597 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-symbol/arkts-no-symbol-9-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 17, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 17, + "character": 10 + } + }, + { + "messageText": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/arkts-no-ts-deps-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/arkts-no-ts-deps-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c1e3951227f91cb36532c66ac08f9d7d0dd6f68 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/arkts-no-ts-deps-1-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import ets file from ets file + +import { C } from 'lib1-dependencie' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/arkts-no-ts-deps-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/arkts-no-ts-deps-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/arkts-no-ts-deps-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..eae5dfd64cd577d4cb94e3bdd202cc4846e46aa2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-1-ok/lib1-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class C { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/arkts-no-ts-deps-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/arkts-no-ts-deps-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0cff6e48be64c9fbdec1add08f0cba6c5bbf5666 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/arkts-no-ts-deps-10-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import multiple ets file modules into ets files + +import { C, sayHello, message } from 'lib1-dependencie' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/arkts-no-ts-deps-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/arkts-no-ts-deps-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/arkts-no-ts-deps-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..ae5b08efe1e25ebbd233218a6322d1b6388c18df --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-10-ok/lib1-dependencie.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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 class C { + // ... +} + +export let sayHello = () => { + console.log('hello') +} + +export let message = "hello" \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/arkts-no-ts-deps-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/arkts-no-ts-deps-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b1f27f353a6e83815d0a0793e00b4eae7018fae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/arkts-no-ts-deps-2-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import ts file from ets file + +import { C } from 'lib1-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/arkts-no-ts-deps-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/arkts-no-ts-deps-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/arkts-no-ts-deps-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/lib1-dependencie.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/lib1-dependencie.ts new file mode 100644 index 0000000000000000000000000000000000000000..22351fc0a535247ca4aa98b1f6592325b0741e09 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-2-ok/lib1-dependencie.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 class C { + // ... +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/arkts-no-ts-deps-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/arkts-no-ts-deps-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f0c893c84351a7ec73e790cc7e393a439c60e32 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/arkts-no-ts-deps-3-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import js file from ets file + +import { C } from 'lib1-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/arkts-no-ts-deps-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/arkts-no-ts-deps-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/arkts-no-ts-deps-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/lib1-dependencie.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/lib1-dependencie.js new file mode 100644 index 0000000000000000000000000000000000000000..eae5dfd64cd577d4cb94e3bdd202cc4846e46aa2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-3-ok/lib1-dependencie.js @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class C { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/arkts-no-ts-deps-4-error.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/arkts-no-ts-deps-4-error.js new file mode 100644 index 0000000000000000000000000000000000000000..bb410b6c804a25cc2984cdbffd0f153805fdb01e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/arkts-no-ts-deps-4-error.js @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import ets file from js file + +import { C } from 'lib1-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/arkts-no-ts-deps-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/arkts-no-ts-deps-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3f896b0f289f00a517b1c40798ae2a3fe3dc8de1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/arkts-no-ts-deps-4-error.json @@ -0,0 +1,9 @@ +[ + { + "messageText": "arkts-no-ts-deps", + "expectLineAndCharacter": { + "line": 19, + "character": 19 + } + } +] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/lib1-dependencie.ejs b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/lib1-dependencie.ejs new file mode 100644 index 0000000000000000000000000000000000000000..eae5dfd64cd577d4cb94e3bdd202cc4846e46aa2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-4-error/lib1-dependencie.ejs @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class C { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/arkts-no-ts-deps-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/arkts-no-ts-deps-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3f896b0f289f00a517b1c40798ae2a3fe3dc8de1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/arkts-no-ts-deps-5-error.json @@ -0,0 +1,9 @@ +[ + { + "messageText": "arkts-no-ts-deps", + "expectLineAndCharacter": { + "line": 19, + "character": 19 + } + } +] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/arkts-no-ts-deps-5-error.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/arkts-no-ts-deps-5-error.ts new file mode 100644 index 0000000000000000000000000000000000000000..2db73005ff620b688c8d1b9c09d8b2bbd9002ef7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/arkts-no-ts-deps-5-error.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + +// Description: Import ets file from ts file + +import { C } from 'lib1-dependencie'; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/lib1-dependencie.ejs b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/lib1-dependencie.ejs new file mode 100644 index 0000000000000000000000000000000000000000..eae5dfd64cd577d4cb94e3bdd202cc4846e46aa2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-5-error/lib1-dependencie.ejs @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class C { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/arkts-no-ts-deps-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/arkts-no-ts-deps-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5253ef845d4d53bd4313b1f87f88663649825db2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/arkts-no-ts-deps-6-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import multiple ets files into ets files + +import { C } from 'lib1-dependencie' +import { B } from 'lib2-dependencie' +import { A } from 'lib3-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/arkts-no-ts-deps-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/arkts-no-ts-deps-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/arkts-no-ts-deps-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..eae5dfd64cd577d4cb94e3bdd202cc4846e46aa2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib1-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class C { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib2-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib2-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c38b68565534ca7e68c132b3baedef6faf2b70c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib2-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class B { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib3-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib3-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..f51b24433f8badb9ee30cde3729e732617fc1adb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-6-ok/lib3-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class A { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/arkts-no-ts-deps-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/arkts-no-ts-deps-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..07a299ec18c507a2fb64c7e74e237e28fdfcd091 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/arkts-no-ts-deps-7-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import multiple ts files into ets files + +import { C } from 'lib1-dependencie' +import { B } from 'lib2-dependencie' +import { A } from 'lib3-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/arkts-no-ts-deps-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/arkts-no-ts-deps-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/arkts-no-ts-deps-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib1-dependencie.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib1-dependencie.ts new file mode 100644 index 0000000000000000000000000000000000000000..22351fc0a535247ca4aa98b1f6592325b0741e09 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib1-dependencie.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 class C { + // ... +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib2-dependencie.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib2-dependencie.ts new file mode 100644 index 0000000000000000000000000000000000000000..5cbf3d6f4bf189fcd23a2fec25c51bdfa7d83cb0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib2-dependencie.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 class B { + // ... +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib3-dependencie.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib3-dependencie.ts new file mode 100644 index 0000000000000000000000000000000000000000..f4758f988b4191570d5e28528ac711e122eeb257 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-7-ok/lib3-dependencie.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 class A { + // ... +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/arkts-no-ts-deps-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/arkts-no-ts-deps-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..646fbca2c1664c0f57a4de0056d5ec751c44adde --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/arkts-no-ts-deps-8-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import multiple js files into ets files + +import { C } from 'lib1-dependencie' +import { B } from 'lib2-dependencie' +import { A } from 'lib3-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/arkts-no-ts-deps-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/arkts-no-ts-deps-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/arkts-no-ts-deps-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib1-dependencie.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib1-dependencie.js new file mode 100644 index 0000000000000000000000000000000000000000..eae5dfd64cd577d4cb94e3bdd202cc4846e46aa2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib1-dependencie.js @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class C { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib2-dependencie.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib2-dependencie.js new file mode 100644 index 0000000000000000000000000000000000000000..7c38b68565534ca7e68c132b3baedef6faf2b70c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib2-dependencie.js @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class B { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib3-dependencie.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib3-dependencie.js new file mode 100644 index 0000000000000000000000000000000000000000..f51b24433f8badb9ee30cde3729e732617fc1adb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-8-ok/lib3-dependencie.js @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class A { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/arkts-no-ts-deps-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/arkts-no-ts-deps-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..44539af50b1484aeb34b28633ce4f4a1c7bec523 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/arkts-no-ts-deps-9-ok.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Import multiple ets/ts/js files into ets files + +import { C } from 'lib1-dependencie' +import { B } from 'lib2-dependencie' +import { A } from 'lib3-dependencie' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/arkts-no-ts-deps-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/arkts-no-ts-deps-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/arkts-no-ts-deps-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib1-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib1-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..eae5dfd64cd577d4cb94e3bdd202cc4846e46aa2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib1-dependencie.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class C { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib2-dependencie.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib2-dependencie.ts new file mode 100644 index 0000000000000000000000000000000000000000..5cbf3d6f4bf189fcd23a2fec25c51bdfa7d83cb0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib2-dependencie.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 class B { + // ... +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib3-dependencie.js b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib3-dependencie.js new file mode 100644 index 0000000000000000000000000000000000000000..f51b24433f8badb9ee30cde3729e732617fc1adb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-deps/arkts-no-ts-deps-9-ok/lib3-dependencie.js @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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 class A { + // ... +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/@arkts.lang.d.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/@arkts.lang.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..40e381dc2a3c9c96df3b6278ed74fe7a71922dc9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/@arkts.lang.d.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + +declare namespace lang { + interface ISendable {} +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/arkts-no-ts-sendable-type-inheritance.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/arkts-no-ts-sendable-type-inheritance.json new file mode 100644 index 0000000000000000000000000000000000000000..b73cf4e89e8e061ab46b56f4f9deca45317cf6b1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/arkts-no-ts-sendable-type-inheritance.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/arkts-no-ts-sendable-type-inheritance.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/arkts-no-ts-sendable-type-inheritance.ts new file mode 100644 index 0000000000000000000000000000000000000000..5fc5224f93e0b490bca9c67a87be56da59181bf0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/arkts-no-ts-sendable-type-inheritance.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 { A, A1, A as A2, B, B1, B as B2, C, C1, C as C2 } from './lib-dependencie'; +import { I, J } from './lib-dependencie'; + +interface T {} + +class D1 extends A {} +class D2 extends A1 {} +class D3 extends A2 {} +class D4 extends B {} +class D5 extends B1 {} +class D6 extends B2 {} +class D7 extends C {} +class D8 extends C1 {} +class D9 extends C2 {} + +interface I1 extends I {} +interface J1 extends J {} +interface K extends I, J, T {} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/lib-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/lib-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f5ffc7fabf21a2b410152d1ab4d5b2a1341a191 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-ts-sendable-type-inheritance/lib-dependencie.ets @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 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 { lang } from './@arkts.lang' + +@Sendable +class A {} +export { A, A as A1 } + +@Sendable +class B { + public value: number = 0; +} +export { B, B as B1 } + +@Sendable +class C implements lang.ISendable { + public value: number = 0 +} +export { C, C as C1 } + +export interface I extends lang.ISendable { + v: number; +} + +export interface J extends I { + u: number; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fb3471587f3aed98a6f0a31d7858dbbbe0eb92db --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-1-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +const someVar = 10; +if (typeof someVar === "number") { + // Perform actions against numeric types +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..16cd45a95df67a1303bcd2029b89d94b1cb440a7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-10-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +// The choice type is union type 'a' | 'b' | 'c' +const option = "a" as "a" | "b" | "c"; +let choice: typeof option; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..761ea6cf2b5f5645f3a17d684d7792b99764a14f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 19, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 19, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a2af9f54395f606ebf458009101ec24c40abd685 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-2-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +class MyClass { + name: string; + age: number; + constructor(n: string, a: number) { + this.name = n; + this.age = a; + } + sayHello() { + console.log("Hello!"); + } +} +console.log(typeof MyClass.name); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..511255cd1db7de108c176dc66528b1f6240da9e8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-3-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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 fun = () => { + if (typeof param === "string") { + console.log("string"); + } +}; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2ed69ec7f44ca2557828dc322389c605fd2ce91f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-4-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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 someCondition: boolean = true; +let dynamicVar: string | number; +if (someCondition) { + dynamicVar = typeof 10; +} else { + dynamicVar = typeof "Hello"; +} +console.log(dynamicVar); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7066df2ceb20c9cc5c155436157a3e6e266073d6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-5-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +const value = "Hello"; +switch (typeof value) { + case "string": + console.log("string"); + break; + case "number": + console.log("number"); + break; + default: + break; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0c0ee2dd9eb57cbd8f8bd2dc19480edb7ccfc7e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-6-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +const num: number = 5; +type NumType = typeof num; // Type annotation, NumType is of type number diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..eed01a84144138ae066c2f31873c7454944f35d4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 18, + "character": 16 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 18, + "character": 16 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..830c44d78e3b89e9da42e701225e91e7707dd316 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-7-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Type annotation, AddReturnType is of type number +function add(a: number, b: number): number { + return a + b; +} +type AddReturnType = typeof add; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..53f7e4ea8e982a3a2e452d9fe6ede4be4e53d2e5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 21, + "character": 22 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 21, + "character": 22 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..21de36c9ecb3569ba8b18c7d73e045f866c9110e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-8-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +class U { + getName(): string { + return "Alice"; + } +} +const util = new U(); +let method: typeof util.getName; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..256651e5ba050ba69dab896e749feea37334dc28 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 23, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 23, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d617ecb34d9df79e4b648531fae4fdb19fd85467 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-9-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +class Car { + brand = 'Toyota'; + speed = 100; +} +let myCar: typeof Car; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5e251fc4559edb3f6eba734c66a83f878b3514b9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-type-query/arkts-no-type-query-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 21, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 21, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..857940d27b5b11a92a9de935657b0ac951133704 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: JSON parsing error. +*/ +try { + let json = '{"name": "John", age: 30}' // Missing quotation marks causing inability to parse + let user = JSON.parse(json) +} catch (error: any) { + console.error('JSON Error:', error.message) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2f9201a0e60a2a8db5859f650674ba4a62021d3e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 7 + } + }, + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 7 + } + }, + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4632187a8b7504fa5af42fda7ed893bf319ffb90 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Omitting type annotations in catch statements. +*/ +try { + let json = '{"name": "John", age: 30}' // Missing quotation marks causing inability to parse + let user = JSON.parse(json) +} catch (error) { + console.error('JSON Error:', error.message) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..798da20f30def13e33d7c9448df681b706ddfac2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-1-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 7 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..2529a8702a6745ddae6c4376ea90c43031c9cc4f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Array out of bounds access. +*/ +try { + let array: number[] = [1, 2, 3] + let outOfBoundsElement: number = array[10] // Cross border visits +} catch (error: any) { + console.error('Array Error:', error.message) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2eb2ca84e0c59345efc1ba052c7b66d5e32c6e26 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f9230396110615113f3aaf4d00461be2257f0bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Omitting type annotations in catch statements. +*/ +try { + let array: number[] = [1, 2, 3] + let outOfBoundsElement: number = array[10] // Cross border visits +} catch (error) { + console.error('Array Error:', error.message) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..aedc7c5d408086a0c48b598f9a1f8f63576eda52 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Function not defined. +*/ +try { + callUndefinedFunction() // This function is not defined +} catch (error: any) { + console.error('Function Error:', error.message) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9af1063ae0add32bec2501307d90718d88c60bd6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 22, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e1c658098dc77549d80e78c3779fd5902da4d4c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Omitting type annotations in catch statements. +*/ +try { + callUndefinedFunction() // This function is not defined +} catch (error) { + console.error('Function Error:', error.message) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd94a75125f9d9047446856c85050451fd35ac07 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Property access error. +*/ +try { + let obj = {} + console.log(obj.name) // Accessing non-existent properties will result in an error +} catch (error: any) { + console.error('Property Access Error:', error.message) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..736b0b911d59090e55543f6c35d1d7e975439c46 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + }, + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + }, + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f0c6cc37955e9fc97f3e056d0ac570f6dc36bee8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Omitting type annotations in catch statements. +*/ +try { + let obj = {} + console.log(obj.name) // Accessing non-existent properties will result in an error +} catch (error) { + console.error('Property Access Error:', error.message) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..02a342f12d28afc9d9eac58944f2babac054fff3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-4-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f7f54281202b9b02ac4d08fdd59d6c16083cb86 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Counterexample: Type conversion error. +*/ +try { + let num: number = parseInt('abc') // 'abc' cannot be converted to a number + if (isNaN(num)) throw new Error('Not a number') +} catch (error: any) { + console.error('Type Conversion Error:', error.message) +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2eb2ca84e0c59345efc1ba052c7b66d5e32c6e26 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7715057634bd65959b4b7464b2d372dd90489bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* + Positive example: Omitting type annotations in catch statements. +*/ +try { + let num: number = parseInt('abc') // 'abc' cannot be converted to a number + if (isNaN(num)) throw new Error('Not a number') +} catch (error) { + console.error('Type Conversion Error:', error.message) +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-types-in-catch/arkts-no-types-in-catch-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b012c70cbff5316f801c96140a2b4859fab04648 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-1-error.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: Implementing a reference to this type in an interface +interface Self { + setName(name: string): this; +} + +class Person implements Self { + name: string = ''; + + setName(name: string) { + this.name = name; + return this; + } +} + +const person = new Person(); +person.setName('Tom'); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1a6e2a62c94af088e50d8a1d8fba4ab0be88af85 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 19, + "character": 26 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 19, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c2fa295efca86d4e33e1eb50f79475a5f0cb89d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-10-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: The member function in the class returns the instance object of the current class (explicit type) +class Person { + name: string = ''; + + setName(name: string): Person { + this.name = name; + return this; + } +} + +const person = new Person(); +person.setName('Tom'); +const person2 = person.setName('Jerry'); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..52bbeafc642ef9cb2b14e68f36d0ec11ad66724f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-2-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Replace this with an explicit concrete type in a class (number) +class H { + n: number = 0 + + m(d: H) { + console.log(d) + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f7504bd1ce75a0e1e339f49b6e87d95c7501977 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-3-error.ets @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: The member function in the class returns the instance object of the current class or the instance object of the parent class +class Animal { + name: string = ''; + setName(name: string): Animal { + this.name = name; + return this; + } +} +class Cat extends Animal { + meow(): void { + console.log('meow'); + } + setName(name: string): Animal { + return super.setName(name); + } + setName2(name: string): this { + return this.setName(name) as this; + } +} +const cat = new Cat(); +cat.setName2('Tom').meow(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..880e61dee26e65a1d1ea9626ab3d828c0187cb6b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-3-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 32, + "character": 27 + } + }, + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 33, + "character": 34 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 32, + "character": 27 + } + }, + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 33, + "character": 34 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3138e8c39ab53a0a0ec6a9557541336ab978d6bb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-4-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Replace this with an explicit concrete type in a class(srting) +class B { + n: string = '' + + m(c: B) { + console.log(c) + } +} +const b = new B() +b.n = 'he' +b.m(b) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..10a97824662d8e4165fd9b0d6bcc280d9e1df485 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-5-error.ets @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: The member function in a class returns the instance object of the current class or the instance object of the parent class +class Animal { + name: string = ''; + setName(name: string): Animal { + this.name = name; + return this; + } +} +class Cat extends Animal { + meow(): void { + console.log('meow'); + } + setName(name: string): Animal { + return super.setName(name); + } + setName2(name: string): this { + return this.setName(name) as this; + } +} +const cat = new Cat(); +cat.setName2('Tom').meow(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..880e61dee26e65a1d1ea9626ab3d828c0187cb6b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 32, + "character": 27 + } + }, + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 33, + "character": 34 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 32, + "character": 27 + } + }, + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 33, + "character": 34 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e370601cd3f79433c06f0d7d42dcd9cea61fed04 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-6-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Reference of this type in interface +interface ListItem { + getHead(): ListItem +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..87a1827ce5062244d9c391967de8b0805e33f517 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-7-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: The member function in the class returns the instance object of the current class +class Person { + name: string = ''; + setName(name: string): this { + this.name = name; + return this; + } +} +const person = new Person(); +person.setName('Tom').setName('Jerry'); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1cee6eaa7bd7c11a9fa870e31dd57e888ce09f77 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 20, + "character": 26 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 20, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..589f7d403428a011d2f64fe933176a4e7bf1d38a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-8-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Example: Explicitly replacing tllhis with a specific type in a class(boolean) +class E { + n: boolean = true + + m(c: E) { + console.log(c) + } +} +const e = new E() +e.n = false +e.m(e) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff862067a518a2f14ec8f56d9d8b4ee6972367fb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-9-error.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Counterexample: The member function in the class returns the instance object of the current class or the instance object of a subclass +class Animal { + name: string = ''; + setName(name: string): Animal { + this.name = name; + return this; + } +} +class Cat extends Animal { + meow(): void { + console.log('meow'); + } + setName(name: string): this { + return super.setName(name) as this; + } +} +const cat = new Cat();cat.setName('Tom').meow(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..956005e1524939962108392b912afd480a9bf43d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-typing-with-this/arkts-no-typing-with-this-9-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 29, + "character": 26 + } + }, + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 30, + "character": 35 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 29, + "character": 26 + } + }, + { + "messageText": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)", + "expectLineAndCharacter": { + "line": 30, + "character": 35 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..63522c875805c0b631570317699e327f073823c7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 isPrime(x: number): boolean +export as namespace mathLib + +mathLib.isPrime(2) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..697d7d78bc8b89adad6ed3d9e992e0730de24712 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b1965da7f8d1bb5dac5b1062981331162bcf666 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 { mathLib } from 'arkts-no-umd-1-ok' +mathLib.isPrime(2) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..fe011a3fc246678db93307bc4afb5832a9c448cc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-1-ok/arkts-no-umd-1-ok.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace mathLib { + export isPrime(x: number): boolean +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5ee1c4bfd900a54c1816d2c8769c46ecc39dfd42 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-error.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 bar = 33 +export as namespace foo + +console.log(foo.bar) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..697d7d78bc8b89adad6ed3d9e992e0730de24712 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b2f9210c8c1cd3b5ddec7b193fa766782237099 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 { foo } from 'arkts-no-umd-2-ok' +console.log(foo.bar) + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..4b47b18f0a766bc0945339d3b6274c09a27beb1c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-2-ok/arkts-no-umd-2-ok.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +namespace foo{ + export bar =33 +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..488af571f9e805522627e3a8eca3d7ad18192aab --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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 enum Color { + RED, + GREEN, + YELLOW, + BLACK, + BLUE +} +export as namespace foo + +console.log(foo.Color) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f41e7295925bb44cab2563323b745621cd12f197 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ff1494467a6ca027038ea089983390499a1912e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 { foo } from 'arkts-no-umd-3-ok' +console.log(foo.Color.RED) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..932bc236214b01ace61302f8e5b8f05b1e304f28 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-3-ok/arkts-no-umd-3-ok.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + +namespace foo { + export enum Color { + RED, + GREEN, + YELLOW, + BLACK, + BLUE + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f18470c1e156bce2cd34674ec12e1b2a771ee139 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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 interface Person { + firstName: string; + lastName: string; + age: number; +} +export as namespace foo +console.log(foo.Person) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..dd395bd5f721e6fa8d2aae880fa81f3294515455 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3bda283446b798e0c822b61364a73d5975eba516 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 { foo } from 'arkts-no-umd-4-ok' +console.log(foo.Person) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..323be0a71296100cbe24cda015dbc3623d4376c1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-4-ok/arkts-no-umd-4-ok.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + +namespace foo { + export interface Person { + firstName: string; + lastName: string; + age: number; + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c89757dbaf9705fbce91f61e8688217243fe89c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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 class Foo { + static bar() { + return 'hello'; + } +} +export as namespace foo +console.log(foo.Foo.bar()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..dd395bd5f721e6fa8d2aae880fa81f3294515455 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..65bbfa7a012ff88e89552b77751ef187fc50b917 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 { foo } from 'arkts-no-umd-5-ok' +console.log(foo.Foo.bar()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..e8d4d5c8dfcdbe0aabb2794a3094010383f0c869 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-5-ok/arkts-no-umd-5-ok.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + +namespace foo { + export class Foo { + static bar() { + return 'hello'; + } + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5fd1db39b036834b00353cf57928209a31d5ca4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 SomeNameSpaceName { + export interface ISomeInterfaceName {} + export class SomeClassName {} +} +export as namespace foo +console.log(foo.SomeClassName) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f9109a67a55d70b49a2757af627381050423d696 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Universal module definitions (UMD) are not supported (arkts-no-umd)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..750dcd73514166fb70b92ae7d6e7b806287ff866 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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 { foo } from 'arkts-no-umd-6-ok' +console.log(foo.SomeClassName) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.ts b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.ts new file mode 100644 index 0000000000000000000000000000000000000000..2f5aadf1467e035f02ce83eb62808ace4023ec22 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-umd/arkts-no-umd-6-ok/arkts-no-umd-6-ok.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + +namespace foo { + namespace SomeNameSpaceName { + export interface ISomeInterfaceName {} + export class SomeClassName {} + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8fd2ea7566720e7ecf525b31bde3dd3685afbf6b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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 o1 = { n: 42, s: 'foo' } +let o2: Object = { n: 42, s: 'foo' } +let o3: object = { n: 42, s: 'foo' } + +let oo: Object[] = [ + { n: 1, s: '1' }, + { n: 2, s: '2' }, +] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..32b952eddba37a3b1551a2cd482ffe1e4306da35 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-error.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 10 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 18 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 18 + } + }, + { + "messageText": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 17, + "character": 10 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 18 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 19, + "character": 18 + } + }, + { + "messageText": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..cad09d3a4c99e473df9e20d76ca972de4c8acfda --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +class C1 { + n: number = 0 + s: string = '' +} + +let eu: C1 = { n: 42, s: 'foo' } + +let na: C1[] = [ + { n: 1, s: '1' }, + { n: 2, s: '2' }, +] \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b375ad679fd0ca0ff7e57fd207e6cb42c7571b9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +class C2 { + s: string + constructor(s: string) { + this.s = 's =' + s + } +} +let o4: C2 = { s: 'foo' } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d2b22537c001a73c52e4b7b47f8ccbe08ffe3672 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 14 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c02f4fd5ff3c6357053c1ba10c815fe79bd6fcc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +class MyBox { + s: string + constructor(s: string) { + this.s = 's =' + s + } +} +let Oc = new MyBox('foo') \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6a46d85cef5f40a3b58a30cf3821ba83626f540 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +class C3 { + readonly n: number = 0 + readonly s: string = '' +} +let o5: C3 = { n: 42, s: 'foo' } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b3cd1f4105dc35f0921e4e6e0d9fdd54150c3b6d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 14 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..eecfc8b1db04115781c579fda1a466fd161be80b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-ok.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +class O3 { + n: number = 0 + s: string = '' +} +let oo3: O3 = { n: 42, s: 'foo' } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d50669286521db04d14fc7a19f2ee328571f8420 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +abstract class A {} +let o6: A = {} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..477f70ca43328dd1780c2ee7b509ff1634d84c3f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 18, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d432bd5db17254394f1eb098207d013e640dbc9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +abstract class B {} +class C extends B {} +let oo6: C = {} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5994fbeaa288fdc0974d02b25c04909cc3a10abc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-error.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +class C4 { + n: number = 0 + s: string = '' + f() { + console.log('Hello') + } +} +let o7: C4 = { n: 42, s: 'foo', f: () => {} } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c8bc32a72ded25385e44d642868374f77a6e44a8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 14 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 14 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..20de3737b93e2ee41cb4e2ac7bd3ff62b4e209ac --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Cc4 { + n: number = 0 + s: string = '' + f() { + console.log('Hello') + } +} +let oo7 = new Cc4() +oo7.n = 42 +oo7.s = 'foo' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0c2ca71ebe5a2e8128e9d6957e0d4462d6a6c5c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +class Point { + x: number = 0 + y: number = 0 +} + +function identify(o: Point): Point { + return o +} + +let p = { x: 5, y: 10 } +identify(p) + +identify({ x: 5, y: 10 }) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1af39ae123a89ab34448a6baa8e281cfa3de6928 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 26, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 26, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0fed79b313a6158588c0dba935d9d5fed3234cdb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-ok.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +class PointDown { + x: number = 0 + y: number = 0 +} + +function id_x_y(o: PointDown): PointDown { + return o +} + +let p1: PointDown = { x: 5, y: 10 } +id_x_y(p1) + +id_x_y({ x: 5, y: 10 }) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-untyped-obj-literals/arkts-no-untyped-obj-literals-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3fd6a6bc5f48a1e9c49ef5850be21c4d76dbd8bd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Todo { + title: string; + description: string; + completed: boolean; +} + +type TodoPreview = Pick; + +const todo: TodoPreview = { + title: "Clean room", + completed: false, +}; + +console.log(todo) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e0c850deccab6871f03f1c677ce16f012d53e285 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 27 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 27 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..66ce4ab06679cdfb48c231c697021d9dc79b705a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 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. + */ + + +// use Partial + interface Todo { + title: string; + description: string; +} + +function updateTodo(todo: Todo, fieldsToUpdate: Partial) { + return { ...todo, ...fieldsToUpdate }; +} + +const todo1:Todo = { + title: "organize desk", + description: "clear clutter", +}; + +const todo2 = updateTodo(todo1, { + description: "throw out trash", +}); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..a051a4a9c1cf799a5b0dd768915ed378e7621d00 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-1-ok.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 10 + } + }, + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 24, + "character": 12 + } + }, + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 24, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 10 + } + }, + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 24, + "character": 12 + } + }, + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 24, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..226b7488baa8a3d7f846b5f2222cd417144946e1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-10-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +function toHex(this: Number) { + return this.toString(16); +} + +function numberToString(n: ThisParameterType) { + return toHex.apply(n); +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ef555e8a152063d10c39fcbb0fe2cd44d1a61cf6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-10-error.json @@ -0,0 +1,76 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 28 + } + }, + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 21, + "character": 46 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + }, + { + "messageText": "Function return type inference is limited (arkts-no-implicit-return-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 28 + } + }, + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 21, + "character": 46 + } + }, + { + "messageText": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", + "expectLineAndCharacter": { + "line": 22, + "character": 16 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..dee70dd0e02c249b00209391538cacbff1759375 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-11-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +function toHex(this: Number) { + return this.toString(16); +} + +const fiveToHex: OmitThisParameter = toHex.bind(5); + +console.log(fiveToHex()); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..34f649ebfb595c262b51c6db3cc62e02bd9ce65d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-11-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 18 + } + }, + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 21, + "character": 36 + } + }, + { + "messageText": "\"Function.apply\", \"Function.bind\", \"Function.call\" are not supported (arkts-no-func-apply-bind-call)", + "expectLineAndCharacter": { + "line": 21, + "character": 52 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)", + "expectLineAndCharacter": { + "line": 18, + "character": 10 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 18 + } + }, + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 21, + "character": 36 + } + }, + { + "messageText": "'Function.bind' is not supported (arkts-no-func-bind)", + "expectLineAndCharacter": { + "line": 21, + "character": 58 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-12-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-12-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7b569f64f9f37002668af16deebfabec6b276648 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-12-error.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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. + */ + + +type ObjectDescriptor = { + data?: D; + methods?: M & ThisType; // Type of 'this' in methods is D & M +}; + +function makeObject(desc: ObjectDescriptor): D & M { + let data: object = desc.data || {}; + let methods: object = desc.methods || {}; + return { ...data, ...methods } as D & M; +} + +let obj = makeObject({ + data: { x: 0, y: 0 }, + methods: { + moveBy(dx: number, dy: number) { + this.x += dx; // Strongly typed this + this.y += dy; // Strongly typed this + }, + }, +}); + +obj.x = 10; +obj.y = 20; +obj.moveBy(5, 5); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-12-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-12-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5c32ae38478442c4eb15c8e9448bb344ecd1bcb4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-12-error.json @@ -0,0 +1,202 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 31 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 13 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 17 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 26 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 58 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 35 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 41 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 10 + } + }, + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 25, + "character": 12 + } + }, + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 25, + "character": 21 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 25, + "character": 37 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 28, + "character": 22 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 29, + "character": 9 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 30, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 31 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 13 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 17 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 26 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 58 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 23, + "character": 35 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 41 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 25, + "character": 10 + } + }, + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 25, + "character": 12 + } + }, + { + "messageText": "It is possible to spread only arrays or classes derived from arrays into the rest parameter or array literals (arkts-no-spread)", + "expectLineAndCharacter": { + "line": 25, + "character": 21 + } + }, + { + "messageText": "Use inheritance instead of intersection types (arkts-no-intersection-types)", + "expectLineAndCharacter": { + "line": 25, + "character": 37 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 28, + "character": 22 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 29, + "character": 9 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 30, + "character": 12 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6df1c3f4e3d687219cee0eb6abe0979e84fa7a17 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-error.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Todo { + title: string; + description: string; + completed: boolean; + createdAt: number; +} + +type TodoPreview = Omit; + +const todo: TodoPreview = { + title: "Clean room", + completed: false, + createdAt: 1615544252770, +}; + +console.log(todo) +const todo: TodoPreview + +type TodoInfo = Omit; + +const todoInfo: TodoInfo = { + title: "Pick up kids", + description: "Kindergarten closes at 5pm", +}; + +console.log(todoInfo) diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6574a9f9fed161a98fdd3df2509edd5893855142 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 24, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 26, + "character": 27 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 35, + "character": 17 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 37, + "character": 28 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 24, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 26, + "character": 27 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 35, + "character": 17 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 37, + "character": 28 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d8b0ca999f1972da5038301e075cc3d76e29e64 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Props { + a?: number; + b?: string; +} + +let obj: Props = { a: 5 }; + +let objr: Required = { a: 5 }; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..934df5908d82342a899b61ab4a59b71fcf3162c9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +type T0 = Exclude<"a" | "b" | "c", "a">; + +type T1 = Exclude<"a" | "b" | "c", "a" | "b">; + +type T2 = Exclude void), Function>; + +type Shape = + | { kind: "circle"; radius: number } + | { kind: "square"; x: number } + | { kind: "triangle"; x: number; y: number }; + +type T3 = Exclude diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5036831163f99e6fbfb52dcd059d518079162a5b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-error.json @@ -0,0 +1,118 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 11 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 11 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 25, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 11 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 26 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 11 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 21, + "character": 11 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 25, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 11 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a840c01f8a4f028f3e375615575f944472256906 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Todo { + title: string; +} + +const todo: Readonly = { + title: "Delete inactive users", +}; + +todo.title = "Hello"; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c8b23f6b7132573693dbed15b922cb89c49c8926 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + +type T0 = Extract<"a" | "b" | "c", "a" | "f">; + +type T1 = Extract void), Function>; + +type Shape = + | { kind: "circle"; radius: number } + | { kind: "square"; x: number } + | { kind: "triangle"; x: number; y: number }; + +type T2 = Extract \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..33766973a88705938dea835af04956bf34556aa1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-error.json @@ -0,0 +1,104 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 11 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 11 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 26 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 11 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 23, + "character": 5 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 24, + "character": 5 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 11 + } + }, + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 26, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..53f56d79e4ce446ea1ebc6302b57c3e73a6a85e4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-ok.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface CatInfo { + age: number; + breed: string; +} + +type CatName = "miffy" | "boris" | "mordred"; + +const cats: Record = { + miffy: { age: 10, breed: "Persian" }, + boris: { age: 5, breed: "Maine Coon" }, + mordred: { age: 16, breed: "British Shorthair" }, +}; + +console.log(cats.boris); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..531b932e66cc91449e13699cdd461a0ce076f02d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-4-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 40 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 24, + "character": 40 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..21faff677830c674def82a285611144f58aec82d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-5-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +type T0 = NonNullable; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..15d05127326b277b5a1a2314ed9a11e3d4be9674 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4be9b102c4cd87f3b2a9efd44bb65f760f2a99f4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-6-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare function f1(arg: { a: number; b: string }): void; + +type T0 = Parameters<() => string>; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..43083013a235e5f003a6d163b22cca1769b90d1c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 26 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 26 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e21a24c089ad28f1576adaf1fb75523bbf4f44c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-7-error.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +type t = ConstructorParameters; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c681aaad2e8ebb55a39aa7bb4eb690ccb828163b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..32ce369ced6970a7e051f1508395cd659b4297b5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-8-error.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +declare function f1(): { a: number; b: string }; + +type T0 = ReturnType<() => string>; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8a580704e271ff3894ffcdab4c86f168df10bc9f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-8-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 24 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)", + "expectLineAndCharacter": { + "line": 17, + "character": 24 + } + }, + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 19, + "character": 11 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f67e9bb9624259d6dc33f1b9f2087e6c5a581f4f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-9-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +class C { + x = 0; + y = 0; +} + +type T0 = InstanceType; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8ada5c61024e5d6b8b61dfebc863428366c4892b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-utility-types/arkts-no-utility-types-9-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 11 + } + }, + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 22, + "character": 24 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Some of utility types are not supported (arkts-no-utility-types)", + "expectLineAndCharacter": { + "line": 22, + "character": 11 + } + }, + { + "messageText": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "expectLineAndCharacter": { + "line": 22, + "character": 24 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d73296dd46b55f813ded27b06700d07743711af --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-1-ok.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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 age: number = 30; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9b4cc53deabb3a6919959ee2ca64d6d38ff8c6e9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-10-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +function checkAge(age: number): string { + if (age >= 18) { + var message: string = "You are an adult!"; + return message; + } else { + var message: string = "You are a minor!"; + return message; + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5396fadc58f2a84189c2778dc9abf6a0f29b4344 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-10-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 19, + "character": 5 + } + }, + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 22, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 19, + "character": 5 + } + }, + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 22, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-11-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-11-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a66528875dac318cbc7be7357868a7cb8e1ca173 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-11-ok.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 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. + */ + + +const a: number = 1; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-11-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-11-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-11-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-12-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-12-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e2d634de56dccd1b15a9c3d480961d70be4139a4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-12-ok.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +const arr: string[] = ["a", "b", "c"]; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-12-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-12-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-12-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-13-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-13-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0e45dbb71f4a6b8ca88e2bdd2a8f1a6c5a00709 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-13-ok.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + + +const fun = (): void => { + console.log(111); +}; + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-13-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-13-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-13-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-14-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-14-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3bb072847fd596ef019e870463924ecf02dc2117 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-14-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Obj { + name: string; + age: number; +} +const obj: Obj = { + name: "hututu", + age: 18, +}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-14-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-14-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-14-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..810b224c808175039a45091e07e3eaba737cfa69 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-2-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Use let in a loop to avoid closure issues +for (let i = 0; i < 5; i++) { + setTimeout(() => { + console.log(i); + }, 100); +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..569234bb9b066dbc74c2d6eb672a0913c5afbd72 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-3-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The let keyword can be used to declare variables in a block-level scope, helping programmers avoid errors. Therefore, ArkTS does not support var, please declare variables with let. +type: Positive example +*/ +let isAdmin: boolean = false; + +if (isAdmin) { + let accessLevel: string = "admin"; +} else { + let accessLevel: string = "user"; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..40e2acf29720ec56ccfc4f00a6989470004ea52b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-4-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The let keyword can be used to declare variables in a block-level scope, helping programmers avoid errors. Therefore, ArkTS does not support var, please declare variables with let. +type: Positive example +*/ +let funcs: Function[] = []; + +for (let i = 0; i < 5; i++) { + funcs.push(() => i); +} + +console.log(funcs[0]()); // output 0,Instead of 5 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe06a54affd5f6193ec9a1a95e36b70afa031a9a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-5-ok.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The let keyword can be used to declare variables in a block-level scope, helping programmers avoid errors. Therefore, ArkTS does not support var, please declare variables with let. +type: Positive example +*/ +function checkAge(age: number): string { + if (age >= 18) { + let message: string = "You are an adult!"; + return message; + } else { + let message: string = "You are a minor!"; + return message; + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..6889428d5cb8bf783fb9ef109a790bc74824afd6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-6-error.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counterexample: Declare the underlying data type and initialize the variable, using var +var age: number = 30; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..875bc6c995f0e3152f0158a1b5d6116f0a2b9423 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..f66b7158a3312b39fa9f332cb87604739faf1ec2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-7-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +// Counter-example: Use var in a loop +for (var i = 0; i < 5; i++) { + setTimeout(() => { + console.log(i); + }, 100); +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..45ddabc623a81a2a65ed5813f26a219bd9e692a6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 18, + "character": 6 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 18, + "character": 6 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff3220413fd84a09551f97f7cf08de9e49888838 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-8-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +var isAdmin: boolean = false; + +if (isAdmin) { + var accessLevel: string = "admin"; +} else { + var accessLevel: string = "user"; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5b944c2143660ea5789d5857c4cc04b76a2052c7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-8-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1a237f8cb8813f3366da849e3f19e72738cdb055 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-9-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + + +var funcs: Function[] = []; + +for (var i = 0; i < 5; i++) { + funcs.push(() => i); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..dcb2bfd0a3102e1c38b1d51a203c7146395d7776 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-var/arkts-no-var-9-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 19, + "character": 6 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Use \"let\" instead of \"var\" (arkts-no-var)", + "expectLineAndCharacter": { + "line": 19, + "character": 6 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..7b015b9f23532ad715fdddfc1011fbbc01cd4eb9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-1-ok.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + + + /* +description:ArkTS does not support the with statement and uses other syntax to represent the same semantics. +*/ +interface O { + a: number; + b: number; +} + +let obj: O = { a: 1, b: 2 }; +console.log(obj.a + obj.b); // Direct access to properties diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..422f6d6347d30701ea4c677fabcf23d00c0e743b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-10-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +function withObject(obj: T, callback: (obj: T) => void) { + callback(obj); +} + +const person = { + name: "Alice", + age: 25, + address: "123 Main St", +}; + +withObject(person, ({ name, age, address }) => { + console.log(name); // "Alice" + console.log(age); // 25 + console.log(address); // "123 Main St" +}); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a3d963c672e51fd223beff672c7b07c438d4220e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-10-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 16 + } + }, + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 27, + "character": 21 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 21, + "character": 16 + } + }, + { + "messageText": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)", + "expectLineAndCharacter": { + "line": 27, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..75711a13b6c0c8e0f531662da85b9785eca2ccca --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-2-ok.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Person { + name: string; + age: number; +} + +let person: Person = { name: "Alice", age: 25 }; +person.name = "Bob"; // Set the property value directly diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..55eaff6c3e41e9b49c4902b594f12b8d7fbd8cf2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-3-ok.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface InnerData { + value: string; + anotherValue: string; +} + +interface OuterData { + inner: InnerData; +} + +interface Data { + outer: OuterData; +} + +const data: Data = { + outer: { + inner: { + value: "Hello World", + anotherValue: "Goodbye", + }, + }, +}; +const value = data.outer.inner; +const anotherValue = data.outer.inner; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..44143a0e9c12eda9c88695bbd7ed2f7e0a0ec0da --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-4-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface People { + name: string; +} + +const people: People[] = [{ name: "Dave" }, { name: "Eve" }]; +for (let i = 0; i < people.length; i++) { + console.log(people[i].name); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..21f8f175097b16751950e32ab9a4af8c9e48bcee --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-5-ok.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Person { + name: string; + age: number; +} + +function updatePerson(person: Person) { + person.name = "Charlie"; + person.age++; +} + +const person: Person = { + name: "Alice", + age: 25, +}; +updatePerson(person); +console.log(person); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1577e6b81527435178a8bfc4997be289fced504e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-6-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Obj { + a: number; + b: number; +} + +let obj: Obj = { a: 1, b: 2 }; +with (obj) { + console.log(a + b); +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f768fd1b7584b00e340f48bc0e8ac5e61ddc3404 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-6-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"with\" statement is not supported (arkts-no-with)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"with\" statement is not supported (arkts-no-with)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..50bec51fe651db3f58f8581f61e2c025f18e72e4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-7-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface Person { + name: string; + age: number; +} +let person: Person = { name: "Alice", age: 25 }; +with (person) { + name = "Bob"; + age = 30; +} +console.log(person.name); // 'Bob' +console.log(person.age); // 30 diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b120574dfdec6a69f9893ee216eaf715bb05666d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"with\" statement is not supported (arkts-no-with)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"with\" statement is not supported (arkts-no-with)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..38d2f23e802c01b4e5d9832aa267f00356fd5718 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-8-error.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface InnerData { + value: string; + anotherValue: string; +} + +interface OuterData { + inner: InnerData; +} + +interface Data { + outer: OuterData; +} + +let data: Data = { + outer: { inner: { value: "Hello World" } }, +}; +with (data.outer.inner) { + console.log(value); // "Hello World" +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..5add84df13fab7aaf8fd383821bcf611e47cb983 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-8-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"with\" statement is not supported (arkts-no-with)", + "expectLineAndCharacter": { + "line": 33, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"with\" statement is not supported (arkts-no-with)", + "expectLineAndCharacter": { + "line": 33, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff7d1a4803f62720777660d873dfcd49d2be0fbc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-9-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +interface PeopleData { + name: string; +} + +let people: PeopleData[] = [{ name: "Dave" }, { name: "Eve" }]; +for (let i = 0; i < people.length; i++) { + with (people[i]) { + console.log(name); + } +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4c67597a629093de9d1ed42432fc5ead895e3949 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-no-with/arkts-no-with-9-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "\"with\" statement is not supported (arkts-no-with)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "\"with\" statement is not supported (arkts-no-with)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/arkts-only-imported-variables-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/arkts-only-imported-variables-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a3881f67c484d9bae2e85c5c8228136e297014d9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/arkts-only-imported-variables-error.ets @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2024 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 { libPi, libString, libFoo, LibClass, libClassVar, LibRGB } from './sendable_captured_variables_lib' +import libVar from './sendable_captured_variables_lib' +import * as sendableNamespce from './sendable_captured_variables_namespaceimport_lib' + +let localVar = 'local'; + +function localFun(): string { + return 'local foo'; +} + +class LocalClass { + public a: number = 1; + static public b: string = '2'; + foo(): void {} + static bar(): void {} +} + +let localObj: LocalClass = new LocalClass(); + +enum LocalRGB { + RED, + GREEN, + BLUE +} + +const enum ConstRGB { + RED, + GREEN, + BLUE +} + +@Sendable +class SendableClass { + static public pi: number = libPi; + static public hdr: string = libString; + public p = localVar; // ERROR + static public ps = localVar; // ERROR + public sc: SendableClass2 = new SendableClass2(); // ERROR + public csc: ConstRGB = ConstRGB.GREEN; + public arr: Array = new Array(); + + public foo(x: string): string { + let s = localVar; // ERROR + let ss = this.p + SendableClass.ps + x; + s = localFun(); // ERROR + s = libFoo(); + return s + ss; + } + + bar(a: SendableClass2) { + let b = a; + a.a = 2; + let c = new sendableNamespce.SendableClassExp(); // ERROR + } + + baz(): SendableClass2 { + return new SendableClass2(); + } + + bazz(): void { + let a: LibRGB = LibRGB.GREEN; + console.log(LibRGB.RED); + + let b: LocalRGB; + b = LocalRGB.RED; // ERROR + console.log(LocalRGB.BLUE); // ERROR + } + + static { + SendableClass.ps = localVar; // ERROR + let lc: LocalClass; + lc = new LocalClass(); // ERROR + console.log(lc.a); + console.log(LocalClass.b); // ERROR + lc.foo(); + LocalClass.bar(); // ERROR + lc = localObj; // ERROR + console.log(localObj.a); // ERROR + localObj.foo(); // ERROR + + let pps: string = libString; + let libv: number = libVar; + let libc: LibClass; + libc = libClassVar; + + console.log(libc.a); + console.log(LibClass.b); + libc.foo(); + LibClass.bar(); + } +} + +interface B { + +} + +@Sendable +class SendableClass2 { + public a: number = 1; +} + +@Sendable +class C { + static public a: number = 1; + f(p: number) { + @Sendable + class D extends SendableClass2 implements B { // ERRORS + public b: number = C.a; + public d: number = p; // ERROR + } + } +} + +export let b = 1; +@Sendable +class A { + public aa: number = b; // ERROR +} + +namespace Xx { + export let b = 1; + @Sendable + class A { + public aa: number = b; // ERROR + } +} + +function sealed(ctor: Function) {} + +@Sendable +class D { + public d: number = Xx.b; // ERROR + foo() { + @sealed // ERROR + class B {} + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/arkts-only-imported-variables-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/arkts-only-imported-variables-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0a6cdbb1c54a0439c596b4fa243a605e207083cb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/arkts-only-imported-variables-error.json @@ -0,0 +1,223 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 48, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 113, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 118, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 122, + "character": 5 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 131, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 138, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 146, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 150, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 52, + "character": 14 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 53, + "character": 22 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 59, + "character": 13 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 61, + "character": 9 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 69, + "character": 17 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 81, + "character": 9 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 82, + "character": 17 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 86, + "character": 24 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 88, + "character": 14 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 90, + "character": 17 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 92, + "character": 5 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 93, + "character": 10 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 94, + "character": 17 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 95, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 52, + "character": 3 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 53, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 56, + "character": 3 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 123, + "character": 47 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 125, + "character": 26 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 133, + "character": 23 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 140, + "character": 25 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 148, + "character": 22 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 150, + "character": 6 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/sendable_captured_variables_lib.d.ts b/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/sendable_captured_variables_lib.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..74a24de18e833798e00d803f672431c8bd05d2bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/sendable_captured_variables_lib.d.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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 libPi = 3.14; +export let libString; + +export function libFoo(): string; + +export enum LibRGB { + RED, + GREEN, + BLUE +} + +export class LibClass { + a: number; + static b: string; + foo(): void; + static bar(): void; +} + +export let libClassVar: LibClass; + +declare let libVar: number; +export default libVar; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/sendable_captured_variables_namespaceimport_lib.d.ts b/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/sendable_captured_variables_namespaceimport_lib.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ca9a7a20cd94a9f46dbd2d0d07a42549d0e98af0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-only-imported-variables/sendable_captured_variables_namespaceimport_lib.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +export class SendableClassExp { + a: number = 1; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..41f0a7d10936da5c87d999bdc38448b1c45659ca --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-error.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 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. + */ + +// Only object, Object, and any type can be casted to Sendable type +// If other types are casted to Sendable, an error occurs + +@Sendable +class SendableClass {} + +function myFunctionA(obj: number) { + obj as SendableClass; // ERROR +} + +function myFunctionB(obj: string) { + obj as SendableClass; // ERROR +} + +function myFunctionC(obj: boolean) { + obj as SendableClass; // ERROR +} + +function myFunctionD(obj: never) { + obj as SendableClass; // ERROR +} + +function myFunctionE(obj: void) { + obj as SendableClass; // ERROR +} + +function myFunctionF(obj: [number, string]) { + obj as SendableClass; // ERROR +} + +function myFunctionG(obj: number | string) { + obj as SendableClass; // ERROR +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..aba411c6f4094cc4ff70ebf638cde73aaa34804b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 31, + "character": 3 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 35, + "character": 3 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 43, + "character": 3 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 47, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..cfed2e93b50d25ee253dd5a3a5983f5cf4cadc5d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-ok.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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. + */ + +// Only object, Object, and any type can be casted to Sendable type +// If other types are casted to Sendable, an error occurs + +@Sendable +class SendableClass {} + +function myFunctionB(obj: object) { + obj as SendableClass; // OK +} + +function myFunctionC(obj: Object) { + obj as SendableClass; // OK +} + +function myFunctionD(obj: any) { + obj as SendableClass; // OK +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..f299875b8c88ddb3dd9fde7e6ad600f5b14cc445 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-1-ok.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 30, + "character": 27 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 30, + "character": 27 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..db7d8f051cbe4f67122ef5adfb5b4521d5533878 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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. + */ + +// Only object, Object, and any type can be casted to Sendable type +// If other types are casted to Sendable, an error occurs + +class NonSendableClass {} + +@Sendable +class SendableClass {} + +let a = new NonSendableClass() as SendableClass; // ERROR + +let b = new NonSendableClass(); + +let c = b as SendableClass; // ERROR \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1dcd4eba39f21fa8b6d5c8000221aa0a588fb380 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-error.json @@ -0,0 +1,41 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 24, + "character": 9 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 28, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 24, + "character": 9 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 28, + "character": 9 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9292f1bdf3979e331507c603380044b43931c1bd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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. + */ + +// Only object, Object, and any type can be casted to Sendable type +// If other types are casted to Sendable, an error occurs + +class NonSendableClass {} + +@Sendable +class SendableClass {} + +let a = new SendableClass() as NonSendableClass; // OK, Sendable type can be casted to non-sendable + +let b = Object(); + +let c = b as SendableClass; // OK \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..1b763b5e0da61cf28474c3a4ca1d80ecb17949e1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-2-ok.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 24, + "character": 9 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4396fae785d81b7668a71fbd56c5d5fa933b10c3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-error.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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. + */ + + +class NonSendableClass { public a = '' } +class NonSendableClass2 { public b = '' } +@Sendable +class SendableClass { public a: string = '' } +@Sendable +class SendableClass2 { public b: string = '' } +interface IStruct1 { a: '' } +interface IStruct2 { b: '' } +type alis1 = SendableClass +type alis2 = SendableClass2 + +/* + * 1. `NonSendable` can be converted to `NonSendable`. + * 2. `NonSendable` can be converted to a union type that includes `Sendable`. + * 3. `Sendable` has no conversion restrictions. + * 4. Union types that include `null` or `undefined` can be considered as the type without them. + * 5. Union with system types (e.g., `number`, `string`) have special behavior. + */ +/* // cmp `let struct2 = new NonSendableClass() as IStruct1;` */ +/* // cmp `let struct3 = new NonSendableClass() as IStruct1 | SendableClass;` */ +/* // cmp `let struct4 = new NonSendableClass() as SendableClass | IStruct1;` */ +/* // cmp `let struct5 = new NonSendableClass() as SendableClass | boolean;` */ +let struct6 = new NonSendableClass() as SendableClass | null; // ERROR +let struct7 = new NonSendableClass() as SendableClass | undefined; // ERROR +let struct8 = new NonSendableClass() as SendableClass | alis1; // ERROR +/* // cmp `let struct9 = new NonSendableClass() as SendableClass | alis2;` */ +let struct10 = new NonSendableClass() as SendableClass; // ERROR +/* // cmp `let struct11 = new NonSendableClass() as IStruct1;` */ +let struct12 = new NonSendableClass() as undefined; // TSC + + +let noStruct1 = new NonSendableClass2() as IStruct1; // TSC +let noStruct2 = new NonSendableClass2() as SendableClass | IStruct1; // TSC +let noStruct3 = new NonSendableClass2() as SendableClass | null; // ERROR +let noStruct4 = new NonSendableClass2() as SendableClass | undefined; // ERROR +let noStruct5 = new NonSendableClass2() as SendableClass | boolean; // TSC +let noStruct6 = new NonSendableClass2() as SendableClass; // ERROR +let noStruct7 = new NonSendableClass2() as boolean; // TSC +let noStruct8 = new NonSendableClass2() as SendableClass | number; // TSC \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..3065d76c5d0624510ba4cd122f3a3154bb5a5c02 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-error.json @@ -0,0 +1,139 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Conversion of type 'NonSendableClass' to type 'undefined' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.", + "expectLineAndCharacter": { + "line": 45, + "character": 16 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 39, + "character": 15 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 40, + "character": 15 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 41, + "character": 15 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 43, + "character": 16 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 48, + "character": 17 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 50, + "character": 17 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 51, + "character": 17 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 53, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Conversion of type 'NonSendableClass' to type 'undefined' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.", + "expectLineAndCharacter": { + "line": 45, + "character": 16 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 39, + "character": 15 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 40, + "character": 15 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 41, + "character": 15 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 43, + "character": 16 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 50, + "character": 17 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 51, + "character": 17 + } + }, + { + "messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)", + "expectLineAndCharacter": { + "line": 53, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..01d131738f535f0a5bc63208a364f6e0a494bf31 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-ok.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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. + */ + + +class NonSendableClass { public a = '' } +class NonSendableClass2 { public b = '' } +@Sendable +class SendableClass { public a: string = '' } +@Sendable +class SendableClass2 { public b: string = '' } +interface IStruct1 { a: '' } +interface IStruct2 { b: '' } +type alis1 = SendableClass +type alis2 = SendableClass2 + +/* + * 1. `NonSendable` can be converted to `NonSendable`. + * 2. `NonSendable` can be converted to a union type that includes `Sendable`. + * 3. `Sendable` has no conversion restrictions. + * 4. Union types that include `null` or `undefined` can be considered as the type without them. + * 5. Union with system types (e.g., `number`, `string`) have special behavior. + */ +let struct2 = new NonSendableClass() as IStruct1; +let struct3 = new NonSendableClass() as IStruct1 | SendableClass; +let struct4 = new NonSendableClass() as SendableClass | IStruct1; +let struct5 = new NonSendableClass() as SendableClass | boolean; +/* // cmp `let struct6 = new NonSendableClass() as SendableClass | null; // ERROR` */ +/* // cmp `let struct7= new NonSendableClass() as SendableClass | undefined; // ERROR` */ +/* // cmp `let struct8 = new NonSendableClass() as SendableClass | alis1; // ERROR` */ +let struct9 = new NonSendableClass() as SendableClass | alis2; +/* // cmp `let struct10 = new NonSendableClass() as SendableClass; // ERROR` */ +let struct11 = new NonSendableClass() as IStruct1; +/* // cmp `let struct12 = new NonSendableClass() as undefined; // TSC` */ + + +/* // cmp `let noStruct1 = new NonSendableClass2() as IStruct1; // TSC` */ +/* // cmp `let noStruct2 = new NonSendableClass2() as SendableClass | IStruct1; // TSC` */ +/* // cmp `let noStruct3 = new NonSendableClass2() as SendableClass | null; // ERROR` */ +/* // cmp `let noStruct4 = new NonSendableClass2() as SendableClass | undefined; // ERROR` */ +/* // cmp `let noStruct5 = new NonSendableClass2() as SendableClass | boolean; // TSC` */ +/* // cmp `let noStruct6 = new NonSendableClass2() as SendableClass; // ERROR` */ +/* // cmp `let noStruct7 = new NonSendableClass2() as boolean; // TSC` */ +/* // cmp `let noStruct8 = new NonSendableClass2() as SendableClass | number; // TSC` */ \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..e141770895a8924798e6a3ca23567ce08f937442 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-3-ok.json @@ -0,0 +1,33 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 35, + "character": 15 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 44, + "character": 16 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..e2904058d28dbfd71325e2844677749fc5c9b129 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-4-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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. + */ + + +class NonSendableClass { public a = '' } +class NonSendableClass2 { public b = '' } +@Sendable +class SendableClass { public a: string = '' } +@Sendable +class SendableClass2 { public b: string = '' } +interface IStruct1 { a: '' } +interface IStruct2 { b: '' } +type alis1 = SendableClass +type alis2 = SendableClass2 + +/* + * 1. `any` type can be converted to `Sendable`. + */ + +let objectAnyType = Object() as SendableClass +let objectAnyType2 = 1 as ESObject as SendableClass +let objectAnyType3 = JSON.parse('') as SendableClass \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..53e768cae29d45d53709f8aa554c22a3d42b662b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-4-ok.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 33, + "character": 27 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", + "expectLineAndCharacter": { + "line": 33, + "character": 27 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/@arkts.lang.d.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/@arkts.lang.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..40e381dc2a3c9c96df3b6278ed74fe7a71922dc9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/@arkts.lang.d.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + +declare namespace lang { + interface ISendable {} +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/arkts-sendable-as-expr-ts.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/arkts-sendable-as-expr-ts.json new file mode 100644 index 0000000000000000000000000000000000000000..b73cf4e89e8e061ab46b56f4f9deca45317cf6b1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/arkts-sendable-as-expr-ts.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/arkts-sendable-as-expr-ts.ts b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/arkts-sendable-as-expr-ts.ts new file mode 100644 index 0000000000000000000000000000000000000000..91b7acfd8dc44184a375bbc4ed20074385711313 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/arkts-sendable-as-expr-ts.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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 { A, A1, A as A2, B, B1, B as B2, C, C1, C as C2 } from './lib-dependencie'; +import { I, J } from './lib-dependencie'; + +let a1 = {} as A; +let a2 = {} as A; +let a3 = {} as A; +let b1 = { value: 0 } as B; +let b2 = { value: 0 } as B1; +let b3 = { value: 0 } as B2; +let c1 = { value: 0 } as C; +let c2 = { value: 0 } as C1; +let c3 = { value: 0 } as C2; + +let i = { v: 0 } as I; +let j = { v: 0, u: 0 } as J; + +class D {} + +function foo(d: D): void {} +foo(new D() as A); +foo(new D() as A1); +foo(new D() as A2); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/lib-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/lib-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..84a86df357cdf255efb58e747be20bfc889663d8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/lib-dependencie.ets @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 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 { lang } from './@arkts.lang' + +@Sendable +class A {} +export { A, A as A1 } + +@Sendable +class B { + public value: number = 0 +} +export { B, B as B1 } + +@Sendable +class C implements lang.ISendable { + public value: number = 0 +} +export { C, C as C1 } + +export interface I extends lang.ISendable { + v: number; +} + +export interface J extends I { + u: number; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.ets new file mode 100644 index 0000000000000000000000000000000000000000..c8a4eab5c9d0823a20b981c2e2b0de29d84a7c38 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +function sendableFunction(): void {} + +@Sendable +type SendableType = () => void; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.json new file mode 100644 index 0000000000000000000000000000000000000000..2ba4bafe3d629801759523ef33821bd4dd90ced8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.json @@ -0,0 +1,19 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Sendable functions and sendable typealias are not available when compatibleSdkVersionStage is lowering than beta3 of API12 (arkts-sendable-beta-compatible)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "Sendable functions and sendable typealias are not available when compatibleSdkVersionStage is lowering than beta3 of API12 (arkts-sendable-beta-compatible)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ed8e7dbff96a4ea4099344dc006d74ae9fcb0cd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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. + */ + +function noneSendableFunction(): void {} // OK + +@Concurrent // OK +function noneSendableFunction1(): void; + +function noneSendableFunction1(): void; // OK + +type NoneSendableType = () => void; // OK + +@Sendable // OK +class SendableClass { + +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..e78eb9d572134f03827bccf7c42521b42b2aad9d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..36fd830f03f00b9d7b9dc3c48c8c6b07dda57921 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-error.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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 { NonSendable, SomeDecorator, SomeDecorator2 } from './arkts-sendable-class-decorator-lib-dependencie' + +@NonSendable // should report, arkts-sendable-class-decorator +@Sendable +class SendableClass { + // should report, arkts-sendable-class-decorator + @SomeDecorator + public prop: string = ''; + + constructor() {} + // should report, arkts-sendable-class-decorator + @SomeDecorator + myMethod1() {} + + // should report, arkts-sendable-class-decorator + myMethod2(@SomeDecorator2 param: string) {} + // should report, arkts-sendable-class-decorator + @SomeDecorator + get myPropertyGet(): string { + return this.prop; + } + // should report, arkts-sendable-class-decorator + @SomeDecorator + set myProperty2Set(value: string) { + this.prop = value; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9010ace80924c022772b709305ca3a08be4c235c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-error.json @@ -0,0 +1,97 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 28, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 32, + "character": 13 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 28, + "character": 3 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 32, + "character": 13 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d8aaf9349e14d338ce751280f33b02b7650b1f0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable // OK +class SendableClass { + public prop: string = ''; // OK + + constructor() {} // OK + + myMethod1() {} // OK + + myMethod2(param: string) {} // OK + + get myProperty(): string { // OK + return this.prop; + } + set myProperty(value: string) { // OK + this.prop = value; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..0cd2b238fe4735f679f979d61cb2d784d05fd538 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-1-ok.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7d7ecb4543ab626022e222937b104507632811e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-2-error.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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 { NonSendable, SomeDecorator, SomeDecorator2 } from './arkts-sendable-class-decorator-lib-dependencie' + +@NonSendable // should report, arkts-sendable-class-decorator +@Sendable +class SendableClass { + // should report, arkts-sendable-class-decorator + @SomeDecorator + public prop: string = ''; + + constructor() {} + // should report, arkts-sendable-class-decorator + @SomeDecorator + myMethod1() {} + + // should report, arkts-sendable-class-decorator + myMethod2(@SomeDecorator2 param: string) {} + // should report, arkts-sendable-class-decorator + @SomeDecorator + get myPropertyGet(): string { + return this.prop; + } + // should report, arkts-sendable-class-decorator + @SomeDecorator + set myProperty2Set(value: string) { + this.prop = value; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9010ace80924c022772b709305ca3a08be4c235c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-2-error.json @@ -0,0 +1,97 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 28, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 32, + "character": 13 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 23, + "character": 3 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 28, + "character": 3 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 32, + "character": 13 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-lib-dependencie.ts b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-lib-dependencie.ts new file mode 100644 index 0000000000000000000000000000000000000000..480d1e5b0008a19b57fe323d30dd9f6842dff484 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-decorator/arkts-sendable-class-decorator-lib-dependencie.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 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. + */ + +declare type ClassDecorator = (target: TFunction) => TFunction | void; +// should report, arkts-no-symbol +declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void; +// should report, arkts-no-symbol +declare type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void; +export declare const SomeDecorator: PropertyDecorator; +export declare const SomeDecorator2: ParameterDecorator; +export declare const NonSendable: ClassDecorator; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..80b84394b38d5a1c76b226dffc83283530fb86ec --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-error.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +interface BaseNonSendableInterface {} +interface ISendableExtend1 extends lang.ISendable {} // normal interface can extends ISendable +interface ISendableExtend2 extends lang.ISendable { + p: string +} + +/* + * NonSendable class cannot implements ISendable interface + */ +class NonSendableClass1 implements lang.ISendable {} // ERROR, arkts-sendable-class-inheritance + +class NonSendableClass2 implements ISendableExtend1 {} // ERROR, arkts-sendable-class-inheritance + +class NonSendableClass3 implements ISendableExtend2 { // ERROR, arkts-sendable-class-inheritance + public p = '' +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-error.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a56b0c7715fe62cc43e35c81c52da2074c43648 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-ok.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +@Sendable +class BaseSendableClass {} +class BaseNonSendableClass {} +interface BaseNonSendableInterface {} +interface ISendableExtend1 extends lang.ISendable {} // normal interface can extends ISendable +interface ISendableExtend2 extends lang.ISendable { + p: string +} +interface INonSendable {} + +/* + * NonSendable class can implements only NonSendable interface + */ +class SendableClass0 implements BaseNonSendableInterface {} + + +/* + * Sendable class can implements any interface + */ +@Sendable +class SendableClass1 implements lang.ISendable {} +@Sendable +class SendableClass2 implements ISendableExtend1 {} +@Sendable +class SendableClass3 implements ISendableExtend2 { + public p = '' +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..aa5d96394f1311e688a128edf2be6e9ac4edd2cb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-1-ok.json @@ -0,0 +1,41 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 38, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 40, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 42, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 44, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a849eacf9efaf7aeb2b096cf6138cad0468ddb49 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-error.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +@Sendable +class BaseSendableClass {} +class BaseNonSendableClass {} +interface ISendableExtend extends lang.ISendable {} +interface INonSendable {} +@Sendable +class BaseSendableClass2 implements lang.ISendable {} + +/* + * Sendable and NonSendable class cannot extends from each other + */ +@Sendable +class SendableClass1 extends BaseNonSendableClass {} // ERROR, arkts-sendable-class-inheritance +class NonSendableClass1 extends BaseSendableClass {} // ERROR, arkts-sendable-class-inheritance + + + +class NonSendableClass2 extends BaseSendableClass2 {} // ERROR, arkts-sendable-class-inheritance +// ERROR, arkts-sendable-class-inheritance +class BaseSendableClass4 extends BaseSendableClass implements lang.ISendable {} +// ERROR, arkts-sendable-class-inheritance +class BaseSendableClass5 extends BaseSendableClass implements ISendableExtend {} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7ed49570a0d7084911038b1afc1b4c65f061e9a6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 24, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)", + "expectLineAndCharacter": { + "line": 31, + "character": 30 + } + }, + { + "messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)", + "expectLineAndCharacter": { + "line": 32, + "character": 33 + } + }, + { + "messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)", + "expectLineAndCharacter": { + "line": 36, + "character": 33 + } + }, + { + "messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)", + "expectLineAndCharacter": { + "line": 38, + "character": 34 + } + }, + { + "messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)", + "expectLineAndCharacter": { + "line": 40, + "character": 34 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b3c07aec2dd3e292aef0bd9ec9f2ed5e3da79bca --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-ok.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +@Sendable +class BaseSendableClass {} +class BaseNonSendableClass {} +@Sendable +class BaseSendableClass2 implements lang.ISendable {} +interface ISendableExtend extends lang.ISendable {} +interface INonSendable {} + +/* + * Sendable class can extend only Sendable class + */ +@Sendable +class SendableClass1 extends BaseSendableClass {} // OK + + +/* + * Sendable class can implements any interface(plus version) + */ +@Sendable +class SendableClass4 extends BaseSendableClass implements INonSendable {} +@Sendable +class SendableClass5 implements INonSendable {} +@Sendable +class SendableClass6 extends BaseSendableClass implements lang.ISendable {} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..73ebe857c2bb7bdf1fe894ea75cf067e3026359a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-class-inheritance/arkts-sendable-class-inheritance-2-ok.json @@ -0,0 +1,47 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 37, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 39, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 41, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..87e621aeaffcf18ab9b746050c4f4202d2fa638f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.ets @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClass1 { + +} + +@Sendable +function sendableFunction1() { + +}; + +@Sendable +export class SendableClass2 { + +} + +@Sendable +export function sendableFunction2() { + +}; + +@Sendable +class SendableClass3 { + +} + +@Sendable +function sendableFunction3() { + +}; + +@Sendable +class SendableClass4 { + +} + +@Sendable +function sendableFunction4() { + +}; + +@Sendable +class SendableClass5 { + +} + +@Sendable +function sendableFunction5() { + +}; + +@Sendable +class SendableClass { + handle() { + new SendableClass1(); // OK + sendableFunction1(); // OK + new SendableClass2(); // WARING, export decl + sendableFunction2(); // WARING, export decl + new SendableClass3(); // WARING, export { decl } + sendableFunction3(); // WARING, export { decl } + new SendableClass4(); // WARING, export { decl as alias } + sendableFunction4(); // WARING, export { decl as alias } + new SendableClass5(); // WARING, export default decl + } +} + +@Sendable +function sendableFunction() { + new SendableClass1(); // OK + sendableFunction1(); // OK + new SendableClass2(); // WARING, export decl + sendableFunction2(); // WARING, export decl + new SendableClass3(); // WARING, export { decl } + sendableFunction3(); // WARING, export { decl } + new SendableClass4(); // WARING, export { decl as alias } + sendableFunction4(); // WARING, export { decl as alias } + new SendableClass5(); // WARING, export default decl +} + +export { SendableClass3, + sendableFunction3, + SendableClass4 as sendableFunction42, + sendableFunction4 as sendableFunction42 }; + + +export default SendableClass5; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4044e40503786f95f19713075e5a1a7735eb897d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.json @@ -0,0 +1,146 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 36, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 46, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 56, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 66, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 71, + "character": 9 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 72, + "character": 5 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 73, + "character": 9 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 74, + "character": 5 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 75, + "character": 9 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 76, + "character": 5 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 77, + "character": 9 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 85, + "character": 7 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 86, + "character": 3 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 87, + "character": 7 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 88, + "character": 3 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 89, + "character": 7 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 90, + "character": 3 + } + }, + { + "messageText": "The exported \"Sendable\" class or function cannot be captured by \"Sendable\" class or function in current file (arkts-sendable-closure-export)", + "expectLineAndCharacter": { + "line": 91, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a74fde6d925338164c2f0e3f13cad33ec2586373 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-2-ok.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClass1 { + +} + +@Sendable +function sendableFunction1(): void{ + +} + +@Sendable +function sendableFunction2(): number{ + return 0; +} + +@Sendable +function sendableFunction3(): string{ + return '1'; +} + +@Sendable +class SendableClass { + new SendableClass1(); // OK + sendableFunction1(); // OK + sendableFunction2(); // OK + sendableFunction3(); // OK + handle() { + new SendableClass1(); // OK + sendableFunction1(); // OK + sendableFunction2(); // OK + sendableFunction3(); // OK + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..59948355ad925e18ada1b9b6501c58eb74144388 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-2-ok.json @@ -0,0 +1,19 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 36, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d810d068ee8785a2e683a276ec7bf6b9a91d532 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +@Sendable +class SendableClass1 { + public [1]: string = ''; + public ['2']: string = ''; + public ['abc']: string = ''; +} + +let a = new SendableClass1(); +a.abc = '123' \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7b28de21d839a1530cf69d046ff2a6e288efae34 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-error.json @@ -0,0 +1,55 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)", + "expectLineAndCharacter": { + "line": 21, + "character": 10 + } + }, + { + "messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)", + "expectLineAndCharacter": { + "line": 22, + "character": 10 + } + }, + { + "messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b7942e6302c1cdf88b7534617dbe69815f03b69 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-ok.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable +class SendableClass1 { + public '1': string = ''; + public '2': string = ''; + public 'abc': string = ''; +} + +let a1 = new SendableClass1(); +a1.abc = '123' + +class NonSendableClass1 { + // public [1]: string, + public ['2']: string = ''; + public ['abc']: string = ''; +} + +let a2 = new NonSendableClass1(); +a2.abc = '123' + + +function f1(i: SendableClass1) {} +f1(new SendableClass1()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..f04e31a436e4af92ac6e30cc3b6d8bd997434230 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-1-ok.json @@ -0,0 +1,47 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 29, + "character": 10 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 30, + "character": 10 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c17f93dff9f7cd0af2b8ab1ebb427482247dce3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +interface ISendableExtend1 extends lang.ISendable { + [1]: string, + ['2']: string, + ['abc']: string, +} + +@Sendable +class ISendableClass implements lang.ISendable { + public [1]: string = ''; + public ['2']: string = ''; + public ['abc']: string = ''; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b9029db2e384f6b005a3642e6afb2451802bbad8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-error.json @@ -0,0 +1,83 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 27, + "character": 10 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 28, + "character": 10 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 29, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)", + "expectLineAndCharacter": { + "line": 27, + "character": 10 + } + }, + { + "messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)", + "expectLineAndCharacter": { + "line": 28, + "character": 10 + } + }, + { + "messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)", + "expectLineAndCharacter": { + "line": 29, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b110697353229a5be652b69b54ec2b1d09c3b57 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-ok.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +interface INonSendableExtend1 { + ['1']: string, + ['2']: string, + ['abc']: string, +} + +@Sendable +class ISendableClass implements lang.ISendable { + public '1': string; + public '2': string; + public 'abc': string; +} + +function f1(i: ISendableClass) {} +f1(new ISendableClass()) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..588764d9441708653e7b0c2fabd47cb0f051a397 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-computed-prop-name/arkts-sendable-computed-prop-name-2-ok.json @@ -0,0 +1,54 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 27, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 28, + "character": 3 + } + }, + { + "messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff255b9dc1ac7a374b33ba0e155040bdf6572ed5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-1-ok.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable // OK +class SendableClass { +} + +@Sendable // OK +function sendableFunction(): void { +}; + +@Sendable // OK +type SendableType = () => void; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..ce649db0e77347bbe4d66387e781be71dd6ea0ed --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-1-ok.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c14430cd7afa6b008579d8c15fbe778b04fd71b9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-2-error.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable // ERROR +struct SendableStruct { +}; + + +class NormalClass { + @Sendable // ERROR + public name: string = 'name'; + + @Sendable // ERROR + handle() { + + }; + + handle2(@Sendable param: string) { // ERROR + + } + + @Sendable // ERROR + get age(): number { + return 1; + } + + @Sendable // ERROR + set age(value: number): void { + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d7cc05870d0458902ec4ab6e75df8293bf175969 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-2-error.json @@ -0,0 +1,83 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 30, + "character": 11 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)", + "expectLineAndCharacter": { + "line": 22, + "character": 3 + } + }, + { + "messageText": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + }, + { + "messageText": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)", + "expectLineAndCharacter": { + "line": 30, + "character": 11 + } + }, + { + "messageText": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)", + "expectLineAndCharacter": { + "line": 39, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1405833051b471cec86bf44375fbdbf8a597238 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-3-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable // ERROR +public name: string = 'name'; + +handle2(@Sendable param: string) { // ERROR + +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..dd9f41ce21df171f05e7715c47adf5736710ad15 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-decorator-limited/arkts-sendable-decorator-limited-3-error.json @@ -0,0 +1,19 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)", + "expectLineAndCharacter": { + "line": 19, + "character": 9 + } + } + ] + } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..54c881f627939ebf89985a4397b47b4d7fcaf26f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable +class SendableClass1 { + public prop1!: string; // should report, arkts-sendable-definite-assignment + constructor() { + this.prop1 = '' + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f2ef421e76e2fee88115991ca5f6f51befb08a28 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Definite assignment assertion is not allowed in \"Sendable\" classes (arkts-sendable-definite-assignment)", + "expectLineAndCharacter": { + "line": 19, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..92a709b1fd8bc0050a6d554b439f54711cc788f3 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-ok.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable +class SendableClass1 { + public prop1: string; // OK + public prop2?: string; + public readonly prop3: string; + constructor() { + this.prop1 = '' + this.prop2 = '' + this.prop3 = '' + this.prop3 = ''! + } +} + +let sendableClassImpl1 = new SendableClass1(); +sendableClassImpl1.prop1!; +sendableClassImpl1.prop2!?.toString(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..0cd2b238fe4735f679f979d61cb2d784d05fd538 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-definite-assignment/arkts-sendable-definite-assignment-1-ok.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/@arkts.lang.d.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/@arkts.lang.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..c47866c59e9c8b254d719a14375de40728160dd0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/@arkts.lang.d.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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. + */ + +declare namespace lang { + interface ISendable {} +} + +export { lang }; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..11c4e1236f348d0757f0c59a9e880330e2a96176 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-1-error.ets @@ -0,0 +1,545 @@ +/* + * Copyright (c) 2024 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 { lang } from './@arkts.lang'; + +enum Color {Red, Green, Blue} + +@Sendable +class SendableClass { + public a: number = 1; +} + +class NoSendableClass { + public b: number = 1; +} + +@Sendable +class A { + booleanProp: boolean = true; + numberProp: number = 42; + stringProp: string = 'Hello'; + arrayProp: number[] = [1, 2, 3]; + tupleProp: [string, number] = ['typescript', 4]; + enumProp: Color = Color.Green; + anyProp: any = { key: 'value' }; + voidProp: void = undefined; + nullProp: null = null; + undefinedProp: undefined = undefined; + objectProp: object = { name: 'John', age: 30 }; + sendableClass: SendableClass = new SendableClass(); + noSendableClass: NoSendableClass = new NoSendableClass(); + + optBooleanProp1?: boolean = true; + optNumberProp1?: number = 42; + optStringProp1?: string = 'Hello'; + optArrayProp1?: number[] = [1, 2, 3]; + optTupleProp1?: [string, number] = ['typescript', 4]; + optEnumProp1?: Color = Color.Green; + optAnyProp1?: any = { key: 'value' }; + optVoidProp1?: void = undefined; + optNullProp1?: null = null; + optUndefinedProp1?: undefined = undefined; + optObjectProp1?: object = { name: 'John', age: 30 }; + optSendableClass1?: SendableClass = new SendableClass(); + optNoSendableClass1?: NoSendableClass = new NoSendableClass(); + + public optBooleanProp2: boolean = true; + public optNumberProp2: number = 42; + public optStringProp2: string = 'Hello'; + public optArrayProp2: number[] = [1, 2, 3]; + public optTupleProp2: [string, number] = ['typescript', 4]; + public optEnumProp2: Color = Color.Green; + public optAnyProp2: any = { key: 'value' }; + public optVoidProp2: void = undefined; + public optNullProp2: null = null; + public optUndefinedProp2: undefined = undefined; + public optObjectProp2: object = { name: 'John', age: 30 }; + public optSendableClass2: SendableClass = new SendableClass(); + public optNoSendableClass2: NoSendableClass = new NoSendableClass(); + + readonly optBooleanProp3: boolean = true; + readonly optNumberProp3: number = 42; + readonly optStringProp3: string = 'Hello'; + readonly optArrayProp3: number[] = [1, 2, 3]; + readonly optTupleProp3: [string, number] = ['typescript', 4]; + readonly optEnumProp3: Color = Color.Green; + readonly optAnyProp3: any = { key: 'value' }; + readonly optVoidProp3: void = undefined; + readonly optNullProp3: null = null; + readonly optUndefinedProp3: undefined = undefined; + readonly optObjectProp3: object = { name: 'John', age: 30 }; + readonly optSendableClass3: SendableClass = new SendableClass(); + readonly optNoSendableClass3: NoSendableClass = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + booleanProp4 = true; + numberProp4 = 42; + stringProp4 = 'Hello'; + arrayProp4 = [1, 2, 3]; + tupleProp4 = ['typescript', 4]; + enumProp4 = Color.Green; + anyProp4 = { key: 'value' }; + voidProp4 = undefined; + nullProp4 = null; + undefinedProp4 = undefined; + objectProp4 = { name: 'John', age: 30 }; + sendableClass4 = new SendableClass(); + noSendableClass4 = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + booleanProp5? = true; + numberProp5? = 42; + stringProp5? = 'Hello'; + arrayProp5? = [1, 2, 3]; + tupleProp5? = ['typescript', 4]; + enumProp5? = Color.Green; + anyProp5? = { key: 'value' }; + voidProp5? = undefined; + nullProp5? = null; + undefinedProp5? = undefined; + objectProp5? = { name: 'John', age: 30 }; + sendableClass5? = new SendableClass(); + noSendableClass5? = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + public optBooleanProp6 = true; + public optNumberProp6 = 42; + public optStringProp6 = 'Hello'; + public optArrayProp6 = [1, 2, 3]; + public optTupleProp6 = ['typescript', 4]; + public optEnumProp6 = Color.Green; + public optAnyProp6 = { key: 'value' }; + public optVoidProp6 = undefined; + public optNullProp6 = null; + public optUndefinedProp6 = undefined; + public optObjectProp6 = { name: 'John', age: 30 }; + public optSendableClass6 = new SendableClass(); + public optNoSendableClass6 = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + readonly optBooleanProp7 = true; + readonly optNumberProp7 = 42; + readonly optStringProp7 = 'Hello'; + readonly optArrayProp7 = [1, 2, 3]; + readonly optTupleProp7 = ['typescript', 4]; + readonly optEnumProp7 = Color.Green; + readonly optAnyProp7 = { key: 'value' }; + readonly optVoidProp7 = undefined; + readonly optNullProp7 = null; + readonly optUndefinedProp7 = undefined; + readonly optObjectProp7 = { name: 'John', age: 30 }; + readonly optSendableClass7 = new SendableClass(); + readonly optNoSendableClass7 = new NoSendableClass(); +} + +@Sendable +class A1 extends A { + constructor() { + super(); + } + booleanProp: boolean = true; + numberProp: number = 42; + stringProp: string = 'Hello'; + arrayProp: number[] = [1, 2, 3]; + tupleProp: [string, number] = ['typescript', 4]; + enumProp: Color = Color.Green; + anyProp: any = { key: 'value' }; + voidProp: void = undefined; + nullProp: null = null; + undefinedProp: undefined = undefined; + objectProp: object = { name: 'John', age: 30 }; + sendableClass: SendableClass = new SendableClass(); + noSendableClass: NoSendableClass = new NoSendableClass(); + + optBooleanProp1?: boolean = true; + optNumberProp1?: number = 42; + optStringProp1?: string = 'Hello'; + optArrayProp1?: number[] = [1, 2, 3]; + optTupleProp1?: [string, number] = ['typescript', 4]; + optEnumProp1?: Color = Color.Green; + optAnyProp1?: any = { key: 'value' }; + optVoidProp1?: void = undefined; + optNullProp1?: null = null; + optUndefinedProp1?: undefined = undefined; + optObjectProp1?: object = { name: 'John', age: 30 }; + optSendableClass1?: SendableClass = new SendableClass(); + optNoSendableClass1?: NoSendableClass = new NoSendableClass(); + + public optBooleanProp2: boolean = true; + public optNumberProp2: number = 42; + public optStringProp2: string = 'Hello'; + public optArrayProp2: number[] = [1, 2, 3]; + public optTupleProp2: [string, number] = ['typescript', 4]; + public optEnumProp2: Color = Color.Green; + public optAnyProp2: any = { key: 'value' }; + public optVoidProp2: void = undefined; + public optNullProp2: null = null; + public optUndefinedProp2: undefined = undefined; + public optObjectProp2: object = { name: 'John', age: 30 }; + public optSendableClass2: SendableClass = new SendableClass(); + public optNoSendableClass2: NoSendableClass = new NoSendableClass(); + + readonly optBooleanProp3: boolean = true; + readonly optNumberProp3: number = 42; + readonly optStringProp3: string = 'Hello'; + readonly optArrayProp3: number[] = [1, 2, 3]; + readonly optTupleProp3: [string, number] = ['typescript', 4]; + readonly optEnumProp3: Color = Color.Green; + readonly optAnyProp3: any = { key: 'value' }; + readonly optVoidProp3: void = undefined; + readonly optNullProp3: null = null; + readonly optUndefinedProp3: undefined = undefined; + readonly optObjectProp3: object = { name: 'John', age: 30 }; + readonly optSendableClass3: SendableClass = new SendableClass(); + readonly optNoSendableClass3: NoSendableClass = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + booleanProp4 = true; + numberProp4 = 42; + stringProp4 = 'Hello'; + arrayProp4 = [1, 2, 3]; + tupleProp4 = ['typescript', 4]; + enumProp4 = Color.Green; + anyProp4 = { key: 'value' }; + voidProp4 = undefined; + nullProp4 = null; + undefinedProp4 = undefined; + objectProp4 = { name: 'John', age: 30 }; + sendableClass4 = new SendableClass(); + noSendableClass4 = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + booleanProp5? = true; + numberProp5? = 42; + stringProp5? = 'Hello'; + arrayProp5? = [1, 2, 3]; + tupleProp5? = ['typescript', 4]; + enumProp5? = Color.Green; + anyProp5? = { key: 'value' }; + voidProp5? = undefined; + nullProp5? = null; + undefinedProp5? = undefined; + objectProp5? = { name: 'John', age: 30 }; + sendableClass5? = new SendableClass(); + noSendableClass5? = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + public optBooleanProp6 = true; + public optNumberProp6 = 42; + public optStringProp6 = 'Hello'; + public optArrayProp6 = [1, 2, 3]; + public optTupleProp6 = ['typescript', 4]; + public optEnumProp6 = Color.Green; + public optAnyProp6 = { key: 'value' }; + public optVoidProp6 = undefined; + public optNullProp6 = null; + public optUndefinedProp6 = undefined; + public optObjectProp6 = { name: 'John', age: 30 }; + public optSendableClass6 = new SendableClass(); + public optNoSendableClass6 = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + readonly optBooleanProp7 = true; + readonly optNumberProp7 = 42; + readonly optStringProp7 = 'Hello'; + readonly optArrayProp7 = [1, 2, 3]; + readonly optTupleProp7 = ['typescript', 4]; + readonly optEnumProp7 = Color.Green; + readonly optAnyProp7 = { key: 'value' }; + readonly optVoidProp7 = undefined; + readonly optNullProp7 = null; + readonly optUndefinedProp7 = undefined; + readonly optObjectProp7 = { name: 'John', age: 30 }; + readonly optSendableClass7 = new SendableClass(); + readonly optNoSendableClass7 = new NoSendableClass(); +} + +@Sendable +class A2 implements lang.ISendable { + booleanProp: boolean = true; + numberProp: number = 42; + stringProp: string = 'Hello'; + arrayProp: number[] = [1, 2, 3]; + tupleProp: [string, number] = ['typescript', 4]; + enumProp: Color = Color.Green; + anyProp: any = { key: 'value' }; + voidProp: void = undefined; + nullProp: null = null; + undefinedProp: undefined = undefined; + objectProp: object = { name: 'John', age: 30 }; + sendableClass: SendableClass = new SendableClass(); + noSendableClass: NoSendableClass = new NoSendableClass(); + + optBooleanProp1?: boolean = true; + optNumberProp1?: number = 42; + optStringProp1?: string = 'Hello'; + optArrayProp1?: number[] = [1, 2, 3]; + optTupleProp1?: [string, number] = ['typescript', 4]; + optEnumProp1?: Color = Color.Green; + optAnyProp1?: any = { key: 'value' }; + optVoidProp1?: void = undefined; + optNullProp1?: null = null; + optUndefinedProp1?: undefined = undefined; + optObjectProp1?: object = { name: 'John', age: 30 }; + optSendableClass1?: SendableClass = new SendableClass(); + optNoSendableClass1?: NoSendableClass = new NoSendableClass(); + + public optBooleanProp2: boolean = true; + public optNumberProp2: number = 42; + public optStringProp2: string = 'Hello'; + public optArrayProp2: number[] = [1, 2, 3]; + public optTupleProp2: [string, number] = ['typescript', 4]; + public optEnumProp2: Color = Color.Green; + public optAnyProp2: any = { key: 'value' }; + public optVoidProp2: void = undefined; + public optNullProp2: null = null; + public optUndefinedProp2: undefined = undefined; + public optObjectProp2: object = { name: 'John', age: 30 }; + public optSendableClass2: SendableClass = new SendableClass(); + public optNoSendableClass2: NoSendableClass = new NoSendableClass(); + + readonly optBooleanProp3: boolean = true; + readonly optNumberProp3: number = 42; + readonly optStringProp3: string = 'Hello'; + readonly optArrayProp3: number[] = [1, 2, 3]; + readonly optTupleProp3: [string, number] = ['typescript', 4]; + readonly optEnumProp3: Color = Color.Green; + readonly optAnyProp3: any = { key: 'value' }; + readonly optVoidProp3: void = undefined; + readonly optNullProp3: null = null; + readonly optUndefinedProp3: undefined = undefined; + readonly optObjectProp3: object = { name: 'John', age: 30 }; + readonly optSendableClass3: SendableClass = new SendableClass(); + readonly optNoSendableClass3: NoSendableClass = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + booleanProp4 = true; + numberProp4 = 42; + stringProp4 = 'Hello'; + arrayProp4 = [1, 2, 3]; + tupleProp4 = ['typescript', 4]; + enumProp4 = Color.Green; + anyProp4 = { key: 'value' }; + voidProp4 = undefined; + nullProp4 = null; + undefinedProp4 = undefined; + objectProp4 = { name: 'John', age: 30 }; + sendableClass4 = new SendableClass(); + noSendableClass4 = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + booleanProp5? = true; + numberProp5? = 42; + stringProp5? = 'Hello'; + arrayProp5? = [1, 2, 3]; + tupleProp5? = ['typescript', 4]; + enumProp5? = Color.Green; + anyProp5? = { key: 'value' }; + voidProp5? = undefined; + nullProp5? = null; + undefinedProp5? = undefined; + objectProp5? = { name: 'John', age: 30 }; + sendableClass5? = new SendableClass(); + noSendableClass5? = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + public optBooleanProp6 = true; + public optNumberProp6 = 42; + public optStringProp6 = 'Hello'; + public optArrayProp6 = [1, 2, 3]; + public optTupleProp6 = ['typescript', 4]; + public optEnumProp6 = Color.Green; + public optAnyProp6 = { key: 'value' }; + public optVoidProp6 = undefined; + public optNullProp6 = null; + public optUndefinedProp6 = undefined; + public optObjectProp6 = { name: 'John', age: 30 }; + public optSendableClass6 = new SendableClass(); + public optNoSendableClass6 = new NoSendableClass(); + + // Error, Field in sendable class must have type annotation (arkts-sendable-explicit-field-type) + readonly optBooleanProp7 = true; + readonly optNumberProp7 = 42; + readonly optStringProp7 = 'Hello'; + readonly optArrayProp7 = [1, 2, 3]; + readonly optTupleProp7 = ['typescript', 4]; + readonly optEnumProp7 = Color.Green; + readonly optAnyProp7 = { key: 'value' }; + readonly optVoidProp7 = undefined; + readonly optNullProp7 = null; + readonly optUndefinedProp7 = undefined; + readonly optObjectProp7 = { name: 'John', age: 30 }; + readonly optSendableClass7 = new SendableClass(); + readonly optNoSendableClass7 = new NoSendableClass(); +} + +class A3 { + booleanProp: boolean = true; + numberProp: number = 42; + stringProp: string = 'Hello'; + arrayProp: number[] = [1, 2, 3]; + tupleProp: [string, number] = ['typescript', 4]; + enumProp: Color = Color.Green; + anyProp: any = { key: 'value' }; + voidProp: void = undefined; + nullProp: null = null; + undefinedProp: undefined = undefined; + objectProp: object = { name: 'John', age: 30 }; + sendableClass: SendableClass = new SendableClass(); + noSendableClass: NoSendableClass = new NoSendableClass(); + + optBooleanProp1?: boolean = true; + optNumberProp1?: number = 42; + optStringProp1?: string = 'Hello'; + optArrayProp1?: number[] = [1, 2, 3]; + optTupleProp1?: [string, number] = ['typescript', 4]; + optEnumProp1?: Color = Color.Green; + optAnyProp1?: any = { key: 'value' }; + optVoidProp1?: void = undefined; + optNullProp1?: null = null; + optUndefinedProp1?: undefined = undefined; + optObjectProp1?: object = { name: 'John', age: 30 }; + optSendableClass1?: SendableClass = new SendableClass(); + optNoSendableClass1?: NoSendableClass = new NoSendableClass(); + + public optBooleanProp2: boolean = true; + public optNumberProp2: number = 42; + public optStringProp2: string = 'Hello'; + public optArrayProp2: number[] = [1, 2, 3]; + public optTupleProp2: [string, number] = ['typescript', 4]; + public optEnumProp2: Color = Color.Green; + public optAnyProp2: any = { key: 'value' }; + public optVoidProp2: void = undefined; + public optNullProp2: null = null; + public optUndefinedProp2: undefined = undefined; + public optObjectProp2: object = { name: 'John', age: 30 }; + public optSendableClass2: SendableClass = new SendableClass(); + public optNoSendableClass2: NoSendableClass = new NoSendableClass(); + + readonly optBooleanProp3: boolean = true; + readonly optNumberProp3: number = 42; + readonly optStringProp3: string = 'Hello'; + readonly optArrayProp3: number[] = [1, 2, 3]; + readonly optTupleProp3: [string, number] = ['typescript', 4]; + readonly optEnumProp3: Color = Color.Green; + readonly optAnyProp3: any = { key: 'value' }; + readonly optVoidProp3: void = undefined; + readonly optNullProp3: null = null; + readonly optUndefinedProp3: undefined = undefined; + readonly optObjectProp3: object = { name: 'John', age: 30 }; + readonly optSendableClass3: SendableClass = new SendableClass(); + readonly optNoSendableClass3: NoSendableClass = new NoSendableClass(); + + booleanProp4 = true; + numberProp4 = 42; + stringProp4 = 'Hello'; + arrayProp4 = [1, 2, 3]; + tupleProp4 = ['typescript', 4]; + enumProp4 = Color.Green; + anyProp4 = { key: 'value' }; + voidProp4 = undefined; + nullProp4 = null; + undefinedProp4 = undefined; + objectProp4 = { name: 'John', age: 30 }; + sendableClass4 = new SendableClass(); + noSendableClass4 = new NoSendableClass(); + + booleanProp5? = true; + numberProp5? = 42; + stringProp5? = 'Hello'; + arrayProp5? = [1, 2, 3]; + tupleProp5? = ['typescript', 4]; + enumProp5? = Color.Green; + anyProp5? = { key: 'value' }; + voidProp5? = undefined; + nullProp5? = null; + undefinedProp5? = undefined; + objectProp5? = { name: 'John', age: 30 }; + sendableClass5? = new SendableClass(); + noSendableClass5? = new NoSendableClass(); + + public optBooleanProp6 = true; + public optNumberProp6 = 42; + public optStringProp6 = 'Hello'; + public optArrayProp6 = [1, 2, 3]; + public optTupleProp6 = ['typescript', 4]; + public optEnumProp6 = Color.Green; + public optAnyProp6 = { key: 'value' }; + public optVoidProp6 = undefined; + public optNullProp6 = null; + public optUndefinedProp6 = undefined; + public optObjectProp6 = { name: 'John', age: 30 }; + public optSendableClass6 = new SendableClass(); + public optNoSendableClass6 = new NoSendableClass(); + + readonly optBooleanProp7 = true; + readonly optNumberProp7 = 42; + readonly optStringProp7 = 'Hello'; + readonly optArrayProp7 = [1, 2, 3]; + readonly optTupleProp7 = ['typescript', 4]; + readonly optEnumProp7 = Color.Green; + readonly optAnyProp7 = { key: 'value' }; + readonly optVoidProp7 = undefined; + readonly optNullProp7 = null; + readonly optUndefinedProp7 = undefined; + readonly optObjectProp7 = { name: 'John', age: 30 }; + readonly optSendableClass7 = new SendableClass(); + readonly optNoSendableClass7 = new NoSendableClass(); +} + +interface I extends lang.ISendable { + booleanProp: boolean; + numberProp: number; + stringProp: string; + arrayProp: number[]; + tupleProp: [string, number]; + enumProp: Color; + anyProp: any; + voidProp: void; + nullProp: null; + undefinedProp: undefined; + objectProp: object; + sendableClass: SendableClass; + noSendableClass: NoSendableClass; + + optBooleanProp1?: boolean; + optNumberProp1?: number; + optStringProp1?: string; + optArrayProp1?: number[]; + optTupleProp1?: [string, number]; + optEnumProp1?: Color; + optAnyProp1?: any; + optVoidProp1?: void; + optNullProp1?: null; + optUndefinedProp1?: undefined; + optObjectProp1?: object; + optSendableClass1?: SendableClass; + optNoSendableClass1?: NoSendableClass; + + readonly optBooleanProp3: boolean; + readonly optNumberProp3: number; + readonly optStringProp3: string; + readonly optArrayProp3: number[]; + readonly optTupleProp3: [string, number]; + readonly optEnumProp3: Color; + readonly optAnyProp3: any; + readonly optVoidProp3: void; + readonly optNullProp3: null; + readonly optUndefinedProp3: undefined; + readonly optObjectProp3: object; + readonly optSendableClass3: SendableClass; + readonly optNoSendableClass3: NoSendableClass; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f8b3550cacc0809b14fdf47973047065a7a17a80 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-1-error.json @@ -0,0 +1,3135 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 29, + "character": 1 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 37, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 41, + "character": 26 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 51, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 55, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 65, + "character": 25 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 69, + "character": 37 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 79, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 83, + "character": 39 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 94, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 98, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 109, + "character": 17 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 113, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 124, + "character": 26 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 128, + "character": 29 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 139, + "character": 28 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 143, + "character": 31 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 148, + "character": 1 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 159, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 163, + "character": 26 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 173, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 177, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 187, + "character": 25 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 191, + "character": 37 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 201, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 205, + "character": 39 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 216, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 220, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 231, + "character": 17 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 235, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 246, + "character": 26 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 250, + "character": 29 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 261, + "character": 28 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 265, + "character": 31 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 270, + "character": 1 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 278, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 282, + "character": 26 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 292, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 296, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 306, + "character": 25 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 310, + "character": 37 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 320, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 324, + "character": 39 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 335, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 339, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 350, + "character": 17 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 354, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 365, + "character": 26 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 369, + "character": 29 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 380, + "character": 28 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 384, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 396, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 400, + "character": 26 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 410, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 414, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 424, + "character": 25 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 428, + "character": 37 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 438, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 442, + "character": 39 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 452, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 456, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 466, + "character": 17 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 470, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 480, + "character": 26 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 484, + "character": 29 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 494, + "character": 28 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 498, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 510, + "character": 14 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 524, + "character": 19 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 538, + "character": 27 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 36, + "character": 23 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 43, + "character": 44 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 50, + "character": 28 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 57, + "character": 49 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 64, + "character": 34 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 71, + "character": 55 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 78, + "character": 36 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 85, + "character": 57 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 93, + "character": 17 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 100, + "character": 28 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 108, + "character": 18 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 115, + "character": 29 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 123, + "character": 27 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 130, + "character": 38 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 138, + "character": 29 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 145, + "character": 40 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 34, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 35, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 36, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 37, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 37, + "character": 14 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 38, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 41, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 41, + "character": 26 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 43, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 48, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 49, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 50, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 51, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 51, + "character": 19 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 52, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 55, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 55, + "character": 31 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 57, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 62, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 63, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 64, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 65, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 65, + "character": 25 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 66, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 69, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 69, + "character": 37 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 71, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 76, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 77, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 78, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 79, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 79, + "character": 27 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 80, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 83, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 83, + "character": 39 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 85, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 88, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 89, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 90, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 91, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 92, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 93, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 94, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 94, + "character": 16 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 95, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 96, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 97, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 98, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 98, + "character": 19 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 99, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 100, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 103, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 104, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 105, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 106, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 107, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 108, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 109, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 109, + "character": 17 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 110, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 111, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 112, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 113, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 113, + "character": 20 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 114, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 115, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 118, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 119, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 120, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 121, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 122, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 123, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 124, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 124, + "character": 26 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 125, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 126, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 127, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 128, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 128, + "character": 29 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 129, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 130, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 133, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 134, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 135, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 136, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 137, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 138, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 139, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 139, + "character": 28 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 140, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 141, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 142, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 143, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 143, + "character": 31 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 144, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 145, + "character": 5 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 158, + "character": 23 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 165, + "character": 44 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 172, + "character": 28 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 179, + "character": 49 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 186, + "character": 34 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 193, + "character": 55 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 200, + "character": 36 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 207, + "character": 57 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 215, + "character": 17 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 222, + "character": 28 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 230, + "character": 18 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 237, + "character": 29 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 245, + "character": 27 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 252, + "character": 38 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 260, + "character": 29 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 267, + "character": 40 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 156, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 157, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 158, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 159, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 159, + "character": 14 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 160, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 163, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 163, + "character": 26 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 165, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 170, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 171, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 172, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 173, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 173, + "character": 19 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 174, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 177, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 177, + "character": 31 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 179, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 184, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 185, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 186, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 187, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 187, + "character": 25 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 188, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 191, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 191, + "character": 37 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 193, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 198, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 199, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 200, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 201, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 201, + "character": 27 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 202, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 205, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 205, + "character": 39 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 207, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 210, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 211, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 212, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 213, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 214, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 215, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 216, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 216, + "character": 16 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 217, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 218, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 219, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 220, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 220, + "character": 19 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 221, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 222, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 225, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 226, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 227, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 228, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 229, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 230, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 231, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 231, + "character": 17 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 232, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 233, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 234, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 235, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 235, + "character": 20 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 236, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 237, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 240, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 241, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 242, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 243, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 244, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 245, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 246, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 246, + "character": 26 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 247, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 248, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 249, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 250, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 250, + "character": 29 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 251, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 252, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 255, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 256, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 257, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 258, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 259, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 260, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 261, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 261, + "character": 28 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 262, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 263, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 264, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 265, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 265, + "character": 31 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 266, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 267, + "character": 5 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 277, + "character": 23 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 284, + "character": 44 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 291, + "character": 28 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 298, + "character": 49 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 305, + "character": 34 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 312, + "character": 55 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 319, + "character": 36 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 326, + "character": 57 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 334, + "character": 17 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 341, + "character": 28 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 349, + "character": 18 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 356, + "character": 29 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 364, + "character": 27 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 371, + "character": 38 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 379, + "character": 29 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 386, + "character": 40 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 275, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 276, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 277, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 278, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 278, + "character": 14 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 279, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 282, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 282, + "character": 26 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 284, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 289, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 290, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 291, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 292, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 292, + "character": 19 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 293, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 296, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 296, + "character": 31 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 298, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 303, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 304, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 305, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 306, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 306, + "character": 25 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 307, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 310, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 310, + "character": 37 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 312, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 317, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 318, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 319, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 320, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 320, + "character": 27 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 321, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 324, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 324, + "character": 39 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 326, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 329, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 330, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 331, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 332, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 333, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 334, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 335, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 335, + "character": 16 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 336, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 337, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 338, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 339, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 339, + "character": 19 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 340, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 341, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 344, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 345, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 346, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 347, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 348, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 349, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 350, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 350, + "character": 17 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 351, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 352, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 353, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 354, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 354, + "character": 20 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 355, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 356, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 359, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 360, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 361, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 362, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 363, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 364, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 365, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 365, + "character": 26 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 366, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 367, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 368, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 369, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 369, + "character": 29 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 370, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 371, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 374, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 375, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 376, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 377, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 378, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 379, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 380, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 380, + "character": 28 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 381, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 382, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 383, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 384, + "character": 5 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 384, + "character": 31 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 385, + "character": 5 + } + }, + { + "messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)", + "expectLineAndCharacter": { + "line": 386, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 396, + "character": 14 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 400, + "character": 26 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 410, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 414, + "character": 31 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 424, + "character": 25 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 428, + "character": 37 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 438, + "character": 27 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 442, + "character": 39 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 452, + "character": 16 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 456, + "character": 19 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 466, + "character": 17 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 470, + "character": 20 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 480, + "character": 26 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 484, + "character": 29 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 494, + "character": 28 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 498, + "character": 31 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 507, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 508, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 509, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 510, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 510, + "character": 14 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 511, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 514, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 516, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 521, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 522, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 523, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 524, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 524, + "character": 19 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 525, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 528, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 530, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 535, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 536, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 537, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 538, + "character": 5 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 538, + "character": 27 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 539, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 542, + "character": 5 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 544, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..440124e58143ca531d7aa6cec564ed7b4ab7c566 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-2-error.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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. + */ + +class A {} +class B {} + +declare type Nullable = T | undefined; +type MyType = B | undefined; + +class C { + public c: number; +} + +@Sendable +class D { + public a: Nullable; // NOT OK + public b: Nullable = new C(); // NOT OK + public c: Nullable = 1; // OK + public d: MyType; // NOT OK + public e: Nullable || number; // NOT OK +} + +let d = new D(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d317f5ead56340e55722609c0300b7ba52ed5666 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-explicit-field-type/arkts-sendable-explicit-field-type-2-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Property 'c' has no initializer and is not definitely assigned in the constructor.", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Property 'c' has no initializer and is not definitely assigned in the constructor.", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 29, + "character": 31 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 28, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 31, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 32, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..bc3168a76ee192530f6bb2f4030d0d9ae4364e2c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-1-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +function sendableFunction(): void {} +function noneSendableFunction(): void {} + +@Sendable +type SendableType = () => void; +type NoneSendableType = () => void; + +const a1: NoneSendableType = sendableFunction; +const a2: NoneSendableType = noneSendableFunction; +const a4: SendableType = noneSendableFunction as SendableType; // ERROR +const a5: SendableType = a1 as SendableType; // ERROR +const a6: SendableType = a2 as SendableType; // ERROR \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..4497548542659faa130cc5ff5ba0a5dd50b8b0b2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-1-error.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Casting \"Non-sendable\" function to \"Sendable\" typeAlias is not allowed (arkts-sendable-function-as-expr)", + "expectLineAndCharacter": { + "line": 26, + "character": 26 + } + }, + { + "messageText": "Casting \"Non-sendable\" function to \"Sendable\" typeAlias is not allowed (arkts-sendable-function-as-expr)", + "expectLineAndCharacter": { + "line": 27, + "character": 26 + } + }, + { + "messageText": "Casting \"Non-sendable\" function to \"Sendable\" typeAlias is not allowed (arkts-sendable-function-as-expr)", + "expectLineAndCharacter": { + "line": 28, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5daed20d5307d3ec20d5301c3b27f112552b4b5c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-2-ok.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +function sendableFunction(): void {} +function noneSendableFunction(): void {} + +@Sendable +type SendableType = () => void; +type NoneSendableType = () => void; + +const a1: NoneSendableType = sendableFunction; +const a2: NoneSendableType = noneSendableFunction; +const a3: SendableType = sendableFunction as SendableType; // OK +const a4: NoneSendableType = noneSendableFunction as NoneSendableType; // OK diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..92652c4844663d543692d8343c811565861c60bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-as-expr/arkts-sendable-function-as-expr-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3aa303efd2307140874f63f285b9fc7a12eb7e34 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-1-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +function sendableFunction(): void {} +function noneSendableFunction(): void {} + +@Sendable +type SendableType = () => void; +type NoneSendableType = () => void; + +const af = () => {}; + +const a2: SendableType = noneSendableFunction; // ERROR +const a3: SendableType = af; // ERROR +const a4: NoneSendableType = noneSendableFunction; // OK +const a6: SendableType = a4; // ERROR \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..fae24f40fe5d07f4db8bf8647cfd12d10a127e30 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-1-error.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Only \"Sendable\" function or \"Sendable\" typeAlias object can be assigned to \"Sendable\" typeAlias (arkts-sendable-function-assignment)", + "expectLineAndCharacter": { + "line": 26, + "character": 7 + } + }, + { + "messageText": "Only \"Sendable\" function or \"Sendable\" typeAlias object can be assigned to \"Sendable\" typeAlias (arkts-sendable-function-assignment)", + "expectLineAndCharacter": { + "line": 27, + "character": 7 + } + }, + { + "messageText": "Only \"Sendable\" function or \"Sendable\" typeAlias object can be assigned to \"Sendable\" typeAlias (arkts-sendable-function-assignment)", + "expectLineAndCharacter": { + "line": 29, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..db8904995efde1fac619f67c87113ee91653735a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-2-ok.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +function sendableFunction(): void {} +function noneSendableFunction(): void {} + +@Sendable +type SendableType = () => void; +type NoneSendableType = () => void; + +const af = () => {}; + + +const a1: SendableType = sendableFunction; // OK +const a2: NoneSendableType = noneSendableFunction; // OK +const a3: SendableType = a1; // OK \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..92652c4844663d543692d8343c811565861c60bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-assignment/arkts-sendable-function-assignment-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-decorator/arkts-sendable-function-decorator-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-decorator/arkts-sendable-function-decorator-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..64f8093f1a2292675f6a465e711e4ef15bc169cf --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-decorator/arkts-sendable-function-decorator-1-error.ets @@ -0,0 +1,13 @@ + + +@Sendable // OK +function sf():void { +} +@Sendable // OK +function stf(p:T):T { + return p; +} +@Sendable +@Other // ERROR +function sf2():void { +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-decorator/arkts-sendable-function-decorator-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-decorator/arkts-sendable-function-decorator-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..7c62268344d39e2ecf6c7e1b42aa7f7059cd3226 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-decorator/arkts-sendable-function-decorator-1-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" function (arkts-sendable-function-decorator)", + "expectLineAndCharacter": { + "line": 11, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-imported-variables/arkts-sendable-function-imported-variables-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-imported-variables/arkts-sendable-function-imported-variables-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e288094d9625d066478ef674fff87e08d5303936 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-imported-variables/arkts-sendable-function-imported-variables-1-error.ets @@ -0,0 +1,43 @@ + + +@Sendable +function sf():void {} +function nf():void {} +@Sendable +type Sft = () => void; +type Nft = () => void; +function localDecorator() {}; + + +@Sendable +class Sc {} +class Nc {} + +@Sendable +class SendableClassClosure { + constructor() { + const a1:Sft = sf; // OK + const a2:Nft = nf; // ERROR + const a3:Sc = new Sc(); // OK + const a4:Nc = new Nc(); // ERROR + } + + @localDecorator // ERROR + handle() {} +} + +@Sendable +@nf +function sendableFunctionClosure() { + const a1:Sft = sf; // OK + const a2:Nft = nf; // ERROR + const a3:Sc = new Sc(); // OK + const a4:Nc = new Nc(); // ERROR +} + +namespace Ns { + @Sendable + function sf():void; + @Sendable + function sf():void {} +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-imported-variables/arkts-sendable-function-imported-variables-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-imported-variables/arkts-sendable-function-imported-variables-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a139616b3f4130b0a14de1ec0a0f7de2cafabcbb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-imported-variables/arkts-sendable-function-imported-variables-1-error.json @@ -0,0 +1,69 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 12, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 20, + "character": 20 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 22, + "character": 23 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)", + "expectLineAndCharacter": { + "line": 25, + "character": 3 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" function (arkts-sendable-function-decorator)", + "expectLineAndCharacter": { + "line": 30, + "character": 1 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" function (arkts-sendable-function-imported-variables)", + "expectLineAndCharacter": { + "line": 33, + "character": 18 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" function (arkts-sendable-function-imported-variables)", + "expectLineAndCharacter": { + "line": 35, + "character": 21 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..04051030f772fc9a9ee3eb28217983006ef20c2e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-1-error.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 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. + */ + +// check overloading +@Sendable +function sendableFunction1(): void; +function sendableFunction1(): void; // ERROR +@Sendable +function sendableFunction1(): void {} // OK + +@Sendable +function sendableFunction2(): void ; + +@Sendable +@Other // ERROR +function sendableFunction2(): void; + +@Sendable +function sendableFunction2(): void {} + +function noneSendableFunction(): void {} + +@Sendable +function sendableFunction1(): string { + let a: string = 'one'; + return a; +} + +function sendableFunction1(): string { // ERROR + let a: string = 'two'; + return a; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0a483507ba106a46509e32dd697e7da41d010f57 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-1-error.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "When declaring \"@Sendable\" overloaded function, needs to add \"@Sendable\" decorator on each function (arkts-sendable-function-overload-decorator)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" function (arkts-sendable-function-decorator)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + }, + { + "messageText": "When declaring \"@Sendable\" overloaded function, needs to add \"@Sendable\" decorator on each function (arkts-sendable-function-overload-decorator)", + "expectLineAndCharacter": { + "line": 41, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b28f7584cdf6421372d3b1fec981613bda501866 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-2-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 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. + */ + +// check overloading +@Sendable +function sendableFunction1(): void; // OK +@Sendable +function sendableFunction1(): void; // OK +@Sendable +function sendableFunction1(): void {} // OK diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..92652c4844663d543692d8343c811565861c60bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-overload-decorator/arkts-sendable-function-overload-decorator-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..885388db4ef5e807a00eaaa44e86ed3210d69c4a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-1-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +function sendableFunction(): void {} +function noneSendableFunction(): void {} + +sendableFunction.aa = 1; // ERROR +noneSendableFunction.aa = 1; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..0dbf22e02f8a781d44619aadd66494c75841587f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-1-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "The property of \"Sendable\" function is limited (arkts-sendable-function-property)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..a125b88ac6b503863b9dd8a0af1a4bd59309c85a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-2-ok.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 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. + */ + +function noneSendableFunction(): void {} + +noneSendableFunction.number: number = 1; +noneSendableFunction.string: string = '1'; +noneSendableFunction.boolean: boolean = false; +noneSendableFunction.numArray: number[] = [1, 2, 3]; +noneSendableFunction.strArray: Array = ['a', 'b', 'c']; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..92652c4844663d543692d8343c811565861c60bc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-function-property/arkts-sendable-function-property-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/@arkts.lang.d.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/@arkts.lang.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..40e381dc2a3c9c96df3b6278ed74fe7a71922dc9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/@arkts.lang.d.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + +declare namespace lang { + interface ISendable {} +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1d3d3260d6a2d120b47ed560cfeffdbab2970ab --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-1-ok.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClassA { + var1: number = 1; + var2: string = '1'; +} + +@Sendable +class SendableClassB { + var1: number = 1; + var2: string = '1'; +} + +let A1: SendableClassA = new SendableClassA(); +let A2: SendableClassA = new SendableClassA(); +let A3: SendableClassA = new SendableClassA(); +let A4: SendableClassA = new SendableClassA(); +let A5: SendableClassA = new SendableClassA(); +let A6: SendableClassA = new SendableClassA(); +let A7: SendableClassA = new SendableClassA(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..1a385c1f04bf4ebd05d7c0b06477a8a85e3a74aa --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-1-ok.json @@ -0,0 +1,19 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..84c4c070f5c91afff1ca5362ef783ea6eb19c1a6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-2-error.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClassA { + var1: number = 1; + var2: string = '1'; +} + +class NoneSendableClassA { + var1: number = 1; + var2: string = '1'; +} + +let A1: SendableClassA = new SendableClassA(); // error + +@Sendable +class SendableClassC { + var1: number = 1; + var2: string = '1'; +} + +@Sendable +class SendableClassD { + var1: number = 1; + var2: string = '1'; +} + +let u1: NoneSendableClassA | SendableClassC = new SendableClassC(); +let u2: NoneSendableClassA | SendableClassC = new SendableClassC(); // error + +type unionA = string | T; +let u3: unionA = new NoneSendableClassA(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a27ce02e8f2331514ca148798af12390d150a2b6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-2-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 29, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 35, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 27, + "character": 24 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 27, + "character": 65 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 42, + "character": 45 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..84310b71b942eb95fb6f0c3fdb91fe591a1abc63 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-3-error.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 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. + */ + +namespace collections { + @Sendable + export class Array { + constructor(){}; + } + + @Sendable + export class Map { + constructor(){}; + } +} + +class NoneSendableClassA { + var1: number = 1; + var2: string = '1'; +} + +@Sendable +class SendableClassA { + var1: number = 1; + var2: string = '1'; +} + +let arr1: collections.Array = new collections.Array(); // error +let arr2: collections.Array = new collections.Array(); // error +let arr3: collections.Array = new collections.Array(); //error +let arr4: collections.Array = new collections.Array(); +let arr5: collections.Array = new collections.Array(); + +let map1: collections.Map = new collections.Map(); // error +let map2: collections.Map = new collections.Map(); // error +let map3: collections.Map = new collections.Map(); // error +let map4: collections.Map = new collections.Map(); +let map5: collections.Map = new collections.Map(); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..6a6ae5b98a38e8bb7866a7faee1f2d8d722cff68 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-3-error.json @@ -0,0 +1,83 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 5 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 33, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 39, + "character": 29 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 39, + "character": 73 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 40, + "character": 29 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 41, + "character": 29 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 45, + "character": 34 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 45, + "character": 83 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 46, + "character": 34 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 47, + "character": 34 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..38dc42578ef1052b98581ec1c07b39a0110f301c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-error.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable +class SendableClassT { + public var1: number = 1; + public var2: string = '1'; +} + +@Sendable +class SendableClass1 { + public var1: number = 1; + public var2: string = '1'; +} + +@Sendable +class SendableClass2 { + public var1: number = 1; + public var2: string = '1'; +} + +class NonSendableClass1 {} +class NonSendableClass2 { public p1 = 1 } + +/* + * 1. The generic parameter of `SendableClass` must be of a `Sendable` type. + * 2. If the parameter is a union, each type in the union must be a `Sendable` type. + */ +let A1: SendableClassT = new SendableClassT(); +let A2: SendableClassT = new SendableClassT(); +let A3: SendableClassT = new SendableClassT(); +let A4: SendableClassT = + new SendableClassT(); +let A5: SendableClassT = + new SendableClassT(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..92440976adaa30c9ed39b711cf5083a4d38d13e7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-error.json @@ -0,0 +1,83 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 29, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 42, + "character": 24 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 42, + "character": 81 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 43, + "character": 24 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 44, + "character": 24 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 44, + "character": 81 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 45, + "character": 24 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 46, + "character": 22 + } + }, + { + "messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)", + "expectLineAndCharacter": { + "line": 48, + "character": 22 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f20e4c048d15a17bb94056ba6a7c8b32d519fb4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-ok.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable +class SendableClassT { + public var1: number = 1; + public var2: string = '1'; +} + +@Sendable +class SendableClass1 { + public var1: number = 1; + public var2: string = '1'; +} + +@Sendable +class SendableClass2 { + public var1: number = 1; + public var2: string = '1'; +} + +class NonSendableClass1 {} +class NonSendableClass2 { public p1 = 1 } + +/* + * 1. The generic parameter of `SendableClass` must be of a `Sendable` type. + * 2. If the parameter is a union, each type in the union must be a `Sendable` type. + */ +let A1: SendableClassT = new SendableClassT(); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..be387f8cf86ae2c83593204115001bb260f13fb5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types-4-ok.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 23, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 29, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types.json new file mode 100644 index 0000000000000000000000000000000000000000..b73cf4e89e8e061ab46b56f4f9deca45317cf6b1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types.ts b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types.ts new file mode 100644 index 0000000000000000000000000000000000000000..7b1f0fca49bf26d95959794c6fa677c23524a465 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/arkts-sendable-generic-types.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 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 { A, A1, A as A2, B, B1, B as B2, C, C1, C as C2 } from './lib-dependencie'; + +class D {} +interface T {} + +let a1 = new A(); +let a2 = new A1(); +let a3 = new A2(); +let a4 = new A(); +let a5 = new A1(); +let a6 = new A2(); +let a7 = new A(); +let a8 = new A1(); +let a9 = new A2(); + +let b1 = new B(); +let b2 = new B1(); +let b3 = new B2(); +let b4 = new B(); +let b5 = new B1(); +let b6 = new B2(); +let b7 = new B(); +let b8 = new B1(); +let b9 = new B2(); + +let c1 = new C(); +let c2 = new C1(); +let c3 = new C2(); +let c4 = new C(); +let c5 = new C1(); +let c6 = new C2(); +let c7 = new C(); +let c8 = new C1(); +let c9 = new C2(); diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/lib-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/lib-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..751dd77e7c576fc458d817993f5147128760c0f0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-generic-types/lib-dependencie.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 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 { lang } from './@arkts.lang' + +@Sendable +class A {} +export { A, A as A1 } + +@Sendable +class B { + public value: number = 0 +} +export { B, B as B1 } + +@Sendable +class C implements lang.ISendable { + public value: number = 0 +} +export { C, C as C1 } diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..55e0ba5fc87eac28ef482d962f2957fbfd49f21a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-1-ok.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClassA { + a: number = 1 +} + +@Sendable +class SendableClassB { + b: SendableClassA = new SendableClassA() +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..ede3b495a44060e0d13f504d6c001e05236e5c7a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-1-ok.json @@ -0,0 +1,19 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..66f06028dd1155d43f5cdac9d9d6394d438347a6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-2-ok.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClassA { + static a: number = 1; +} + +@Sendable +class SendableClassB { + b: number = A.a +} + +@Sendable +class C { + static public a: number = 1; + f(p: number) { + @Sendable + class D { + public b: number = C.a; // ERROR + } + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..2ab62d6e79934e433722f9faaf4c5f4e7397060a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-2-ok.json @@ -0,0 +1,33 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 30, + "character": 5 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..b9e725b8be664f78d8ec15348f65c42ef3e6b36b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-3-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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. + */ + +if (true) { + @Sendable + class SendableClassA { + static a: number = 1; + } + + @Sendable + class SendableClassB { + b: SendableClassA = new SendableClassA() + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..1e18f0d6a096c0769dcd33b6bb4b0f8050eb3ee6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-3-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 5 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 24, + "character": 33 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..d154a4f6b3ac16b4ffae1ef9cd8d9c239ebaac5e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-4-error.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 a: number = 1; + +@Sendable +class SendableClassA { + b: number = a +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..cd7b36268f8f352a76747ad99e8f3537bb88ce41 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-4-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 20, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb7fd307ceec8a51bb086bb2c9a8f4e598eabcac --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-5-error.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClassA { + a: number = 1 +} + +@Sendable +class SendableClassB { + method() { + let a = SendableClassA + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..50e109c8f5eb241ed471c99c71d3d65229badd23 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-5-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 24, + "character": 17 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "expectLineAndCharacter": { + "line": 24, + "character": 17 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..70de79874800507d8964785cc2d45559bc224b1c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-6-error.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClassA { + a: number +} + +@Sendable +class SendableClassB extends SendableClassA { + a1: number = 1 +} + +@Sendable +class SendableClassC { + method() { + let p = (new SendableClassB() as SendableClassA) + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ee840e212524aa8ea11848ff29417339598998ea --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-6-error.json @@ -0,0 +1,41 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Property 'a' has no initializer and is not definitely assigned in the constructor.", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Property 'a' has no initializer and is not definitely assigned in the constructor.", + "expectLineAndCharacter": { + "line": 18, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..7afc5ca93429371321b629dd9fd08b65696b6c73 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-7-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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. + */ + +funtion foo() { + +} + +@Sendable +class SendableClassA { + method() { + let a = foo + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9cecc6273e5d46da770bffe5b4d15b6a3411c459 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-7-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + }, + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 13 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "expectLineAndCharacter": { + "line": 23, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..daf009463b7b65d7c09d8c1bcdbe37839cac9deb --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-8-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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. + */ + +@Sendable +class SendableClassA { + p: number = 1 +} +let a:SendableClassA = new SendableClassA() + +@Sendable +class SendableClassB { + ma: SendableClassA = a +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f6d83a1cb4b6601032322bde66cf23aaee04b57f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-imported-variables/arkts-sendable-imported-variables-8-error.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 16, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 24, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/@arkts.lang.d.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/@arkts.lang.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..40e381dc2a3c9c96df3b6278ed74fe7a71922dc9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/@arkts.lang.d.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + +declare namespace lang { + interface ISendable {} +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab02282116b4d57669f5877ed87ad6eaf4fef994 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-error.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +interface INonSendable {}; +let vArray = [1, 2]; +let vObj1: INonSendable = {} +let vObj2: lang.ISendable = {} // should report, arkts-sendable-obj-init +interface ISendableExtend1 extends lang.ISendable {} +let vObj3: ISendableExtend1 = {} // should report, arkts-sendable-obj-init + +@Sendable +class BaseSendClass1 {} +@Sendable +class BaseSendClass2 implements lang.ISendable {} + +/* // cmp `let a1:BaseSendClass1 = new BaseSendClass1();` */ +/* // cmp `let a2:BaseSendClass1 = 1;` */ +/* // cmp `let a3:BaseSendClass1 = '1';` */ +let a4:BaseSendClass1 = {}; // should report, arkts-sendable-obj-init +let a5:BaseSendClass1 = [1, 2]; // should report, arkts-sendable-obj-init +/* // cmp `let a6:BaseSendClass1 = vArray;` */ +let a7:BaseSendClass1 = vObj1; // should report, arkts-no-structural-typing +let a8:BaseSendClass2 = vObj1; // should report, arkts-no-structural-typing +/* // cmp `let a9:BaseSendClass1 = true;` */ \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..75a04f35df2b0f7e023ee954ef5fbc07af0b1da8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-error.json @@ -0,0 +1,62 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 37, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 38, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 34, + "character": 25 + } + }, + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 35, + "character": 25 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 37, + "character": 5 + } + }, + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 38, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5d26befec104fc7269553de7aa13764a56a15fee --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-ok.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +interface INonSendable {}; +let vArray = [1, 2]; +let vObj1: INonSendable = {} +/* // cmp `let vObj2: lang.ISendable = {} // should report, arkts-sendable-obj-init` */ +interface ISendableExtend1 extends lang.ISendable {} +/* // cmp `let vObj3: ISendableExtend1 = {} // should report, arkts-sendable-obj-init` */ + +@Sendable +class BaseSendClass1 {} +@Sendable +class BaseSendClass2 implements lang.ISendable {} + +let a1:BaseSendClass1 = new BaseSendClass1(); +let a2:BaseSendClass1 = 1; // Native support, when class is {} +let a3:BaseSendClass1 = '1'; // Native support, when class is {} +/* // cmp `let a4:BaseSendClass1 = {}; // should report, arkts-sendable-obj-init` */ +/* // cmp `let a5:BaseSendClass1 = [1, 2]; // should report, arkts-sendable-obj-init` */ +let a6:BaseSendClass1 = vArray; // Native support, when class is {} +/* // cmp `let a7:BaseSendClass1 = vObj1; // should report, arkts-no-structural-typing` */ +/* // cmp `let a8:BaseSendClass2 = vObj1; // should report, arkts-no-structural-typing` */ +let a9:BaseSendClass1 = true; // Native support, when class is {} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..a2087685ba1ebcd05325fe580d00ec4b7e78560a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-1-ok.json @@ -0,0 +1,27 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 28, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Structural typing is not supported (arkts-no-structural-typing)", + "expectLineAndCharacter": { + "line": 36, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..c6c3fb280d263f1f7d81120ca7f479d598b66643 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-error.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable +class BaseSendClass1 {} +class BaseNonSendableClass1 {} + +interface A { + p1: BaseSendClass1 + p2: BaseSendClass1 + p3: BaseSendClass1 + p4: BaseSendClass1 + p5: BaseSendClass1 + p6: BaseSendClass1 + p7: BaseSendClass1 + p8: BaseSendClass1 | BaseNonSendableClass1 + p9: BaseNonSendableClass1 +} + +interface INonSendable {}; +let vArray = [1, 2]; +let vObj1: INonSendable = {} + +// Because vObj1 triggers rule arkts-no-structural-typing convert to arkts-no-untyped-obj-literals. +let v: A = { + p1: new BaseSendClass1(), + p2: 1, + p3: '1', + p4: vObj1, + p5: vArray, + p6: {}, + p7: [], + p8: {}, + p9: {} +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..96db0497d3c89499a744c25f2123a408ffaed58d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + }, + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 38, + "character": 12 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "expectLineAndCharacter": { + "line": 38, + "character": 12 + } + }, + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 44, + "character": 7 + } + }, + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 45, + "character": 7 + } + }, + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 46, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..86b3a46d1f1cc58001839d297a65de74ad420399 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-ok.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable +class BaseSendClass1 {} +class BaseNonSendableClass1 {} + +interface A { + p1: BaseSendClass1 + p2: BaseSendClass1 + p3: BaseSendClass1 + p4: BaseSendClass1 + p5: BaseSendClass1 + p6: BaseSendClass1 + p7: BaseSendClass1 + p8: BaseSendClass1 | BaseNonSendableClass1 + p9: BaseNonSendableClass1 +} + +let v: A = { + p1: new BaseSendClass1(), + p2: new BaseSendClass1(), + p3: new BaseSendClass1(), + p4: new BaseSendClass1(), + p5: new BaseSendClass1(), + p6: new BaseSendClass1(), + p7: new BaseSendClass1(), + p8: new BaseNonSendableClass1(), + p9: new BaseNonSendableClass1(), +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..0cd2b238fe4735f679f979d61cb2d784d05fd538 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-2-ok.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a145d8ee3283ce6fe22726298f31e05400931d8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-3-error.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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. + */ + + +@Sendable +class SendableClass9 { + // should report, arkts-sendable-obj-init + public prop1: SendableClass9 = { prop1: new SendableClass9(), prop2: new SendableClass9() }; + // should report, arkts-sendable-obj-init + public prop2: SendableClass9 = [1, 2]; +} + +// should report, arkts-sendable-obj-init +let v0: SendableClass9 = { prop1: new SendableClass9(), prop2: new SendableClass9() }; +// should report, arkts-sendable-obj-init +let v1: SendableClass9 = [1, 2]; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..d3dfba1b48f9abb211018bcbc374a8ea2b00ec1d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init-3-error.json @@ -0,0 +1,41 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 17, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 20, + "character": 34 + } + }, + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 22, + "character": 34 + } + }, + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 26, + "character": 26 + } + }, + { + "messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)", + "expectLineAndCharacter": { + "line": 28, + "character": 26 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init.json new file mode 100644 index 0000000000000000000000000000000000000000..9faef86fe1c77593b138c4f74ef7c6d48791f297 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 18, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init.ts b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init.ts new file mode 100644 index 0000000000000000000000000000000000000000..973b8769c97bb4f99c5550943d847df9599a0fe1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/arkts-sendable-obj-init.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 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 { A, A1, A as A2, B, B1, B as B2, C, C1, C as C2 } from './lib-dependencie'; +import { I, J } from './lib-dependencie'; + +let a1: A = {}; +let a2: A1 = {}; +let a3: A2 = {}; +let b1: B = { value: 0 }; +let b2: B1 = { value: 0 }; +let b3: B2 = { value: 0 }; +let c1: C = { value: 0 }; +let c2: C1 = { value: 0 }; +let c3: C2 = { value: 0 }; + +let i = { v: 0 }; +let j = { v: 0, u: 0 }; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/lib-dependencie.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/lib-dependencie.ets new file mode 100644 index 0000000000000000000000000000000000000000..5815fa586c24a69939c1140c2281fe40051fbb1a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-obj-init/lib-dependencie.ets @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 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 { lang } from './@arkts.lang' + +@Sendable +class A {} +export { A, A as A1 } + +@Sendable +class B {} +export { B, B as B1 } + +@Sendable +class C implements lang.ISendable { + public value: number = 0 +} +export { C, C as C1 } + +export interface I extends lang.ISendable { + v: number; +} + +export interface J extends I { + u: number; +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d1a01ea2a2efb8da4a06e82524f7efbd72074a5 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-error.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +class NonSendableClass2 {} +@Sendable +class SendableClass10 {} +type alias0 = number | null; +type alias1 = SendableClass10; +type alias2 = NonSendableClass2; +type alias3 = NonSendableClass2 | undefined; + +@Sendable +class SendableClass3 { + public prop1: string[]; // should report, arkts-sendable-prop-types + public prop2: NonSendableClass2; // should report, arkts-sendable-prop-types + public prop3: NonSendableClass2 | null; // should report, arkts-sendable-prop-types + public prop4: NonSendableClass2 | undefined; // should report, arkts-sendable-prop-types + public prop5: NonSendableClass2 | null | undefined; // should report, arkts-sendable-prop-types + public prop6: alias2; // should report, arkts-sendable-prop-types + public prop7: alias3; // should report, arkts-sendable-prop-types + + constructor() { + this.prop1 = [''] + this.prop2 = new NonSendableClass2(); // should report, arkts-sendable-imported-variables + this.prop3 = null; + this.prop4 = undefined; + this.prop5 = undefined; + this.prop6 = new NonSendableClass2(); // should report, arkts-sendable-imported-variables + this.prop7 = undefined; + } +} + + +class B {} + +@Sendable +class C {} + +interface A extends lang.ISendable { + c: B; // should report, arkts-sendable-prop-types +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..481c9fbf08850254ffd09ce151c31952257b8bc8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-error.json @@ -0,0 +1,90 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 51, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 39, + "character": 22 + } + }, + { + "messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)", + "expectLineAndCharacter": { + "line": 43, + "character": 22 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 29, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 30, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 31, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 32, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 33, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 34, + "character": 3 + } + }, + { + "messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)", + "expectLineAndCharacter": { + "line": 35, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b57ba23a8a560066e65e30fe90ba4ef3dfe7f6bd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-ok.ets @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 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 { lang } from '../common-lib/@arkts.lang'; + +class NonSendableClass2 {} +@Sendable +class SendableClass10 {} +type alias0 = number | null; +type alias1 = SendableClass10; +type alias2 = NonSendableClass2; +type alias3 = NonSendableClass2 | undefined; + +@Sendable +class SendableClass4 { + public prop1: number; // OK + public prop2: string; // OK + public prop3: boolean; // OK + public prop4: bigint; // OK + public prop5: SendableClass10; // OK + public prop6: null; // OK + public prop7: undefined; // OK + public prop8: U; // OK + public prop9: T | number | undefined; // OK + public prop10: alias0; // OK + public prop11: alias1; // OK + + constructor(u: U, t: T) { + this.prop1 = 1; + this.prop2 = ''; + this.prop3 = true; + this.prop4 = BigInt(11111); + this.prop5 = new SendableClass10(); + this.prop6 = null; + this.prop7 = undefined; + this.prop8 = u; + this.prop9 = undefined; + this.prop10 = null; + this.prop11 = new SendableClass10(); + } +} + + +class B {} +@Sendable +class C {} + +interface A extends lang.ISendable { + a: number; // OK + b: C; // OK +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..d77ab0234c611d925ef211da9b717fbea0e9d188 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-prop-types/arkts-sendable-prop-types-1-ok.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 20, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 27, + "character": 1 + } + }, + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 58, + "character": 1 + } + } + ], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-declaration/arkts-sendable-typealias-declaration-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-declaration/arkts-sendable-typealias-declaration-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..e6329748bf38471c1298dedc603f09b64d4d060d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-declaration/arkts-sendable-typealias-declaration-1-error.ets @@ -0,0 +1,16 @@ +@Sendable +type Sft = () => void; // OK +@Sendable +type Sft2 = () => void; // OK +@Sendable +type Sft3 = (p:T) => T; // OK +@Sendable +type Sft5 = number; // ERROR +@Sendable +type Sft6 = Sft; // ERROR +type Sft7 = () => void; + +@Sendable +type Sft8 = Sft4; // ERROR + +type Nft = () => void; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-declaration/arkts-sendable-typealias-declaration-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-declaration/arkts-sendable-typealias-declaration-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..48a6ce9272268569e2ba178a27b11685b3f2b623 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-declaration/arkts-sendable-typealias-declaration-1-error.json @@ -0,0 +1,26 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Only \"FunctionType\" can declare \"Sendable\" typeAlias (arkts-sendable-typeAlias-declaration)", + "expectLineAndCharacter": { + "line": 8, + "character": 13 + } + }, + { + "messageText": "Only \"FunctionType\" can declare \"Sendable\" typeAlias (arkts-sendable-typeAlias-declaration)", + "expectLineAndCharacter": { + "line": 10, + "character": 13 + } + }, + { + "messageText": "Only \"FunctionType\" can declare \"Sendable\" typeAlias (arkts-sendable-typeAlias-declaration)", + "expectLineAndCharacter": { + "line": 14, + "character": 13 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-decorator/arkts-sendable-typealias-decorator-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-decorator/arkts-sendable-typealias-decorator-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca74ef3c695ee7408db6276a62e2b5ec92281857 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-decorator/arkts-sendable-typealias-decorator-1-error.ets @@ -0,0 +1,3 @@ +@Sendable +@Other // ERROR +type Sft = () => void; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-decorator/arkts-sendable-typealias-decorator-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-decorator/arkts-sendable-typealias-decorator-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..34528be2df06684267a982086afe772a74d23e65 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-sendable-typealias-decorator/arkts-sendable-typealias-decorator-1-error.json @@ -0,0 +1,12 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [ + { + "messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" typeAlias (arkts-sendable-typealias-decorator)", + "expectLineAndCharacter": { + "line": 2, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/@arkts.lang.d.ets b/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/@arkts.lang.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..c47866c59e9c8b254d719a14375de40728160dd0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/@arkts.lang.d.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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. + */ + +declare namespace lang { + interface ISendable {} +} + +export { lang }; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/shared-module.ets b/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/shared-module.ets new file mode 100644 index 0000000000000000000000000000000000000000..76da83c646af0213be1bac7c58ce21a4dd8ab0b4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/shared-module.ets @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2024 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 {lang} from "@arkts.lang"; + +'use shared' + +export const enum A{a, b} // ok, const enum is sendable type +export enum B{a, b} // error, enum is not sendable type +export let var1: number | A; // ok, union type of const enum and number +export let var2: A.a; // error, enum member is not sendable type + +export class C{} // error, class is not sendable type +@Sendable +export class D{} // ok, sendable class is sendable type +export {D as DD}; +export let var3: A | C; //error + +export interface E{} // error, interface is not sendable type +type ee = E; +export {ee}; // error +let var4: C | ee; +export {var4}; // error + +export * as ns from '@arkts.lang'; // err, ns is not sendable type +export * from '@arkts.lang'; // error, export * from 'xxx' is not supported +export default D; // ok + +export let var6: A | A.a; // error, union type of sendable and unsendbale +export let var7: string | B = 'aaa'; // error , union type of sendable and unsendbale +export let var8 = var7; // ok, no explicit type, the inferred type of var8 is string +namespace ns { + export let a: C; // ok, exports from namespace is not checked +} + +export {ns} // error, ns is not sendable type + +function fun: boolean() {} +export {fun} + +@Sendable +export function sf():void { +} + +@Sendable +function sf2():void { +} +export {sf2}; + +export const primitive_str = 'a'; // OK +export const primitive_num = 1; // OK +export const primitive_bool = true; // OK +export const primitive_big = 1n; // OK + +export enum NormalEnum { // ERROR, + a, + b, + c, + d +} + +export const enum ConstEnum { // OK + a, + b, + c, + d +} + +export const unite1 = // ERROR + Math.random() < 0.5 + ? NormalEnum.a + : primitive_str; + +export const unite2 = Math.random() < 0.5 ? primitive_str : primitive_big; // OK + +export { + primitive_str as strAlias, + primitive_num as numAlias, + primitive_bool as boolAlias, + primitive_big as bigAlias, + NormalEnum as NormalEnumAlas // ERROR +}; + +export type TypeC = C; // ERROR +export type TypeE = E; // ERROR diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/shared-module.json b/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/shared-module.json new file mode 100644 index 0000000000000000000000000000000000000000..74a7f2566cc6c8bbae9b83fc33663f095eb09a08 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-shared-module-exports/shared-module.json @@ -0,0 +1,139 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 21, + "character": 13 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 23, + "character": 12 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 25, + "character": 14 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 29, + "character": 12 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 31, + "character": 18 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 33, + "character": 9 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 35, + "character": 9 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 37, + "character": 13 + } + }, + { + "messageText": "\"export * from ...\" is not allowed in shared module (arkts-shared-module-no-wildcard-export)", + "expectLineAndCharacter": { + "line": 38, + "character": 1 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 41, + "character": 12 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 42, + "character": 12 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 48, + "character": 9 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 51, + "character": 9 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 67, + "character": 13 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 81, + "character": 14 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 93, + "character": 17 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 96, + "character": 1 + } + }, + { + "messageText": "Only \"Sendable\" entities can be exported in shared module (arkts-shared-module-exports)", + "expectLineAndCharacter": { + "line": 97, + "character": 1 + } + } + ] + } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..18f4a7aecb9980a2bb96640462cd41712b7667e8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-1-error.ets @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Use @ts-nocheck to turn off type checking + +// @ts-nocheck +let s: string = null + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a2f7ea27d793c2e34fd036efa81c323110240068 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-1-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f4572a76b6685afea0644e15abd0397fb7d2bf8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-10-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Turn off type checking and declare variables correctly + +// @ts-nocheck +let s: string = 'abc' diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a2f7ea27d793c2e34fd036efa81c323110240068 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-10-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8267d369c83b7a39ed2f2ffb46da9512be430945 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-2-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Use @ts-ignore to turn off type checking + +// @ts-ignore +let s: string = null \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a2f7ea27d793c2e34fd036efa81c323110240068 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..85be24142e0379b1e9018740338b63cbc956cfc8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-3-ok.ets @@ -0,0 +1,19 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Do not turn off type checking + +let s: string | null = null \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-4-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-4-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..84bce3e12db7e9a71048fea0f8e7f08ff59ee397 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-4-error.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Use both @ts-ignore and @ts-nocheck to close type checking + +// @ts-nocheck +let s1: string = null // no error + +// @ts-ignore +let s2: string = null // no error \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-4-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-4-error.json new file mode 100644 index 0000000000000000000000000000000000000000..8dc7ed9d778d525d20b73f6acc71c5468f41df15 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-4-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1dd3e8742fd3b33cf94ceaa1c17542ce979febea --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-5-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Use multiple @ts-ignore + +// @ts-ignore +let s: string = null // no error + +// @ts-ignore +let t: string = null // no error + +// @ts-ignore +let r: string = null // no error \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..f98c9d8ab3da16b660664c7379f9e74e7c35181d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-5-error.json @@ -0,0 +1,48 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + }, + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + }, + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c736884bd474873449a9e510ec4346974849ec6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-6-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Use @ts-check + +// @ts-check +const x: number = 'hello'; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1afaefee2f1fcddbcd862fef3156fae69ecb979e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-7-error.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Use @ts-expect-error + +// @ts-expect-error +const x: number = 'hello'; \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..a2f7ea27d793c2e34fd036efa81c323110240068 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-7-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)", + "expectLineAndCharacter": { + "line": 19, + "character": 1 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..1170f5a2670e2c8ba97b7f126e5d868467a11617 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-8-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Do not turn off type checking and declare multiple variables + +let s1: string | null = null +let s2: boolean | null = false +let s3: number = 12345 +let s4: string[] = ['1', '2', '3',] + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..bea6df0c1d44645ff91ac513b9c959cde8d34128 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-9-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description : Do not turn off type checking and declare variables in conditions + +let condition = true + +if (condition) { + let s1: string | null = null +} else { + let s2: number = 12345 +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing-required/arkts-strict-typing-required-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a7ffaad120a57f0eb05f4affa530bcb6c99ed9b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-1-error.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Declaring a class is not initialized + +class C { + name: string + age: number +} + +let c = new C() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..35100a5b651fbb1822fc8c125c8da95ef9b69d10 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-1-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Property 'name' has no initializer and is not definitely assigned in the constructor.", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Property 'age' has no initializer and is not definitely assigned in the constructor.", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Property 'name' has no initializer and is not definitely assigned in the constructor.", + "expectLineAndCharacter": { + "line": 20, + "character": 3 + } + }, + { + "messageText": "Property 'age' has no initializer and is not definitely assigned in the constructor.", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-10-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-10-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..894d19f4d601b77e8c18e43801d04db03fe462f7 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-10-ok.ets @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The function takes an argument to an interface type and returns a string. + +interface Person { + name: string; + age: number; +} + +function getName(person: Person): string { + return person.name; +} + diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-10-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-10-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-10-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-11-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-11-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff00decd405599af821ae979d9c983604328f380 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-11-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +function foo(s: string): string { + if (s != '') { + console.log(s) + return s + } else { + console.log(s) + } +} + +let n: number = null \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-11-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-11-error.json new file mode 100644 index 0000000000000000000000000000000000000000..ae253627a8728352695fe3d63bc38d29afb3b909 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-11-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function lacks ending return statement and return type does not include 'undefined'.", + "expectLineAndCharacter": { + "line": 17, + "character": 26 + } + }, + { + "messageText": "Type 'null' is not assignable to type 'number'.", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function lacks ending return statement and return type does not include 'undefined'.", + "expectLineAndCharacter": { + "line": 17, + "character": 26 + } + }, + { + "messageText": "Type 'null' is not assignable to type 'number'.", + "expectLineAndCharacter": { + "line": 26, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..924121d9823d631e1223cca6fc07f7db83f9bc43 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-2-ok.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Declare a class and use a deterministic assignment assertion + +class C { + name: string = '' + age!: number + + initAge(age: number) { + this.age = age + } +} + +let c = new C() +c.initAge(10) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..396c106ac8dd131ee28fe102057ebbd636cf253e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-2-ok.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "expectLineAndCharacter": { + "line": 21, + "character": 3 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..d47005064559c257a3e620a96e18071fa7d5651a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-3-ok.ets @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Declare the variable type correctly + +function foo(s: string): string { + console.log(s) + return s +} + +let n1: number | null = null +let n2: number = 0 \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..11623e223563577616f2825c785d1333db698bc8 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-4-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The function return value is of the correct type + +function bar(flag: boolean): string { + if (flag) { + return "true"; + } else { + return "false"; + } +} +bar(true) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-5-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-5-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..8419d3572e5f9cebf32200f1ed0eec0d5e10f925 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-5-error.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The function return value is incorrect + +function fn(flag: boolean): string { + if (flag) { + return "true"; + } + // There is no default return statement +} + +fn(true) \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-5-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-5-error.json new file mode 100644 index 0000000000000000000000000000000000000000..2fa5794231d195c0d224c7ef2b8b69ea54bb31f4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-5-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Function lacks ending return statement and return type does not include 'undefined'.", + "expectLineAndCharacter": { + "line": 19, + "character": 29 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Function lacks ending return statement and return type does not include 'undefined'.", + "expectLineAndCharacter": { + "line": 19, + "character": 29 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-6-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-6-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ea028392a07740ee9c1126bca0e491b4d92889f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-6-ok.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Strict match function return value + +type AddFunction = (a: number, b: number) => number; +const add: AddFunction = (a, b) => a + b; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-6-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-6-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-6-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-7-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-7-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab40d7fd166f13f1806fecdc6cbc229d6f3421ae --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-7-ok.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Declare a class and initialize it + +class Example { + numberProperty: number = 0; + stringProperty: string = "initial value"; +} + +let e1 = new Example() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-7-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-7-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-7-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-8-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-8-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..b64de3e59152e2601d7557a2061aac404805c149 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-8-ok.ets @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: Declare a class and initialize it + +class Example { + optionalProperty?: string; + constructor() { + this.optionalProperty = "initialized"; + } +} + +let e1 = new Example() diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-8-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-8-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-8-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-9-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-9-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..6561c80816c5cf437a0df18a62fd19e4983ac425 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-9-ok.ets @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 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. +*/ + + +// Description: The function takes a parameter of a generic type and returns an array of that argument. + +function toArray(value: T): T[] { + return [value]; +} + +const array = toArray("Hello, TypeScript!"); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-9-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-9-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict-typing/arkts-strict-typing-9-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-1-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-1-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..dabb4f3dd1d186b2de8bced5e9b0a8e19735e079 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-1-error.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 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 {doSomething, TestClassC, TestClassD} from './test'; + +class TestClassB { + private c: TestClassD | undefined = new TestClassD(); + add() { + doSomething({ + topic: (topic: string) => { + let a = new TestClassC(); + this.c = a; + this.c = a; + } + }, '') + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-1-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-1-error.json new file mode 100644 index 0000000000000000000000000000000000000000..99d0a8a14e7eef765f32127fb0d341d27c70586b --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-1-error.json @@ -0,0 +1,13 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type 'TestClassC' is not assignable to type 'TestClassD'.", + "expectLineAndCharacter": { + "line": 25, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + ] + } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-2-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-2-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4851c27d3f611f277eed824f51a727ec38354602 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-2-error.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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 {doSomething, TestClassC, TestClassD, test} from './test'; + +class TestClassB { + private c: TestClassD | undefined = new TestClassD(); + add() { + doSomething({ + topic: (topic: string) => { + let a = new TestClassC(); + this.c = a; + this.c = a; + } + }, ''); + let b = new TestClassC(); + test(b); + test(b); + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-2-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-2-error.json new file mode 100644 index 0000000000000000000000000000000000000000..b679bd5e85a19eed44909bdd279ba8c38745e09a --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-2-error.json @@ -0,0 +1,20 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Type 'TestClassC' is not assignable to type 'TestClassD'.", + "expectLineAndCharacter": { + "line": 24, + "character": 9 + } + }, + { + "messageText": "Type 'TestClassC' is not assignable to type 'TestClassD'.", + "expectLineAndCharacter": { + "line": 25, + "character": 9 + } + } + ], + "arktsVersion_1_1": [ + ] + } \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-3-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-3-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..97fd4b684918a75e48f87ab8af366061cfa63fa0 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-3-error.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 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 {CallbackType, callback} from './unknow-type'; + +function fooLocal(callback: CallbackType): void { + +} + +fooLocal(callback); +fooLocal(callback); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-3-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-3-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9c035a0fff0f125bde99e50a328b8829b338cefc --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict/arkts-strict-3-error.json @@ -0,0 +1,13 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Argument of type '(name: string, param: Object) => void' is not assignable to parameter of type 'CallbackType'.", + "expectLineAndCharacter": { + "line": 23, + "character": 10 + } + } + ], + "arktsVersion_1_1": [ + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict/test.ts b/ets2panda/linter/arkTSTest/testcase/arkts-strict/test.ts new file mode 100644 index 0000000000000000000000000000000000000000..ff18c09d44fe94507960c893be9c53c829b7a3c6 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict/test.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 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 interface a { + test: (topic: string) => void; +} + +export function doSomething(a: a, topic: string): void {} + +export class TestClassC { + public ccc: null = null; +} + +export class TestClassD { + public ccc: string = ''; +} + +export function test(b: TestClassD): void {} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-strict/unknow-type.ts b/ets2panda/linter/arkTSTest/testcase/arkts-strict/unknow-type.ts new file mode 100644 index 0000000000000000000000000000000000000000..4e783ea9e588bddb38f281cd3499c135e4c4c537 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-strict/unknow-type.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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 type CallbackType = (name: string, param: unknown) => void; + +export const callback = (name: string, param: Object): void => {}; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-1-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-1-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a37a4b9aadd95c99222372491180aeda724a45e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-1-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of types (classes, interfaces, enums) and namespaces must be unique and different from other names (e.g., variable names, function names). The names of the two classes are not the same +type: Positive example +*/ +class Add { + constructor() {} + calculate(x: number, y: number): number { + return x + y; + } +} +class Subtract { + calculate(x: number, y: number): number { + return x - y; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-1-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-1-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-1-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-10-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-10-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f69b2869821b35b8e7d830d888cc9b63ac7b6ac --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-10-error.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of types (classes, interfaces, enums) and namespaces must be unique and different from other names (e.g., variable names, function names). +Negative example: The interface name conflicts with the type name +*/ +interface Car { + brand: string; + model: string; +} + +class Car { + foo() { + console.log("foo"); + } +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-10-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-10-error.json new file mode 100644 index 0000000000000000000000000000000000000000..e1d6f98c987b76a001c4014a51c0c5a27fdc4083 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-10-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 26, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 11 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 26, + "character": 7 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-2-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-2-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..48bd65d9ce287ebea1ad6b6dbcf3623fd96f2f2c --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-2-ok.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of the two interfaces are not the same +type: Positive example +*/ +interface Person { + name: string; + age: number; +} + +interface Animal { + species: string; + age: number; +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-2-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-2-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-2-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-3-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-3-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d564fde4f51f9ef6a8be70dda9cb51ea049fb80 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-3-ok.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of the two enumerations are not the same +type: Positive example +*/ +enum Direction { + Up, + Down, + Left, + Right, +} + +enum Color { + Red, + Green, + Blue, +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-3-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-3-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-3-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-4-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-4-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..678ece15eca097d532e2eaae5a4bfd106fe4893f --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-4-ok.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of the two namespaces are not the same +type: Positive example +*/ +namespace Geometry { + export class Circle { + private radius: number; + constructor(radus: number) { + this.radius = radus; + } + calculateArea(): number { + return Math.PI * this.radius * this.radius; + } + } +} + +namespace Utilities { + export class Rectangle { + private width: number; + private height: number; + constructor(width: number, height: number) { + this.width = width; + this.height = height; + } + + calculateArea(): number { + return this.width * this.height; + } + } +} + +const circle = new Geometry.Circle(5); +const rectangle = new Utilities.Rectangle(4, 6); \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-4-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-4-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-4-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-5-ok.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-5-ok.ets new file mode 100644 index 0000000000000000000000000000000000000000..5fd8665bb1ccd1dfbfaa831be68083753dcdaf9e --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-5-ok.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of the classes and interfaces are not the same +type: Positive example +*/ +interface Animal { + species: string; + age: number; +} + +class Add { + constructor() {} + calculate(x: number, y: number): number { + return x + y; + } +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-5-ok.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-5-ok.json new file mode 100644 index 0000000000000000000000000000000000000000..27f2271930a16e3a6eef2797ef552f56afd1417d --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-5-ok.json @@ -0,0 +1,4 @@ +{ + "arktsVersion_1_0": [], + "arktsVersion_1_1": [] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-6-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-6-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d425c66711a551dbb7a41b347f43889b632c9a4 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-6-error.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of types (classes, interfaces, enums) and namespaces must be unique and different from other names (e.g., variable names, function names). +Counterexample: The variable name and type name are the same +*/ +let X: string; +type X = number[]; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-6-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-6-error.json new file mode 100644 index 0000000000000000000000000000000000000000..9ecc2eecdb43c333b1dd587f5e779416e7160436 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-6-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 5 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 22, + "character": 6 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-7-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-7-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..3aaa71512b0570395598a66b206d2b24fd281ec1 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-7-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of types (classes, interfaces, enums) and namespaces must be unique and different from other names (e.g., variable names, function names). +Counterexample: The interface name and function name conflict +*/ +interface Person { + name: string; + age: number; +} +function Person(name: string, age: number) { + // Function definition, same name as interface +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-7-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-7-error.json new file mode 100644 index 0000000000000000000000000000000000000000..bb823eaa787a3dae93aa10d359870b1b97b8aeda --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-7-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 11 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 25, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-8-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-8-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..02fbd3c3f51bb186bde39b9b73af0eb37f4653b9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-8-error.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of types (classes, interfaces, enums) and namespaces must be unique and different from other names (e.g., variable names, function names). +Counterexample: Namespace and variable names conflict +*/ +namespace Geometry { + // Namespace definition +} + +let Geometry: string; diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-8-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-8-error.json new file mode 100644 index 0000000000000000000000000000000000000000..c8aa08121ec95e32dd1c6a089d33ae3e793d19dd --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-8-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 25, + "character": 5 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 11 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 25, + "character": 5 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-9-error.ets b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-9-error.ets new file mode 100644 index 0000000000000000000000000000000000000000..1751a12092aba41ee25d0ee82137a03322782da2 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-9-error.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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. + */ + + +/* +description:The names of types (classes, interfaces, enums) and namespaces must be unique and different from other names (e.g., variable names, function names). +Counterexample: Namespace and function naming conflicts +*/ +namespace Geometry { + // Namespace definition +} + +function Geometry() { + // Function with same name as namespace +} diff --git a/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-9-error.json b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-9-error.json new file mode 100644 index 0000000000000000000000000000000000000000..bb823eaa787a3dae93aa10d359870b1b97b8aeda --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/arkts-unique-names/arkts-unique-names-9-error.json @@ -0,0 +1,34 @@ +{ + "arktsVersion_1_0": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 1 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 25, + "character": 1 + } + } + ], + "arktsVersion_1_1": [ + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 21, + "character": 11 + } + }, + { + "messageText": "Use unique names for types and namespaces. (arkts-unique-names)", + "expectLineAndCharacter": { + "line": 25, + "character": 10 + } + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/arkTSTest/testcase/common-lib/@arkts.lang.d.ets b/ets2panda/linter/arkTSTest/testcase/common-lib/@arkts.lang.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..40e381dc2a3c9c96df3b6278ed74fe7a71922dc9 --- /dev/null +++ b/ets2panda/linter/arkTSTest/testcase/common-lib/@arkts.lang.d.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + +declare namespace lang { + interface ISendable {} +} diff --git a/ets2panda/linter/arkTSTest/tsconfig.json b/ets2panda/linter/arkTSTest/tsconfig.json new file mode 100644 index 0000000000000000000000000000000000000000..f134e99076baa07bf23adc06691aa78455e0c58a --- /dev/null +++ b/ets2panda/linter/arkTSTest/tsconfig.json @@ -0,0 +1,803 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "ets": { + "emitDecorators":[ + { + "name":"Entry", + "emitParameters" : true + }, + { + "name":"Component", + "emitParameters" : false + }, + { + "name":"CustomDialog", + "emitParameters" : false + }, + { + "name":"Consume", + "emitParameters" : true + }, + { + "name":"Link", + "emitParameters" : false + }, + { + "name":"LocalStorageLink", + "emitParameters" : true + }, + { + "name":"LocalStorageProp", + "emitParameters" : true + }, + { + "name":"ObjectLink", + "emitParameters" : false + }, + { + "name":"Prop", + "emitParameters" : false + }, + { + "name":"Provide", + "emitParameters" : true + }, + { + "name":"State", + "emitParameters" : false + }, + { + "name":"StorageLink", + "emitParameters" : true + }, + { + "name":"StorageProp", + "emitParameters" : true + }, + { + "name":"Builder", + "emitParameters" : false + }, + { + "name":"BuilderParam", + "emitParameters" : false + }, + { + "name":"Observed", + "emitParameters" : false + } + ], + "propertyDecorators": [ + { + "name": "Link", + "needInitialization": false + }, + { + "name": "Prop", + "needInitialization": false + }, + { + "name": "ObjectLink", + "needInitialization": false + }, + { + "name": "Consume", + "needInitialization": false + } + ], + "render": { + "method": ["build", "pageTransition"], + "decorator": ["Builder", "LocalBuilder"] + }, + "components": [ + "AbilityComponent", + "AlphabetIndexer", + "Animator", + "Badge", + "Blank", + "Button", + "Calendar", + "CalendarPicker", + "Camera", + "Canvas", + "Checkbox", + "CheckboxGroup", + "Circle", + "ColorPicker", + "ColorPickerDialog", + "Column", + "ColumnSplit", + "Counter", + "DataPanel", + "DatePicker", + "Divider", + "EffectComponent", + "Ellipse", + "Flex", + "FormComponent", + "FormLink", + "Gauge", + "GeometryView", + "Grid", + "GridItem", + "GridContainer", + "Hyperlink", + "Image", + "ImageAnimator", + "Line", + "List", + "ListItem", + "ListItemGroup", + "LoadingProgress", + "Marquee", + "Menu", + "MenuItem", + "MenuItemGroup", + "NavDestination", + "NavRouter", + "Navigation", + "Navigator", + "Option", + "PageTransitionEnter", + "PageTransitionExit", + "Panel", + "Particle", + "Path", + "PatternLock", + "Piece", + "PluginComponent", + "Polygon", + "Polyline", + "Progress", + "QRCode", + "Radio", + "Rating", + "Rect", + "Refresh", + "RelativeContainer", + "RemoteWindow", + "RootScene", + "Row", + "RowSplit", + "RichText", + "Screen", + "Scroll", + "ScrollBar", + "Search", + "Section", + "Select", + "Shape", + "Sheet", + "SideBarContainer", + "Slider", + "Span", + "Stack", + "Stepper", + "StepperItem", + "Swiper", + "TabContent", + "Tabs", + "Text", + "TextPicker", + "TextClock", + "TextArea", + "TextInput", + "TextTimer", + "TimePicker", + "Toggle", + "Video", + "Web", + "WindowScene", + "XComponent", + "GridRow", + "GridCol", + "WaterFlow", + "FlowItem", + "ImageSpan", + "LocationButton", + "PasteButton", + "SaveButton", + "UIExtensionComponent", + "RichEditor" + ], + "extend": { + "decorator": ["Extend", "AnimatableExtend"], + "components": [ + { + "name": "AbilityComponent", + "type": "AbilityComponentAttribute", + "instance": "AbilityComponentInstance" + }, + { + "name": "AlphabetIndexer", + "type": "AlphabetIndexerAttribute", + "instance": "AlphabetIndexerInstance" + }, + { + "name": "Animator", + "type": "AnimatorAttribute", + "instance": "AnimatorInstance" + }, + { + "name": "Badge", + "type": "BadgeAttribute", + "instance": "BadgeInstance" + }, + { + "name": "Blank", + "type": "BlankAttribute", + "instance": "BlankInstance" + }, + { + "name": "Button", + "type": "ButtonAttribute", + "instance": "ButtonInstance" + }, + { + "name": "Calendar", + "type": "CalendarAttribute", + "instance": "CalendarInstance" + }, + { + "name": "CalendarPicker", + "type": "CalendarPickerAttribute", + "instance": "CalendarPickerInstance" + }, + { + "name": "Camera", + "type": "CameraAttribute", + "instance": "CameraInstance" + }, + { + "name": "Canvas", + "type": "CanvasAttribute", + "instance": "CanvasInstance" + }, + { + "name": "Checkbox", + "type": "CheckboxAttribute", + "instance": "CheckboxInstance" + }, + { + "name": "CheckboxGroup", + "type": "CheckboxGroupAttribute", + "instance": "CheckboxGroupInstance" + }, + { + "name": "Circle", + "type": "CircleAttribute", + "instance": "CircleInstance" + }, + { + "name": "ColorPicker", + "type": "ColorPickerAttribute", + "instance": "ColorPickerInstance" + }, + { + "name": "ColorPickerDialog", + "type": "ColorPickerDialogAttribute", + "instance": "ColorPickerDialogInstance" + }, + { + "name": "Column", + "type": "ColumnAttribute", + "instance": "ColumnInstance" + }, + { + "name": "ColumnSplit", + "type": "ColumnSplitAttribute", + "instance": "ColumnSplitInstance" + }, + { + "name": "Counter", + "type": "CounterAttribute", + "instance": "CounterInstance" + }, + { + "name": "DataPanel", + "type": "DataPanelAttribute", + "instance": "DataPanelInstance" + }, + { + "name": "DatePicker", + "type": "DatePickerAttribute", + "instance": "DatePickerInstance" + }, + { + "name": "Divider", + "type": "DividerAttribute", + "instance": "DividerInstance" + }, + { + "name": "EffectComponent", + "type": "EffectComponentAttribute", + "instance": "EffectComponentInstance" + }, + { + "name": "Ellipse", + "type": "EllipseAttribute", + "instance": "EllipseInstance" + }, + { + "name": "Flex", + "type": "FlexAttribute", + "instance": "FlexInstance" + }, + { + "name": "FormComponent", + "type": "FormComponentAttribute", + "instance": "FormComponentInstance" + }, + { + "name": "FormLink", + "type": "FormLinkAttribute", + "instance": "FormLinkInstance" + }, + { + "name": "Gauge", + "type": "GaugeAttribute", + "instance": "GaugeInstance" + }, + { + "name": "GeometryView", + "type": "GeometryViewAttribute", + "instance": "GeometryViewInstance" + }, + { + "name": "Grid", + "type": "GridAttribute", + "instance": "GridInstance" + }, + { + "name": "GridItem", + "type": "GridItemAttribute", + "instance": "GridItemInstance" + }, + { + "name": "GridContainer", + "type": "GridContainerAttribute", + "instance": "GridContainerInstance" + }, + { + "name": "Hyperlink", + "type": "HyperlinkAttribute", + "instance": "HyperlinkInstance" + }, + { + "name": "Image", + "type": "ImageAttribute", + "instance": "ImageInstance" + }, + { + "name": "ImageAnimator", + "type": "ImageAnimatorAttribute", + "instance": "ImageAnimatorInstance" + }, + { + "name": "Line", + "type": "LineAttribute", + "instance": "LineInstance" + }, + { + "name": "List", + "type": "ListAttribute", + "instance": "ListInstance" + }, + { + "name": "ListItem", + "type": "ListItemAttribute", + "instance": "ListItemInstance" + }, + { + "name": "ListItemGroup", + "type": "ListItemGroupAttribute", + "instance": "ListItemGroupInstance" + }, + { + "name": "LoadingProgress", + "type": "LoadingProgressAttribute", + "instance": "LoadingProgressInstance" + }, + { + "name": "Marquee", + "type": "MarqueeAttribute", + "instance": "MarqueeInstance" + }, + { + "name": "Menu", + "type": "MenuAttribute", + "instance": "MenuInstance" + }, + { + "name": "MenuItem", + "type": "MenuItemAttribute", + "instance": "MenuItemInstance" + }, + { + "name": "MenuItemGroup", + "type": "MenuItemGroupAttribute", + "instance": "MenuItemGroupInstance" + }, + { + "name": "NavDestination", + "type": "NavDestinationAttribute", + "instance": "NavDestinationInstance" + }, + { + "name": "NavRouter", + "type": "NavRouterAttribute", + "instance": "NavRouterInstance" + }, + { + "name": "Navigation", + "type": "NavigationAttribute", + "instance": "NavigationInstance" + }, + { + "name": "Navigator", + "type": "NavigatorAttribute", + "instance": "NavigatorInstance" + }, + { + "name": "Option", + "type": "OptionAttribute", + "instance": "OptionInstance" + }, + { + "name": "PageTransitionEnter", + "type": "PageTransitionEnterAttribute", + "instance": "PageTransitionEnterInstance" + }, + { + "name": "PageTransitionExit", + "type": "PageTransitionExitAttribute", + "instance": "PageTransitionExitInstance" + }, + { + "name": "Panel", + "type": "PanelAttribute", + "instance": "PanelInstance" + }, + { + "name": "Particle", + "type": "ParticleAttribute", + "instance": "ParticleInstance" + }, + { + "name": "Path", + "type": "PathAttribute", + "instance": "PathInstance" + }, + { + "name": "PatternLock", + "type": "PatternLockAttribute", + "instance": "PatternLockInstance" + }, + { + "name": "Piece", + "type": "PieceAttribute", + "instance": "PieceInstance" + }, + { + "name": "PluginComponent", + "type": "PluginComponentAttribute", + "instance": "PluginComponentInstance" + }, + { + "name": "Polygon", + "type": "PolygonAttribute", + "instance": "PolygonInstance" + }, + { + "name": "Polyline", + "type": "PolylineAttribute", + "instance": "PolylineInstance" + }, + { + "name": "Progress", + "type": "ProgressAttribute", + "instance": "ProgressInstance" + }, + { + "name": "QRCode", + "type": "QRCodeAttribute", + "instance": "QRCodeInstance" + }, + { + "name": "Radio", + "type": "RadioAttribute", + "instance": "RadioInstance" + }, + { + "name": "Rating", + "type": "RatingAttribute", + "instance": "RatingInstance" + }, + { + "name": "Rect", + "type": "RectAttribute", + "instance": "RectInstance" + }, + { + "name": "RelativeContainer", + "type": "RelativeContainerAttribute", + "instance": "RelativeContainerInstance" + }, + { + "name": "Refresh", + "type": "RefreshAttribute", + "instance": "RefreshInstance" + }, + { + "name": "RemoteWindow", + "type": "RemoteWindowAttribute", + "instance": "RemoteWindowInstance" + }, + { + "name": "RootScene", + "type": "RootSceneAttribute", + "instance": "RootSceneInstance" + }, + { + "name": "Row", + "type": "RowAttribute", + "instance": "RowInstance" + }, + { + "name": "RowSplit", + "type": "RowSplitAttribute", + "instance": "RowSplitInstance" + }, + { + "name": "RichText", + "type": "RichTextAttribute", + "instance": "RichTextInstance" + }, + { + "name": "Screen", + "type": "ScreenAttribute", + "instance": "ScreenInstance" + }, + { + "name": "Scroll", + "type": "ScrollAttribute", + "instance": "ScrollInstance" + }, + { + "name": "ScrollBar", + "type": "ScrollBarAttribute", + "instance": "ScrollBarInstance" + }, + { + "name": "Search", + "type": "SearchAttribute", + "instance": "SearchInstance" + }, + { + "name": "Section", + "type": "SectionAttribute", + "instance": "SectionInstance" + }, + { + "name": "Select", + "type": "SelectAttribute", + "instance": "SelectInstance" + }, + { + "name": "Shape", + "type": "ShapeAttribute", + "instance": "ShapeInstance" + }, + { + "name": "Sheet", + "type": "SheetAttribute", + "instance": "SheetInstance" + }, + { + "name": "SideBarContainer", + "type": "SideBarContainerAttribute", + "instance": "SideBarContainerInstance" + }, + { + "name": "Slider", + "type": "SliderAttribute", + "instance": "SliderInstance" + }, + { + "name": "Span", + "type": "SpanAttribute", + "instance": "SpanInstance" + }, + { + "name": "Stack", + "type": "StackAttribute", + "instance": "StackInstance" + }, + { + "name": "Stepper", + "type": "StepperAttribute", + "instance": "StepperInstance" + }, + { + "name": "StepperItem", + "type": "StepperItemAttribute", + "instance": "StepperItemInstance" + }, + { + "name": "Swiper", + "type": "SwiperAttribute", + "instance": "SwiperInstance" + }, + { + "name": "TabContent", + "type": "TabContentAttribute", + "instance": "TabContentInstance" + }, + { + "name": "Tabs", + "type": "TabsAttribute", + "instance": "TabsInstance" + }, + { + "name": "Text", + "type": "TextAttribute", + "instance": "TextInstance" + }, + { + "name": "TextPicker", + "type": "TextPickerAttribute", + "instance": "TextPickerInstance" + }, + { + "name": "TextClock", + "type": "TextClockAttribute", + "instance": "TextClockInstance" + }, + { + "name": "TextArea", + "type": "TextAreaAttribute", + "instance": "TextAreaInstance" + }, + { + "name": "TextInput", + "type": "TextInputAttribute", + "instance": "TextInputInstance" + }, + { + "name": "TextTimer", + "type": "TextTimerAttribute", + "instance": "TextTimerInstance" + }, + { + "name": "TimePicker", + "type": "TimePickerAttribute", + "instance": "TimePickerInstance" + }, + { + "name": "Toggle", + "type": "ToggleAttribute", + "instance": "ToggleInstance" + }, + { + "name": "Video", + "type": "VideoAttribute", + "instance": "VideoInstance" + }, + { + "name": "Web", + "type": "WebAttribute", + "instance": "WebInstance" + }, + { + "name": "WindowScene", + "type": "WindowSceneAttribute", + "instance": "WindowSceneInstance" + }, + { + "name": "XComponent", + "type": "XComponentAttribute", + "instance": "XComponentInstance" + }, + { + "name": "GridRow", + "type": "GridRowAttribute", + "instance": "GridRowInstance" + }, + { + "name": "GridCol", + "type": "GridColAttribute", + "instance": "GridColInstance" + }, + { + "name": "WaterFlow", + "type": "WaterFlowAttribute", + "instance": "WaterFlowInstance" + }, + { + "name": "FlowItem", + "type": "FlowItemAttribute", + "instance": "FlowItemInstance" + }, + { + "name": "ImageSpan", + "type": "ImageSpanAttribute", + "instance": "ImageSpanInstance" + }, + { + "name": "LocationButton", + "type": "LocationButtonAttribute", + "instance": "LocationButtonInstance" + }, + { + "name": "PasteButton", + "type": "PasteButtonAttribute", + "instance": "PasteButtonInstance" + }, + { + "name": "SaveButton", + "type": "SaveButtonAttribute", + "instance": "SaveButtonInstance" + }, + { + "name": "UIExtensionComponent", + "type": "UIExtensionComponentAttribute", + "instance": "UIExtensionComponentInstance" + }, + { + "name": "RichEditor", + "type": "RichEditorAttribute", + "instance": "RichEditorInstance" + } + ] + }, + "styles": { + "decorator": "Styles", + "component": { + "name": "Common", + "type": "T", + "instance": "CommonInstance" + }, + "property": "stateStyles" + }, + "concurrent": { + "decorator": "Concurrent" + }, + "customComponent": "CustomComponent", + "syntaxComponents": { + "paramsUICallback": [ + "ForEach", + "LazyForEach" + ], + "attrUICallback": [ + { + "name": "Repeat", + "attributes": ["each", "template"] + } + ] + } + }, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + // "importsNotUsedAsValues": "preserve", + "noImplicitAny": false, + "noUnusedLocals": false, + "noUnusedParameters": false, + "experimentalDecorators": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "module": "commonjs", + "target": "es2021", + "types": [], + "typeRoots": [], + "lib": [ + "es2021" + ], + "alwaysStrict": true + }, + "exclude": [ + "node_modules" + ] +} diff --git a/ets2panda/linter/babel.config.js b/ets2panda/linter/babel.config.js new file mode 100644 index 0000000000000000000000000000000000000000..2d61ee448c02555eda118137957c8089f2c3fb0e --- /dev/null +++ b/ets2panda/linter/babel.config.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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. + */ + +module.exports = function(api) { + api.cache(true); + + const presets = ['@babel/typescript']; + const plugins = [ + '@babel/plugin-transform-modules-commonjs', + '@babel/plugin-proposal-class-properties', + '@babel/plugin-transform-class-static-block', + [ + '@babel/plugin-transform-arrow-functions', + { + spec: true + } + ] + ]; +const sourceMaps = true; + return { + presets, + plugins, + sourceMaps + }; +}; diff --git a/ets2panda/linter/lib/CommandLineOptions.ts b/ets2panda/linter/lib/CommandLineOptions.ts index efc6dbde60d9c79ea4ac7bc31f7984ec3b386c8b..99da19e069ba7f295e1adb1e35a0877d0a57fd57 100644 --- a/ets2panda/linter/lib/CommandLineOptions.ts +++ b/ets2panda/linter/lib/CommandLineOptions.ts @@ -24,4 +24,5 @@ export interface CommandLineOptions { inputFiles: string[]; enableAutofix: boolean; arkts2: boolean; + enableUseRtLogic?: boolean; } diff --git a/ets2panda/linter/lib/CookBookMsg.ts b/ets2panda/linter/lib/CookBookMsg.ts index 3bc7f2cf00f1f5ee271d7ae3d23a32def1024726..c2f9701ef14d70a3d7e6622849ac06344c19cbef 100644 --- a/ets2panda/linter/lib/CookBookMsg.ts +++ b/ets2panda/linter/lib/CookBookMsg.ts @@ -23,7 +23,7 @@ for (let i = 0; i <= 183; i++) { cookBookTag[1] = 'Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)'; cookBookTag[2] = '"Symbol()" API is not supported (arkts-no-symbol)'; -cookBookTag[3] = 'Private \'#\' identifiers are not supported (arkts-no-private-identifiers)'; +cookBookTag[3] = 'Private "#" identifiers are not supported (arkts-no-private-identifiers)'; cookBookTag[4] = 'Use unique names for types and namespaces. (arkts-unique-names)'; cookBookTag[5] = 'Use "let" instead of "var" (arkts-no-var)'; cookBookTag[6] = ''; @@ -164,7 +164,7 @@ cookBookTag[136] = 'Prototype assignment is not supported (arkts-no-prototype-as cookBookTag[137] = '"globalThis" is not supported (arkts-no-globalthis)'; cookBookTag[138] = 'Some of utility types are not supported (arkts-no-utility-types)'; cookBookTag[139] = 'Declaring properties on functions is not supported (arkts-no-func-props)'; -cookBookTag[140] = '"Function.bind" is not supported (arkts-no-func-bind)'; +cookBookTag[140] = '\'Function.bind\' is not supported (arkts-no-func-bind)'; cookBookTag[141] = ''; cookBookTag[142] = '"as const" assertions are not supported (arkts-no-as-const)'; cookBookTag[143] = 'Import assertions are not supported (arkts-no-import-assertions)'; @@ -175,13 +175,13 @@ cookBookTag[147] = 'No dependencies on TypeScript code are currently allowed (ar cookBookTag[148] = ''; cookBookTag[149] = 'Classes cannot be used as objects (arkts-no-classes-as-obj)'; cookBookTag[150] = '"import" statements after other statements are not allowed (arkts-no-misplaced-imports)'; -cookBookTag[151] = 'Usage of "ESObject" type is restricted (arkts-limited-esobj)'; -cookBookTag[152] = '"Function.apply", "Function.call" are not supported (arkts-no-func-apply-call)'; +cookBookTag[151] = 'Usage of \'ESObject\' type is restricted (arkts-limited-esobj)'; +cookBookTag[152] = '\'Function.apply\', \'Function.call\' are not supported (arkts-no-func-apply-call)'; cookBookTag[153] = 'The inheritance for "Sendable" classes is limited (arkts-sendable-class-inheritance)'; cookBookTag[154] = 'Properties in "Sendable" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)'; cookBookTag[155] = - 'Definite assignment assertion in not allowed in "Sendable" classes (arkts-sendable-definite-assignment)'; + 'Definite assignment assertion is not allowed in "Sendable" classes (arkts-sendable-definite-assignment)'; cookBookTag[156] = 'Type arguments of generic "Sendable" type must be a "Sendable" data type (arkts-sendable-generic-types)'; cookBookTag[157] = 'Only imported variables can be captured by "Sendable" class (arkts-sendable-imported-variables)'; @@ -203,15 +203,15 @@ cookBookTag[167] = 'In sdk ts files, "Sendable" class and "Sendable" interface can not be exported (arkts-no-dts-sendable-type-export)'; cookBookTag[168] = 'In ts files, entities from ets files can not be re-exported (arkts-no-ts-re-export-ets)'; cookBookTag[169] = - 'Namespace import are nbot allowed for importing from ets to ts file (arkts-no-namespace-import-in-ts-import-ets)'; + 'Namespace import is not allowed for importing from ets to ts file (arkts-no-namespace-import-in-ts-import-ets)'; cookBookTag[170] = - 'Side effect import are not allowed for importing from ets to ts file (arkts-no-side-effect-import-in-ts-import-ets)'; + 'Side effect import is not allowed for importing from ets to ts file (artkts-no-side-effect-import-in-ts-import-ets)'; cookBookTag[171] = 'Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)'; cookBookTag[172] = 'Only imported variables can be captured by "Sendable" function (arkts-sendable-function-imported-variables)'; cookBookTag[173] = 'Only "@Sendable" decorator can be used on "Sendable" function (arkts-sendable-function-decorator)'; cookBookTag[174] = - 'Only "@Sendable" decorator can be used on "Sendable" typeAlias (arkts-sendable-typeAlias-decorator)'; + 'Only "@Sendable" decorator can be used on "Sendable" typeAlias (arkts-sendable-typealias-decorator)'; cookBookTag[175] = 'Only "FunctionType" can declare "Sendable" typeAlias (arkts-sendable-typeAlias-declaration)'; cookBookTag[176] = 'Only "Sendable" function or "Sendable" typeAlias object can be assigned to "Sendable" typeAlias (arkts-sendable-function-assignment)'; @@ -221,7 +221,7 @@ cookBookTag[178] = 'The property of "Sendable" function is limited (arkts-sendab cookBookTag[179] = 'Casting "Non-sendable" function to "Sendable" typeAlias is not allowed (arkts-sendable-function-as-expr)'; cookBookTag[180] = - 'The "@Sendable" decorator can only be used on "class", "function", "typeAlias" (arkts-sendable-decorator-limited)'; + 'The "@Sendable" decorator can only be used on "class", "function" and "typeAlias" (arkts-sendable-decorator-limited)'; cookBookTag[181] = 'The exported "Sendable" class or function cannot be captured by "Sendable" class or function in current file (arkts-sendable-closure-export)'; cookBookTag[182] = diff --git a/ets2panda/linter/lib/FaultAttrs.ts b/ets2panda/linter/lib/FaultAttrs.ts index 9d553324d35c1fe684b5aad96338ca53e063c287..b00b9d29c42fa8f582813564f604e81a2d205497 100644 --- a/ets2panda/linter/lib/FaultAttrs.ts +++ b/ets2panda/linter/lib/FaultAttrs.ts @@ -127,7 +127,7 @@ faultsAttrs[FaultID.SendableTypeInheritance] = new FaultAttributes(166); faultsAttrs[FaultID.SendableTypeExported] = new FaultAttributes(167); faultsAttrs[FaultID.NoTsReExportEts] = new FaultAttributes(168); faultsAttrs[FaultID.NoNameSpaceImportEtsToTs] = new FaultAttributes(169); -faultsAttrs[FaultID.NoSIdeEffectImportEtsToTs] = new FaultAttributes(170); +faultsAttrs[FaultID.NoSideEffectImportEtsToTs] = new FaultAttributes(170); faultsAttrs[FaultID.SendableExplicitFieldType] = new FaultAttributes(171); faultsAttrs[FaultID.SendableFunctionImportedVariables] = new FaultAttributes(172); faultsAttrs[FaultID.SendableFunctionDecorator] = new FaultAttributes(173); diff --git a/ets2panda/linter/lib/FaultDesc.ts b/ets2panda/linter/lib/FaultDesc.ts index 3793c05f19b1438404e6a70ce652bca55d90ad03..16a290f01b71c19b4fac38cf587670e024045447 100644 --- a/ets2panda/linter/lib/FaultDesc.ts +++ b/ets2panda/linter/lib/FaultDesc.ts @@ -114,7 +114,7 @@ faultDesc[FaultID.NoTsImportEts] = 'No ts Import Ets'; faultDesc[FaultID.SendableTypeInheritance] = 'Sendable type inheritance'; faultDesc[FaultID.SendableTypeExported] = 'Sendable type exported'; faultDesc[FaultID.NoTsReExportEts] = 'No ts re-export ets'; -faultDesc[FaultID.NoSIdeEffectImportEtsToTs] = 'No side effect import ets to ts'; +faultDesc[FaultID.NoSideEffectImportEtsToTs] = 'No side effect import ets to ts'; faultDesc[FaultID.NoNameSpaceImportEtsToTs] = 'No namespace import ets to ts'; faultDesc[FaultID.SendableExplicitFieldType] = 'Field in sendable class must have type annotation'; faultDesc[FaultID.SendableFunctionImportedVariables] = 'Sendable function imported variables'; diff --git a/ets2panda/linter/lib/InteropTypescriptLinter.ts b/ets2panda/linter/lib/InteropTypescriptLinter.ts index cc6222e59f02a9b7d9d9c4259145a278706235e5..0937079c8d6f31b3bda1a54adab258f58e5bdc32 100644 --- a/ets2panda/linter/lib/InteropTypescriptLinter.ts +++ b/ets2panda/linter/lib/InteropTypescriptLinter.ts @@ -24,7 +24,7 @@ import { ProblemSeverity } from './ProblemSeverity'; import { FaultID } from './Problems'; import { LinterConfig } from './TypeScriptLinterConfig'; import { cookBookRefToFixTitle } from './autofixes/AutofixTitles'; -import type { Autofix, Autofixer } from './autofixes/Autofixer'; +import type { Autofix } from './autofixes/Autofixer'; import { TsUtils } from './utils/TsUtils'; import { ARKTS_COLLECTIONS_D_ETS, ARKTS_LANG_D_ETS } from './utils/consts/SupportedDetsIndexableTypes'; import { D_ETS, D_TS, ETS, KIT } from './utils/consts/TsSuffix'; @@ -69,8 +69,6 @@ export class InteropTypescriptLinter { currentErrorLine: number; currentWarningLine: number; - autofixer: Autofixer | undefined; - private sourceFile?: ts.SourceFile; private isInSdk?: boolean; static ideMode: boolean = false; @@ -78,9 +76,12 @@ export class InteropTypescriptLinter { static kitInfos = new Map(); private static etsLoaderPath?: string; private static sdkPath?: string; - static useSdkLogic = false; static advancedClassChecks = false; + static initGlobals(): void { + InteropTypescriptLinter.kitInfos = new Map(); + } + private initCounters(): void { for (let i = 0; i < FaultID.LAST_ID; i++) { this.nodeCounters[i] = 0; @@ -92,13 +93,14 @@ export class InteropTypescriptLinter { private readonly tsTypeChecker: ts.TypeChecker, private readonly compileOptions: ts.CompilerOptions, private readonly arkts2: boolean, - etsLoaderPath: string | undefined + etsLoaderPath: string | undefined, + isUseRtLogic?: boolean ) { this.tsUtils = new TsUtils( this.tsTypeChecker, InteropTypescriptLinter.testMode, InteropTypescriptLinter.advancedClassChecks, - InteropTypescriptLinter.useSdkLogic, + !!isUseRtLogic, this.arkts2 ); this.currentErrorLine = 0; @@ -198,20 +200,14 @@ export class InteropTypescriptLinter { private visitSourceFile(sf: ts.SourceFile): void { const callback = (node: ts.Node): void => { this.totalVisitedNodes++; - - const incrementedType = LinterConfig.incrementOnlyTokens.get(node.kind); - if (incrementedType !== undefined) { - this.incrementCounters(node, incrementedType); - } else { - const handler = this.handlersMap.get(node.kind); - if (handler !== undefined) { - - /* - * possibly requested cancellation will be checked in a limited number of handlers - * checked nodes are selected as construct nodes, similar to how TSC does - */ - handler.call(this, node); - } + const handler = this.handlersMap.get(node.kind); + if (handler !== undefined) { + + /* + * possibly requested cancellation will be checked in a limited number of handlers + * checked nodes are selected as construct nodes, similar to how TSC does + */ + handler.call(this, node); } }; const stopCondition = (node: ts.Node): boolean => { @@ -273,7 +269,7 @@ export class InteropTypescriptLinter { } if (!importClause) { - this.incrementCounters(node, FaultID.NoNameSpaceImportEtsToTs); + this.incrementCounters(node, FaultID.NoSideEffectImportEtsToTs); return; } this.checkImportClause(importClause, resolvedModule); diff --git a/ets2panda/linter/lib/LinterRunner.ts b/ets2panda/linter/lib/LinterRunner.ts index 70fb9a04b3cb6ebe93be3ba8120480390187f6ba..3c5d0a575a775e35575e25357174f1392c213be5 100644 --- a/ets2panda/linter/lib/LinterRunner.ts +++ b/ets2panda/linter/lib/LinterRunner.ts @@ -35,6 +35,7 @@ import { import { mergeArrayMaps } from './utils/functions/MergeArrayMaps'; import { pathContainsDirectory } from './utils/functions/PathHelper'; import { LibraryTypeCallDiagnosticChecker } from './utils/functions/LibraryTypeCallDiagnosticChecker'; +import { DEFAULT_COMPATIBLE_SDK_VERSION } from './utils/consts/VersionInfo'; function prepareInputFilesList(cmdOptions: CommandLineOptions): string[] { let inputFiles = cmdOptions.inputFiles; @@ -110,12 +111,13 @@ export function lint(options: LintOptions, etsLoaderPath: string | undefined): L tsProgram.getTypeChecker(), cmdOptions.enableAutofix, cmdOptions.arkts2, + !!cmdOptions.enableUseRtLogic, options.cancellationToken, options.incrementalLintInfo, tscStrictDiagnostics, options.reportAutofixCb, options.isEtsFileCb, - options.compatibleSdkVersion, + Number(options.compatibleSdkVersion) || DEFAULT_COMPATIBLE_SDK_VERSION, options.compatibleSdkVersionStage ) : new InteropTypescriptLinter( @@ -131,7 +133,6 @@ export function lint(options: LintOptions, etsLoaderPath: string | undefined): L const [errorNodesTotal, warningNodes] = countProblems(linter); logTotalProblemsInfo(errorNodesTotal, warningNodes, linter); logProblemsPercentageByFeatures(linter); - return { errorNodes: errorNodesTotal, problemsInfos: mergeArrayMaps(problemsInfos, transformTscDiagnostics(tscStrictDiagnostics)) diff --git a/ets2panda/linter/lib/Problems.ts b/ets2panda/linter/lib/Problems.ts index f6085be1b2be26c0b508d2550bdfbd1da77341c9..482567ed0fa44d18127de15006131d1127967436 100644 --- a/ets2panda/linter/lib/Problems.ts +++ b/ets2panda/linter/lib/Problems.ts @@ -116,7 +116,7 @@ export enum FaultID { SendableTypeExported, NoTsReExportEts, NoNameSpaceImportEtsToTs, - NoSIdeEffectImportEtsToTs, + NoSideEffectImportEtsToTs, SendableExplicitFieldType, SendableFunctionImportedVariables, SendableFunctionDecorator, diff --git a/ets2panda/linter/lib/TypeScriptLinter.ts b/ets2panda/linter/lib/TypeScriptLinter.ts index 5f6fd2ee51f398bdb88778dac62c42c1418c7b04..65514d9197ccdcf42748f83c8ea87b555c4c1dcf 100644 --- a/ets2panda/linter/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/lib/TypeScriptLinter.ts @@ -96,7 +96,6 @@ export class TypeScriptLinter { currentErrorLine: number; currentWarningLine: number; - walkedComments: Set; libraryTypeCallDiagnosticChecker: LibraryTypeCallDiagnosticChecker; supportedStdCallApiChecker: SupportedStdCallApiChecker; @@ -113,7 +112,6 @@ export class TypeScriptLinter { static ideMode: boolean = false; static testMode: boolean = false; static useRelaxedRules = false; - static useSdkLogic = false; static advancedClassChecks = false; static initGlobals(): void { @@ -147,29 +145,29 @@ export class TypeScriptLinter { private readonly tsTypeChecker: ts.TypeChecker, private readonly enableAutofix: boolean, private readonly arkts2: boolean, + private readonly useRtLogic: boolean, private readonly cancellationToken?: ts.CancellationToken, private readonly incrementalLintInfo?: IncrementalLintInfo, private readonly tscStrictDiagnostics?: Map, private readonly reportAutofixCb?: ReportAutofixCallback, private readonly isEtsFileCb?: IsEtsFileCallback, - compatibleSdkVersion?: string, + compatibleSdkVersion?: number, compatibleSdkVersionStage?: string ) { this.tsUtils = new TsUtils( this.tsTypeChecker, TypeScriptLinter.testMode, TypeScriptLinter.advancedClassChecks, - TypeScriptLinter.useSdkLogic, + useRtLogic, this.arkts2 ); this.currentErrorLine = 0; this.currentWarningLine = 0; - this.walkedComments = new Set(); this.libraryTypeCallDiagnosticChecker = new LibraryTypeCallDiagnosticChecker( TypeScriptLinter.filteredDiagnosticMessages ); this.supportedStdCallApiChecker = new SupportedStdCallApiChecker(this.tsUtils, this.tsTypeChecker); - this.compatibleSdkVersion = Number(compatibleSdkVersion) || DEFAULT_COMPATIBLE_SDK_VERSION; + this.compatibleSdkVersion = compatibleSdkVersion ?? DEFAULT_COMPATIBLE_SDK_VERSION; this.compatibleSdkVersionStage = compatibleSdkVersionStage || DEFAULT_COMPATIBLE_SDK_VERSION_STAGE; this.initEtsHandlers(); this.initCounters(); @@ -648,10 +646,7 @@ export class TypeScriptLinter { private checkForLoopDestructuring(forInit: ts.ForInitializer): void { if (ts.isVariableDeclarationList(forInit) && forInit.declarations.length === 1) { const varDecl = forInit.declarations[0]; - if ( - !TypeScriptLinter.useSdkLogic && - (ts.isArrayBindingPattern(varDecl.name) || ts.isObjectBindingPattern(varDecl.name)) - ) { + if (this.useRtLogic && (ts.isArrayBindingPattern(varDecl.name) || ts.isObjectBindingPattern(varDecl.name))) { this.incrementCounters(varDecl, FaultID.DestructuringDeclaration); } } @@ -766,7 +761,7 @@ export class TypeScriptLinter { const decorators = ts.getDecorators(node); this.filterOutDecoratorsDiagnostics( decorators, - TypeScriptLinter.useSdkLogic ? NON_INITIALIZABLE_PROPERTY_DECORATORS_TSC : NON_INITIALIZABLE_PROPERTY_DECORATORS, + this.useRtLogic ? NON_INITIALIZABLE_PROPERTY_DECORATORS : NON_INITIALIZABLE_PROPERTY_DECORATORS_TSC, { begin: propName.getStart(), end: propName.getStart() }, PROPERTY_HAS_NO_INITIALIZER_ERROR_CODE ); @@ -1047,7 +1042,7 @@ export class TypeScriptLinter { private handleMissingReturnType( funcLikeDecl: ts.FunctionLikeDeclaration | ts.MethodSignature ): [boolean, ts.TypeNode | undefined] { - if (!TypeScriptLinter.useSdkLogic && funcLikeDecl.type) { + if (this.useRtLogic && funcLikeDecl.type) { return [false, funcLikeDecl.type]; } @@ -1291,7 +1286,7 @@ export class TypeScriptLinter { private handleVariableDeclaration(node: ts.Node): void { const tsVarDecl = node as ts.VariableDeclaration; if ( - TypeScriptLinter.useSdkLogic || + !this.useRtLogic || ts.isVariableDeclarationList(tsVarDecl.parent) && ts.isVariableStatement(tsVarDecl.parent.parent) ) { this.handleDeclarationDestructuring(tsVarDecl); @@ -2160,7 +2155,7 @@ export class TypeScriptLinter { this.libraryTypeCallDiagnosticChecker, inLibCall ); - if (hasFiltered) { + if (this.useRtLogic && hasFiltered) { this.filterOutDiagnostics( { begin: callExpr.getStart(), end: callExpr.getEnd() }, OBJECT_IS_POSSIBLY_UNDEFINED_ERROR_CODE @@ -2278,7 +2273,7 @@ export class TypeScriptLinter { const hasSingleTypeArgument = !!typeRef.typeArguments && typeRef.typeArguments.length === 1; let argType; - if (TypeScriptLinter.useSdkLogic) { + if (!this.useRtLogic) { const firstTypeArg = !!typeRef.typeArguments && hasSingleTypeArgument && typeRef.typeArguments[0]; argType = firstTypeArg && this.tsTypeChecker.getTypeFromTypeNode(firstTypeArg); } else { @@ -2317,9 +2312,7 @@ export class TypeScriptLinter { const spreadExprType = this.tsUtils.getTypeOrTypeConstraintAtLocation(node.expression); if ( spreadExprType && - (!TypeScriptLinter.useSdkLogic || - ts.isCallLikeExpression(node.parent) || - ts.isArrayLiteralExpression(node.parent)) && + (this.useRtLogic || ts.isCallLikeExpression(node.parent) || ts.isArrayLiteralExpression(node.parent)) && this.tsUtils.isOrDerivedFrom(spreadExprType, this.tsUtils.isArray) ) { return; @@ -2782,7 +2775,6 @@ export class TypeScriptLinter { this.autofixer = new Autofixer(this.tsTypeChecker, this.tsUtils, sourceFile, this.cancellationToken); } - this.walkedComments.clear(); this.sourceFile = sourceFile; this.fileExportSendableDeclCaches = undefined; this.visitSourceFile(this.sourceFile); @@ -2913,10 +2905,9 @@ export class TypeScriptLinter { } private handleImportType(node: ts.Node): void { - if(!this.arkts2) { + if (!this.arkts2) { return; } this.incrementCounters(node, FaultID.ImportType); } } - diff --git a/ets2panda/linter/lib/utils/TsUtils.ts b/ets2panda/linter/lib/utils/TsUtils.ts index d0f8fe72952470c04cc11ff8a6807d62bd21e161..86eb3b358183a5aeb9cac3dc3eaf426c2a770f12 100644 --- a/ets2panda/linter/lib/utils/TsUtils.ts +++ b/ets2panda/linter/lib/utils/TsUtils.ts @@ -50,7 +50,7 @@ export class TsUtils { private readonly tsTypeChecker: ts.TypeChecker, private readonly testMode: boolean, private readonly advancedClassChecks: boolean, - private readonly useSdkLogic: boolean, + private readonly useRtLogic: boolean, private readonly arkts2: boolean ) {} @@ -62,7 +62,7 @@ export class TsUtils { } isNumberLikeType(tsType: ts.Type): boolean { - if (!this.useSdkLogic && tsType.isUnion()) { + if (this.useRtLogic && tsType.isUnion()) { for (const tsCompType of tsType.types) { if ((tsCompType.flags & ts.TypeFlags.NumberLike) === 0) { return false; @@ -334,8 +334,7 @@ export class TsUtils { } // Avoid type recursion in heritage by caching checked types. - // eslint-disable-next-line no-param-reassign - (checkedBaseTypes ||= new Set()).add(tsType); + (checkedBaseTypes = checkedBaseTypes || new Set()).add(tsType); for (const tsTypeDecl of tsType.symbol.declarations) { const isClassOrInterfaceDecl = ts.isClassDeclaration(tsTypeDecl) || ts.isInterfaceDeclaration(tsTypeDecl); @@ -935,7 +934,7 @@ export class TsUtils { } getNonNullableType(t: ts.Type): ts.Type { - const isNullableUnionType = this.useSdkLogic ? t.isUnion() : TsUtils.isNullableUnionType(t); + const isNullableUnionType = this.useRtLogic ? TsUtils.isNullableUnionType(t) : t.isUnion(); if (isNullableUnionType) { return t.getNonNullableType(); } @@ -1006,9 +1005,9 @@ export class TsUtils { // eslint-disable-next-line no-nested-ternary const rhsSym = ts.isCallExpression(rhsExpr) ? this.getSymbolOfCallExpression(rhsExpr) : - this.useSdkLogic ? - this.tsTypeChecker.getSymbolAtLocation(rhsExpr) : - this.trueSymbolAtLocation(rhsExpr); + this.useRtLogic ? + this.trueSymbolAtLocation(rhsExpr) : + this.tsTypeChecker.getSymbolAtLocation(rhsExpr); if (rhsSym && this.isLibrarySymbol(rhsSym)) { return true; } @@ -1183,7 +1182,7 @@ export class TsUtils { isSymbolAPI(symbol: ts.Symbol): boolean { const parentName = this.getParentSymbolName(symbol); - if (this.useSdkLogic) { + if (!this.useRtLogic) { const name = parentName ? parentName : symbol.escapedName; return name === SYMBOL || name === SYMBOL_CONSTRUCTOR; } @@ -1191,7 +1190,7 @@ export class TsUtils { } isSymbolIterator(symbol: ts.Symbol): boolean { - if (this.useSdkLogic) { + if (!this.useRtLogic) { const name = symbol.name; const parName = this.getParentSymbolName(symbol); return (parName === SYMBOL || parName === SYMBOL_CONSTRUCTOR) && name === ITERATOR; @@ -1841,9 +1840,9 @@ export class TsUtils { return false; } - const isEts = this.useSdkLogic ? - getScriptKind(sourceFile) === ts.ScriptKind.ETS : - !!isEtsFileCb && isEtsFileCb(sourceFile); + const isEts = this.useRtLogic ? + !!isEtsFileCb && isEtsFileCb(sourceFile) : + getScriptKind(sourceFile) === ts.ScriptKind.ETS; return ( isEts && sourceFile.isDeclarationFile && @@ -1857,7 +1856,7 @@ export class TsUtils { const modifiers = ts.getModifiers(decl); return ( !!modifiers && - (this.useSdkLogic && TsUtils.hasModifier(modifiers, ts.SyntaxKind.ReadonlyKeyword) || + (!this.useRtLogic && TsUtils.hasModifier(modifiers, ts.SyntaxKind.ReadonlyKeyword) || TsUtils.hasModifier(modifiers, ts.SyntaxKind.PublicKeyword) || TsUtils.hasModifier(modifiers, ts.SyntaxKind.ProtectedKeyword) || TsUtils.hasModifier(modifiers, ts.SyntaxKind.PrivateKeyword)) @@ -2328,7 +2327,7 @@ export class TsUtils { if (isFromPrivateIdentifierOrSdk) { // eslint-disable-next-line no-param-reassign - classType ??= this.tsTypeChecker.getTypeAtLocation(tsClassLikeDecl); + classType = classType ?? this.tsTypeChecker.getTypeAtLocation(tsClassLikeDecl); const proceedClassTypeResult = this.proceedClassType(targetMember, classType, isFromPrivateIdentifier); if (proceedClassTypeResult) { return proceedClassTypeResult; @@ -2339,7 +2338,7 @@ export class TsUtils { } private isFromPrivateIdentifierOrSdk(isFromPrivateIdentifier: boolean): boolean { - return !this.useSdkLogic || isFromPrivateIdentifier; + return this.useRtLogic || isFromPrivateIdentifier; } private static isIdentifierOrPrivateIdentifier(node?: ts.PropertyName): node is ts.Identifier | ts.PrivateIdentifier { diff --git a/ets2panda/linter/package.json b/ets2panda/linter/package.json index 840b6266ddf1b44e55389364c3e5daa72ba72ad7..f260668ffd9776c59f43160a470eda3770484b55 100644 --- a/ets2panda/linter/package.json +++ b/ets2panda/linter/package.json @@ -18,21 +18,40 @@ "pack:linter": "rimraf bundle && mkdir bundle && npm pack --pack-destination bundle", "pretest": " npm run fix", "test": "npm run test_main && npm run test_rules && npm run test_regression", - "test_main": "npm run compile && rimraf test/results && node build/src/TestRunner.js test", - "test_regression": "npm run compile && rimraf test_regression/results && node build/src/TestRunner.js test_regression", - "test_rules": "npm run compile && rimraf test_rules/results && node build/src/TestRunner.js test_rules", + "test_main": "npm run compile && rimraf test/results_rt && node build/src/TestRunner.js -P:test", + "test_regression": "npm run compile && rimraf test_regression/results_rt && node build/src/TestRunner.js -P:test_regression", + "test_rules": "npm run compile && rimraf test_rules/results_rt && node build/src/TestRunner.js -P:test_rules", + "test_sdk": "npm run test_main_sdk && npm run test_rules_sdk && npm run test_regression_sdk", + "test_main_sdk": "npm run compile && rimraf test/results_sdk && node build/src/TestRunner.js -P:test -SDK", + "test_regression_sdk": "npm run compile && rimraf test_regression/results_sdk && node build/src/TestRunner.js -P:test_regression -SDK", + "test_rules_sdk": "npm run compile && rimraf test_rules/results_sdk && node build/src/TestRunner.js -P:test_rules -SDK", + "test_ts_import_ets": "npm run compile && rimraf test_ts_import_ets/ts/results_sdk && node build/src/TestRunner.js -P:test_ts_import_ets/ts -SDK -CheckTs", "test_extended_features": "npm run compile && rimraf test_extended_features/results && node build/src/TestRunner.js test_extended_features", "update-tests": "node scripts/update-test-results.mjs test test_rules test_regression test_extended_features", "eslint-check": "npx eslint --ext .ts .", "eslint-fix": "npm run eslint-check -- --fix", "prettier-fix": "npx prettier --write .", - "fix": "npm run prettier-fix && npm run eslint-fix" + "fix": "npm run prettier-fix && npm run eslint-fix", + "build_lib": "./node_modules/.bin/babel ./lib --out-dir arkTSTest/lib --extensions .ts", + "build_sdk": "./node_modules/.bin/babel ./sdk --out-dir arkTSTest/linterLib --extensions .ts", + "build_src": "./node_modules/.bin/babel ./src --out-dir arkTSTest/src --extensions .ts", + "build_utils": "./node_modules/.bin/babel ./utils --out-dir arkTSTest/utils --extensions .ts", + "build_linter": "npm run build_sdk && npm run build_lib && npm run build_src && npm run build_utils" }, "dependencies": { + "@babel/cli": "7.20.7", + "@babel/core": "7.20.12", + "@babel/plugin-proposal-class-properties": "7.18.6", + "@babel/plugin-transform-class-static-block": "^7.24.4", + "@babel/preset-env": "7.20.2", + "@babel/preset-typescript": "7.18.6", + "@babel/runtime": "7.20.13", + "babel-loader": "9.1.2", "commander": "9.4.0", "log4js": "6.4.0" }, "devDependencies": { + "@rollup/plugin-babel": "6.0.3", "@stylistic/eslint-plugin": "latest", "@types/node": "18.11.7", "@typescript-eslint/eslint-plugin": "latest", diff --git a/ets2panda/linter/sdk/ArkTSTimePrinter.ts b/ets2panda/linter/sdk/ArkTSTimePrinter.ts new file mode 100644 index 0000000000000000000000000000000000000000..606438f3935030f3669b1f82962a569279fdc57c --- /dev/null +++ b/ets2panda/linter/sdk/ArkTSTimePrinter.ts @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2024 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 enum TimePhase { + START = 'start', + GET_PROGRAM = 'getProgram(not ArkTSLinter)', + GET_REVERSE_STRICT_BUILDER_PROGRAM = 'getReverseStrictBuilderProgram', + UPDATE_ERROR_FILE = 'updateErrorFile', + INIT = 'init', + STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS = 'strictProgramGetSemanticDiagnostics', + STRICT_PROGRAM_GET_SYNTACTIC_DIAGNOSTICS = 'strictProgramGetSyntacticDiagnostics', + NON_STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS = 'nonStrictProgramGetSemanticDiagnostics', + NON_STRICT_PROGRAM_GET_SYNTACTIC_DIAGNOSTICS = 'nonStrictProgramGetSyntacticDiagnostics', + GET_TSC_DIAGNOSTICS = 'getTscDiagnostics', + EMIT_BUILD_INFO = 'emitBuildInfo', + LINT = 'lint' +} + +const MILLISECOND_TO_SECOND = 1000.0; + +export class ArkTSLinterTimePrinter { + private static instance?: ArkTSLinterTimePrinter; + private arkTSTimePrintSwitch: boolean; + private readonly timeMap = new Map(); + + private constructor(ArkTSTimePrintSwitch: boolean = false) { + this.arkTSTimePrintSwitch = ArkTSTimePrintSwitch; + } + + static getInstance(): ArkTSLinterTimePrinter { + if (!ArkTSLinterTimePrinter.instance) { + ArkTSLinterTimePrinter.instance = new ArkTSLinterTimePrinter(); + } + return ArkTSLinterTimePrinter.instance; + } + + static destroyInstance(): void { + ArkTSLinterTimePrinter.instance = undefined; + } + + setArkTSTimePrintSwitch(arkTSTimePrintSwitch: boolean): void { + this.arkTSTimePrintSwitch = arkTSTimePrintSwitch; + } + + appendTime(key: string): void { + if (this.arkTSTimePrintSwitch) { + this.timeMap.set(key, Date.now()); + } + } + + // eslint-disable-next-line class-methods-use-this + private formatMapAsTable(map: Map): string { + if (!map.has(TimePhase.START)) { + return 'ArkTSLinterTimePrinter: START phase is not exist!'; + } + let maxKeyLength = 0; + let lastVal = 0; + let sum = 0; + const printMap = new Map(map); + printMap.forEach((value, key) => { + maxKeyLength = Math.max(maxKeyLength, key.toString().length); + if (key !== TimePhase.START) { + const relativeVal = value - lastVal; + if (key !== TimePhase.GET_PROGRAM) { + sum += relativeVal; + } + printMap.set(key, relativeVal / MILLISECOND_TO_SECOND); + } + lastVal = value; + }); + printMap.set('total', sum / MILLISECOND_TO_SECOND); + + let table = ''; + printMap.forEach((value, key) => { + if (key !== TimePhase.START) { + const paddedKey = key.toString().padEnd(maxKeyLength, ' '); + table += `${paddedKey} | ${value.toString()}\n`; + } + }); + const header = `${'Phase'.padEnd(maxKeyLength, ' ')} | Time(seconds)\n`; + const FIXLENGTH = ('Phase' + 'Time').length; + const separator = '-'.repeat(maxKeyLength + FIXLENGTH) + '\n'; + return `${header}${separator}${table}`; + } + + printTimes(): void { + if (this.arkTSTimePrintSwitch) { + const formattedMap = this.formatMapAsTable(this.timeMap); + console.log(formattedMap); + } + } +} diff --git a/ets2panda/linter/sdk/linter_1_1/IncrementalLinter.ts b/ets2panda/linter/sdk/linter_1_1/IncrementalLinter.ts new file mode 100644 index 0000000000000000000000000000000000000000..2c2299b927764f49e4817c0c6c6aa13800446582 --- /dev/null +++ b/ets2panda/linter/sdk/linter_1_1/IncrementalLinter.ts @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024 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 * as ts from 'typescript'; + +export class IncrementalLinterState { + // @ts-expect-error : should expect method + private readonly changedFiles: ts.Set = new ts.Set(); + // @ts-expect-error : should expect method + private readonly programState: ts.ReusableBuilderProgramState; + private readonly oldDiagnostics: + | undefined + // @ts-expect-error : should expect method + | ts.ESMap; + + constructor(builderProgram: ts.BuilderProgram, arkTSVersion?: string) { + // @ts-expect-error : should expect method + this.programState = builderProgram.getState(); + this.oldDiagnostics = this.programState.arktsLinterDiagnosticsPerFile; + this.programState.arktsLinterDiagnosticsPerFile = new Map(); + this.changedFiles = IncrementalLinterState.collectChangedFilesFromProgramState(this.programState, arkTSVersion); + } + + isFileChanged(srcFile: ts.SourceFile): boolean { + // @ts-expect-error : should expect method + return this.changedFiles.has(srcFile.resolvedPath); + } + + getOldDiagnostics(srcFile: ts.SourceFile): ts.Diagnostic[] { + // @ts-expect-error : should expect method + return (this.oldDiagnostics?.get(srcFile.resolvedPath) as ts.Diagnostic[]) ?? []; + } + + updateDiagnostics(srcFile: ts.SourceFile, newDiagnostics: ts.Diagnostic[]): void { + // @ts-expect-error : should expect method + this.programState.arktsLinterDiagnosticsPerFile?.set(srcFile.resolvedPath, newDiagnostics); + } + + updateProgramStateArkTSVersion(arkTSVersion?: string): void { + this.programState.arkTSVersion = arkTSVersion; + } + + static emitBuildInfo(buildInfoWriteFile: ts.WriteFileCallback, builderProgram: ts.BuilderProgram): void { + // @ts-expect-error : should expect method + builderProgram.emitBuildInfo(buildInfoWriteFile); + } + + private static collectChangedFilesFromProgramState( + // @ts-expect-error : should expect method + state: ts.ReusableBuilderProgramState, + arkTSVersion?: string + ): ts.Set { + + /* + * If old arkTSVersion from last run is not same current arkTSVersion from ets_loader, + * then process all files in project. + */ + if (state.arkTSVersion !== arkTSVersion) { + // @ts-expect-error : should expect method + return new ts.Set(IncrementalLinterState.arrayFrom(state.fileInfos.keys())); + } + + // @ts-expect-error : should expect method + const changedFiles = new ts.Set(state.changedFilesSet); + + /* + * If any source file that affects global scope has been changed, + * then process all files in project. + */ + for (const changedFile of IncrementalLinterState.arrayFrom(changedFiles.keys())) { + const fileInfo = state.fileInfos.get(changedFile); + if (fileInfo?.affectsGlobalScope) { + // @ts-expect-error : should expect method + return new ts.Set(IncrementalLinterState.arrayFrom(state.fileInfos.keys())); + } + } + + if (!state.referencedMap) { + return changedFiles; + } + + // @ts-expect-error : should expect method + const seenPaths = new ts.Set(); + const queue = IncrementalLinterState.arrayFrom(changedFiles.keys()); + while (queue.length) { + const path = queue.pop()!; + if (!seenPaths.has(path)) { + seenPaths.add(path); + + // @ts-expect-error : should expect method + queue.push(...ts.BuilderState.getReferencedByPaths(state, path)); + } + } + return seenPaths; + } + + private static arrayFrom(iterator: Iterator): ts.Path[] { + const result: ts.Path[] = []; + for (let iterResult = iterator.next(); !iterResult.done; iterResult = iterator.next()) { + result.push(iterResult.value); + } + return result; + } +} diff --git a/ets2panda/linter/sdk/linter_1_1/LintParameter.ts b/ets2panda/linter/sdk/linter_1_1/LintParameter.ts new file mode 100644 index 0000000000000000000000000000000000000000..ed31ce04a21708028f02fbeffbb622cc51413b8f --- /dev/null +++ b/ets2panda/linter/sdk/linter_1_1/LintParameter.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 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 type * as ts from 'typescript'; +import type { InteropTypescriptLinter } from '../../lib/InteropTypescriptLinter'; +import type { TypeScriptLinter } from '../../lib/TypeScriptLinter'; +import type { IncrementalLinterState } from './IncrementalLinter'; + +export interface LintParameter { + incrementalLinterState: IncrementalLinterState; + typeScriptLinter: TypeScriptLinter; + interopTypescriptLinter: InteropTypescriptLinter; + tscStrictDiagnostics: Map; + diagnostics: ts.Diagnostic[]; + etsLoaderPath?: string; + tsImportSendableEnable?: boolean; +} diff --git a/ets2panda/linter/sdk/linter_1_1/RunArkTSLinter.ts b/ets2panda/linter/sdk/linter_1_1/RunArkTSLinter.ts new file mode 100644 index 0000000000000000000000000000000000000000..b67669151d785a453d3dfa811e8076e40f8114e7 --- /dev/null +++ b/ets2panda/linter/sdk/linter_1_1/RunArkTSLinter.ts @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2024 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, softwareP + * 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 * as ts from 'typescript'; +import * as path from 'node:path'; +import type { ProblemInfo } from '../../lib/ProblemInfo'; +import { ProblemSeverity } from '../../lib/ProblemSeverity'; +import { TypeScriptLinter } from '../../lib/TypeScriptLinter'; +import { getTscDiagnostics } from '../../lib/ts-diagnostics/GetTscDiagnostics'; +import { ArkTSLinterTimePrinter, TimePhase } from '../ArkTSTimePrinter'; +import { getScriptKind } from '../../lib/utils/functions/GetScriptKind'; +import { SdkTSCCompiledProgram } from './SdkTSCCompiledProgram'; +import { IncrementalLinterState } from './IncrementalLinter'; +import { InteropTypescriptLinter } from '../../lib/InteropTypescriptLinter'; +import type { SdkOptions } from './SdkOptions'; +import type { LintParameter } from './LintParameter'; +import { LibraryTypeCallDiagnosticChecker } from '../../lib/utils/functions/LibraryTypeCallDiagnosticChecker'; + +const LINTER_MSG_CODE_START = -1; + +function makeDiag( + category: ts.DiagnosticCategory, + file: ts.SourceFile, + start: number, + length: number, + messageText: string +): ts.Diagnostic { + const code = LINTER_MSG_CODE_START; + return { category, code, file, start, length, messageText }; +} + +export function translateDiag(srcFile: ts.SourceFile, problemInfo: ProblemInfo): ts.Diagnostic { + const severity = + problemInfo.severity === ProblemSeverity.ERROR ? ts.DiagnosticCategory.Error : ts.DiagnosticCategory.Warning; + const length = problemInfo.end - problemInfo.start + 1; + return makeDiag(severity, srcFile, problemInfo.start, length, problemInfo.rule); +} + +export function runArkTSLinter( + tsBuilderProgram: ts.BuilderProgram, + srcFile?: ts.SourceFile, + buildInfoWriteFile?: ts.WriteFileCallback, + arkTSVersion?: string, + sdkOptions?: SdkOptions +): ts.Diagnostic[] { + const diagnostics: ts.Diagnostic[] = []; + const tscDiagnosticsLinter = new SdkTSCCompiledProgram(tsBuilderProgram); + const program = tscDiagnosticsLinter.getProgram(); + const incrementalLinterState = new IncrementalLinterState(tsBuilderProgram, arkTSVersion); + incrementalLinterState.updateProgramStateArkTSVersion(arkTSVersion); + const timePrinterInstance = ArkTSLinterTimePrinter.getInstance(); + timePrinterInstance.appendTime(TimePhase.INIT); + tscDiagnosticsLinter.updateCompilationDiagnostics(); + const srcFiles: ts.SourceFile[] = getSrcFiles(program, srcFile); + const tscStrictDiagnostics = getTscDiagnostics( + tscDiagnosticsLinter, + srcFiles.filter((file) => { + return incrementalLinterState.isFileChanged(file); + }) + ); + timePrinterInstance.appendTime(TimePhase.GET_TSC_DIAGNOSTICS); + const etsLoaderPath = program.getCompilerOptions().etsLoaderPath; + const tsImportSendableEnable = program.getCompilerOptions().tsImportSendableEnable; + const typeScriptLinter = createTypeScriptLinter(program, tscStrictDiagnostics, sdkOptions); + LibraryTypeCallDiagnosticChecker.rebuildTscDiagnostics(tscStrictDiagnostics); + const interopTypescriptLinter = createInteropTypescriptLinter( + program, + tsBuilderProgram.getCompilerOptions(), + !!sdkOptions?.isUseRtLogic + ); + processFiles(srcFiles, { + incrementalLinterState, + typeScriptLinter, + interopTypescriptLinter, + tscStrictDiagnostics, + diagnostics, + etsLoaderPath, + tsImportSendableEnable + }); + timePrinterInstance.appendTime(TimePhase.LINT); + if (buildInfoWriteFile) { + IncrementalLinterState.emitBuildInfo(buildInfoWriteFile, tscDiagnosticsLinter.getBuilderProgram()); + timePrinterInstance.appendTime(TimePhase.EMIT_BUILD_INFO); + } + releaseResources(); + return diagnostics; +} + +function processFiles(srcFiles: ts.SourceFile[], lintParameter: LintParameter): void { + for (const fileToLint of srcFiles) { + const scriptKind = getScriptKind(fileToLint); + if (scriptKind !== ts.ScriptKind.ETS && scriptKind !== ts.ScriptKind.TS) { + continue; + } + + const currentDiagnostics = getDiagnostic(fileToLint, scriptKind, lintParameter); + lintParameter.diagnostics.push(...currentDiagnostics); + lintParameter.incrementalLinterState.updateDiagnostics(fileToLint, currentDiagnostics); + } +} + +function getDiagnostic( + fileToLint: ts.SourceFile, + scriptKind: ts.ScriptKind, + lintParameter: LintParameter +): ts.Diagnostic[] { + let currentDiagnostics: ts.Diagnostic[] = []; + if (lintParameter.incrementalLinterState.isFileChanged(fileToLint)) { + if (scriptKind === ts.ScriptKind.ETS) { + lintParameter.typeScriptLinter.lint(fileToLint); + + // Get list of bad nodes from the current run. + currentDiagnostics = lintParameter.tscStrictDiagnostics.get(path.normalize(fileToLint.fileName)) ?? []; + lintParameter.typeScriptLinter.problemsInfos.forEach((x) => { + return currentDiagnostics.push(translateDiag(fileToLint, x)); + }); + lintParameter.typeScriptLinter.problemsInfos.length = 0; + } else { + if ( + path.basename(fileToLint.fileName).toLowerCase(). + indexOf('@kit.') === 0 || + ts.isOHModules(fileToLint.fileName) + ) { + return currentDiagnostics; + } + + const isInSdk = lintParameter.etsLoaderPath ? + path. + normalize(fileToLint.fileName). + // @ts-expect-error : should expect method + indexOf(ts.resolvePath(lintParameter.etsLoaderPath, '../..')) === 0 : + false; + if (!lintParameter.tsImportSendableEnable && !isInSdk) { + return currentDiagnostics; + } + + lintParameter.interopTypescriptLinter.lint(fileToLint); + lintParameter.interopTypescriptLinter.problemsInfos.forEach((x) => { + return currentDiagnostics.push(translateDiag(fileToLint, x)); + }); + lintParameter.interopTypescriptLinter.problemsInfos.length = 0; + } + } else { + // Get diagnostics from old run. + currentDiagnostics = lintParameter.incrementalLinterState.getOldDiagnostics(fileToLint); + } + return currentDiagnostics; +} + +function getSrcFiles(program: ts.Program, srcFile?: ts.SourceFile): ts.SourceFile[] { + let srcFiles: ts.SourceFile[] = []; + if (srcFile) { + srcFiles.push(srcFile); + } else { + srcFiles = program.getSourceFiles() as ts.SourceFile[]; + } + return srcFiles; +} + +function createTypeScriptLinter( + program: ts.Program, + tscStrictDiagnostics: Map, + sdkOptions?: SdkOptions +): TypeScriptLinter { + TypeScriptLinter.initGlobals(); + TypeScriptLinter.ideMode = true; + return new TypeScriptLinter( + program.getLinterTypeChecker(), + !!sdkOptions?.needAutoFix, + false, + !!sdkOptions?.isUseRtLogic, + undefined, + undefined, + tscStrictDiagnostics, + undefined, + undefined, + program.getCompilerOptions().compatibleSdkVersion, + program.getCompilerOptions().compatibleSdkVersionStage + ); +} + +function createInteropTypescriptLinter( + program: ts.Program, + compileOptions: ts.CompilerOptions, + isUseRtLogic: boolean +): InteropTypescriptLinter { + InteropTypescriptLinter.initGlobals(); + InteropTypescriptLinter.ideMode = true; + return new InteropTypescriptLinter( + program.getLinterTypeChecker(), + compileOptions, + false, + compileOptions.etsLoaderPath, + isUseRtLogic + ); +} + +// Reclaim memory for Hvigor with "no-parallel" and "daemon". +function releaseResources(): void {} diff --git a/ets2panda/linter/sdk/linter_1_1/SdkOptions.ts b/ets2panda/linter/sdk/linter_1_1/SdkOptions.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3a6080392bd2797cdb7dbd766a25d61d8e5b3fd --- /dev/null +++ b/ets2panda/linter/sdk/linter_1_1/SdkOptions.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 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 interface SdkOptions { + needAutoFix?: boolean; + isUseRtLogic?: boolean; +} diff --git a/ets2panda/linter/sdk/linter_1_1/SdkTSCCompiledProgram.ts b/ets2panda/linter/sdk/linter_1_1/SdkTSCCompiledProgram.ts new file mode 100644 index 0000000000000000000000000000000000000000..60142f120e34043c727cffa319719755152ff5c7 --- /dev/null +++ b/ets2panda/linter/sdk/linter_1_1/SdkTSCCompiledProgram.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 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, softwareP + * 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 type * as ts from 'typescript'; +import { ArkTSLinterTimePrinter, TimePhase } from '../ArkTSTimePrinter'; +import type { TSCCompiledProgram } from '../../lib/ts-diagnostics/TSCCompiledProgram'; +import { getStrictDiagnostics } from './SdkTypeScriptDiagnosticsExtractor'; + +export class SdkTSCCompiledProgram implements TSCCompiledProgram { + private readonly builerProgram: ts.BuilderProgram; + + constructor(builerProgram: ts.BuilderProgram) { + this.builerProgram = builerProgram; + } + + getProgram(): ts.Program { + return this.builerProgram.getProgram(); + } + + getBuilderProgram(): ts.BuilderProgram { + return this.builerProgram; + } + + getStrictDiagnostics(fileName: string): ts.Diagnostic[] { + return getStrictDiagnostics(this.getBuilderProgram(), fileName); + } + + /** + * Updates all diagnostics in TSC compilation program after the incremental build. + */ + updateCompilationDiagnostics(): void { + this.builerProgram.getSemanticDiagnostics(); + const timePrinterInstance = ArkTSLinterTimePrinter.getInstance(); + timePrinterInstance.appendTime(TimePhase.STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS); + this.builerProgram.getSyntacticDiagnostics(); + timePrinterInstance.appendTime(TimePhase.STRICT_PROGRAM_GET_SYNTACTIC_DIAGNOSTICS); + } +} diff --git a/ets2panda/linter/sdk/linter_1_1/SdkTypeScriptDiagnosticsExtractor.ts b/ets2panda/linter/sdk/linter_1_1/SdkTypeScriptDiagnosticsExtractor.ts new file mode 100644 index 0000000000000000000000000000000000000000..b8f40acae450303c2d881bfb68eaf3307565343a --- /dev/null +++ b/ets2panda/linter/sdk/linter_1_1/SdkTypeScriptDiagnosticsExtractor.ts @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023-2024 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 type * as ts from 'typescript'; + +/** + * Returns diagnostics which appear in strict compilation mode only + */ +export function getStrictDiagnostics( + builderProgram: ts.BuilderProgram, + fileName: string, + cancellationToken?: ts.CancellationToken +): ts.Diagnostic[] { + // applying filter is a workaround for tsc bug + const strict = getAllDiagnostics(builderProgram, fileName, cancellationToken, true).filter((diag) => { + return !(diag.length === 0 && diag.start === 0); + }); + const nonStrict = getAllDiagnostics(builderProgram, fileName, cancellationToken, false); + + // collect hashes for later easier comparison + const nonStrictHashes = nonStrict.reduce((result, value) => { + const hash = hashDiagnostic(value); + if (hash) { + result.add(hash); + } + return result; + }, new Set()); + // return diagnostics which weren't detected in non-strict mode + return strict.filter((value) => { + const hash = hashDiagnostic(value); + return hash && !nonStrictHashes.has(hash); + }); +} + +function getAllDiagnostics( + builderProgram: ts.BuilderProgram, + fileName: string, + cancellationToken?: ts.CancellationToken, + isStrict: boolean = false +): ts.Diagnostic[] { + const sourceFile = builderProgram.getSourceFile(fileName); + const syntacticDiagnostics: readonly ts.Diagnostic[] = builderProgram.getSyntacticDiagnostics( + sourceFile, + cancellationToken + ); + if (isStrict) { + return !builderProgram.builderProgramForLinter ? + [] : + builderProgram.builderProgramForLinter. + getSemanticDiagnostics(sourceFile, cancellationToken). + concat(syntacticDiagnostics). + filter((diag) => { + return diag.file === sourceFile; + }); + } + return builderProgram. + getSemanticDiagnostics(sourceFile, cancellationToken). + concat(syntacticDiagnostics). + filter((diag) => { + return diag.file === sourceFile; + }); +} + +function hashDiagnostic(diagnostic: ts.Diagnostic): string | undefined { + if (diagnostic.start === undefined || diagnostic.length === undefined) { + return undefined; + } + return `${diagnostic.code}%${diagnostic.start}%${diagnostic.length}`; +} diff --git a/ets2panda/linter/src/CommandLineParser.ts b/ets2panda/linter/src/CommandLineParser.ts index 30c5f9db39a904522fecc27e4ed5052837d011d7..47633fc3f09da24ffe7ecb73d1930ff473965c53 100644 --- a/ets2panda/linter/src/CommandLineParser.ts +++ b/ets2panda/linter/src/CommandLineParser.ts @@ -63,7 +63,8 @@ function formCommandLineOptions(program: Command): CommandLineOptions { inputFiles: inputFiles, warningsAsErrors: false, enableAutofix: false, - arkts2: false + arkts2: false, + enableUseRtLogic: true }; const options = program.opts(); if (options.TSC_Errors) { @@ -90,6 +91,9 @@ function formCommandLineOptions(program: Command): CommandLineOptions { if (options.warningsAsErrors) { opts.warningsAsErrors = true; } + if (!options.enableUseRtLogic) { + opts.enableUseRtLogic = false; + } return opts; } @@ -105,6 +109,7 @@ export function parseCommandLine(commandLineArgs: string[]): CommandLineOptions option('--project-folder ', 'path to folder containig TS files to verify', addProjectFolder, []). option('--autofix', 'automatically fix problems found by linter'). option('--arkts-2', 'enable ArkTS 2.0 mode'). + option('--enableUseRtLogic', 'linter with RT'). addOption(new Option('--warnings-as-errors', 'treat warnings as errors').hideHelp(true)); program.argument('[srcFile...]', 'files to be verified', addSrcFile); diff --git a/ets2panda/linter/src/Compiler.ts b/ets2panda/linter/src/Compiler.ts index 6079a9a674a3ec4d3e9c8d48f5dc0465dc2352f7..ab91f2764060b364bfa9d9f72f910136c62ea8ab 100644 --- a/ets2panda/linter/src/Compiler.ts +++ b/ets2panda/linter/src/Compiler.ts @@ -32,13 +32,13 @@ function compile(cmdOptions: CommandLineOptions, overrideCompilerOptions: ts.Com return program; } -export function compileLintOptions(cmdOptions: CommandLineOptions): LintOptions { +export function compileLintOptions(cmdOptions: CommandLineOptions, enableCheckTsFile?: boolean): LintOptions { const strict = compile(cmdOptions, getOverrideCompilerOptions(true)); const nonStrict = compile(cmdOptions, getOverrideCompilerOptions(false)); return { cmdOptions: cmdOptions, tscCompiledProgram: new TSCCompiledProgramWithDiagnostics(strict, nonStrict, cmdOptions.inputFiles), - isEtsFile: true + isEtsFile: !enableCheckTsFile }; } diff --git a/ets2panda/linter/src/TestRunner.ts b/ets2panda/linter/src/TestRunner.ts index 330b9659fb606be0b0ffb0e6dea20b4f0a1cb6cc..a88eab30388439e36e12381c386e7e6f529c929c 100644 --- a/ets2panda/linter/src/TestRunner.ts +++ b/ets2panda/linter/src/TestRunner.ts @@ -16,32 +16,54 @@ import { Logger } from '../lib/Logger'; import { LoggerImpl } from './LoggerImpl'; Logger.init(new LoggerImpl()); - import * as fs from 'node:fs'; import * as path from 'node:path'; import * as ts from 'typescript'; import type { CommandLineOptions } from '../lib/CommandLineOptions'; import { lint } from '../lib/LinterRunner'; import { TypeScriptLinter } from '../lib/TypeScriptLinter'; +import { InteropTypescriptLinter } from '../lib/InteropTypescriptLinter'; import type { Autofix } from '../lib/autofixes/Autofixer'; import { parseCommandLine } from './CommandLineParser'; import { compileLintOptions } from './Compiler'; import { getEtsLoaderPath } from './LinterCLI'; import { ProblemSeverity } from '../lib/ProblemSeverity'; +import type { ProblemInfo } from '../lib/ProblemInfo'; +let enableUseRtLogic = true; +let enableCheckTsFile = false; const TEST_DIR = 'test'; const TAB = ' '; +// initial configuration +const options = ts.readConfigFile('./tsconfig.json', ts.sys.readFile).config.compilerOptions; +const allPath = ['*']; +Object.assign(options, { + emitNodeModulesFiles: true, + importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Preserve, + module: ts.ModuleKind.ES2020, + moduleResolution: ts.ModuleResolutionKind.NodeJs, + noEmit: true, + target: ts.ScriptTarget.ES2021, + baseUrl: '/', + paths: { + '*': allPath + }, + lib: ['lib.es2021.d.ts'], + types: [], + etsLoaderPath: 'null_sdkPath' +}); interface TestNodeInfo { line: number; column: number; endLine: number; endColumn: number; - problem: string; + problem?: string; autofix?: Autofix[]; suggest?: string; rule?: string; severity?: string; + exclusive?: string; } enum Mode { @@ -58,7 +80,7 @@ const DIFF_EXT = '.diff'; const testExtensionSts = '.sts'; const testExtensionDSts = '.d.sts'; -function runTests(testDirs: string[]): number { +function runTests(): void { /* * Set the IDE mode manually to enable storing information @@ -66,15 +88,14 @@ function runTests(testDirs: string[]): number { */ TypeScriptLinter.ideMode = true; TypeScriptLinter.testMode = true; + InteropTypescriptLinter.ideMode = true; + InteropTypescriptLinter.testMode = true; let hasComparisonFailures = false; let passed = 0; let failed = 0; + const testDirs = getParam(); // Get tests from test directory - if (!testDirs?.length) { - // eslint-disable-next-line no-param-reassign - testDirs = [TEST_DIR]; - } for (const testDir of testDirs) { const testFiles: string[] = fs.readdirSync(testDir).filter((x) => { return ( @@ -124,6 +145,28 @@ function runTestFiles(testFiles: string[], testDir: string): [number, number, bo return [passed, failed, hasComparisonFailures]; } +function getParam(): string[] { + let pathArg = null; + for (const key of process.argv) { + if (key.includes('-P:')) { + pathArg = key.replace('-P:', '').split(','); + } + + if (key.includes('-SDK')) { + enableUseRtLogic = false; + } + + if (key.includes('-CheckTs')) { + enableCheckTsFile = true; + } + } + + if (!pathArg?.length) { + pathArg = [TEST_DIR]; + } + return pathArg; +} + function parseArgs(testDir: string, testFile: string, mode: Mode): CommandLineOptions { // Configure test parameters and run linter. const cmdArgs: string[] = [path.join(testDir, testFile)]; @@ -134,6 +177,7 @@ function parseArgs(testDir: string, testFile: string, mode: Mode): CommandLineOp const args = JSON.parse(data); if (args.testMode !== undefined) { TypeScriptLinter.testMode = args.testMode; + InteropTypescriptLinter.testMode = args.testMode; } if (args.arkts2 === true) { cmdArgs.push('--arkts-2'); @@ -144,6 +188,10 @@ function parseArgs(testDir: string, testFile: string, mode: Mode): CommandLineOp cmdArgs.push('--autofix'); } + if (enableUseRtLogic) { + cmdArgs.push('--enableUseRtLogic'); + } + return parseCommandLine(cmdArgs); } @@ -157,6 +205,16 @@ function compareExpectedAndActual(testDir: string, testFile: string, mode: Mode, const expectedResultFile = fs.readFileSync(path.join(testDir, testResultFileName)).toString(); expectedResult = JSON.parse(expectedResultFile); + /** + * The exclusive field is added to identify whether the use case is exclusive to the RT or SDK + * RT means the RT exclusive + * SDK means the SDK exclusive + * undefined means shared + */ + expectedResult.nodes = expectedResult?.nodes.filter((x) => { + return !x?.exclusive || x.exclusive === (enableUseRtLogic ? 'RT' : 'SDK'); + }); + if (!expectedResult?.nodes || expectedResult.nodes.length !== resultNodes.length) { const expectedResultCount = expectedResult?.nodes ? expectedResult.nodes.length : 0; diff = `Expected count: ${expectedResultCount} vs actual count: ${resultNodes.length}`; @@ -183,11 +241,12 @@ function runTest(testDir: string, testFile: string, mode: Mode): boolean { Logger.info(`Running test ${testFile} (${Mode[mode]} mode)`); TypeScriptLinter.initGlobals(); + InteropTypescriptLinter.initGlobals(); const currentTestMode = TypeScriptLinter.testMode; - + const currentInteropTestMode = InteropTypescriptLinter.testMode; const cmdOptions = parseArgs(testDir, testFile, mode); - const lintOptions = compileLintOptions(cmdOptions); + const lintOptions = compileLintOptions(cmdOptions, enableCheckTsFile); lintOptions.compatibleSdkVersion = '12'; lintOptions.compatibleSdkVersionStage = 'beta3'; const result = lint(lintOptions, getEtsLoaderPath(lintOptions)); @@ -197,9 +256,22 @@ function runTest(testDir: string, testFile: string, mode: Mode): boolean { } TypeScriptLinter.testMode = currentTestMode; + InteropTypescriptLinter.testMode = currentInteropTestMode; // Get list of bad nodes from the current run. - const resultNodes: TestNodeInfo[] = fileProblems.map((x) => { + const resultNodes = getResultNodesByRunLinter(fileProblems, mode); + + // Read file with expected test result. + const testResult = compareExpectedAndActual(testDir, testFile, mode, resultNodes); + + // Write file with actual test results. + writeActualResultFile(testDir, testFile, mode, resultNodes, testResult); + + return !!testResult; +} + +function getResultNodesByRunLinter(fileProblems: ProblemInfo[], mode: Mode): TestNodeInfo[] { + return fileProblems.map((x) => { return { line: x.line, column: x.column, @@ -212,14 +284,6 @@ function runTest(testDir: string, testFile: string, mode: Mode): boolean { severity: ProblemSeverity[x.severity] }; }); - - // Read file with expected test result. - const testResult = compareExpectedAndActual(testDir, testFile, mode, resultNodes); - - // Write file with actual test results. - writeActualResultFile(testDir, testFile, mode, resultNodes, testResult); - - return !!testResult; } function expectedAndActualMatch(expectedNodes: TestNodeInfo[], actualNodes: TestNodeInfo[]): string { @@ -230,6 +294,9 @@ function expectedAndActualMatch(expectedNodes: TestNodeInfo[], actualNodes: Test if (!locationMatch(expect, actual) || actual.problem !== expect.problem) { return reportDiff(expect, actual); } + if (checkHighLightRange(expect, actual)) { + return reportDiff(expect, actual); + } if (!autofixArraysMatch(expect.autofix, actual.autofix)) { return reportDiff(expect, actual); } @@ -256,6 +323,13 @@ function locationMatch(expected: TestNodeInfo, actual: TestNodeInfo): boolean { ); } +function checkHighLightRange(expect: TestNodeInfo, actual: TestNodeInfo): boolean { + return ( + !!expect.endLine && actual.endLine !== expect.endLine || + !!expect.endColumn && actual.endColumn !== expect.endColumn + ); +} + function autofixArraysMatch(expected: Autofix[] | undefined, actual: Autofix[] | undefined): boolean { if (!expected && !actual) { return true; @@ -282,7 +356,7 @@ function writeActualResultFile( resultNodes: TestNodeInfo[], diff: string ): void { - const actualResultsDir = path.join(testDir, 'results'); + const actualResultsDir = path.join(testDir, enableUseRtLogic ? 'results_rt' : 'results_sdk'); const resultExt = RESULT_EXT[mode]; if (!fs.existsSync(actualResultsDir)) { fs.mkdirSync(actualResultsDir); @@ -309,4 +383,4 @@ ${actualNode}`; return diff; } -runTests(process.argv.slice(2)); +runTests(); diff --git a/ets2panda/linter/src/tsconfig.json b/ets2panda/linter/src/tsconfig.json new file mode 100644 index 0000000000000000000000000000000000000000..521bf626f37b514108d3a6dc5c46019040950328 --- /dev/null +++ b/ets2panda/linter/src/tsconfig.json @@ -0,0 +1,791 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "ets": { + "emitDecorators":[ + { + "name":"Entry", + "emitParameters" : true + }, + { + "name":"Component", + "emitParameters" : false + }, + { + "name":"CustomDialog", + "emitParameters" : false + }, + { + "name":"Consume", + "emitParameters" : true + }, + { + "name":"Link", + "emitParameters" : false + }, + { + "name":"LocalStorageLink", + "emitParameters" : true + }, + { + "name":"LocalStorageProp", + "emitParameters" : true + }, + { + "name":"ObjectLink", + "emitParameters" : false + }, + { + "name":"Prop", + "emitParameters" : false + }, + { + "name":"Provide", + "emitParameters" : true + }, + { + "name":"State", + "emitParameters" : false + }, + { + "name":"StorageLink", + "emitParameters" : true + }, + { + "name":"StorageProp", + "emitParameters" : true + }, + { + "name":"Builder", + "emitParameters" : false + }, + { + "name":"BuilderParam", + "emitParameters" : false + }, + { + "name":"Observed", + "emitParameters" : false + } + ], + "propertyDecorators": [ + { + "name": "Link", + "needInitialization": false + }, + { + "name": "Prop", + "needInitialization": false + }, + { + "name": "ObjectLink", + "needInitialization": false + }, + { + "name": "Consume", + "needInitialization": false + } + ], + "render": { + "method": ["build", "pageTransition"], + "decorator": "Builder" + }, + "components": [ + "AbilityComponent", + "AlphabetIndexer", + "Animator", + "Badge", + "Blank", + "Button", + "Calendar", + "CalendarPicker", + "Camera", + "Canvas", + "Checkbox", + "CheckboxGroup", + "Circle", + "ColorPicker", + "ColorPickerDialog", + "Column", + "ColumnSplit", + "Counter", + "DataPanel", + "DatePicker", + "Divider", + "EffectComponent", + "Ellipse", + "Flex", + "FormComponent", + "FormLink", + "Gauge", + "GeometryView", + "Grid", + "GridItem", + "GridContainer", + "Hyperlink", + "Image", + "ImageAnimator", + "Line", + "List", + "ListItem", + "ListItemGroup", + "LoadingProgress", + "Marquee", + "Menu", + "MenuItem", + "MenuItemGroup", + "NavDestination", + "NavRouter", + "Navigation", + "Navigator", + "Option", + "PageTransitionEnter", + "PageTransitionExit", + "Panel", + "Particle", + "Path", + "PatternLock", + "Piece", + "PluginComponent", + "Polygon", + "Polyline", + "Progress", + "QRCode", + "Radio", + "Rating", + "Rect", + "Refresh", + "RelativeContainer", + "RemoteWindow", + "RootScene", + "Row", + "RowSplit", + "RichText", + "Screen", + "Scroll", + "ScrollBar", + "Search", + "Section", + "Select", + "Shape", + "Sheet", + "SideBarContainer", + "Slider", + "Span", + "Stack", + "Stepper", + "StepperItem", + "Swiper", + "TabContent", + "Tabs", + "Text", + "TextPicker", + "TextClock", + "TextArea", + "TextInput", + "TextTimer", + "TimePicker", + "Toggle", + "Video", + "Web", + "WindowScene", + "XComponent", + "GridRow", + "GridCol", + "WaterFlow", + "FlowItem", + "ImageSpan", + "LocationButton", + "PasteButton", + "SaveButton", + "UIExtensionComponent", + "RichEditor" + ], + "extend": { + "decorator": ["Extend", "AnimatableExtend"], + "components": [ + { + "name": "AbilityComponent", + "type": "AbilityComponentAttribute", + "instance": "AbilityComponentInstance" + }, + { + "name": "AlphabetIndexer", + "type": "AlphabetIndexerAttribute", + "instance": "AlphabetIndexerInstance" + }, + { + "name": "Animator", + "type": "AnimatorAttribute", + "instance": "AnimatorInstance" + }, + { + "name": "Badge", + "type": "BadgeAttribute", + "instance": "BadgeInstance" + }, + { + "name": "Blank", + "type": "BlankAttribute", + "instance": "BlankInstance" + }, + { + "name": "Button", + "type": "ButtonAttribute", + "instance": "ButtonInstance" + }, + { + "name": "Calendar", + "type": "CalendarAttribute", + "instance": "CalendarInstance" + }, + { + "name": "CalendarPicker", + "type": "CalendarPickerAttribute", + "instance": "CalendarPickerInstance" + }, + { + "name": "Camera", + "type": "CameraAttribute", + "instance": "CameraInstance" + }, + { + "name": "Canvas", + "type": "CanvasAttribute", + "instance": "CanvasInstance" + }, + { + "name": "Checkbox", + "type": "CheckboxAttribute", + "instance": "CheckboxInstance" + }, + { + "name": "CheckboxGroup", + "type": "CheckboxGroupAttribute", + "instance": "CheckboxGroupInstance" + }, + { + "name": "Circle", + "type": "CircleAttribute", + "instance": "CircleInstance" + }, + { + "name": "ColorPicker", + "type": "ColorPickerAttribute", + "instance": "ColorPickerInstance" + }, + { + "name": "ColorPickerDialog", + "type": "ColorPickerDialogAttribute", + "instance": "ColorPickerDialogInstance" + }, + { + "name": "Column", + "type": "ColumnAttribute", + "instance": "ColumnInstance" + }, + { + "name": "ColumnSplit", + "type": "ColumnSplitAttribute", + "instance": "ColumnSplitInstance" + }, + { + "name": "Counter", + "type": "CounterAttribute", + "instance": "CounterInstance" + }, + { + "name": "DataPanel", + "type": "DataPanelAttribute", + "instance": "DataPanelInstance" + }, + { + "name": "DatePicker", + "type": "DatePickerAttribute", + "instance": "DatePickerInstance" + }, + { + "name": "Divider", + "type": "DividerAttribute", + "instance": "DividerInstance" + }, + { + "name": "EffectComponent", + "type": "EffectComponentAttribute", + "instance": "EffectComponentInstance" + }, + { + "name": "Ellipse", + "type": "EllipseAttribute", + "instance": "EllipseInstance" + }, + { + "name": "Flex", + "type": "FlexAttribute", + "instance": "FlexInstance" + }, + { + "name": "FormComponent", + "type": "FormComponentAttribute", + "instance": "FormComponentInstance" + }, + { + "name": "FormLink", + "type": "FormLinkAttribute", + "instance": "FormLinkInstance" + }, + { + "name": "Gauge", + "type": "GaugeAttribute", + "instance": "GaugeInstance" + }, + { + "name": "GeometryView", + "type": "GeometryViewAttribute", + "instance": "GeometryViewInstance" + }, + { + "name": "Grid", + "type": "GridAttribute", + "instance": "GridInstance" + }, + { + "name": "GridItem", + "type": "GridItemAttribute", + "instance": "GridItemInstance" + }, + { + "name": "GridContainer", + "type": "GridContainerAttribute", + "instance": "GridContainerInstance" + }, + { + "name": "Hyperlink", + "type": "HyperlinkAttribute", + "instance": "HyperlinkInstance" + }, + { + "name": "Image", + "type": "ImageAttribute", + "instance": "ImageInstance" + }, + { + "name": "ImageAnimator", + "type": "ImageAnimatorAttribute", + "instance": "ImageAnimatorInstance" + }, + { + "name": "Line", + "type": "LineAttribute", + "instance": "LineInstance" + }, + { + "name": "List", + "type": "ListAttribute", + "instance": "ListInstance" + }, + { + "name": "ListItem", + "type": "ListItemAttribute", + "instance": "ListItemInstance" + }, + { + "name": "ListItemGroup", + "type": "ListItemGroupAttribute", + "instance": "ListItemGroupInstance" + }, + { + "name": "LoadingProgress", + "type": "LoadingProgressAttribute", + "instance": "LoadingProgressInstance" + }, + { + "name": "Marquee", + "type": "MarqueeAttribute", + "instance": "MarqueeInstance" + }, + { + "name": "Menu", + "type": "MenuAttribute", + "instance": "MenuInstance" + }, + { + "name": "MenuItem", + "type": "MenuItemAttribute", + "instance": "MenuItemInstance" + }, + { + "name": "MenuItemGroup", + "type": "MenuItemGroupAttribute", + "instance": "MenuItemGroupInstance" + }, + { + "name": "NavDestination", + "type": "NavDestinationAttribute", + "instance": "NavDestinationInstance" + }, + { + "name": "NavRouter", + "type": "NavRouterAttribute", + "instance": "NavRouterInstance" + }, + { + "name": "Navigation", + "type": "NavigationAttribute", + "instance": "NavigationInstance" + }, + { + "name": "Navigator", + "type": "NavigatorAttribute", + "instance": "NavigatorInstance" + }, + { + "name": "Option", + "type": "OptionAttribute", + "instance": "OptionInstance" + }, + { + "name": "PageTransitionEnter", + "type": "PageTransitionEnterAttribute", + "instance": "PageTransitionEnterInstance" + }, + { + "name": "PageTransitionExit", + "type": "PageTransitionExitAttribute", + "instance": "PageTransitionExitInstance" + }, + { + "name": "Panel", + "type": "PanelAttribute", + "instance": "PanelInstance" + }, + { + "name": "Particle", + "type": "ParticleAttribute", + "instance": "ParticleInstance" + }, + { + "name": "Path", + "type": "PathAttribute", + "instance": "PathInstance" + }, + { + "name": "PatternLock", + "type": "PatternLockAttribute", + "instance": "PatternLockInstance" + }, + { + "name": "Piece", + "type": "PieceAttribute", + "instance": "PieceInstance" + }, + { + "name": "PluginComponent", + "type": "PluginComponentAttribute", + "instance": "PluginComponentInstance" + }, + { + "name": "Polygon", + "type": "PolygonAttribute", + "instance": "PolygonInstance" + }, + { + "name": "Polyline", + "type": "PolylineAttribute", + "instance": "PolylineInstance" + }, + { + "name": "Progress", + "type": "ProgressAttribute", + "instance": "ProgressInstance" + }, + { + "name": "QRCode", + "type": "QRCodeAttribute", + "instance": "QRCodeInstance" + }, + { + "name": "Radio", + "type": "RadioAttribute", + "instance": "RadioInstance" + }, + { + "name": "Rating", + "type": "RatingAttribute", + "instance": "RatingInstance" + }, + { + "name": "Rect", + "type": "RectAttribute", + "instance": "RectInstance" + }, + { + "name": "RelativeContainer", + "type": "RelativeContainerAttribute", + "instance": "RelativeContainerInstance" + }, + { + "name": "Refresh", + "type": "RefreshAttribute", + "instance": "RefreshInstance" + }, + { + "name": "RemoteWindow", + "type": "RemoteWindowAttribute", + "instance": "RemoteWindowInstance" + }, + { + "name": "RootScene", + "type": "RootSceneAttribute", + "instance": "RootSceneInstance" + }, + { + "name": "Row", + "type": "RowAttribute", + "instance": "RowInstance" + }, + { + "name": "RowSplit", + "type": "RowSplitAttribute", + "instance": "RowSplitInstance" + }, + { + "name": "RichText", + "type": "RichTextAttribute", + "instance": "RichTextInstance" + }, + { + "name": "Screen", + "type": "ScreenAttribute", + "instance": "ScreenInstance" + }, + { + "name": "Scroll", + "type": "ScrollAttribute", + "instance": "ScrollInstance" + }, + { + "name": "ScrollBar", + "type": "ScrollBarAttribute", + "instance": "ScrollBarInstance" + }, + { + "name": "Search", + "type": "SearchAttribute", + "instance": "SearchInstance" + }, + { + "name": "Section", + "type": "SectionAttribute", + "instance": "SectionInstance" + }, + { + "name": "Select", + "type": "SelectAttribute", + "instance": "SelectInstance" + }, + { + "name": "Shape", + "type": "ShapeAttribute", + "instance": "ShapeInstance" + }, + { + "name": "Sheet", + "type": "SheetAttribute", + "instance": "SheetInstance" + }, + { + "name": "SideBarContainer", + "type": "SideBarContainerAttribute", + "instance": "SideBarContainerInstance" + }, + { + "name": "Slider", + "type": "SliderAttribute", + "instance": "SliderInstance" + }, + { + "name": "Span", + "type": "SpanAttribute", + "instance": "SpanInstance" + }, + { + "name": "Stack", + "type": "StackAttribute", + "instance": "StackInstance" + }, + { + "name": "Stepper", + "type": "StepperAttribute", + "instance": "StepperInstance" + }, + { + "name": "StepperItem", + "type": "StepperItemAttribute", + "instance": "StepperItemInstance" + }, + { + "name": "Swiper", + "type": "SwiperAttribute", + "instance": "SwiperInstance" + }, + { + "name": "TabContent", + "type": "TabContentAttribute", + "instance": "TabContentInstance" + }, + { + "name": "Tabs", + "type": "TabsAttribute", + "instance": "TabsInstance" + }, + { + "name": "Text", + "type": "TextAttribute", + "instance": "TextInstance" + }, + { + "name": "TextPicker", + "type": "TextPickerAttribute", + "instance": "TextPickerInstance" + }, + { + "name": "TextClock", + "type": "TextClockAttribute", + "instance": "TextClockInstance" + }, + { + "name": "TextArea", + "type": "TextAreaAttribute", + "instance": "TextAreaInstance" + }, + { + "name": "TextInput", + "type": "TextInputAttribute", + "instance": "TextInputInstance" + }, + { + "name": "TextTimer", + "type": "TextTimerAttribute", + "instance": "TextTimerInstance" + }, + { + "name": "TimePicker", + "type": "TimePickerAttribute", + "instance": "TimePickerInstance" + }, + { + "name": "Toggle", + "type": "ToggleAttribute", + "instance": "ToggleInstance" + }, + { + "name": "Video", + "type": "VideoAttribute", + "instance": "VideoInstance" + }, + { + "name": "Web", + "type": "WebAttribute", + "instance": "WebInstance" + }, + { + "name": "WindowScene", + "type": "WindowSceneAttribute", + "instance": "WindowSceneInstance" + }, + { + "name": "XComponent", + "type": "XComponentAttribute", + "instance": "XComponentInstance" + }, + { + "name": "GridRow", + "type": "GridRowAttribute", + "instance": "GridRowInstance" + }, + { + "name": "GridCol", + "type": "GridColAttribute", + "instance": "GridColInstance" + }, + { + "name": "WaterFlow", + "type": "WaterFlowAttribute", + "instance": "WaterFlowInstance" + }, + { + "name": "FlowItem", + "type": "FlowItemAttribute", + "instance": "FlowItemInstance" + }, + { + "name": "ImageSpan", + "type": "ImageSpanAttribute", + "instance": "ImageSpanInstance" + }, + { + "name": "LocationButton", + "type": "LocationButtonAttribute", + "instance": "LocationButtonInstance" + }, + { + "name": "PasteButton", + "type": "PasteButtonAttribute", + "instance": "PasteButtonInstance" + }, + { + "name": "SaveButton", + "type": "SaveButtonAttribute", + "instance": "SaveButtonInstance" + }, + { + "name": "UIExtensionComponent", + "type": "UIExtensionComponentAttribute", + "instance": "UIExtensionComponentInstance" + }, + { + "name": "RichEditor", + "type": "RichEditorAttribute", + "instance": "RichEditorInstance" + } + ] + }, + "styles": { + "decorator": "Styles", + "component": { + "name": "Common", + "type": "T", + "instance": "CommonInstance" + }, + "property": "stateStyles" + }, + "concurrent": { + "decorator": "Concurrent" + }, + "customComponent": "CustomComponent", + }, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + // "importsNotUsedAsValues": "preserve", + "noImplicitAny": false, + "noUnusedLocals": false, + "noUnusedParameters": false, + "experimentalDecorators": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "module": "commonjs", + "target": "es2021", + "types": [], + "typeRoots": [], + "lib": [ + "es2021" + ], + "alwaysStrict": true + }, + "exclude": [ + "node_modules" + ] +} diff --git a/ets2panda/linter/test/es_object.ts.json b/ets2panda/linter/test/es_object.ts.json index ad53bb1456447b6aef94d111e18e583e8b846d0d..0f44c9893bed57b6e414f0b39392799f3f4df711 100644 --- a/ets2panda/linter/test/es_object.ts.json +++ b/ets2panda/linter/test/es_object.ts.json @@ -31,7 +31,7 @@ "endColumn": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -41,7 +41,7 @@ "endColumn": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -51,7 +51,7 @@ "endColumn": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -61,7 +61,7 @@ "endColumn": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -71,7 +71,7 @@ "endColumn": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -81,7 +81,7 @@ "endColumn": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -91,7 +91,7 @@ "endColumn": 29, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -101,7 +101,7 @@ "endColumn": 43, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -111,7 +111,7 @@ "endColumn": 61, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -121,7 +121,7 @@ "endColumn": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -131,7 +131,7 @@ "endColumn": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -141,7 +141,7 @@ "endColumn": 54, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -151,7 +151,7 @@ "endColumn": 66, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -161,7 +161,7 @@ "endColumn": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -171,7 +171,7 @@ "endColumn": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -181,7 +181,7 @@ "endColumn": 54, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -191,7 +191,7 @@ "endColumn": 66, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -201,7 +201,7 @@ "endColumn": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -211,7 +211,7 @@ "endColumn": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -221,7 +221,7 @@ "endColumn": 54, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -231,7 +231,7 @@ "endColumn": 68, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -241,7 +241,7 @@ "endColumn": 27, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -251,7 +251,7 @@ "endColumn": 41, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -261,7 +261,7 @@ "endColumn": 59, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -271,7 +271,7 @@ "endColumn": 71, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -281,7 +281,7 @@ "endColumn": 27, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -291,7 +291,7 @@ "endColumn": 41, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -301,7 +301,7 @@ "endColumn": 59, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -311,7 +311,7 @@ "endColumn": 71, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -321,7 +321,7 @@ "endColumn": 27, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -331,7 +331,7 @@ "endColumn": 41, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -341,7 +341,7 @@ "endColumn": 59, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -351,7 +351,7 @@ "endColumn": 73, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -381,7 +381,7 @@ "endColumn": 26, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -391,7 +391,7 @@ "endColumn": 40, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -401,7 +401,7 @@ "endColumn": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -411,7 +411,7 @@ "endColumn": 23, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -421,7 +421,7 @@ "endColumn": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -431,7 +431,7 @@ "endColumn": 21, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -441,7 +441,7 @@ "endColumn": 23, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -451,7 +451,7 @@ "endColumn": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -461,7 +461,7 @@ "endColumn": 13, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -471,7 +471,7 @@ "endColumn": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -481,7 +481,7 @@ "endColumn": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -491,7 +491,7 @@ "endColumn": 12, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -501,7 +501,7 @@ "endColumn": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -511,7 +511,7 @@ "endColumn": 16, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -521,7 +521,7 @@ "endColumn": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -531,7 +531,7 @@ "endColumn": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -541,7 +541,7 @@ "endColumn": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -551,7 +551,7 @@ "endColumn": 27, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -561,7 +561,7 @@ "endColumn": 30, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -571,7 +571,7 @@ "endColumn": 31, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -581,7 +581,7 @@ "endColumn": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -591,7 +591,7 @@ "endColumn": 40, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -601,7 +601,7 @@ "endColumn": 40, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -611,7 +611,7 @@ "endColumn": 24, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -621,7 +621,7 @@ "endColumn": 12, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -641,7 +641,7 @@ "endColumn": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -651,7 +651,7 @@ "endColumn": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -661,7 +661,7 @@ "endColumn": 26, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -671,7 +671,7 @@ "endColumn": 26, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -691,7 +691,7 @@ "endColumn": 31, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -701,7 +701,7 @@ "endColumn": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -711,7 +711,7 @@ "endColumn": 44, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -721,7 +721,7 @@ "endColumn": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -731,7 +731,7 @@ "endColumn": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -741,7 +741,7 @@ "endColumn": 16, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -751,7 +751,7 @@ "endColumn": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -761,7 +761,7 @@ "endColumn": 40, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -771,7 +771,7 @@ "endColumn": 53, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -781,7 +781,7 @@ "endColumn": 66, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -791,7 +791,7 @@ "endColumn": 40, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -801,7 +801,7 @@ "endColumn": 55, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -811,7 +811,7 @@ "endColumn": 68, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -821,7 +821,7 @@ "endColumn": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -831,7 +831,7 @@ "endColumn": 30, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -841,7 +841,7 @@ "endColumn": 38, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -861,7 +861,7 @@ "endColumn": 21, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -871,7 +871,7 @@ "endColumn": 27, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -881,7 +881,7 @@ "endColumn": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -901,7 +901,7 @@ "endColumn": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -911,7 +911,7 @@ "endColumn": 26, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -921,7 +921,7 @@ "endColumn": 26, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -931,7 +931,7 @@ "endColumn": 26, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -941,7 +941,7 @@ "endColumn": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -951,7 +951,7 @@ "endColumn": 10, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" }, { @@ -961,7 +961,7 @@ "endColumn": 12, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "WARNING" } ] diff --git a/ets2panda/linter/test/es_object_arkts2.ts.json b/ets2panda/linter/test/es_object_arkts2.ts.json index d2e5507ad8104e81997ebbe172ca7ef0a8a2950f..3b78acc07ab9d1c6c79c254e9804e007174d0b58 100644 --- a/ets2panda/linter/test/es_object_arkts2.ts.json +++ b/ets2panda/linter/test/es_object_arkts2.ts.json @@ -31,7 +31,7 @@ "endColumn": 17, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -41,7 +41,7 @@ "endColumn": 17, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -51,7 +51,7 @@ "endColumn": 19, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -61,7 +61,7 @@ "endColumn": 17, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -71,7 +71,7 @@ "endColumn": 17, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -81,7 +81,7 @@ "endColumn": 19, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -91,7 +91,7 @@ "endColumn": 29, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -101,7 +101,7 @@ "endColumn": 43, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -111,7 +111,7 @@ "endColumn": 61, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -121,7 +121,7 @@ "endColumn": 22, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -131,7 +131,7 @@ "endColumn": 36, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -141,7 +141,7 @@ "endColumn": 54, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -151,7 +151,7 @@ "endColumn": 66, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -161,7 +161,7 @@ "endColumn": 22, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -171,7 +171,7 @@ "endColumn": 36, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -181,7 +181,7 @@ "endColumn": 54, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -191,7 +191,7 @@ "endColumn": 66, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -201,7 +201,7 @@ "endColumn": 22, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -211,7 +211,7 @@ "endColumn": 36, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -221,7 +221,7 @@ "endColumn": 54, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -231,7 +231,7 @@ "endColumn": 68, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -241,7 +241,7 @@ "endColumn": 27, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -251,7 +251,7 @@ "endColumn": 41, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -261,7 +261,7 @@ "endColumn": 59, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -271,7 +271,7 @@ "endColumn": 71, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -281,7 +281,7 @@ "endColumn": 27, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -291,7 +291,7 @@ "endColumn": 41, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -301,7 +301,7 @@ "endColumn": 59, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -311,7 +311,7 @@ "endColumn": 71, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -321,7 +321,7 @@ "endColumn": 27, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -331,7 +331,7 @@ "endColumn": 41, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -341,7 +341,7 @@ "endColumn": 59, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -351,7 +351,7 @@ "endColumn": 73, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -381,7 +381,7 @@ "endColumn": 26, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -391,7 +391,7 @@ "endColumn": 40, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -401,7 +401,7 @@ "endColumn": 58, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -411,7 +411,7 @@ "endColumn": 23, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -421,7 +421,7 @@ "endColumn": 25, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -431,7 +431,7 @@ "endColumn": 21, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -441,7 +441,7 @@ "endColumn": 23, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -451,7 +451,7 @@ "endColumn": 9, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -461,7 +461,7 @@ "endColumn": 13, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -471,7 +471,7 @@ "endColumn": 11, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -481,7 +481,7 @@ "endColumn": 11, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -491,7 +491,7 @@ "endColumn": 12, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -501,7 +501,7 @@ "endColumn": 15, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -511,7 +511,7 @@ "endColumn": 16, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -521,7 +521,7 @@ "endColumn": 18, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -531,7 +531,7 @@ "endColumn": 25, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -541,7 +541,7 @@ "endColumn": 25, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -551,7 +551,7 @@ "endColumn": 27, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -561,7 +561,7 @@ "endColumn": 30, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -571,7 +571,7 @@ "endColumn": 31, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -581,7 +581,7 @@ "endColumn": 33, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -591,7 +591,7 @@ "endColumn": 40, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -601,7 +601,7 @@ "endColumn": 40, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -611,7 +611,7 @@ "endColumn": 24, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -621,7 +621,7 @@ "endColumn": 12, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -641,7 +641,7 @@ "endColumn": 19, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -651,7 +651,7 @@ "endColumn": 19, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -661,7 +661,7 @@ "endColumn": 26, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -671,7 +671,7 @@ "endColumn": 26, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -691,7 +691,7 @@ "endColumn": 31, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -701,7 +701,7 @@ "endColumn": 33, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -711,7 +711,7 @@ "endColumn": 44, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -721,7 +721,7 @@ "endColumn": 33, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -731,7 +731,7 @@ "endColumn": 46, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -741,7 +741,7 @@ "endColumn": 16, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -751,7 +751,7 @@ "endColumn": 9, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -761,7 +761,7 @@ "endColumn": 40, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -771,7 +771,7 @@ "endColumn": 53, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -781,7 +781,7 @@ "endColumn": 66, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -791,7 +791,7 @@ "endColumn": 40, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -801,7 +801,7 @@ "endColumn": 55, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -811,7 +811,7 @@ "endColumn": 68, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -821,7 +821,7 @@ "endColumn": 36, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -831,7 +831,7 @@ "endColumn": 30, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -841,7 +841,7 @@ "endColumn": 38, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -861,7 +861,7 @@ "endColumn": 21, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -871,7 +871,7 @@ "endColumn": 27, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -881,7 +881,7 @@ "endColumn": 22, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -901,7 +901,7 @@ "endColumn": 25, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -911,7 +911,7 @@ "endColumn": 26, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -921,7 +921,7 @@ "endColumn": 26, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -931,7 +931,7 @@ "endColumn": 26, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -941,7 +941,7 @@ "endColumn": 15, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -951,7 +951,7 @@ "endColumn": 10, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, { @@ -961,7 +961,7 @@ "endColumn": 12, "problem": "EsObjectTypeError", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)", + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)", "severity": "ERROR" } ] diff --git a/ets2panda/linter/test/function_expression.ts.autofix.json b/ets2panda/linter/test/function_expression.ts.autofix.json index 706fa202988ff5d0d363bc0e417955e71d6fef34..d31f6ecd439a3ddb7a3543220ce0e791a1d77712 100644 --- a/ets2panda/linter/test/function_expression.ts.autofix.json +++ b/ets2panda/linter/test/function_expression.ts.autofix.json @@ -348,7 +348,7 @@ "problem": "FunctionBind", "autofixable": false, "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)" + "rule": "'Function.bind' is not supported (arkts-no-func-bind)" }, { "line": 102, diff --git a/ets2panda/linter/test/function_expression.ts.json b/ets2panda/linter/test/function_expression.ts.json index bde605dc34d6e2e293b1e0e13cb6ebd25c4405d3..54704952fbed168d0e901312a432ff5767ee03bc 100644 --- a/ets2panda/linter/test/function_expression.ts.json +++ b/ets2panda/linter/test/function_expression.ts.json @@ -208,7 +208,7 @@ "column": 7, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)" + "rule": "'Function.bind' is not supported (arkts-no-func-bind)" }, { "line": 102, diff --git a/ets2panda/linter/test/function_object_methods.ts.json b/ets2panda/linter/test/function_object_methods.ts.json index b31bdf9f2dadb16ecce63ff79d25ce1a90b2f29c..924d85510b5becb67e884c70b35888b13d55124b 100644 --- a/ets2panda/linter/test/function_object_methods.ts.json +++ b/ets2panda/linter/test/function_object_methods.ts.json @@ -31,7 +31,7 @@ "endColumn": 45, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -51,7 +51,7 @@ "endColumn": 55, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -61,7 +61,7 @@ "endColumn": 47, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -71,7 +71,7 @@ "endColumn": 50, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -91,7 +91,7 @@ "endColumn": 58, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -111,7 +111,7 @@ "endColumn": 48, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -121,7 +121,7 @@ "endColumn": 70, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -131,7 +131,7 @@ "endColumn": 61, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -141,7 +141,7 @@ "endColumn": 54, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -151,7 +151,7 @@ "endColumn": 53, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -161,7 +161,7 @@ "endColumn": 44, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -181,7 +181,7 @@ "endColumn": 51, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -201,7 +201,7 @@ "endColumn": 43, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -211,7 +211,7 @@ "endColumn": 64, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -221,7 +221,7 @@ "endColumn": 55, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "WARNING" }, { @@ -231,7 +231,7 @@ "endColumn": 43, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -241,7 +241,7 @@ "endColumn": 42, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -251,7 +251,7 @@ "endColumn": 33, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -361,7 +361,7 @@ "endColumn": 37, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -371,7 +371,7 @@ "endColumn": 37, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -381,7 +381,7 @@ "endColumn": 37, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -391,7 +391,7 @@ "endColumn": 37, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -401,7 +401,7 @@ "endColumn": 21, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" } ] diff --git a/ets2panda/linter/test/function_object_methods_arkts2.ts.json b/ets2panda/linter/test/function_object_methods_arkts2.ts.json index c1c2c65c48406da308c9b99831c0fc0dcb787d1d..1b032aba5667b346a60e497640903814b8edd1d5 100644 --- a/ets2panda/linter/test/function_object_methods_arkts2.ts.json +++ b/ets2panda/linter/test/function_object_methods_arkts2.ts.json @@ -31,7 +31,7 @@ "endColumn": 45, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -51,7 +51,7 @@ "endColumn": 55, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -61,7 +61,7 @@ "endColumn": 47, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -71,7 +71,7 @@ "endColumn": 50, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -101,7 +101,7 @@ "endColumn": 58, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -121,7 +121,7 @@ "endColumn": 48, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -131,7 +131,7 @@ "endColumn": 70, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -141,7 +141,7 @@ "endColumn": 61, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -151,7 +151,7 @@ "endColumn": 54, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -161,7 +161,7 @@ "endColumn": 53, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -171,7 +171,7 @@ "endColumn": 44, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -191,7 +191,7 @@ "endColumn": 51, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -211,7 +211,7 @@ "endColumn": 43, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -221,7 +221,7 @@ "endColumn": 64, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -231,7 +231,7 @@ "endColumn": 55, "problem": "FunctionBindError", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)", + "rule": "'Function.bind' is not supported (arkts-no-func-bind)", "severity": "ERROR" }, { @@ -241,7 +241,7 @@ "endColumn": 43, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -251,7 +251,7 @@ "endColumn": 42, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -261,7 +261,7 @@ "endColumn": 33, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -371,7 +371,7 @@ "endColumn": 37, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -381,7 +381,7 @@ "endColumn": 37, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -391,7 +391,7 @@ "endColumn": 37, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -401,7 +401,7 @@ "endColumn": 37, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" }, { @@ -411,7 +411,7 @@ "endColumn": 21, "problem": "FunctionApplyCall", "suggest": "", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)", + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)", "severity": "ERROR" } ] diff --git a/ets2panda/linter/test/private_identifiers.ts.autofix.json b/ets2panda/linter/test/private_identifiers.ts.autofix.json index dc0d90ff8af28a73e106af286d88624e86eb87df..6279bc922a599f6f9d336f42a55d73200f93f8d6 100644 --- a/ets2panda/linter/test/private_identifiers.ts.autofix.json +++ b/ets2panda/linter/test/private_identifiers.ts.autofix.json @@ -80,7 +80,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 20, @@ -88,7 +88,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 22, @@ -108,7 +108,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 23, @@ -136,7 +136,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 24, @@ -156,7 +156,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 25, @@ -176,7 +176,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 26, @@ -196,7 +196,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 27, @@ -216,7 +216,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 29, @@ -236,7 +236,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 32, @@ -244,7 +244,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 35, @@ -252,7 +252,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 37, @@ -272,7 +272,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 38, @@ -292,7 +292,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 40, @@ -312,7 +312,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 41, @@ -332,7 +332,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, @@ -352,7 +352,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, @@ -360,7 +360,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, @@ -380,7 +380,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, @@ -400,7 +400,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, @@ -420,7 +420,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, @@ -440,7 +440,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, @@ -460,7 +460,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, @@ -480,7 +480,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 45, @@ -500,7 +500,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 46, @@ -508,7 +508,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 47, @@ -516,7 +516,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 48, @@ -536,7 +536,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 49, @@ -556,7 +556,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 50, @@ -576,7 +576,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 51, @@ -596,7 +596,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 57, @@ -604,7 +604,8 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)", + "exclusive": "RT" }, { "line": 59, @@ -612,7 +613,8 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)", + "exclusive": "RT" }, { "line": 56, @@ -632,7 +634,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 57, @@ -640,7 +642,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 59, @@ -648,7 +650,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 61, @@ -668,7 +670,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 64, @@ -676,7 +678,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 64, @@ -696,7 +698,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 65, @@ -704,7 +706,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 66, @@ -724,7 +726,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 72, @@ -732,7 +734,8 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)", + "exclusive": "RT" }, { "line": 71, @@ -747,7 +750,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 72, @@ -755,7 +758,7 @@ "problem": "PrivateIdentifier", "autofixable": false, "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 74, diff --git a/ets2panda/linter/test/private_identifiers.ts.json b/ets2panda/linter/test/private_identifiers.ts.json index 052df2f57408adb606370dd9248e56b24138549d..7bb390bedc7a189be7b8f0ec85cf00bcb0f6e8b9 100644 --- a/ets2panda/linter/test/private_identifiers.ts.json +++ b/ets2panda/linter/test/private_identifiers.ts.json @@ -61,21 +61,21 @@ "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 20, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 22, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 23, @@ -89,280 +89,283 @@ "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 24, "column": 10, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 25, "column": 12, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 26, "column": 19, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 27, "column": 19, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 29, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 32, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 35, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 37, "column": 7, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 38, "column": 7, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 40, "column": 14, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 41, "column": 14, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, "column": 22, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, "column": 32, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, "column": 43, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, "column": 53, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, "column": 60, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, "column": 70, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, "column": 77, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 44, "column": 85, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 45, "column": 10, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 46, "column": 10, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 47, "column": 10, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 48, "column": 18, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 49, "column": 10, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 50, "column": 15, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 51, "column": 7, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 57, "column": 3, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)", + "exclusive": "RT" }, { "line": 59, "column": 3, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)", + "exclusive": "RT" }, { "line": 56, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 57, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 59, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 61, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 64, "column": 22, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 64, "column": 32, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 65, "column": 18, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 66, "column": 18, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 72, "column": 3, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)", + "exclusive": "RT" }, { "line": 71, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 72, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 74, diff --git a/ets2panda/linter/test/sendable_decorator_limited.ts.autofix.json b/ets2panda/linter/test/sendable_decorator_limited.ts.autofix.json index daf5696fb22b1aeb2f75ffa943ceaded69c97027..947a8ebc14670d080da015e470b0a35f81fff8bf 100644 --- a/ets2panda/linter/test/sendable_decorator_limited.ts.autofix.json +++ b/ets2panda/linter/test/sendable_decorator_limited.ts.autofix.json @@ -25,7 +25,7 @@ "replacementText": "" } ], - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 33, @@ -38,7 +38,7 @@ "replacementText": "" } ], - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 36, @@ -51,7 +51,7 @@ "replacementText": "" } ], - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 41, @@ -64,7 +64,7 @@ "replacementText": "" } ], - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 45, @@ -77,7 +77,7 @@ "replacementText": "" } ], - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 50, @@ -90,7 +90,7 @@ "replacementText": "" } ], - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" } ] } diff --git a/ets2panda/linter/test/sendable_decorator_limited.ts.json b/ets2panda/linter/test/sendable_decorator_limited.ts.json index 88d06ce606dadd774ed214b226b91deac9b59db1..e9ce9d4667a68897ff4410e7974e9b4b5c309436 100644 --- a/ets2panda/linter/test/sendable_decorator_limited.ts.json +++ b/ets2panda/linter/test/sendable_decorator_limited.ts.json @@ -18,37 +18,37 @@ "line": 27, "column": 1, "problem": "SendableDecoratorLimited", - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 33, "column": 3, "problem": "SendableDecoratorLimited", - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 36, "column": 3, "problem": "SendableDecoratorLimited", - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 41, "column": 11, "problem": "SendableDecoratorLimited", - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 45, "column": 3, "problem": "SendableDecoratorLimited", - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" }, { "line": 50, "column": 3, "problem": "SendableDecoratorLimited", - "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\", \"typeAlias\" (arkts-sendable-decorator-limited)" + "rule": "The \"@Sendable\" decorator can only be used on \"class\", \"function\" and \"typeAlias\" (arkts-sendable-decorator-limited)" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_function.ts.json b/ets2panda/linter/test/sendable_function.ts.json index 28b2a630545193abe88335781dc9730ec81f3952..fbb9be266a98ec2d723f6560bad5dc3a67f92067 100644 --- a/ets2panda/linter/test/sendable_function.ts.json +++ b/ets2panda/linter/test/sendable_function.ts.json @@ -36,7 +36,7 @@ "line": 71, "column": 1, "problem": "SendableTypeAliasDecorator", - "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" typeAlias (arkts-sendable-typeAlias-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" typeAlias (arkts-sendable-typealias-decorator)" }, { "line": 74, diff --git a/ets2panda/linter/test/unique_names.ts.json b/ets2panda/linter/test/unique_names.ts.json index a96902a4f07ed22ba828e32e2f5151cb471a8005..a277a96ad4e438d206a8a442db48633c012c2f69 100644 --- a/ets2panda/linter/test/unique_names.ts.json +++ b/ets2panda/linter/test/unique_names.ts.json @@ -502,21 +502,21 @@ "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 169, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 174, "column": 3, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 196, diff --git a/ets2panda/linter/test/utility_types.ts.json b/ets2panda/linter/test/utility_types.ts.json index f2f10564923187d1ac42af1dc8f4b8fd045f03f1..9b635cbb5d83a819d7bc9e3e508e8c053a26839d 100644 --- a/ets2panda/linter/test/utility_types.ts.json +++ b/ets2panda/linter/test/utility_types.ts.json @@ -403,7 +403,7 @@ "line": 178, "column": 18, "problem": "FunctionApplyCall", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)" + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)" }, { "line": 184, @@ -438,7 +438,7 @@ "column": 60, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)" + "rule": "'Function.bind' is not supported (arkts-no-func-bind)" }, { "line": 208, diff --git a/ets2panda/linter/test_rules/rule140.ts.autofix.json b/ets2panda/linter/test_rules/rule140.ts.autofix.json index 74f63e4e2dde3a52dd67016bf8d846490bf591ac..f36bd51ee6a9daef80de92ee91b7c558ccdd0423 100644 --- a/ets2panda/linter/test_rules/rule140.ts.autofix.json +++ b/ets2panda/linter/test_rules/rule140.ts.autofix.json @@ -67,7 +67,7 @@ "column": 39, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)" + "rule": "'Function.bind' is not supported (arkts-no-func-bind)" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test_rules/rule140.ts.json b/ets2panda/linter/test_rules/rule140.ts.json index e899d725e7a383792ef3d8277c250ae3de8182f7..390b36aeeb3ba54746d4c0e6b397d48051e491ba 100644 --- a/ets2panda/linter/test_rules/rule140.ts.json +++ b/ets2panda/linter/test_rules/rule140.ts.json @@ -54,7 +54,7 @@ "column": 39, "problem": "FunctionBind", "suggest": "", - "rule": "\"Function.bind\" is not supported (arkts-no-func-bind)" + "rule": "'Function.bind' is not supported (arkts-no-func-bind)" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test_rules/rule151.ts.json b/ets2panda/linter/test_rules/rule151.ts.json index 0dac4afe26aac725cf87c2d4d54c02005e5622d8..aaf07d68022a435fcbffea635f5767d87a76f16b 100644 --- a/ets2panda/linter/test_rules/rule151.ts.json +++ b/ets2panda/linter/test_rules/rule151.ts.json @@ -26,231 +26,231 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 21, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 22, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 25, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 26, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 27, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 21, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 35, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 29, "column": 53, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 35, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 39, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 14, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 46, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 43, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 48, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 52, "column": 63, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 19, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 33, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 51, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 56, "column": 65, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 60, @@ -271,175 +271,175 @@ "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 64, "column": 50, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 66, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 67, "column": 17, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 70, "column": 13, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 71, "column": 15, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 77, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 78, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 79, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 80, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 82, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 83, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 85, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 86, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 87, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 88, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 90, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 91, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 93, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 94, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 95, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 96, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 98, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 99, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 103, @@ -453,28 +453,28 @@ "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 106, "column": 11, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 108, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 109, "column": 18, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 114, @@ -488,112 +488,112 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 119, "column": 36, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 25, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 136, "column": 38, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 148, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 149, "column": 1, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 45, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 154, "column": 58, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 32, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 47, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 162, "column": 60, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 170, "column": 28, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 172, "column": 22, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 174, "column": 30, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 176, @@ -607,21 +607,21 @@ "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 178, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 179, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 181, @@ -635,49 +635,49 @@ "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 183, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 184, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 185, "column": 9, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 188, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 189, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" }, { "line": 190, "column": 5, "problem": "EsObjectType", "suggest": "", - "rule": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)" + "rule": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test_rules/rule152.ts.json b/ets2panda/linter/test_rules/rule152.ts.json index 611fe5106417f4135600e6c05ef73bc46658910a..6d72d4fdf26846f463c979e6642a63bd440d506e 100644 --- a/ets2panda/linter/test_rules/rule152.ts.json +++ b/ets2panda/linter/test_rules/rule152.ts.json @@ -32,13 +32,13 @@ "line": 31, "column": 23, "problem": "FunctionApplyCall", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)" + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)" }, { "line": 32, "column": 23, "problem": "FunctionApplyCall", - "rule": "\"Function.apply\", \"Function.call\" are not supported (arkts-no-func-apply-call)" + "rule": "'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)" }, { "line": 17, diff --git a/ets2panda/linter/test_rules/rule155.ts.json b/ets2panda/linter/test_rules/rule155.ts.json index e12f94149268bf16cb61eb298e8f74af56c8eb04..84f4636c21bda66d426a9d942444857fe50469bb 100644 --- a/ets2panda/linter/test_rules/rule155.ts.json +++ b/ets2panda/linter/test_rules/rule155.ts.json @@ -18,13 +18,13 @@ "line": 20, "column": 5, "problem": "SendableDefiniteAssignment", - "rule": "Definite assignment assertion in not allowed in \"Sendable\" classes (arkts-sendable-definite-assignment)" + "rule": "Definite assignment assertion is not allowed in \"Sendable\" classes (arkts-sendable-definite-assignment)" }, { "line": 21, "column": 5, "problem": "SendableDefiniteAssignment", - "rule": "Definite assignment assertion in not allowed in \"Sendable\" classes (arkts-sendable-definite-assignment)" + "rule": "Definite assignment assertion is not allowed in \"Sendable\" classes (arkts-sendable-definite-assignment)" }, { "line": 28, diff --git a/ets2panda/linter/test_rules/rule25.ts.autofix.json b/ets2panda/linter/test_rules/rule25.ts.autofix.json index 384a5a2ecfcf35c2beaede6dd3ad40816987ccc1..b5176705d863db8fa0345b846867a08ec8fa21a0 100644 --- a/ets2panda/linter/test_rules/rule25.ts.autofix.json +++ b/ets2panda/linter/test_rules/rule25.ts.autofix.json @@ -116,6 +116,31 @@ ], "suggest": "", "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)" + }, + { + "line": 49, + "column": 17, + "problem": "ParameterProperties", + "autofix": [ + { + "start": 1301, + "end": 1301, + "replacementText": "readonly a: A;\n" + }, + { + "start": 1313, + "end": 1326, + "replacementText": "a: A" + }, + { + "start": 1328, + "end": 1353, + "replacementText": "{\n this.a = a;\n this.a = a;\n}" + } + ], + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "exclusive": "SDK" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test_rules/rule25.ts.json b/ets2panda/linter/test_rules/rule25.ts.json index 2e800d8d9ea534de2091092c41c0d9d5f8c542ea..03148a87df8e0f1ef62ecb52fcfbd4cbee2a090b 100644 --- a/ets2panda/linter/test_rules/rule25.ts.json +++ b/ets2panda/linter/test_rules/rule25.ts.json @@ -34,6 +34,14 @@ "problem": "ParameterProperties", "suggest": "", "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)" + }, + { + "line": 49, + "column": 17, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)", + "exclusive": "SDK" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test_rules/rule3.ts.autofix.json b/ets2panda/linter/test_rules/rule3.ts.autofix.json index f8dda0dd41b700f729a102131e9fe9192097db7a..a64aa6fbad9639336fdf4da9b8df484720409609 100644 --- a/ets2panda/linter/test_rules/rule3.ts.autofix.json +++ b/ets2panda/linter/test_rules/rule3.ts.autofix.json @@ -27,7 +27,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 26, @@ -57,7 +57,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 27, @@ -87,7 +87,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 30, @@ -117,7 +117,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 30, @@ -147,7 +147,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 34, @@ -177,7 +177,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 34, @@ -207,7 +207,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 34, @@ -237,7 +237,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 34, @@ -267,7 +267,7 @@ } ], "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" } ] } diff --git a/ets2panda/linter/test_rules/rule3.ts.json b/ets2panda/linter/test_rules/rule3.ts.json index 55f72a4c8759b9e9009353aed2eddaeb01e427e5..c810de15514f8f00c7649f0d12864d85178334c5 100644 --- a/ets2panda/linter/test_rules/rule3.ts.json +++ b/ets2panda/linter/test_rules/rule3.ts.json @@ -19,63 +19,63 @@ "column": 5, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 26, "column": 5, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 27, "column": 5, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 30, "column": 21, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 30, "column": 31, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 34, "column": 21, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 34, "column": 31, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 34, "column": 41, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" }, { "line": 34, "column": 51, "problem": "PrivateIdentifier", "suggest": "", - "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + "rule": "Private \"#\" identifiers are not supported (arkts-no-private-identifiers)" } ] } diff --git a/ets2panda/linter/test_ts_import_ets/ets/test1.ets b/ets2panda/linter/test_ts_import_ets/ets/test1.ets new file mode 100644 index 0000000000000000000000000000000000000000..74995ee0d7030d4ffbc27946c99fe00ca65ac8ae --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ets/test1.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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 lang from '@arkts.lang'; + +export class A {}; + +@Sendable +export class B {} + +export interface I extends lang.ISendable {} + +export interface J {} diff --git a/ets2panda/linter/test_ts_import_ets/ets/test2.ets b/ets2panda/linter/test_ts_import_ets/ets/test2.ets new file mode 100644 index 0000000000000000000000000000000000000000..97c40416e6092b1247135f4a4754bf11d3ca189e --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ets/test2.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024 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 class A {}; +export default class B {} diff --git a/ets2panda/linter/test_ts_import_ets/ets/test3.ets b/ets2panda/linter/test_ts_import_ets/ets/test3.ets new file mode 100644 index 0000000000000000000000000000000000000000..0699dbe188c386c9cb4710349781616f27c45495 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ets/test3.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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 class A {}; diff --git a/ets2panda/linter/test_ts_import_ets/ets/test4.ets b/ets2panda/linter/test_ts_import_ets/ets/test4.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0f1547a532819ed175ec0f4c0030ec19da7356f --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ets/test4.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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 lang from '@arkts.lang'; + +@Sendable +class A {} +export { A, A as A1 } + +@Sendable +class B { + public value: number = 0; +} +export { B, B as B1 } + +@Sendable +class C implements lang.ISendable { + public value: number = 0; +} +export { C, C as C1} + +export interface I extends lang.ISendable { + v: number; +} + +export interface J extends I { + u: number; +} diff --git a/ets2panda/linter/test_ts_import_ets/ets/test5.ets b/ets2panda/linter/test_ts_import_ets/ets/test5.ets new file mode 100644 index 0000000000000000000000000000000000000000..16d1f6f3553f9322b1283171ab0fb6f6ff1856a3 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ets/test5.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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 lang from '@arkts.lang'; + +@Sendable +class A {} +export { A, A as A1 } + +@Sendable +class B { + public value: number = 0; +} +export { B, B as B1 } + +@Sendable +class C implements lang.ISendable { + public value: number = 0; +} +export { C, C as C1} diff --git a/ets2panda/linter/test_ts_import_ets/ets/test6.ets b/ets2panda/linter/test_ts_import_ets/ets/test6.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0f1547a532819ed175ec0f4c0030ec19da7356f --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ets/test6.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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 lang from '@arkts.lang'; + +@Sendable +class A {} +export { A, A as A1 } + +@Sendable +class B { + public value: number = 0; +} +export { B, B as B1 } + +@Sendable +class C implements lang.ISendable { + public value: number = 0; +} +export { C, C as C1} + +export interface I extends lang.ISendable { + v: number; +} + +export interface J extends I { + u: number; +} diff --git a/ets2panda/linter/test_ts_import_ets/ets/test7.ets b/ets2panda/linter/test_ts_import_ets/ets/test7.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0f1547a532819ed175ec0f4c0030ec19da7356f --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ets/test7.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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 lang from '@arkts.lang'; + +@Sendable +class A {} +export { A, A as A1 } + +@Sendable +class B { + public value: number = 0; +} +export { B, B as B1 } + +@Sendable +class C implements lang.ISendable { + public value: number = 0; +} +export { C, C as C1} + +export interface I extends lang.ISendable { + v: number; +} + +export interface J extends I { + u: number; +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test1.ts b/ets2panda/linter/test_ts_import_ets/ts/test1.ts new file mode 100644 index 0000000000000000000000000000000000000000..92ea31dfaf2c585c3bf40a3137ffe7da53b16d20 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test1.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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 { A, B } from '../ets/test1'; // A报错: arkts-no-ts-import-ets +import { I, J } from '../ets/test1'; // arkts-no-ts-import-ets +import { A as A1, B as B1 } from '../ets/test1'; // arkts-no-ts-import-ets +import { I as I1, J as J1 } from '../ets/test1'; // arkts-no-ts-import-ets +import '../ets/test1'; // arkts-no-ts-import-ets diff --git a/ets2panda/linter/test_ts_import_ets/ts/test1.ts.autofix.skip b/ets2panda/linter/test_ts_import_ets/ts/test1.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..5ed5642250add4b27ac8756dd92e00667a285aad --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test1.ts.autofix.skip @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2024 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." + ], + "nodes": [ + + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test1.ts.json b/ets2panda/linter/test_ts_import_ets/ts/test1.ts.json new file mode 100644 index 0000000000000000000000000000000000000000..c6945a139c3ad354f5b34f6928d2e1d5b79dd015 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test1.ts.json @@ -0,0 +1,67 @@ +{ + "copyright": [ + "Copyright (c) 2023-2024 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." + ], + "nodes": [ + { + "line": 16, + "column": 10, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 17, + "column": 10, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 17, + "column": 13, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 18, + "column": 15, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 19, + "column": 15, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 19, + "column": 24, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 20, + "column": 1, + "problem": "NoSideEffectImportEtsToTs", + "suggest": "", + "rule": "Side effect import is not allowed for importing from ets to ts file (artkts-no-side-effect-import-in-ts-import-ets)" + } + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test2.ts b/ets2panda/linter/test_ts_import_ets/ts/test2.ts new file mode 100644 index 0000000000000000000000000000000000000000..7103bde1578cbed1b688345f9ea983f3cd5875f2 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test2.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 * from '../ets/test2'; // arkts-no-ts-import-ets +export * as name1 from '../ets/test2'; // arkts-no-ts-import-ets +export { A } from '../ets/test2'; // arkts-no-ts-import-ets +export { A as name2 } from '../ets/test2'; // arkts-no-ts-import-ets +export { default, /* ..., */ } from '../ets/test2'; // arkts-no-ts-import-ets +export { default as name3 } from '../ets/test2'; // arkts-no-ts-import-ets diff --git a/ets2panda/linter/test_ts_import_ets/ts/test2.ts.autofix.skip b/ets2panda/linter/test_ts_import_ets/ts/test2.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..5ed5642250add4b27ac8756dd92e00667a285aad --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test2.ts.autofix.skip @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2024 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." + ], + "nodes": [ + + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test2.ts.json b/ets2panda/linter/test_ts_import_ets/ts/test2.ts.json new file mode 100644 index 0000000000000000000000000000000000000000..e4b7364bc8e64f4670fd90f360af37688f8debb5 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test2.ts.json @@ -0,0 +1,60 @@ +{ + "copyright": [ + "Copyright (c) 2023-2024 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." + ], + "nodes": [ + { + "line": 16, + "column": 15, + "problem": "NoTsReExportEts", + "suggest": "", + "rule": "In ts files, entities from ets files can not be re-exported (arkts-no-ts-re-export-ets)" + }, + { + "line": 17, + "column": 24, + "problem": "NoTsReExportEts", + "suggest": "", + "rule": "In ts files, entities from ets files can not be re-exported (arkts-no-ts-re-export-ets)" + }, + { + "line": 18, + "column": 19, + "problem": "NoTsReExportEts", + "suggest": "", + "rule": "In ts files, entities from ets files can not be re-exported (arkts-no-ts-re-export-ets)" + }, + { + "line": 19, + "column": 28, + "problem": "NoTsReExportEts", + "suggest": "", + "rule": "In ts files, entities from ets files can not be re-exported (arkts-no-ts-re-export-ets)" + }, + { + "line": 20, + "column": 37, + "problem": "NoTsReExportEts", + "suggest": "", + "rule": "In ts files, entities from ets files can not be re-exported (arkts-no-ts-re-export-ets)" + }, + { + "line": 21, + "column": 34, + "problem": "NoTsReExportEts", + "suggest": "", + "rule": "In ts files, entities from ets files can not be re-exported (arkts-no-ts-re-export-ets)" + } + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test3.ts b/ets2panda/linter/test_ts_import_ets/ts/test3.ts new file mode 100644 index 0000000000000000000000000000000000000000..57fc8e2140fdd241a6222ee59aafde83f85e4d49 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test3.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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("../ets/test3"); // Importing ArkTS files in JS and TS files in forbidden. diff --git a/ets2panda/linter/test_ts_import_ets/ts/test3.ts.autofix.skip b/ets2panda/linter/test_ts_import_ets/ts/test3.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..5ed5642250add4b27ac8756dd92e00667a285aad --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test3.ts.autofix.skip @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2024 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." + ], + "nodes": [ + + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test3.ts.json b/ets2panda/linter/test_ts_import_ets/ts/test3.ts.json new file mode 100644 index 0000000000000000000000000000000000000000..c42710415a2e1d9836b9fa4a1b7e890b851017fb --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test3.ts.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2023-2024 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." + ], + "nodes": [ + + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test4.ts b/ets2panda/linter/test_ts_import_ets/ts/test4.ts new file mode 100644 index 0000000000000000000000000000000000000000..7da0c257508a3649abfa49b4b61703d8a789e709 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test4.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 { A, A1, A as A2, B, B1, B as B2, C, C1, C as C2 } from '../ets/test4' +import { I, J } from '../ets/test4' + +interface T {} + +class D1 extends A {} +class D2 extends A1 {} +class D3 extends A2 {} +class D4 extends B {} +class D5 extends B1 {} +class D6 extends B2 {} +class D7 extends C {} +class DerivedFromC1 extends C1 {} +class DerivedFromC2 extends C2 {} + +interface I1 extends I {} +interface J1 extends J {} +interface K extends I, J, T {} + +export let t = 123; diff --git a/ets2panda/linter/test_ts_import_ets/ts/test4.ts.autofix.skip b/ets2panda/linter/test_ts_import_ets/ts/test4.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..5ed5642250add4b27ac8756dd92e00667a285aad --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test4.ts.autofix.skip @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2024 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." + ], + "nodes": [ + + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test4.ts.json b/ets2panda/linter/test_ts_import_ets/ts/test4.ts.json new file mode 100644 index 0000000000000000000000000000000000000000..2c9d59c56203910d03529cb985121f4cab9b2322 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test4.ts.json @@ -0,0 +1,95 @@ +{ + "copyright": [ + "Copyright (c) 2023-2024 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." + ], + "nodes": [ + { + "line": 17, + "column": 10, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 17, + "column": 13, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 21, + "column": 18, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + }, + { + "line": 22, + "column": 18, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + }, + { + "line": 23, + "column": 18, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + }, + { + "line": 24, + "column": 18, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + }, + { + "line": 25, + "column": 18, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + }, + { + "line": 26, + "column": 18, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + }, + { + "line": 27, + "column": 18, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + }, + { + "line": 28, + "column": 29, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + }, + { + "line": 29, + "column": 29, + "problem": "SendableTypeInheritance", + "suggest": "", + "rule": "In ts files, \"Sendable\" types cannot be used in implements and extends clauses (arkts-no-ts-sendable-type-inheritance)" + } + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test5.ts b/ets2panda/linter/test_ts_import_ets/ts/test5.ts new file mode 100644 index 0000000000000000000000000000000000000000..e55925e40b2bf52831ca5d3bffd59536041e4fc8 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test5.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 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 { A, A1, A as A2, B, B1, B as B2, C, C1, C as C2 } from '../ets/test5' + +class D {} +interface T {} + +let a1 = new A(); +let a2 = new A1(); +let a3 = new A2(); +let a4 = new A(); +let a5 = new A1(); +let a6 = new A2(); +let a7 = new A(); +let a8 = new A1(); +let a9 = new A2(); + +let b1 = new B(); +let b2 = new B1(); +let b3 = new B2(); +let b4 = new B(); +let b5 = new B1(); +let b6 = new B2(); +let b7 = new B(); +let b8 = new B1(); +let b9 = new B2(); + +let c1 = new C(); +let c2 = new C1(); +let c3 = new C2(); +let c4 = new C(); +let c5 = new C1(); +let cb6 = new C2(); +let c7 = new C(); +let c8 = new C1(); +let c9 = new C2(); + +export let t = 123; diff --git a/ets2panda/linter/test_ts_import_ets/ts/test5.ts.autofix.skip b/ets2panda/linter/test_ts_import_ets/ts/test5.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..5ed5642250add4b27ac8756dd92e00667a285aad --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test5.ts.autofix.skip @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2024 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." + ], + "nodes": [ + + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test5.ts.json b/ets2panda/linter/test_ts_import_ets/ts/test5.ts.json new file mode 100644 index 0000000000000000000000000000000000000000..a715c9a403d33136b128d99e87ce0cf9dbfe69be --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test5.ts.json @@ -0,0 +1,186 @@ +{ + "copyright": [ + "Copyright (c) 2023-2024 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." + ], + "nodes": [ + { + "line": 24, + "column": 16, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 25, + "column": 17, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 17, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 27, + "column": 16, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 28, + "column": 17, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 29, + "column": 17, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 34, + "column": 24, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 35, + "column": 25, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 36, + "column": 25, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 37, + "column": 16, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 37, + "column": 19, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 38, + "column": 17, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 38, + "column": 20, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 39, + "column": 17, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 39, + "column": 20, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 44, + "column": 24, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 45, + "column": 25, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 46, + "column": 26, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 47, + "column": 16, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 47, + "column": 19, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 48, + "column": 17, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 48, + "column": 20, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 49, + "column": 17, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 49, + "column": 20, + "problem": "SendableGenericTypes", + "suggest": "", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + } + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test6.ts b/ets2panda/linter/test_ts_import_ets/ts/test6.ts new file mode 100644 index 0000000000000000000000000000000000000000..b06677b7c00bcfaca5ae51c4e86a4d6b015983fe --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test6.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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 { A, A1, A as A2, B, B1, B as B2, C, C1, C as C2 } from '../ets/test6' +import { I, J } from '../ets/test6' + +let a1: A = {}; +let a2: A1 = {}; +let a3: A2 = {}; +let b1: B = { value: 0 }; +let b2: B1 = { value: 0 }; +let b3: B2 = { value: 0 }; +let c1: C = { value: 0 }; +let c2: C1 = { value: 0 }; +let c3: C2 = { value: 0 }; + +let i: I = { v: 0 }; +let j: J = { v: 0, u: 0 }; + +export let t = 123; diff --git a/ets2panda/linter/test_ts_import_ets/ts/test6.ts.autofix.skip b/ets2panda/linter/test_ts_import_ets/ts/test6.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..5ed5642250add4b27ac8756dd92e00667a285aad --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test6.ts.autofix.skip @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2024 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." + ], + "nodes": [ + + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test6.ts.json b/ets2panda/linter/test_ts_import_ets/ts/test6.ts.json new file mode 100644 index 0000000000000000000000000000000000000000..ed680be1835f4669fd31cf0e17be611a4f744545 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test6.ts.json @@ -0,0 +1,95 @@ +{ + "copyright": [ + "Copyright (c) 2023-2024 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." + ], + "nodes": [ + { + "line": 17, + "column": 10, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 17, + "column": 13, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 19, + "column": 13, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 20, + "column": 14, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 21, + "column": 14, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 22, + "column": 13, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 23, + "column": 14, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 24, + "column": 14, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 25, + "column": 13, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 26, + "column": 14, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 27, + "column": 14, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + } + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test7.ts b/ets2panda/linter/test_ts_import_ets/ts/test7.ts new file mode 100644 index 0000000000000000000000000000000000000000..c3c9bce44747bebf47522bb557cefec682aee63b --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test7.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 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 { A, A1, A as A2, B, B1, B as B2, C, C1, C as C2 } from '../ets/test7' +import { I, J } from '../ets/test7' + +let a1 = {} as A; +let a2 = {} as A1; +let a3 = {} as A2; +let b1 = { value: 0 } as B; +let b2 = { value: 0 } as B1; +let b3 = { value: 0 } as B2; +let c1 = { value: 0 } as C; +let c2 = { value: 0 } as C1; +let c3 = { value: 0 } as C2; + +let i = { v: 0 } as I; +let j = { v: 0, u: 0 } as J; + +class D {} + +function foo(d: D) {} +foo(new D() as A); +foo(new D() as A1); +foo(new D() as A2); + +export let t = 123; diff --git a/ets2panda/linter/test_ts_import_ets/ts/test7.ts.autofix.skip b/ets2panda/linter/test_ts_import_ets/ts/test7.ts.autofix.skip new file mode 100644 index 0000000000000000000000000000000000000000..5ed5642250add4b27ac8756dd92e00667a285aad --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test7.ts.autofix.skip @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2024 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." + ], + "nodes": [ + + ] +} diff --git a/ets2panda/linter/test_ts_import_ets/ts/test7.ts.json b/ets2panda/linter/test_ts_import_ets/ts/test7.ts.json new file mode 100644 index 0000000000000000000000000000000000000000..e82d4d63e94dbe2e7b8b8988ed6595fe690445d3 --- /dev/null +++ b/ets2panda/linter/test_ts_import_ets/ts/test7.ts.json @@ -0,0 +1,179 @@ +{ + "copyright": [ + "Copyright (c) 2023-2024 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." + ], + "nodes": [ + { + "line": 17, + "column": 10, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 17, + "column": 13, + "problem": "NoTsImportEts", + "suggest": "", + "rule": "Only \"Sendable\" classes and \"Sendable\" interfaces are allowed for importing from ets into ts file (arkts-no-ts-import-ets)" + }, + { + "line": 19, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 19, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 20, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 20, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 21, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 21, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 22, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 22, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 23, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 23, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 24, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 24, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 25, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 25, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 26, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 26, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 27, + "column": 10, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 27, + "column": 10, + "problem": "SendableObjectInitialization", + "suggest": "", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 35, + "column": 5, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 36, + "column": 5, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 37, + "column": 5, + "problem": "SendableAsExpr", + "suggest": "", + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + } + ] +} diff --git a/ets2panda/linter/tsconfig.json b/ets2panda/linter/tsconfig.json index 5e1d00ae015576cb61181716a3726ab419935bc2..af818f0f5682990ce66cbfca551c14b9b42fb7fe 100644 --- a/ets2panda/linter/tsconfig.json +++ b/ets2panda/linter/tsconfig.json @@ -12,5 +12,5 @@ "strict": true }, - "include": ["src/**/*", "lib/**/*", "utils/*"] + "include": ["src/**/*", "lib/**/*", "utils/*", "sdk/**/*"] }