diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 91a0529e756f8d56673e6ee62ad0c6c7ed0378c1..0c613f3a2f533822cdcd66546a4178ca2ce4e214 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -80,7 +80,9 @@ "arkts-not-support-tuple-generic-validation", "arkts-no-optional-tuple-type", "arkts-no-large-numeric-literal", - "arkts-no-instanceof-func" + "arkts-no-instanceof-func", + "arkts-no-unfixed-len-tuple", + "arkts-no-super-call-in-static-context" ], "interop": [ "arkts-interop-js2s-inherit-js-class", diff --git a/ets2panda/linter/src/cli/CommandLineParser.ts b/ets2panda/linter/src/cli/CommandLineParser.ts index 83d0e13743dc04ff0c1a287f41d1060121bb917b..e84fb2a7ad4ca2886f82256cdceebf4f7b746278 100644 --- a/ets2panda/linter/src/cli/CommandLineParser.ts +++ b/ets2panda/linter/src/cli/CommandLineParser.ts @@ -22,7 +22,11 @@ import type { CommandLineOptions } from '../lib/CommandLineOptions'; import { cookBookTag } from '../lib/CookBookMsg'; import { Logger } from '../lib/Logger'; import { ARKTS_IGNORE_DIRS_OH_MODULES } from '../lib/utils/consts/ArktsIgnorePaths'; -import { getConfiguredRuleTags, getConfigureRulePath, getRulesFromConfig } from '../lib/utils/functions/ConfiguredRulesProcess'; +import { + getConfiguredRuleTags, + getConfigureRulePath, + getRulesFromConfig +} from '../lib/utils/functions/ConfiguredRulesProcess'; import { extractRuleTags } from '../lib/utils/functions/CookBookUtils'; import { logTscDiagnostic } from '../lib/utils/functions/LogTscDiagnostic'; diff --git a/ets2panda/linter/src/cli/LinterCLI.ts b/ets2panda/linter/src/cli/LinterCLI.ts index 9d8ae8337f1a0130cd49e30139e9e795171d26d2..be7e4cdaaa633e0441d49d7d9fb98d34281deaa5 100644 --- a/ets2panda/linter/src/cli/LinterCLI.ts +++ b/ets2panda/linter/src/cli/LinterCLI.ts @@ -32,7 +32,7 @@ import { logStatistics } from '../lib/statistics/StatisticsLogger'; import { compileLintOptions, getEtsLoaderPath } from '../lib/ts-compiler/Compiler'; import { processSyncErr, processSyncOut } from '../lib/utils/functions/ProcessWrite'; import { parseCommandLine } from './CommandLineParser'; -import { getwholeRules } from '../lib/utils/functions/ConfiguredRulesProcess'; +import { getAllLinterRules } from '../lib/utils/functions/ConfiguredRulesProcess'; export function run(): void { const commandLineArgs = process.argv.slice(2); @@ -78,7 +78,7 @@ async function runIdeInteractiveMode(cmdOptions: CommandLineOptions): Promise { - return apilistItem.api_info.api_name === errorNode.getText(); + return ( + apilistItem.api_info.api_name === errorNode.getText() && + fileName.endsWith(path.normalize(apilistItem.file_path)) + ); }); if (!hasSameApiName) { return; } - if (ts.isTypeReferenceNode(errorNode)) { - errorNode = errorNode.typeName; - } + const matchedApi = apiNamesArr.some((sdkInfo) => { const isSameName = sdkInfo.api_info.api_name === apiName; const isGlobal = sdkInfo.is_global; return isSameName && isGlobal; }); - const checkSymbol = this.isIdentifierFromSDK(errorNode); + const checkSymbol = TypeScriptLinter.isIdentifierFromSDK(symbol); const type = this.tsTypeChecker.getTypeAtLocation(errorNode); const typeName = this.tsTypeChecker.typeToString(type); @@ -10026,8 +10036,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return false; } - private isIdentifierFromSDK(node: ts.Node): boolean { - const symbol = this.tsTypeChecker.getSymbolAtLocation(node); + static isIdentifierFromSDK(symbol: ts.Symbol | undefined): boolean { if (!symbol) { return true; } @@ -12457,6 +12466,14 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!this.options.arkts2) { return; } + + if (TypeScriptLinter.isInForLoopBody(tsAsExpr)) { + const identifier = TypeScriptLinter.getIdentifierFromAsExpression(tsAsExpr); + if (identifier && this.isDeclaredOutsideForLoop(identifier)) { + return; + } + } + const asType = this.tsTypeChecker.getTypeAtLocation(tsAsExpr.type); const originType = this.tsTypeChecker.getTypeAtLocation(tsAsExpr.expression); const originTypeStr = this.tsTypeChecker.typeToString(originType); @@ -12465,6 +12482,34 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } + private isDeclaredOutsideForLoop(identifier: ts.Identifier): boolean { + const symbol = this.tsTypeChecker.getSymbolAtLocation(identifier); + if (!symbol) { + return false; + } + + const declarations = symbol.declarations ?? []; + for (const decl of declarations) { + if (ts.findAncestor(decl, ts.isForStatement)) { + return false; + } + } + + return true; + } + + private static getIdentifierFromAsExpression(asExpr: ts.AsExpression): ts.Identifier | undefined { + const expr = asExpr.expression; + if (ts.isIdentifier(expr)) { + // case: data as Type + return expr; + } else if (ts.isElementAccessExpression(expr) && ts.isIdentifier(expr.expression)) { + // case: data[i] as Type + return expr.expression; + } + return undefined; + } + private handleAssignmentNotsLikeSmartType(tsBinaryExpr: ts.BinaryExpression): void { if (!this.options.arkts2) { return; @@ -15536,4 +15581,29 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { '"toJson" and "fromJson" (arkui-persistencev2-connect-serialization)'; this.incrementCounters(callExpr, FaultID.PersistenceV2ConnectNeedAddParam, undefined, errorMsg); } + + private handleRestType(node: ts.Node): void { + if (!this.options.arkts2) { + return; + } + if (node.parent && ts.isTupleTypeNode(node.parent)) { + this.incrementCounters(node, FaultID.unfixedTuple); + } + } + + private handleSuperKeyword(node: ts.Node): void { + if (!this.options.arkts2) { + return; + } + const staticContext = ts.findAncestor(node, (parent) => { + return ( + parent && + (ts.canHaveModifiers(parent) && TsUtils.hasModifier(parent.modifiers, ts.SyntaxKind.StaticKeyword) || + ts.isClassStaticBlockDeclaration(parent)) + ); + }); + if (staticContext) { + this.incrementCounters(node, FaultID.SuperInStaticContext); + } + } } diff --git a/ets2panda/linter/src/lib/statistics/scan/ProblemStatisticsCommonFunction.ts b/ets2panda/linter/src/lib/statistics/scan/ProblemStatisticsCommonFunction.ts index a9c638bd7d0429808444a1d826fc3e0ed37ab139..e8e8f93510106e82eda0a9a245e7856ff5aa23a5 100644 --- a/ets2panda/linter/src/lib/statistics/scan/ProblemStatisticsCommonFunction.ts +++ b/ets2panda/linter/src/lib/statistics/scan/ProblemStatisticsCommonFunction.ts @@ -27,7 +27,7 @@ import type { RuleDetailedErrorInfo } from './RuleDetailedErrorInfo'; import type { StatisticsReportInPutInfo } from './StatisticsReportInPutInfo'; import type { TimeRecorder } from './TimeRecorder'; import { WorkLoadInfo } from './WorkLoadInfo'; -import { getwholeRules } from '../../utils/functions/ConfiguredRulesProcess'; +import { getAllLinterRules } from '../../utils/functions/ConfiguredRulesProcess'; export function getProblemStatisticsInfo( problemNumbers: ProblemNumbersInfo, @@ -153,7 +153,7 @@ export async function generateScanProbelemStatisticsReport( workLoadInfo.calculateFixRate(problemNumbers); const statisticsReportData = getProblemStatisticsInfo( problemNumbers, - getProcessedRuleToNumbersMap(statisticsReportInPutInfo.ruleToNumbersMap, statisticsReportInPutInfo.wholeRules), + getProcessedRuleToNumbersMap(statisticsReportInPutInfo.ruleToNumbersMap, statisticsReportInPutInfo.allLinterRules), statisticsReportInPutInfo.ruleToAutoFixedNumbersMap, statisticsReportInPutInfo.timeRecorder, workLoadInfo @@ -165,18 +165,21 @@ export async function generateScanProbelemStatisticsReport( ); } -function getProcessedRuleToNumbersMap(ruleToNumbersMap: Map, wholeLinterRules: string[]) : Map { +function getProcessedRuleToNumbersMap( + ruleToNumbersMap: Map, + allLinterRules: string[] +): Map { const processedRuleToNumbersMap: Map = new Map(); const homecheckRuleToNumbersMap: Map = ruleToNumbersMap; - wholeLinterRules.forEach((ruleName) => { + allLinterRules.forEach((ruleName) => { const ruleNumber = ruleToNumbersMap.get(ruleName) || 0; homecheckRuleToNumbersMap.delete(ruleName); processedRuleToNumbersMap.set(ruleName, ruleNumber); }); - + homecheckRuleToNumbersMap.forEach((number, ruleName) => { processedRuleToNumbersMap.set(ruleName, number); - }) + }); return processedRuleToNumbersMap; } @@ -213,7 +216,7 @@ export function generateMigrationStatisicsReport( const statisticsReportData = getProblemStatisticsInfo( problemNumbers, - getProcessedRuleToNumbersMap(ruleToNumbersMap, getwholeRules()), + getProcessedRuleToNumbersMap(ruleToNumbersMap, getAllLinterRules()), ruleToAutoFixedNumbersMap, timeRecorder ); diff --git a/ets2panda/linter/src/lib/statistics/scan/StatisticsReportInPutInfo.ts b/ets2panda/linter/src/lib/statistics/scan/StatisticsReportInPutInfo.ts index b43198f2fe80379338ac267289c162c59ab69600..a841890f976e085f546d76fb5f527ea40c92d083 100644 --- a/ets2panda/linter/src/lib/statistics/scan/StatisticsReportInPutInfo.ts +++ b/ets2panda/linter/src/lib/statistics/scan/StatisticsReportInPutInfo.ts @@ -20,7 +20,7 @@ export class StatisticsReportInPutInfo { totalProblemNumbers: number = 0; arkOnePointOneProblemNumbers: number = 0; ruleToNumbersMap: Map = {} as Map; - wholeRules: string[] = [] as string[]; + allLinterRules: string[] = [] as string[]; ruleToAutoFixedNumbersMap: Map = {} as Map; cmdOptions: CommandLineOptions = {} as CommandLineOptions; timeRecorder: TimeRecorder = {} as TimeRecorder; diff --git a/ets2panda/linter/src/lib/utils/TsUtils.ts b/ets2panda/linter/src/lib/utils/TsUtils.ts index d49c2cdff90b6f373fae3ef111910582e071cbcc..3aa1893629cf4d0872461b648811448b079a9595 100644 --- a/ets2panda/linter/src/lib/utils/TsUtils.ts +++ b/ets2panda/linter/src/lib/utils/TsUtils.ts @@ -3590,7 +3590,7 @@ export class TsUtils { return false; } - projectPath.concat(PATH_SEPARATOR + currentModule); + projectPath = projectPath.concat(PATH_SEPARATOR + currentModule); } const importedFile = path.resolve(projectPath, importFilePath + extension); diff --git a/ets2panda/linter/src/lib/utils/functions/ConfiguredRulesProcess.ts b/ets2panda/linter/src/lib/utils/functions/ConfiguredRulesProcess.ts index 65ee056abc9fd480f9d3625541c8c71054d2ecec..27bf5988bdf90f09b96cc29e3546d7c95d570935 100644 --- a/ets2panda/linter/src/lib/utils/functions/ConfiguredRulesProcess.ts +++ b/ets2panda/linter/src/lib/utils/functions/ConfiguredRulesProcess.ts @@ -97,7 +97,7 @@ function isStringArray(value: any): value is string[] { ); } -export function getwholeRules() : string[] { +export function getAllLinterRules(): string[] { const configureRulePath = getDefaultConfigurePath(); const configuredRulesMap = getRulesFromConfig(configureRulePath); return Array.from(configuredRulesMap.values()).flat(); diff --git a/ets2panda/linter/test/deprecatedapi/common_api.ets.arkts2.json b/ets2panda/linter/test/deprecatedapi/common_api.ets.arkts2.json index 477f1080b2c1d43ffaf34a277a37d8a6e339d5b1..d74d9c0a2c9518d08b2163fc2b28a4c6a26fbc04 100644 --- a/ets2panda/linter/test/deprecatedapi/common_api.ets.arkts2.json +++ b/ets2panda/linter/test/deprecatedapi/common_api.ets.arkts2.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 19, - "column": 23, - "endLine": 19, - "endColumn": 32, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 20, "column": 22, @@ -164,16 +154,6 @@ "rule": "The ArkUI interface \"TransitionOptions\" is deprecated (arkui-deprecated-interface)", "severity": "ERROR" }, - { - "line": 47, - "column": 17, - "endLine": 47, - "endColumn": 26, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 50, "column": 36, @@ -264,16 +244,6 @@ "rule": "The ArkUI interface \"LayoutChild\" is deprecated (arkui-deprecated-interface)", "severity": "ERROR" }, - { - "line": 96, - "column": 31, - "endLine": 96, - "endColumn": 40, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 97, "column": 26, @@ -294,16 +264,6 @@ "rule": "The ArkUI interface \"getY\" is deprecated (arkui-deprecated-interface)", "severity": "ERROR" }, - { - "line": 98, - "column": 23, - "endLine": 98, - "endColumn": 32, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 99, "column": 34, @@ -324,16 +284,6 @@ "rule": "The ArkUI interface \"getY\" is deprecated (arkui-deprecated-interface)", "severity": "ERROR" }, - { - "line": 109, - "column": 26, - "endLine": 109, - "endColumn": 35, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 111, "column": 28, diff --git a/ets2panda/linter/test/deprecatedapi/dragController.ets.arkts2.json b/ets2panda/linter/test/deprecatedapi/dragController.ets.arkts2.json index 1e77318c1ced04e869a879e0b62ceddc8888b911..f6115f9b1400c878506799ce8a1f3c4a40d6b30d 100644 --- a/ets2panda/linter/test/deprecatedapi/dragController.ets.arkts2.json +++ b/ets2panda/linter/test/deprecatedapi/dragController.ets.arkts2.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 48, - "column": 33, - "endLine": 48, - "endColumn": 46, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, { "line": 67, "column": 27, diff --git a/ets2panda/linter/test/deprecatedapi/progress.ets.arkts2.json b/ets2panda/linter/test/deprecatedapi/progress.ets.arkts2.json index efa1d99076c1c870277089fe767d0e8faf6cd6c3..9f2cb2ef50766faf9c49734ec706c3f4099620ba 100755 --- a/ets2panda/linter/test/deprecatedapi/progress.ets.arkts2.json +++ b/ets2panda/linter/test/deprecatedapi/progress.ets.arkts2.json @@ -14,26 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 19, - "column": 26, - "endLine": 19, - "endColumn": 40, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 19, - "column": 47, - "endLine": 19, - "endColumn": 61, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 19, "column": 47, diff --git a/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets new file mode 100644 index 0000000000000000000000000000000000000000..9cb64f10753599a2ecfd5175b344e9cb2da30861 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A { + static foo() { + return 123; + } + static a: number = 1.0; +} + +class B extends A { + static x1: number = super.foo(); // report error for calling super class in static context. + static x2: number = super.a; // report error for calling super class in static context. + static foo() { + let x3: number = super.a; // report error for calling super class in static method. + return super.foo() + 456; // report error for calling super class in static method. + } + static { + let x4: number = super.a; // report error for calling super class in static code block. + super.foo(); // report error for calling super class in static code block. + } +} diff --git a/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.args.json b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..d8d3390ad9befeca9b595017d9eea0f5ada3d049 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.arkts2.json b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..4755c1876845bb5d1f38081f1c4e71cb0af5cddb --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.arkts2.json @@ -0,0 +1,88 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 30, + "column": 3, + "endLine": 33, + "endColumn": 4, + "problem": "NoStaticOnClass", + "suggest": "", + "rule": "Class cannot have static codeblocks. (arkts-class-lazy-import)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 23, + "endLine": 24, + "endColumn": 28, + "problem": "SuperInStaticContext", + "suggest": "", + "rule": "Subclass can't call members of super class in static context (arkts-no-super-call-in-static-context)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 23, + "endLine": 25, + "endColumn": 28, + "problem": "SuperInStaticContext", + "suggest": "", + "rule": "Subclass can't call members of super class in static context (arkts-no-super-call-in-static-context)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 22, + "endLine": 27, + "endColumn": 27, + "problem": "SuperInStaticContext", + "suggest": "", + "rule": "Subclass can't call members of super class in static context (arkts-no-super-call-in-static-context)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 12, + "endLine": 28, + "endColumn": 17, + "problem": "SuperInStaticContext", + "suggest": "", + "rule": "Subclass can't call members of super class in static context (arkts-no-super-call-in-static-context)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 22, + "endLine": 31, + "endColumn": 27, + "problem": "SuperInStaticContext", + "suggest": "", + "rule": "Subclass can't call members of super class in static context (arkts-no-super-call-in-static-context)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 5, + "endLine": 32, + "endColumn": 10, + "problem": "SuperInStaticContext", + "suggest": "", + "rule": "Subclass can't call members of super class in static context (arkts-no-super-call-in-static-context)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.json b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-negative.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets new file mode 100644 index 0000000000000000000000000000000000000000..4bd51f8c1a4d3ad05e97881b8bb1563d1959e3c0 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A { + static foo() { + return 123; + } +} + +class B extends A { + static foo() { + return A.foo() + 456; + } + static { + console.log('asd'); + A.foo(); + } +} + +class Animal1 { + name: string; + constructor(name: string) { + this.name = name; + } +} +class Dog1 extends Animal1 { + breed: string; + constructor(name: string, breed: string) { + super(name); + this.breed = breed; + } +} + +class Animal2 { + move(): void { + console.log("Moving..."); + } +} +class Dog2 extends Animal2 { + move(): void { + super.move(); + console.log("Running..."); + } +} + +class Base1 { + greet(): void { + console.log("Hello, world!"); + } +} +class Derived1 extends Base1 { + greet(): void { + super.greet(); + console.log("Hello from Derived class!"); + } +} + +class Base2 { + value: number; + constructor() { + this.value = 100; + } +} +class Derived2 extends Base2 { + constructor() { + super(); + this.value += 50; + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.args.json b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..d8d3390ad9befeca9b595017d9eea0f5ada3d049 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.arkts2.json b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..65e7c7a06a97d629db327ae4590cbaf99cb639ef --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.arkts2.json @@ -0,0 +1,28 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 26, + "column": 3, + "endLine": 29, + "endColumn": 4, + "problem": "NoStaticOnClass", + "suggest": "", + "rule": "Class cannot have static codeblocks. (arkts-class-lazy-import)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.json b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-super-call-in-static-context-positive.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/no_ts_like_smart_type.ets b/ets2panda/linter/test/main/no_ts_like_smart_type.ets index 8a353aff28cf146621574305a40c890447ebd62e..d7b51db205f71bcce62ef33cbef39d93e6621c6c 100755 --- a/ets2panda/linter/test/main/no_ts_like_smart_type.ets +++ b/ets2panda/linter/test/main/no_ts_like_smart_type.ets @@ -249,7 +249,7 @@ export class AB { return this.count_; //legal }) } -} +} class AG { h?: number; @@ -306,4 +306,62 @@ if (obj && obj.h == 3) { // valid(guarded) function check43(obj?: AG) { const val = obj.h; // NOT guarded return val; -} \ No newline at end of file +} + +} + +let NextID: number = 1; + +class downloadFilesData { + id: number; + url: string; + fileStatus: number; + downloadTime: number; + + constructor( + url: string = '', + fileStatus: number = 0, + downloadTime: number = 0, + ) { + this.id = NextID++; + this.url = url; + this.fileStatus = fileStatus; + this.downloadTime = downloadTime; + } +} + +class Downloader { + downloadFileArray: downloadFilesData[] = []; + + loadInitializationDataSource() { + let stringData = JSON.stringify([ + { + "url": "https://example.com/file1.zip", + "fileStatus": 1, + "downloadTime": 1734931200 + }, + { + "url": "https://example.com/file2.mp4", + "fileStatus": 0, + "downloadTime": 0 + }, + { + "url": "https://example.com/file3.pdf", + "fileStatus": 2, + "downloadTime": 1734931300 + } + ]); + + let data: [] = JSON.parse(stringData) as []; + + for (let i = 0; i < data.length; i++) { + const downloadItemData = data[i] as downloadFilesData; + let downloadData: downloadFilesData = new downloadFilesData( + downloadItemData.url, + downloadItemData.fileStatus, + downloadItemData.downloadTime + ); + this.downloadFileArray.push(downloadData); + } + } +} diff --git a/ets2panda/linter/test/main/no_ts_like_smart_type.ets.arkts2.json b/ets2panda/linter/test/main/no_ts_like_smart_type.ets.arkts2.json old mode 100755 new mode 100644 index d5577d300c913d9edae09ad5e758f030664b2895..14bb6037da9ced68fe2554de13bd02a18e4da5ef --- a/ets2panda/linter/test/main/no_ts_like_smart_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/no_ts_like_smart_type.ets.arkts2.json @@ -1,18 +1,4 @@ { - "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], "result": [ { "line": 30, @@ -294,6 +280,36 @@ "rule": "Smart type differences (arkts-no-ts-like-smart-type)", "severity": "ERROR" }, + { + "line": 337, + "column": 27, + "endLine": 337, + "endColumn": 36, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 337, + "column": 27, + "endLine": 337, + "endColumn": 36, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 357, + "column": 25, + "endLine": 357, + "endColumn": 36, + "problem": "NoTuplesArrays", + "suggest": "", + "rule": "Array and tuple are different type(arkts-no-tuples-arrays)", + "severity": "ERROR" + }, { "line": 137, "column": 5, diff --git a/ets2panda/linter/test/main/no_ts_like_smart_type.ets.json b/ets2panda/linter/test/main/no_ts_like_smart_type.ets.json old mode 100755 new mode 100644 index f892c8a98b9b895030306a9bdceadd6557e948de..1956437aeefa800c27da7d5b6fee943d858db914 --- a/ets2panda/linter/test/main/no_ts_like_smart_type.ets.json +++ b/ets2panda/linter/test/main/no_ts_like_smart_type.ets.json @@ -1,19 +1,95 @@ { - "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], "result": [ + { + "line": 339, + "column": 9, + "endLine": 339, + "endColumn": 14, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 340, + "column": 9, + "endLine": 340, + "endColumn": 21, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 341, + "column": 9, + "endLine": 341, + "endColumn": 23, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 344, + "column": 9, + "endLine": 344, + "endColumn": 14, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 345, + "column": 9, + "endLine": 345, + "endColumn": 21, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 346, + "column": 9, + "endLine": 346, + "endColumn": 23, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 349, + "column": 9, + "endLine": 349, + "endColumn": 14, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 350, + "column": 9, + "endLine": 350, + "endColumn": 21, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 351, + "column": 9, + "endLine": 351, + "endColumn": 23, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, { "line": 137, "column": 5, diff --git a/ets2panda/linter/test/main/styles_decorator_struct_1.ets.arkts2.json b/ets2panda/linter/test/main/styles_decorator_struct_1.ets.arkts2.json index a0db52745005abb7565736bee4d045e0bd6fad5b..50f72ada9e20aa847b0bdafe9f1df2b082ca16dd 100644 --- a/ets2panda/linter/test/main/styles_decorator_struct_1.ets.arkts2.json +++ b/ets2panda/linter/test/main/styles_decorator_struct_1.ets.arkts2.json @@ -54,16 +54,6 @@ "rule": "\"@Styles\" decorator is not supported (arkui-no-styles-decorator)", "severity": "ERROR" }, - { - "line": 103, - "column": 24, - "endLine": 103, - "endColumn": 37, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, { "line": 105, "column": 3, diff --git a/ets2panda/linter/test/main/styles_decorator_struct_1.ets.autofix.json b/ets2panda/linter/test/main/styles_decorator_struct_1.ets.autofix.json index 0d3f2bf7cf16ebbf5a94f2c9e6efff77fc57ba32..67362091ff081e0ccf0e4b362ade85a0cde99560 100644 --- a/ets2panda/linter/test/main/styles_decorator_struct_1.ets.autofix.json +++ b/ets2panda/linter/test/main/styles_decorator_struct_1.ets.autofix.json @@ -134,16 +134,6 @@ "rule": "\"@Styles\" decorator is not supported (arkui-no-styles-decorator)", "severity": "ERROR" }, - { - "line": 103, - "column": 24, - "endLine": 103, - "endColumn": 37, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, { "line": 105, "column": 3, diff --git a/ets2panda/linter/test/main/styles_decorator_struct_1.ets.migrate.json b/ets2panda/linter/test/main/styles_decorator_struct_1.ets.migrate.json index a860c9a7c737de13ba90727d6d826c1ea9a3b79d..309824bb24ffc2af087747a532a9645fd52770ab 100644 --- a/ets2panda/linter/test/main/styles_decorator_struct_1.ets.migrate.json +++ b/ets2panda/linter/test/main/styles_decorator_struct_1.ets.migrate.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 116, - "column": 24, - "endLine": 116, - "endColumn": 37, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, { "line": 120, "column": 26, diff --git a/ets2panda/linter/test/main/styles_decorator_struct_2.ets.arkts2.json b/ets2panda/linter/test/main/styles_decorator_struct_2.ets.arkts2.json index 4eb3f7e1641e26122e6247f6ed8650b680c456c8..4e818a87e4df71b7cb588336adf463716520d14f 100644 --- a/ets2panda/linter/test/main/styles_decorator_struct_2.ets.arkts2.json +++ b/ets2panda/linter/test/main/styles_decorator_struct_2.ets.arkts2.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 103, - "column": 24, - "endLine": 103, - "endColumn": 37, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, { "line": 107, "column": 26, diff --git a/ets2panda/linter/test/main/styles_decorator_struct_2.ets.autofix.json b/ets2panda/linter/test/main/styles_decorator_struct_2.ets.autofix.json index 4eb3f7e1641e26122e6247f6ed8650b680c456c8..4e818a87e4df71b7cb588336adf463716520d14f 100644 --- a/ets2panda/linter/test/main/styles_decorator_struct_2.ets.autofix.json +++ b/ets2panda/linter/test/main/styles_decorator_struct_2.ets.autofix.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 103, - "column": 24, - "endLine": 103, - "endColumn": 37, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, { "line": 107, "column": 26, diff --git a/ets2panda/linter/test/main/styles_decorator_struct_2.ets.migrate.json b/ets2panda/linter/test/main/styles_decorator_struct_2.ets.migrate.json index 4eb3f7e1641e26122e6247f6ed8650b680c456c8..4e818a87e4df71b7cb588336adf463716520d14f 100644 --- a/ets2panda/linter/test/main/styles_decorator_struct_2.ets.migrate.json +++ b/ets2panda/linter/test/main/styles_decorator_struct_2.ets.migrate.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 103, - "column": 24, - "endLine": 103, - "endColumn": 37, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, { "line": 107, "column": 26, diff --git a/ets2panda/linter/test/main/unfixed_tuple_negative.ets b/ets2panda/linter/test/main/unfixed_tuple_negative.ets new file mode 100644 index 0000000000000000000000000000000000000000..05723324d0197b9c094334504294a368ef3f08a8 --- /dev/null +++ b/ets2panda/linter/test/main/unfixed_tuple_negative.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const s: [string, ...boolean[]] = ['',true] // report error for unfixed tuple + +type Tuple1 = [string, ...boolean[]]; // report error for unfixed tuple + +type Tuple2 = [number, string, ...number[]]; // report error for unfixed tuple + +type Tuple3 = [...string[]]; // report error for unfixed tuple + +type Tuple4 = [...boolean[], number]; // report error for unfixed tuple + +type NestedTuple = [string, ...[number, boolean][]]; // report error for unfixed tuple + +function logTuple(args: [string, ...number[]]) { // report error for unfixed tuple + +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/unfixed_tuple_negative.ets.args.json b/ets2panda/linter/test/main/unfixed_tuple_negative.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..bc4d2071daf6e9354e711c3b74b6be2b56659066 --- /dev/null +++ b/ets2panda/linter/test/main/unfixed_tuple_negative.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/unfixed_tuple_negative.ets.arkts2.json b/ets2panda/linter/test/main/unfixed_tuple_negative.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..cf32008b804f2c10b091d56d81a4e56816b5966e --- /dev/null +++ b/ets2panda/linter/test/main/unfixed_tuple_negative.ets.arkts2.json @@ -0,0 +1,88 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 16, + "column": 19, + "endLine": 16, + "endColumn": 31, + "problem": "unfixedTuple", + "suggest": "", + "rule": "No unfixed length tuple support (arkts-no-unfixed-len-tuple)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 24, + "endLine": 18, + "endColumn": 36, + "problem": "unfixedTuple", + "suggest": "", + "rule": "No unfixed length tuple support (arkts-no-unfixed-len-tuple)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 32, + "endLine": 20, + "endColumn": 43, + "problem": "unfixedTuple", + "suggest": "", + "rule": "No unfixed length tuple support (arkts-no-unfixed-len-tuple)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 16, + "endLine": 22, + "endColumn": 27, + "problem": "unfixedTuple", + "suggest": "", + "rule": "No unfixed length tuple support (arkts-no-unfixed-len-tuple)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 16, + "endLine": 24, + "endColumn": 28, + "problem": "unfixedTuple", + "suggest": "", + "rule": "No unfixed length tuple support (arkts-no-unfixed-len-tuple)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 29, + "endLine": 26, + "endColumn": 51, + "problem": "unfixedTuple", + "suggest": "", + "rule": "No unfixed length tuple support (arkts-no-unfixed-len-tuple)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 34, + "endLine": 28, + "endColumn": 45, + "problem": "unfixedTuple", + "suggest": "", + "rule": "No unfixed length tuple support (arkts-no-unfixed-len-tuple)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/unfixed_tuple_negative.ets.json b/ets2panda/linter/test/main/unfixed_tuple_negative.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/unfixed_tuple_negative.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/unfixed_tuple_positive.ets b/ets2panda/linter/test/main/unfixed_tuple_positive.ets new file mode 100644 index 0000000000000000000000000000000000000000..e45b73893e04dc924b46c640d07b1ea95be48ee2 --- /dev/null +++ b/ets2panda/linter/test/main/unfixed_tuple_positive.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const s: [string, boolean[]] = ['',[true]] // ok + +const s1: [string, boolean] = ['',true] // ok + +type Tuple1 = [string, boolean[]]; // ok + +type Tuple2 = [number, string, number[]]; // ok + +type Tuple3 = [string[]]; // ok + +type Tuple4 = [boolean[], number]; // ok + +type NestedTuple = [string, [number, boolean][]]; // ok + +function logTuple(args: [string, number[]]) { // ok + +} + +function sum(...numbers: number[]): number { // ok + return numbers.reduce((total, num) => total + num, 0); +} diff --git a/ets2panda/linter/test/main/unfixed_tuple_positive.ets.args.json b/ets2panda/linter/test/main/unfixed_tuple_positive.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..bc4d2071daf6e9354e711c3b74b6be2b56659066 --- /dev/null +++ b/ets2panda/linter/test/main/unfixed_tuple_positive.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/unfixed_tuple_positive.ets.arkts2.json b/ets2panda/linter/test/main/unfixed_tuple_positive.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/unfixed_tuple_positive.ets.arkts2.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/unfixed_tuple_positive.ets.json b/ets2panda/linter/test/main/unfixed_tuple_positive.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/unfixed_tuple_positive.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json b/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json index 250fb9600ab36002fb381ff2873132546af54e73..b41be47d2ad5875650537a6bbcec26e96e8846f8 100644 --- a/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json +++ b/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json @@ -14,26 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 20, - "column": 19, - "endLine": 20, - "endColumn": 28, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 20, - "column": 35, - "endLine": 20, - "endColumn": 44, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 20, "column": 35, @@ -44,26 +24,6 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, - { - "line": 21, - "column": 19, - "endLine": 21, - "endColumn": 28, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 22, - "column": 27, - "endLine": 22, - "endColumn": 36, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 22, "column": 44, @@ -84,16 +44,6 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, - { - "line": 25, - "column": 31, - "endLine": 25, - "endColumn": 40, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 25, "column": 31, @@ -104,76 +54,6 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, - { - "line": 30, - "column": 38, - "endLine": 30, - "endColumn": 47, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 40, - "column": 30, - "endLine": 40, - "endColumn": 39, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 46, - "column": 42, - "endLine": 46, - "endColumn": 60, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 47, - "column": 42, - "endLine": 47, - "endColumn": 60, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 49, - "column": 31, - "endLine": 49, - "endColumn": 49, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 50, - "column": 31, - "endLine": 50, - "endColumn": 49, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, - { - "line": 53, - "column": 18, - "endLine": 53, - "endColumn": 36, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 54, "column": 15, @@ -194,16 +74,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 54, - "column": 19, - "endLine": 54, - "endColumn": 37, - "problem": "DuplicateDeclNameFromSdk", - "suggest": "", - "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", - "severity": "ERROR" - }, { "line": 67, "column": 3,