diff --git a/ets2panda/linter/homecheck/src/checker/migration/InteropBackwardDFACheck.ts b/ets2panda/linter/homecheck/src/checker/migration/InteropBackwardDFACheck.ts index 7f231f51fa3db655bf3a89af303d2d8361a9625d..71d73b3b28c0a6a21270d02bcf504d1b70311ede 100644 --- a/ets2panda/linter/homecheck/src/checker/migration/InteropBackwardDFACheck.ts +++ b/ets2panda/linter/homecheck/src/checker/migration/InteropBackwardDFACheck.ts @@ -33,6 +33,10 @@ import { UnknownType, Local, ArkClass, + ArkInvokeStmt, + ArkReturnStmt, + ArkThrowStmt, + PrimitiveType, } from 'arkanalyzer/lib'; import Logger, { LOG_MODULE_TYPE } from 'arkanalyzer/lib/utils/logger'; import { BaseChecker, BaseMetaData } from '../BaseChecker'; @@ -292,8 +296,8 @@ export class InteropBackwardDFACheck implements BaseChecker { } } const rightOpTy = rightOp.getType(); - if (!this.isIrrelevantType(rightOpTy)) { - const rightOpTyLang = this.getTypeDefinedLang(rightOpTy, scene); + if (!this.isIrrelevantType(rightOpTy) && !(rightOpTy instanceof PrimitiveType)) { + const rightOpTyLang = this.getTypeDefinedLang(rightOpTy, scene) ?? currentStmt.getCfg().getDeclaringMethod().getLanguage(); if (rightOpTyLang && rightOpTyLang !== apiLanguage) { res.push({ problemStmt: currentStmt, objLanguage: rightOpTyLang }); continue; @@ -331,42 +335,35 @@ export class InteropBackwardDFACheck implements BaseChecker { this.cg.getInvokeStmtByMethod(currentStmt.getCfg().getDeclaringMethod().getSignature()).forEach(cs => { const declaringMtd = cs.getCfg().getDeclaringMethod(); DVFGHelper.buildSingleDVFG(declaringMtd, scene); - const argDefs = this.findArgumentDef( - cs, - paramIdx, - apiLanguage, - importVarMap, - topLevelVarMap, - scene - ); + const argDefs = this.findArgumentDef(cs, paramIdx, apiLanguage, importVarMap, topLevelVarMap, scene); if (this.isLanguage(argDefs)) { // imported var res.push({ problemStmt: cs, objLanguage: argDefs as Language }); } else { argDefs.forEach(d => { - this.checkFromStmt( - d, - apiLanguage, - res, - visited, - importVarMap, - topLevelVarMap, - scene, - depth + 1 - ); + this.checkFromStmt(d, apiLanguage, res, visited, importVarMap, topLevelVarMap, scene, depth + 1); }); } }); continue; } - current.getIncomingEdge().forEach(e => worklist.push(e.getSrcNode() as DVFGNode)); if (stmt instanceof ArkAssignStmt) { const rightOp = stmt.getRightOp(); if (rightOp instanceof Local && !rightOp.getDeclaringStmt()) { (topLevelVarMap.get(rightOp.getName()) ?? []).forEach(def => { worklist.push(DVFGHelper.getOrNewDVFGNode(def, scene)); }); + } else { + current.getIncomingEdge().forEach(e => { + const srcNode = e.getSrcNode() as DVFGNode; + const srcStmt = srcNode.getStmt(); + if (srcStmt.getDef() === stmt.getRightOp()) { + worklist.push(srcNode); + } + }) } + } else if ((stmt instanceof ArkReturnStmt) || (stmt instanceof ArkThrowStmt)) { + current.getIncomingEdge().forEach(e => worklist.push(e.getSrcNode() as DVFGNode)); } } } @@ -430,8 +427,8 @@ export class InteropBackwardDFACheck implements BaseChecker { } } const argTy = arg.getType(); - if (!this.isIrrelevantType(argTy)) { - const argTyLang = this.getTypeDefinedLang(argTy, scene); + if (!this.isIrrelevantType(argTy) && !(argTy instanceof PrimitiveType)) { + const argTyLang = this.getTypeDefinedLang(argTy, scene) ?? stmt.getCfg().getDeclaringMethod().getLanguage(); if (argTyLang && argTyLang !== apiLanguage) { return argTyLang; } diff --git a/ets2panda/linter/homecheck/src/checker/migration/NoTSLikeAsCheck.ts b/ets2panda/linter/homecheck/src/checker/migration/NoTSLikeAsCheck.ts index 3c7fb7450ab5e02a8d5551c0945879e1bf7aa3f6..bd36723fa88da1c411771da95c4b14c6b491e7d0 100644 --- a/ets2panda/linter/homecheck/src/checker/migration/NoTSLikeAsCheck.ts +++ b/ets2panda/linter/homecheck/src/checker/migration/NoTSLikeAsCheck.ts @@ -71,6 +71,7 @@ enum TypeAssuranceCondition { export class NoTSLikeAsCheck implements BaseChecker { readonly metaData: BaseMetaData = gMetaData; + readonly checkedBinaryOperator: string[] = ['+', '-', '*', '/', '%', '**']; public rule: Rule; public defects: Defects[] = []; public issues: IssueReport[] = []; @@ -147,8 +148,8 @@ export class NoTSLikeAsCheck implements BaseChecker { continue; } - // 判断是否为cast表达式的自增自减运算,属于告警场景之一 - if (this.isCastExprWithIncrementDecrement(stmt)) { + // 判断是否为cast表达式的算数运算,属于告警场景之一 + if (this.isCastExprWithNumericOperation(stmt)) { this.addIssueReport(stmt, castExpr, undefined, true); continue; } @@ -178,6 +179,29 @@ export class NoTSLikeAsCheck implements BaseChecker { } } + private isCastExprWithNumericOperation(stmt: Stmt): boolean { + if (this.isCastExprWithIncrementDecrement(stmt)) { + return true; + } + if (!(stmt instanceof ArkAssignStmt)) { + return false; + } + const leftOp = stmt.getLeftOp(); + if (!(leftOp instanceof ArkCastExpr)) { + return false; + } + const rightOp = stmt.getRightOp(); + if (!(rightOp instanceof ArkNormalBinopExpr)) { + return false; + } + const op1 = rightOp.getOp1(); + if (leftOp !== op1) { + return false; + } + const operator = rightOp.getOperator(); + return this.checkedBinaryOperator.includes(operator); + } + private isCastExprWithIncrementDecrement(stmt: Stmt): boolean { if (!(stmt instanceof ArkAssignStmt) || !(stmt.getRightOp() instanceof ArkCastExpr)) { return false; @@ -585,10 +609,20 @@ export class NoTSLikeAsCheck implements BaseChecker { return null; } const rightOp = stmt.getRightOp(); - if (!(rightOp instanceof ArkCastExpr)) { - return null; + if (rightOp instanceof ArkCastExpr) { + return rightOp; + } + if (rightOp instanceof ArkNormalBinopExpr) { + const op1 = rightOp.getOp1(); + const op2 = rightOp.getOp2(); + if (op1 instanceof ArkCastExpr) { + return op1; + } + if (op2 instanceof ArkCastExpr) { + return op2; + } } - return rightOp; + return null; } private collectArgDefs(argIdx: number, callsites: Stmt[]): Stmt[] { @@ -611,7 +645,6 @@ export class NoTSLikeAsCheck implements BaseChecker { const problem = 'As'; const descPrefix = 'The value in type assertion is assigned by value with interface annotation'; let desc = `(${this.rule.ruleId.replace('@migration/', '')})`; - if (incrementCase) { desc = 'Can not use neither increment nor decrement with cast expression ' + desc; } else if (relatedStmt === undefined) { diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index faeb575025c45d935602171d85292961ec6e4996..f67ac33cb405aca2cdade5ada614980da4b1c1d9 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -267,4 +267,4 @@ faultsAttrs[FaultID.NumericBigintCompare] = new FaultAttributes(376); faultsAttrs[FaultID.NondecimalBigint] = new FaultAttributes(377); faultsAttrs[FaultID.UnsupportOperator] = new FaultAttributes(378); faultsAttrs[FaultID.StateStylesBlockNeedArrowFunc] = new FaultAttributes(381); -faultsAttrs[FaultID.PromiseVoidNeedResolveArg] = new FaultAttributes(382); \ No newline at end of file +faultsAttrs[FaultID.PromiseVoidNeedResolveArg] = new FaultAttributes(382); diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 393b46cc964a27a7a94ab5adc6a74035cb3e3ae5..dcb878796da2ccf96777761fc6bffc612e965492 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -22,7 +22,7 @@ import { Autofixer } from './autofixes/Autofixer'; import { PROMISE_METHODS, SYMBOL, SYMBOL_CONSTRUCTOR, TsUtils } from './utils/TsUtils'; import { FUNCTION_HAS_NO_RETURN_ERROR_CODE } from './utils/consts/FunctionHasNoReturnErrorCode'; import { LIMITED_STANDARD_UTILITY_TYPES } from './utils/consts/LimitedStandardUtilityTypes'; -import { LIKE_FUNCTION } from './utils/consts/LikeFunction'; +import { LIKE_FUNCTION, LIKE_FUNCTION_CONSTRUCTOR } from './utils/consts/LikeFunction'; import { METHOD_DECLARATION } from './utils/consts/MethodDeclaration'; import { METHOD_SIGNATURE } from './utils/consts/MethodSignature'; import { OPTIONAL_METHOD } from './utils/consts/OptionalMethod'; @@ -160,6 +160,10 @@ import { ERROR_PROP_LIST } from './utils/consts/ErrorProp'; import { D_ETS, D_TS } from './utils/consts/TsSuffix'; import { arkTsBuiltInTypeName } from './utils/consts/ArkuiImportList'; import { ERROR_TASKPOOL_PROP_LIST } from './utils/consts/ErrorProp'; +import { COMMON_UNION_MEMBER_ACCESS_WHITELIST} from './utils/consts/ArktsWhiteApiPaths'; +import type { BaseClassConstructorInfo, ConstructorParameter, ExtendedIdentifierInfo } from './utils/consts/Types'; +import { ExtendedIdentifierType } from './utils/consts/Types'; +import { STRING_ERROR_LITERAL } from './utils/consts/Literals'; export class TypeScriptLinter extends BaseTypeScriptLinter { supportedStdCallApiChecker: SupportedStdCallApiChecker; @@ -625,7 +629,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return ( ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop) && - (ts.isCallExpression(objLitExpr.parent) || ts.isNewExpression(objLitExpr.parent)) + (ts.isCallExpression(objLitExpr.parent) || ts.isNewExpression(objLitExpr.parent)) ); } @@ -1253,6 +1257,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.checkConstrutorAccess(node as ts.PropertyAccessExpression); this.handleTaskPoolDeprecatedUsages(node as ts.PropertyAccessExpression); this.handleNoTuplesArraysForPropertyAccessExpression(node as ts.PropertyAccessExpression); + this.handleUnsafeOptionalCallComparison(node as ts.PropertyAccessExpression); if (ts.isCallExpression(node.parent) && node === node.parent.expression) { return; } @@ -1268,14 +1273,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); } - if ( - !this.options.arkts2 && - !!exprSym && - this.tsUtils.isStdSymbolAPI(exprSym) && - !ALLOWED_STD_SYMBOL_API.includes(exprSym.getName()) - ) { - this.incrementCounters(propertyAccessNode, FaultID.SymbolType); - } + this.checkSymbolAPI(propertyAccessNode, exprSym); if (this.options.advancedClassChecks && this.tsUtils.isClassObjectExpression(propertyAccessNode.expression)) { this.incrementCounters(propertyAccessNode.expression, FaultID.ClassAsObject); } @@ -1291,6 +1289,17 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.fixJsImportPropertyAccessExpression(node); } + private checkSymbolAPI(node: ts.PropertyAccessExpression, exprSym: ts.Symbol | undefined): void { + if ( + !this.options.arkts2 && + !!exprSym && + this.tsUtils.isStdSymbolAPI(exprSym) && + !ALLOWED_STD_SYMBOL_API.includes(exprSym.getName()) + ) { + this.incrementCounters(node, FaultID.SymbolType); + } + } + propertyAccessExpressionForBuiltin(decl: ts.PropertyAccessExpression): void { if (this.options.arkts2) { this.handleSymbolIterator(decl); @@ -1437,7 +1446,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } const baseExprType = this.tsTypeChecker.getTypeAtLocation(propertyAccessNode.expression); - if (!baseExprType.isUnion() || this.tsTypeChecker.typeToString(baseExprType) === 'ArrayBufferLike') { + const baseExprSym = baseExprType.aliasSymbol || baseExprType.getSymbol(); + const symbolName = baseExprSym ? baseExprSym.name : this.tsTypeChecker.typeToString(baseExprType); + if (!baseExprType.isUnion() || COMMON_UNION_MEMBER_ACCESS_WHITELIST.has(symbolName)) { return; } const allType = baseExprType.types; @@ -1534,7 +1545,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handlePropertyDeclarationForProp(node); this.handleSdkGlobalApi(node); this.handleObjectLiteralAssignmentToClass(node); - this.handleNumericPublicStatic(node) + this.handleNumericPublicStatic(node); } private handleSendableClassProperty(node: ts.PropertyDeclaration): void { @@ -2077,7 +2088,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleObjectLiteralAssignmentToClass(tsBinaryExpr); this.handleAssignmentNotsLikeSmartType(tsBinaryExpr); } - + private handleNumericPublicStatic(node: ts.PropertyDeclaration): void { if (!this.options.arkts2) { return; @@ -2091,8 +2102,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } if (node.initializer) { - if (ts.isBinaryExpression(node.initializer) && - this.isNumericExpression(node.initializer)) { + if (ts.isBinaryExpression(node.initializer) && this.isNumericExpression(node.initializer)) { const autofix = this.autofixer?.fixNumericPublicStatic(node); this.incrementCounters(node, FaultID.NumericSemantics, autofix); } @@ -2106,10 +2116,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!ts.isBinaryExpression(node)) { return false; } - return ( - this.isNumericExpression(node.left) && - this.isNumericExpression(node.right) - ); + return this.isNumericExpression(node.left) && this.isNumericExpression(node.right); } private checkInterOpImportJsDataCompare(expr: ts.BinaryExpression): void { @@ -3301,25 +3308,24 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } - const classType = this.tsTypeChecker.getTypeAtLocation(classDecl); - const allBaseTypes = this.getAllBaseTypes(classType, classDecl); + const isStatic = node.modifiers?.some(mod => { + return mod.kind === ts.SyntaxKind.StaticKeyword; + }) || false; + const classType: ts.Type | undefined = this.getClassType(classDecl, isStatic); + const allBaseTypes = classType && this.getAllBaseTypes(classType, classDecl, isStatic); if (!allBaseTypes || allBaseTypes.length === 0) { return; } - const methodName = node.name.text; - for (const baseType of allBaseTypes) { const baseMethod = baseType.getProperty(methodName); if (!baseMethod) { continue; } - + const baseMethodDecl = baseMethod.declarations?.find((d) => { - return ( - (ts.isMethodDeclaration(d) || ts.isMethodSignature(d)) && - this.tsTypeChecker.getTypeAtLocation(d.parent) === baseType - ); + return (ts.isMethodDeclaration(d) || ts.isMethodSignature(d)) && + this.isDeclarationInType(d, baseType, isStatic); }) as ts.MethodDeclaration | ts.MethodSignature; if (!baseMethodDecl) { @@ -3327,17 +3333,104 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } this.checkMethodParameters(node, baseMethodDecl); - this.checkMethodReturnType(node, baseMethodDecl); break; } } - private getAllBaseTypes(type: ts.Type, classDecl: ts.ClassDeclaration): ts.Type[] | undefined { + private getClassType( classDecl: ts.ClassDeclaration, isStatic?: boolean): ts.Type | undefined { + let classType: ts.Type; + + if (isStatic) { + const classConstructorSymbol = classDecl.symbol; + if (!classConstructorSymbol) { + return undefined; + } + classType = this.tsTypeChecker.getTypeOfSymbolAtLocation(classConstructorSymbol, classDecl); + } else { + classType = this.tsTypeChecker.getTypeAtLocation(classDecl); + } + return classType; + } + + private isDeclarationInType(decl: ts.Declaration, type: ts.Type, isStatic: boolean = false): boolean { + const declParent = decl.parent; + if (!declParent) { + return false; + } + + let declParentType: ts.Type; + if (isStatic && ts.isClassDeclaration(declParent)) { + if (!declParent.symbol) { + return false; + } + declParentType = this.tsTypeChecker.getTypeOfSymbolAtLocation(declParent.symbol, declParent); + } else { + declParentType = this.tsTypeChecker.getTypeAtLocation(declParent); + } + + return this.isSameType(declParentType, type); + } + + private isSameType(type1: ts.Type, type2: ts.Type): boolean { + if (type1.flags & ts.TypeFlags.Any || type2.flags & ts.TypeFlags.Any) { + return true; + } + + if (type1.flags & ts.TypeFlags.TypeParameter && type2.flags & ts.TypeFlags.TypeParameter) { + const constraint1 = (type1 as ts.TypeParameter).getConstraint(); + const constraint2 = (type2 as ts.TypeParameter).getConstraint(); + if (constraint1 && constraint2) { + return this.isSameType(constraint1, constraint2); + } + } + + if (!type1.symbol || type1.symbol !== type2.symbol) { + return false; + } + const type1Args = (type1 as ts.TypeReference).typeArguments; + const type2Args = (type2 as ts.TypeReference).typeArguments; + + if (type1Args && type2Args && type1Args.length === type2Args.length) { + for (let i = 0; i < type1Args.length; i++) { + if (!this.isTypeAssignable(type2Args[i], type1Args[i])) { + return false; + } + } + return true; + } + + return this.tsTypeChecker.typeToString(type1) === this.tsTypeChecker.typeToString(type2); + } + + private getAllBaseTypes(type: ts.Type, classDecl: ts.ClassDeclaration, isStatic?: boolean): ts.Type[] | undefined { + if (isStatic) { + const baseTypes: ts.Type[] = []; + if (!classDecl.heritageClauses) { + return baseTypes; + } + for (const clause of classDecl.heritageClauses) { + if (clause.token !== ts.SyntaxKind.ExtendsKeyword) { + continue; + } + for (const typeNode of clause.types) { + const baseType = this.tsTypeChecker.getTypeAtLocation(typeNode); + baseTypes.push(baseType); + } + } + + return baseTypes; + } + const baseClasses = type.getBaseTypes() || []; + const resolvedBaseClasses = baseClasses.flatMap((baseType) => { + const symbol = baseType.getSymbol(); + return symbol ? [this.tsTypeChecker.getDeclaredTypeOfSymbol(symbol)] : [baseType]; + }); + if (!classDecl.heritageClauses) { - return baseClasses; + return resolvedBaseClasses; } const interfaces: ts.Type[] = []; for (const clause of classDecl.heritageClauses) { @@ -3347,13 +3440,17 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { for (const typeNode of clause.types) { const interfaceType = this.tsTypeChecker.getTypeAtLocation(typeNode); interfaces.push(interfaceType); - const parentInterfaces = interfaceType.getBaseTypes(); - if (parentInterfaces) { - interfaces.push(...parentInterfaces); - } + + const baseInterfaces = interfaceType.getBaseTypes() || []; + baseInterfaces.forEach((baseInterface) => { + const symbol = baseInterface.getSymbol(); + if (symbol) { + interfaces.push(this.tsTypeChecker.getDeclaredTypeOfSymbol(symbol)); + } + }); } } - return [...baseClasses, ...interfaces]; + return [...resolvedBaseClasses, ...interfaces]; } /** @@ -3467,15 +3564,29 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return type; } - /** - * Child type should include all types of parent type (be same or wider). - * Returns true if every type in baseType is also included in derivedType. - */ private isTypeSameOrWider(baseType: ts.Type, derivedType: ts.Type): boolean { + if (derivedType.flags & ts.TypeFlags.Any) { + return true; + } + + if (baseType.symbol === derivedType.symbol && baseType.symbol) { + const baseArgs = (baseType as ts.TypeReference).typeArguments; + const derivedArgs = (derivedType as ts.TypeReference).typeArguments; + + if (!baseArgs || !derivedArgs || baseArgs.length !== derivedArgs.length) { + return false; + } + for (let i = 0; i < baseArgs.length; i++) { + if (!this.isTypeAssignable(baseArgs[i], derivedArgs[i])) { + return false; + } + } + return true; + } + const baseTypeSet = new Set(this.flattenUnionTypes(baseType)); const derivedTypeSet = new Set(this.flattenUnionTypes(derivedType)); - // Check if every type in baseType is also present in derivedType for (const typeStr of baseTypeSet) { if (!derivedTypeSet.has(typeStr)) { if (TypeScriptLinter.areWrapperAndPrimitiveTypesEqual(typeStr, derivedTypeSet)) { @@ -3484,19 +3595,31 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return false; } } - return true; } - // Checks structural assignability between two types. private isTypeAssignable(fromType: ts.Type, toType: ts.Type): boolean { - if (this.isDerivedTypeAssignable(fromType, toType)) { + if (fromType.flags & ts.TypeFlags.Any) { return true; } + + if (fromType.symbol === toType.symbol && fromType.symbol) { + const fromArgs = (fromType as ts.TypeReference).typeArguments; + const toArgs = (toType as ts.TypeReference).typeArguments; + + if (fromArgs && toArgs && fromArgs.length === toArgs.length) { + for (let i = 0; i < fromArgs.length; i++) { + if (!this.isTypeAssignable(fromArgs[i], toArgs[i])) { + return false; + } + } + return true; + } + } + const fromTypes = this.flattenUnionTypes(fromType); const toTypes = new Set(this.flattenUnionTypes(toType)); - // All types in `fromTypes` should exist in `toTypes` for assignability. return fromTypes.every((typeStr) => { if (toTypes.has(typeStr)) { return true; @@ -3962,7 +4085,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.tsUtils.isOrDerivedFrom(type, this.tsUtils.isStdRecordType) || this.tsUtils.isOrDerivedFrom(type, this.tsUtils.isStringType) || !this.options.arkts2 && - (this.tsUtils.isOrDerivedFrom(type, this.tsUtils.isStdMapType) || TsUtils.isIntrinsicObjectType(type)) || + (this.tsUtils.isOrDerivedFrom(type, this.tsUtils.isStdMapType) || TsUtils.isIntrinsicObjectType(type)) || TsUtils.isEnumType(type) || // we allow EsObject here beacuse it is reported later using FaultId.EsObjectType TsUtils.isEsValueType(typeNode) @@ -4119,7 +4242,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.incrementCounters(argExpr, FaultID.ArrayIndexExprType, autofix); } } else if (this.tsTypeChecker.typeToString(argType) === 'number') { - if (this.isArrayIndexValidNumber(argExpr)) { + if (this.isArrayIndexValidNumber(argExpr) || this.hasNonIntegerInitializer(argExpr)) { return; } const autofix = this.autofixer?.fixArrayIndexExprType(argExpr); @@ -4133,6 +4256,27 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } + /** + * Returns true if the identifier’s initializer is a non-integer numeric literal (e.g. 1.3, 2.5). + */ + private hasNonIntegerInitializer(argExpr: ts.Expression): boolean { + if (!ts.isIdentifier(argExpr)) { + return false; + } + const declNode = this.tsUtils.getDeclarationNode(argExpr); + if ( + declNode && + ts.isVariableDeclaration(declNode) && + declNode.initializer && + ts.isNumericLiteral(declNode.initializer) + ) { + const raw = declNode.initializer.getText(); + const num = Number(raw); + return !Number.isInteger(num); + } + return false; + } + private checkNumericArgumentDeclaration(argExpr: ts.Expression): void { const symbol = this.tsTypeChecker.getSymbolAtLocation(argExpr); @@ -4151,15 +4295,12 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const isNumericInitializer = initializer && ts.isNumericLiteral(initializer); const initializerNumber = isNumericInitializer ? Number(initializerText) : NaN; const isUnsafeNumber = isNumericInitializer && !Number.isInteger(initializerNumber); + const containsDot = initializerText.includes('.'); - if (isUnsafeNumber) { + if (containsDot || isUnsafeNumber || initializerText === 'undefined') { const autofix = this.autofixer?.fixArrayIndexExprType(argExpr); this.incrementCounters(argExpr, FaultID.ArrayIndexExprType, autofix); } - - if (initializerText === 'undefined') { - this.handleUndefinedInitializer(argExpr, firstDeclaration); - } } private evaluateValueFromDeclaration(argExpr: ts.Expression): number | null | 'skip' { @@ -4225,15 +4366,6 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return evaluatedValue >= 0; } - private handleUndefinedInitializer(argExpr: ts.Expression, declaration: ts.VariableDeclaration): void { - if (ts.isParameter(declaration)) { - const autofix = this.autofixer?.fixArrayIndexExprType(argExpr); - this.incrementCounters(argExpr, FaultID.ArrayIndexExprType, autofix); - } else { - this.incrementCounters(argExpr, FaultID.ArrayIndexExprType); - } - } - private handleEnumMember(node: ts.Node): void { const tsEnumMember = node as ts.EnumMember; const tsEnumMemberType = this.tsTypeChecker.getTypeAtLocation(tsEnumMember); @@ -4298,6 +4430,17 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!initializer) { return; } + if (ts.isAsExpression(initializer) || ts.isTypeAssertionExpression(initializer)) { + const typeNode = ts.isAsExpression(initializer) + ? initializer.type + : initializer.type; + + if (typeNode.kind === ts.SyntaxKind.NumberKeyword) { + this.incrementCounters(enumMember, FaultID.EnumMemberNonConstInit); + return; + } + } + let value; if (ts.isNumericLiteral(initializer)) { value = parseFloat(initializer.text); @@ -4485,10 +4628,21 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const expression = callExpr.expression; const type = this.tsTypeChecker.getTypeAtLocation(expression); const typeText = this.tsTypeChecker.typeToString(type); - if (typeText === LIKE_FUNCTION) { + + if (LIKE_FUNCTION !== typeText) { + return; + } + if (ts.isNewExpression(expression) || ts.isCallExpression(expression)) { + const exprIndentifier = expression.expression; + const typeExprIndent = this.tsTypeChecker.getTypeAtLocation(exprIndentifier); + const typeTextExprIndent = this.tsTypeChecker.typeToString(typeExprIndent); + if (typeTextExprIndent === LIKE_FUNCTION_CONSTRUCTOR) { + this.incrementCounters(expression, FaultID.ExplicitFunctionType); + } + } else { const autofix = this.autofixer?.fixNoTsLikeFunctionCall(callExpr); this.incrementCounters(expression, FaultID.ExplicitFunctionType, autofix); - } + } } private handleAppStorageCallExpression(tsCallExpr: ts.CallExpression): void { @@ -5273,6 +5427,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleObjectLiteralAssignmentToClass(tsAsExpr); this.handleArrayTypeImmutable(tsAsExpr, exprType, targetType); this.handleNotsLikeSmartTypeOnAsExpression(tsAsExpr); + this.handleLimitedVoidTypeOnAsExpression(tsAsExpr); } private handleAsExprStructuralTyping(asExpr: ts.AsExpression, targetType: ts.Type, exprType: ts.Type): void { @@ -6285,7 +6440,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if ( this.compatibleSdkVersion > SENDBALE_FUNCTION_START_VERSION || this.compatibleSdkVersion === SENDBALE_FUNCTION_START_VERSION && - !SENDABLE_FUNCTION_UNSUPPORTED_STAGES_IN_API12.includes(this.compatibleSdkVersionStage) + !SENDABLE_FUNCTION_UNSUPPORTED_STAGES_IN_API12.includes(this.compatibleSdkVersionStage) ) { return true; } @@ -6331,6 +6486,16 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } + private handleLimitedVoidTypeOnAsExpression(node: ts.AsExpression): void { + if (!this.options.arkts2) { + return; + } + const targetType = this.tsTypeChecker.getTypeAtLocation(node.type); + if (TsUtils.isVoidType(targetType)) { + this.incrementCounters(node.type, FaultID.LimitedVoidType); + } + } + private handleLimitedVoidWithCall(node: ts.CallExpression): void { if ( ts.isExpressionStatement(node.parent) || @@ -6489,10 +6654,10 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const typeText = this.tsTypeChecker.typeToString(t); return Boolean( t.flags & ts.TypeFlags.StringLike || - typeText === 'String' || - t.flags & ts.TypeFlags.NumberLike && (/^\d+$/).test(typeText) || - isLiteralInitialized && !hasExplicitTypeAnnotation && !isFloatLiteral || - t.flags & ts.TypeFlags.EnumLike + typeText === 'String' || + t.flags & ts.TypeFlags.NumberLike && (/^\d+$/).test(typeText) || + isLiteralInitialized && !hasExplicitTypeAnnotation && !isFloatLiteral || + t.flags & ts.TypeFlags.EnumLike ); }; @@ -6764,9 +6929,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } if ( this.tsUtils.isOrDerivedFrom(lhsType, this.tsUtils.isArray) && - this.tsUtils.isOrDerivedFrom(rhsType, TsUtils.isTuple) || + this.tsUtils.isOrDerivedFrom(rhsType, TsUtils.isTuple) || this.tsUtils.isOrDerivedFrom(rhsType, this.tsUtils.isArray) && - this.tsUtils.isOrDerivedFrom(lhsType, TsUtils.isTuple) + this.tsUtils.isOrDerivedFrom(lhsType, TsUtils.isTuple) ) { this.incrementCounters(node, FaultID.NoTuplesArrays); } @@ -8918,7 +9083,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { * @param node The HeritageClause node (extends clause) to analyze. */ private handleMissingSuperCallInExtendedClass(node: ts.HeritageClause): void { - if (!this.options.arkts2 || !this.useStatic) { + if (!this.options.arkts2) { return; } @@ -8927,78 +9092,249 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } - // Get the parent class declaration (what the child class extends) - const parentClass = this.getParentClassDeclaration(node); - if (!parentClass) { + if (!ts.isClassDeclaration(node.parent)) { return; } - // If parent class has a parameterless constructor (or no constructor at all), child is fine - if (TypeScriptLinter.parentHasParameterlessConstructor(parentClass)) { + /* + * Get the parent class declaration (what the child class extends) + * This could be a stdlib error type + */ + const identInfo = this.getExtendedIdentifiersInfo(node); + if (identInfo.type === ExtendedIdentifierType.UNKNOWN) { + // if it's unknown return return; } - // The child class node (the one extending) - const childClass = node.parent; - if (!ts.isClassDeclaration(childClass)) { + if (identInfo.type === ExtendedIdentifierType.ERROR) { + this.handleErrorClassExtend(node.parent); + // handled error case return return; } - // Look for child class constructor - const childConstructor = childClass.members.find(ts.isConstructorDeclaration); + if (identInfo.type === ExtendedIdentifierType.CLASS) { + // If it's class, get the constructor's parameters and match against it. + const extendedClassInfo = this.extractExtendedClassConstructorInfo(identInfo.decl); + if (!extendedClassInfo) { + return; + } - /* - * If child has no constructor → error (super() cannot be called) - * If child constructor exists but does not contain super() → error - */ - if (!childConstructor?.body || !TypeScriptLinter.childHasSuperCall(childConstructor)) { - this.incrementCounters(node, FaultID.MissingSuperCall); + this.handleExtendCustomClass(node.parent, extendedClassInfo); } } - /** - * Retrieves the parent class declaration node from an extends heritage clause. - */ - private getParentClassDeclaration(node: ts.HeritageClause): ts.ClassDeclaration | undefined { - const parentExpr = node.types[0]?.expression; - if (!parentExpr) { + private handleExtendCustomClass( + classDecl: ts.ClassDeclaration, + extendedClassInfo: Set + ): void { + const superCall = TypeScriptLinter.checkIfSuperCallExists(classDecl); + if (!superCall) { + this.incrementCounters(classDecl, FaultID.MissingSuperCall); + return; + } + + outer: for (const ctorParams of extendedClassInfo) { + const matches: boolean[] = []; + if (superCall.arguments.length > ctorParams.length) { + continue; + } + + for (const [idx, param] of ctorParams.entries()) { + const argument = superCall.arguments[idx]; + if (!param.isOptional && !argument) { + matches[idx] = false; + continue outer; + } + + if (!argument && param.isOptional) { + matches[idx] = true; + continue; + } + if (argument !== undefined) { + matches[idx] = this.checkIfArgumentAndParamMatches(param, argument); + if (!matches[idx]) { + continue outer; + } + } + } + + if ( + matches.some((val) => { + return !val; + }) + ) { + continue; + } + return; + } + + this.incrementCounters(classDecl, FaultID.MissingSuperCall); + } + + private checkIfArgumentAndParamMatches(param: ConstructorParameter, argument: ts.Expression): boolean { + const typeNode = this.tsTypeChecker.getTypeAtLocation(argument); + const typeString = this.tsTypeChecker.typeToString(typeNode); + + if (param.type.includes(STRINGLITERAL_STRING) && argument.kind === ts.SyntaxKind.StringLiteral) { + return true; + } + if (param.type.includes(NUMBER_LITERAL) && argument.kind === ts.SyntaxKind.NumericLiteral) { + return true; + } + + if ( + param.type.includes('boolean') && + (argument.kind === ts.SyntaxKind.FalseKeyword || argument.kind === ts.SyntaxKind.TrueKeyword) + ) { + return true; + } + + if (param.type === typeString) { + return true; + } + + return false; + } + + private handleErrorClassExtend(classDecl: ts.ClassDeclaration): void { + // if it's Error, the super method should be called with no arguments or a single string argument + const superCall = TypeScriptLinter.checkIfSuperCallExists(classDecl); + if (!superCall) { + this.incrementCounters(classDecl, FaultID.MissingSuperCall); + return; + } + + if (superCall.arguments.length > 1) { + + /* + * STD Error Type have two constructors + * either empty constructor which is just "Error" message + * or the message you provide, so if it's more than one argument provided, + * this should be raised as an issue + */ + this.incrementCounters(classDecl, FaultID.MissingSuperCall); + return; + } + + if (superCall.arguments.length === 1) { + const argument = superCall.arguments[0]; + const typeNode = this.tsTypeChecker.getTypeAtLocation(argument); + const typeString = this.tsTypeChecker.typeToString(typeNode); + + if (typeString === 'string' || ts.isStringLiteral(argument) || ts.isNumericLiteral(argument)) { + return; + } + this.incrementCounters(classDecl, FaultID.MissingSuperCall); + } + } + + private static checkIfSuperCallExists(classDecl: ts.ClassDeclaration): ts.CallExpression | undefined { + // check if current class has constructor + const constructor = TypeScriptLinter.getConstructorOfClass(classDecl); + if (!constructor) { return undefined; } - const parentSymbol = this.tsUtils.trueSymbolAtLocation(parentExpr); - return parentSymbol?.declarations?.find(ts.isClassDeclaration); + const superCallExpr = TypeScriptLinter.getSuperCallExpr(constructor); + if (!superCallExpr) { + return undefined; + } + + return superCallExpr; } /** - * Determines if a parent class has a parameterless constructor. - * If it has no constructor at all, that counts as parameterless. + * Extracts the type of the Identifier node from an extends heritage clause. */ - private static parentHasParameterlessConstructor(parentClass: ts.ClassDeclaration): boolean { - const constructors = parentClass.members.filter(ts.isConstructorDeclaration); - return ( - constructors.length === 0 || - constructors.some((ctor) => { - return ctor.parameters.length === 0; - }) - ); + private getExtendedIdentifiersInfo(node: ts.HeritageClause): ExtendedIdentifierInfo { + const extendedIdentifier = node.types[0]?.expression; + if (!extendedIdentifier) { + return { type: ExtendedIdentifierType.UNKNOWN }; + } + + const symbol = this.tsUtils.trueSymbolAtLocation(extendedIdentifier); + if (!symbol) { + return { type: ExtendedIdentifierType.UNKNOWN }; + } + + if (symbol.getName().includes(STRING_ERROR_LITERAL)) { + const declaration = this.tsUtils.getDeclarationNode(extendedIdentifier); + if (!declaration) { + return { type: ExtendedIdentifierType.ERROR }; + } + + if (declaration.getSourceFile().fileName !== this.sourceFile.fileName) { + return { type: ExtendedIdentifierType.ERROR }; + } + } + + const classDecl = symbol?.declarations?.find(ts.isClassDeclaration); + if (!classDecl) { + return { type: ExtendedIdentifierType.UNKNOWN }; + } + + return { type: ExtendedIdentifierType.CLASS, decl: classDecl }; } - private static childHasSuperCall(constructor: ts.ConstructorDeclaration): boolean { - let superCalled = false; + private extractExtendedClassConstructorInfo(extendedClass: ts.ClassDeclaration): BaseClassConstructorInfo { + const constructors = extendedClass.members.filter(ts.isConstructorDeclaration); + if (constructors.length === 0) { + return undefined; + } + + const allConstructorInformation: BaseClassConstructorInfo = new Set(); + for (const ctor of constructors) { + const allParams: ConstructorParameter[] = []; + const parameters = ctor.parameters; + for (const param of parameters) { + const ident = param.name; + const name = ident.getText(); + const type = this.tsTypeChecker.getTypeAtLocation(ident); + const typeString = this.tsTypeChecker.typeToString(type); + const isOptional = !!param.questionToken; + const info = { name, type: typeString, isOptional }; + allParams.push(info); + } + allConstructorInformation.add(allParams); + } + + return allConstructorInformation; + } + + private static getConstructorOfClass(classDecl: ts.ClassDeclaration): ts.ConstructorDeclaration | undefined { + if (classDecl.members.length === 0) { + return undefined; + } + + for (const member of classDecl.members) { + if (!ts.isConstructorDeclaration(member)) { + continue; + } + return member; + } + return undefined; + } + + private static getSuperCallExpr(constructor: ts.ConstructorDeclaration): ts.CallExpression | undefined { if (!constructor.body) { - return false; + return undefined; } - ts.forEachChild(constructor.body, (stmt) => { - if ( - ts.isExpressionStatement(stmt) && - ts.isCallExpression(stmt.expression) && - stmt.expression.expression.kind === ts.SyntaxKind.SuperKeyword - ) { - superCalled = true; + for (const stmt of constructor.body.statements) { + if (!ts.isExpressionStatement(stmt)) { + continue; } - }); - return superCalled; + const callExpr = stmt.expression; + if (!ts.isCallExpression(callExpr)) { + continue; + } + if (callExpr.expression.kind !== ts.SyntaxKind.SuperKeyword) { + continue; + } + + return callExpr; + } + return undefined; } private handleInterOpImportJs(importDecl: ts.ImportDeclaration): void { @@ -9839,11 +10175,23 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } const expectedType = parameterTypes[index]; + let expectedUnionType: string[] = []; + if (expectedType.includes('|')) { + expectedUnionType = expectedType.split('|').map((item) => { + return item.trim(); + }); + } const actualSym = this.tsTypeChecker.getSymbolAtLocation(arg); const decl = TsUtils.getDeclaration(actualSym); if (decl && ts.isParameter(decl) && decl.type) { const actualType = this.tsTypeChecker.getTypeFromTypeNode(decl.type); const actualTypeName = this.tsTypeChecker.typeToString(actualType); + if (expectedUnionType.length > 0) { + if (!expectedUnionType.includes(actualTypeName)) { + this.incrementCounters(arg, FaultID.NoTsLikeSmartType); + } + return; + } if (actualTypeName !== expectedType) { this.incrementCounters(arg, FaultID.NoTsLikeSmartType); } @@ -9911,6 +10259,24 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return false; } + private handleUnsafeOptionalCallComparison(expr: ts.PropertyAccessExpression): void { + if (!this.options.arkts2) { + return; + } + const declaration = this.tsUtils.getDeclarationNode(expr.expression); + if (!declaration) { + return; + } + + if ( + (ts.isParameter(declaration) || ts.isPropertyDeclaration(declaration)) && + !!declaration.questionToken && + !ts.isPropertyAccessChain(expr) + ) { + this.incrementCounters(expr, FaultID.NoTsLikeSmartType); + } + } + private handleNotsLikeSmartType(classDecl: ts.ClassDeclaration): void { if (!this.options.arkts2) { return; @@ -10127,6 +10493,10 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!this.options.arkts2 || !ts.isNumericLiteral(node)) { return; } + if (TypeScriptLinter.isInEnumOrSwitchCase(node)) { + this.incrementCounters(node, FaultID.NumericSemantics); + return; + } const isInElementAccessExpression = (node: ts.NumericLiteral): boolean => { for (let parent = node.parent; parent; parent = parent.parent) { if (ts.isElementAccessExpression(parent)) { @@ -10146,6 +10516,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (isNoNeedFix) { return; } + const value = parseFloat(node.text); const nodeText = node.getText(); const hasScientificOrRadixNotation = (/[a-zA-Z]/).test(nodeText); @@ -10156,6 +10527,37 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } + private static isInEnumOrSwitchCase(node: ts.NumericLiteral): boolean { + const text = node.getText(); + const isStrictInteger = !text.includes('.'); + + if (TypeScriptLinter.isInSwitchCase(node) && isStrictInteger) { + return true; + } + if (TypeScriptLinter.isInEnumMember(node)) { + return isStrictInteger; + } + return false; + } + + private static isInSwitchCase(node: ts.NumericLiteral): boolean { + for (let parent = node.parent; parent; parent = parent.parent) { + if (ts.isCaseClause(parent) && ts.isSwitchStatement(parent.parent.parent)) { + return true; + } + } + return false; + } + + private static isInEnumMember(node: ts.NumericLiteral): boolean { + for (let parent = node.parent; parent; parent = parent.parent) { + if (ts.isEnumMember(parent)) { + return true; + } + } + return false; + } + private checkArrayUsageWithoutBound(accessExpr: ts.ElementAccessExpression): void { if (this.shouldSkipArrayBoundCheck(accessExpr)) { return; @@ -10174,7 +10576,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if ( this.isInMaxLengthControlledLoop(accessExpr) || TypeScriptLinter.hasDefaultValueProtection(accessExpr) || - this.isInLengthCheckedBlock(accessExpr) + this.isInLengthCheckedBlock(accessExpr) || + this.isInStandardLengthControlledLoop(accessExpr) ) { return true; } @@ -10186,7 +10589,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } if (this.isObjectPropertyAccess(accessExpr)) { - return true; + return true; } return this.isInstanceOfCheck(accessExpr.parent, accessExpr); @@ -10602,9 +11005,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return ( (argType.flags & ts.TypeFlags.NumberLike) !== 0 || argType.isUnionOrIntersection() && - argType.types.some((t) => { - return t.flags & ts.TypeFlags.NumberLike; - }) + argType.types.some((t) => { + return t.flags & ts.TypeFlags.NumberLike; + }) ); }; @@ -10878,10 +11281,12 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return false; } - if (!ts.isPropertyAccessExpression(condition.left) || + if ( + !ts.isPropertyAccessExpression(condition.left) || condition.left.name.text !== LENGTH_IDENTIFIER || !ts.isIdentifier(condition.left.expression) || - condition.left.expression.text !== arrayAccessInfo.arrayIdent.text) { + condition.left.expression.text !== arrayAccessInfo.arrayIdent.text + ) { return false; } @@ -11069,6 +11474,102 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return false; } + private isInStandardLengthControlledLoop(accessExpr: ts.ElementAccessExpression): boolean { + const arrayAccessInfo = this.getArrayAccessInfo(accessExpr); + if (!arrayAccessInfo) { + return false; + } + let parent: ts.Node | undefined = accessExpr; + while (parent && !ts.isForStatement(parent)) { + parent = parent.parent; + } + if (!parent) { + return false + }; + + const forStmt = parent; + + if (!forStmt.condition || !ts.isBinaryExpression(forStmt.condition)) { + return false; + } + + const condition = forStmt.condition; + const isStandardLoop = ( + (condition.operatorToken.kind === ts.SyntaxKind.LessThanToken || + condition.operatorToken.kind === ts.SyntaxKind.LessThanEqualsToken) && + ts.isPropertyAccessExpression(condition.right) && + condition.right.name.text === LENGTH_IDENTIFIER + ); + + if (!isStandardLoop) { + return false; + } + + return !this.hasDangerousArrayOperationsInForLoop(forStmt, arrayAccessInfo.arrayIdent.text); + } + + private hasDangerousArrayOperationsInForLoop(forStmt: ts.ForStatement, arrayName: string): boolean { + if (this.checkArrayModifications(forStmt.statement, arrayName)) { + return true; + } + + if (forStmt.initializer && ts.isVariableDeclarationList(forStmt.initializer)) { + const indexVar = forStmt.initializer.declarations[0]?.name.getText(); + if (indexVar && this.checkIndexModifications(forStmt.statement, indexVar)) { + return true; + } + } + + if (this.checkOutOfBoundAccess(forStmt.statement, arrayName)) { + return true; + } + + return false; + } + private checkArrayModifications(node: ts.Node, arrayName: string): boolean { + let hasModification = false; + ts.forEachChild(node, child => { + if (TypeScriptLinter.isArrayModification(child, arrayName)) { + hasModification = true; + } + if (!hasModification) { + hasModification = this.checkArrayModifications(child, arrayName); + } + }); + return hasModification; + } + + private checkIndexModifications(node: ts.Node, indexVar: string): boolean { + let hasModification = false; + ts.forEachChild(node, child => { + if (ts.isBinaryExpression(child) && + child.operatorToken.kind === ts.SyntaxKind.EqualsToken && + ts.isIdentifier(child.left) && + child.left.text === indexVar) { + hasModification = true; + } + if (!hasModification) { + hasModification = this.checkIndexModifications(child, indexVar); + } + }); + return hasModification; + } + + private checkOutOfBoundAccess(node: ts.Node, arrayName: string): boolean { + let hasOutOfBound = false; + ts.forEachChild(node, child => { + if (ts.isElementAccessExpression(child) && + ts.isIdentifier(child.expression) && + child.expression.text === arrayName && + ts.isNumericLiteral(child.argumentExpression)) { + hasOutOfBound = true; + } + if (!hasOutOfBound) { + hasOutOfBound = this.checkOutOfBoundAccess(child, arrayName); + } + }); + return hasOutOfBound; + } private handleCallExpressionForRepeat(node: ts.CallExpression): void { if (!this.options.arkts2) { return; diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 4a3dbb93cd558096de3d3f7fd5f86c126cbb83f2..bca8d8304e2313dc8a46587c66d274ce8cc7f519 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -3710,18 +3710,17 @@ export class Autofixer { }); if (items.length > 1) { - const formattedList = items - .map((item) => { + const formattedList = items. + map((item) => { return ` ${item.trim()},`; - }) - .join('\n'); + }). + join('\n'); return `{\n${formattedList}\n}`; } return `{${importList}}`; }); } - fixStylesDecoratorGlobal( funcDecl: ts.FunctionDeclaration, calls: ts.Identifier[], @@ -4728,17 +4727,17 @@ export class Autofixer { const expr = callExpr.expression; const hasOptionalChain = !!callExpr.questionDotToken; - const replacementText = hasOptionalChain - ? `${expr.getText()}${callExpr.questionDotToken.getText()}unsafeCall` - : `${expr.getText()}.unsafeCall`; + const replacementText = hasOptionalChain ? + `${expr.getText()}${callExpr.questionDotToken.getText()}unsafeCall` : + `${expr.getText()}.unsafeCall`; - return [{ + return [ + { start: expr.getStart(), - end: hasOptionalChain - ? callExpr.questionDotToken.getEnd() - : expr.getEnd(), + end: hasOptionalChain ? callExpr.questionDotToken.getEnd() : expr.getEnd(), replacementText - }]; + } + ]; } private static createBuiltInTypeInitializer(type: ts.TypeReferenceNode): ts.Expression | undefined { @@ -4909,7 +4908,7 @@ export class Autofixer { const srcFile = node.getSourceFile(); const typeArgsText = `<${typeNode.typeArguments?. map((arg) => { - return this.printer.printNode(ts.EmitHint.Unspecified, arg, srcFile); + return this.nonCommentPrinter.printNode(ts.EmitHint.Unspecified, arg, srcFile); }). join(', ')}>`; // Insert the type arguments immediately after the constructor name @@ -4917,15 +4916,21 @@ export class Autofixer { return [{ start: insertPos, end: insertPos, replacementText: typeArgsText }]; } - private fixGenericCallNoTypeArgsForArrayType(node: ts.NewExpression, arrayTypeNode: ts.ArrayTypeNode): Autofix[] | undefined { + private fixGenericCallNoTypeArgsForArrayType( + node: ts.NewExpression, + arrayTypeNode: ts.ArrayTypeNode + ): Autofix[] | undefined { const elementTypeNode = arrayTypeNode.elementType; const srcFile = node.getSourceFile(); - const typeArgsText = `<${this.printer.printNode(ts.EmitHint.Unspecified, elementTypeNode, srcFile)}>`; + const typeArgsText = `<${this.nonCommentPrinter.printNode(ts.EmitHint.Unspecified, elementTypeNode, srcFile)}>`; const insertPos = node.expression.getEnd(); return [{ start: insertPos, end: insertPos, replacementText: typeArgsText }]; } - private fixGenericCallNoTypeArgsForUnionType(node: ts.NewExpression, unionType: ts.UnionTypeNode): Autofix[] | undefined { + private fixGenericCallNoTypeArgsForUnionType( + node: ts.NewExpression, + unionType: ts.UnionTypeNode + ): Autofix[] | undefined { const matchingTypes = unionType.types.filter((type) => { return ts.isTypeReferenceNode(type) && type.typeName.getText() === node.expression.getText(); }) as ts.TypeReferenceNode[]; @@ -4936,7 +4941,7 @@ export class Autofixer { const srcFile = node.getSourceFile(); const typeArgsText = `<${matchingType.typeArguments. map((arg) => { - return this.printer.printNode(ts.EmitHint.Unspecified, arg, srcFile); + return this.nonCommentPrinter.printNode(ts.EmitHint.Unspecified, arg, srcFile); }). join(', ')}>`; @@ -4967,7 +4972,7 @@ export class Autofixer { } const typeArgsText = `<${typeArgs?. map((arg) => { - return this.printer.printNode(ts.EmitHint.Unspecified, arg, srcFile); + return this.nonCommentPrinter.printNode(ts.EmitHint.Unspecified, arg, srcFile); }). join(', ')}>`; return [{ start: identifier.getEnd(), end: identifier.getEnd(), replacementText: typeArgsText }]; diff --git a/ets2panda/linter/src/lib/utils/TsUtils.ts b/ets2panda/linter/src/lib/utils/TsUtils.ts index 479705c83fb51bb672bc581e70dcaa6e71531c26..7625adfd50722d85f357c1a3b252eb4e2421df1c 100644 --- a/ets2panda/linter/src/lib/utils/TsUtils.ts +++ b/ets2panda/linter/src/lib/utils/TsUtils.ts @@ -2954,6 +2954,13 @@ export class TsUtils { if (TsUtils.hasModifier(ts.getModifiers(propDecl.parent), ts.SyntaxKind.ExportKeyword)) { return false; } + + if ( + ts.isStringLiteral(propDecl.name) && + (ts.isClassDeclaration(propDecl.parent) || ts.isInterfaceDeclaration(propDecl.parent)) + ) { + return false; + } } return true; diff --git a/ets2panda/linter/src/lib/utils/consts/ArktsWhiteApiPaths.ts b/ets2panda/linter/src/lib/utils/consts/ArktsWhiteApiPaths.ts index bd6d904c9391bd94907a86c1fd70364e0f28c294..113c4bdd7992092735bc166f897822ce1132c74c 100755 --- a/ets2panda/linter/src/lib/utils/consts/ArktsWhiteApiPaths.ts +++ b/ets2panda/linter/src/lib/utils/consts/ArktsWhiteApiPaths.ts @@ -14,3 +14,4 @@ */ export const ARKTS_WHITE_API_PATH_TEXTSTYLE = 'component/styled_string.d.ts'; +export const COMMON_UNION_MEMBER_ACCESS_WHITELIST = new Set(['ArrayBufferLike', 'IteratorResult']); \ No newline at end of file diff --git a/ets2panda/linter/src/lib/utils/consts/ArkuiImportList.ts b/ets2panda/linter/src/lib/utils/consts/ArkuiImportList.ts index 3beae87577365b666ebf9f1722014fe7b1b260cf..f8ab0145c549c24f4e0c3526f3aa45adf7e98afc 100644 --- a/ets2panda/linter/src/lib/utils/consts/ArkuiImportList.ts +++ b/ets2panda/linter/src/lib/utils/consts/ArkuiImportList.ts @@ -1616,52 +1616,52 @@ export const arkuiImportList: Set = new Set([ ]); export const arkTsBuiltInTypeName: Set = new Set([ - 'Object', - 'Function', - 'Boolean', - 'Symbol', - 'Number', - 'BigInt', - 'Math', + 'Object', + 'Function', + 'Boolean', + 'Symbol', + 'Number', + 'BigInt', + 'Math', 'Date', - 'String', + 'String', 'RegExp', - 'Array', - 'Int8Array', - 'Uint8Array', - 'Uint8ClampedArray', - 'Int16Array', - 'Uint16Array', - 'Int32Array', + 'Array', + 'Int8Array', + 'Uint8Array', + 'Uint8ClampedArray', + 'Int16Array', + 'Uint16Array', + 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array', - 'BigInt64Array', + 'BigInt64Array', 'BigUint64Array', - 'Map', - 'Set', + 'Map', + 'Set', 'WeakMap', 'WeakSet', - 'ArrayBuffer', - 'SharedArrayBuffer', - 'DataView', - 'JSON', - 'Promise', - 'Generator', - 'GeneratorFunction', + 'ArrayBuffer', + 'SharedArrayBuffer', + 'DataView', + 'JSON', + 'Promise', + 'Generator', + 'GeneratorFunction', 'AsyncFunction', - 'AsyncGenerator', - 'AsyncGeneratorFunction', - 'Reflect', - 'Proxy', + 'AsyncGenerator', + 'AsyncGeneratorFunction', + 'Reflect', + 'Proxy', 'Error', 'EvalError', - 'RangeError', - 'ReferenceError', - 'SyntaxError', - 'TypeError', - 'URIError', + 'RangeError', + 'ReferenceError', + 'SyntaxError', + 'TypeError', + 'URIError', 'AggregateError', 'Intl', 'WebAssembly' -]); \ No newline at end of file +]); diff --git a/ets2panda/linter/src/lib/utils/consts/LikeFunction.ts b/ets2panda/linter/src/lib/utils/consts/LikeFunction.ts index 669b24fd7b6c0af4fcac10613a84daf547c58aa8..38a013ece2d59a515c1962bb37e7041da0a0fa43 100755 --- a/ets2panda/linter/src/lib/utils/consts/LikeFunction.ts +++ b/ets2panda/linter/src/lib/utils/consts/LikeFunction.ts @@ -14,3 +14,5 @@ */ export const LIKE_FUNCTION = 'Function'; + +export const LIKE_FUNCTION_CONSTRUCTOR = 'FunctionConstructor'; diff --git a/ets2panda/linter/src/lib/utils/consts/Types.ts b/ets2panda/linter/src/lib/utils/consts/Types.ts new file mode 100644 index 0000000000000000000000000000000000000000..86abf3d58c423b9fc86627e59255ae2f830f5e3e --- /dev/null +++ b/ets2panda/linter/src/lib/utils/consts/Types.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import type { ClassDeclaration } from 'typescript'; + +export enum ExtendedIdentifierType { + UNKNOWN, + CLASS, + ERROR +} + +export type ExtendedIdentifierInfo = + | { + type: ExtendedIdentifierType.UNKNOWN | ExtendedIdentifierType.ERROR; + } + | { type: ExtendedIdentifierType.CLASS; decl: ClassDeclaration }; + +export type ConstructorParameter = { + name: string; + isOptional: boolean; + type: string; +}; + +export type ParameterName = string; + +export type BaseClassConstructorInfo = Set | undefined; diff --git a/ets2panda/linter/src/lib/utils/consts/WorkloadRelatedConst.ts b/ets2panda/linter/src/lib/utils/consts/WorkloadRelatedConst.ts index c0c5efc0cc019faef4845c53ba7dde729c9e4f7b..676b1fb1e73e634c72dae268c284e2e1569806e0 100644 --- a/ets2panda/linter/src/lib/utils/consts/WorkloadRelatedConst.ts +++ b/ets2panda/linter/src/lib/utils/consts/WorkloadRelatedConst.ts @@ -17,4 +17,4 @@ export const AVERAGE_LINE_FOR_REPAIRE_RULE_COEFFICIENT = 3; export const TEST_DEBUG_WORKLOAD_COEFFICIENT = 1.2; -export const NPAI_REPAIRE_WORKLOADA_COEFFICIEN = 0.2; \ No newline at end of file +export const NPAI_REPAIRE_WORKLOADA_COEFFICIEN = 0.2; diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets b/ets2panda/linter/test/main/array_index_expr_type.ets index a2120f59eadc97cba66aeea25367a218c7845f3e..3d326b6f36709087f7c4aef0dda4339655e6f7a4 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets +++ b/ets2panda/linter/test/main/array_index_expr_type.ets @@ -86,4 +86,18 @@ arr[d] = 1; let test = 1; arr[1 as number]; -arr[test as number]; \ No newline at end of file +arr[test as number]; + +@Component +struct Test { + @Link testIndex: number; + + async cateMode(testIndex: number) { + emitter.on(innerEvent, (eventData) => { + if (this.testIndex == 0) { + let array = [1,2,3]; + array[this.testIndex]; + } + }) + } +} diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets.arkts2.json b/ets2panda/linter/test/main/array_index_expr_type.ets.arkts2.json index 27fa37360de59234f93846778664c5302d071136..31545145079a4bf762ccfc2671c83ee689d2a404 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/array_index_expr_type.ets.arkts2.json @@ -504,16 +504,6 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, - { - "line": 39, - "column": 7, - "endLine": 39, - "endColumn": 14, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, { "line": 40, "column": 1, @@ -524,16 +514,6 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, - { - "line": 40, - "column": 7, - "endLine": 40, - "endColumn": 14, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, { "line": 41, "column": 1, @@ -1063,6 +1043,106 @@ "suggest": "", "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", "severity": "ERROR" + }, + { + "line": 96, + "column": 29, + "endLine": 96, + "endColumn": 38, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 97, + "column": 29, + "endLine": 97, + "endColumn": 30, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 13, + "endLine": 98, + "endColumn": 28, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 22, + "endLine": 98, + "endColumn": 23, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 24, + "endLine": 98, + "endColumn": 25, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 26, + "endLine": 98, + "endColumn": 27, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 9, + "endLine": 99, + "endColumn": 30, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 15, + "endLine": 99, + "endColumn": 29, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 91, + "column": 2, + "endLine": 91, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Component\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 4, + "endLine": 93, + "endColumn": 8, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Link\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets.autofix.json b/ets2panda/linter/test/main/array_index_expr_type.ets.autofix.json index a65d5f7162d0ccc39f79bdecb6b1cea66dc75252..8aff28f18833ef33a985c0474e23397bce8bda52 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets.autofix.json +++ b/ets2panda/linter/test/main/array_index_expr_type.ets.autofix.json @@ -823,27 +823,6 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, - { - "line": 39, - "column": 7, - "endLine": 39, - "endColumn": 14, - "problem": "ArrayIndexExprType", - "autofix": [ - { - "start": 1201, - "end": 1208, - "replacementText": "index_1 as int", - "line": 39, - "column": 7, - "endLine": 39, - "endColumn": 14 - } - ], - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, { "line": 40, "column": 1, @@ -854,27 +833,6 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, - { - "line": 40, - "column": 7, - "endLine": 40, - "endColumn": 14, - "problem": "ArrayIndexExprType", - "autofix": [ - { - "start": 1217, - "end": 1224, - "replacementText": "index_2 as int", - "line": 40, - "column": 7, - "endLine": 40, - "endColumn": 14 - } - ], - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, { "line": 41, "column": 1, @@ -1320,17 +1278,6 @@ "endLine": 65, "endColumn": 9, "problem": "NumericSemantics", - "autofix": [ - { - "start": 1669, - "end": 1670, - "replacementText": "0.0", - "line": 65, - "column": 8, - "endLine": 65, - "endColumn": 9 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -1811,6 +1758,194 @@ "suggest": "", "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", "severity": "ERROR" + }, + { + "line": 96, + "column": 29, + "endLine": 96, + "endColumn": 38, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 97, + "column": 29, + "endLine": 97, + "endColumn": 30, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2137, + "end": 2138, + "replacementText": "0.0", + "line": 97, + "column": 29, + "endLine": 97, + "endColumn": 30 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 13, + "endLine": 98, + "endColumn": 28, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2154, + "end": 2169, + "replacementText": "array: number[] = [1, 2, 3]", + "line": 98, + "column": 13, + "endLine": 98, + "endColumn": 28 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 22, + "endLine": 98, + "endColumn": 23, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2163, + "end": 2164, + "replacementText": "1.0", + "line": 98, + "column": 22, + "endLine": 98, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 24, + "endLine": 98, + "endColumn": 25, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2165, + "end": 2166, + "replacementText": "2.0", + "line": 98, + "column": 24, + "endLine": 98, + "endColumn": 25 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 26, + "endLine": 98, + "endColumn": 27, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2167, + "end": 2168, + "replacementText": "3.0", + "line": 98, + "column": 26, + "endLine": 98, + "endColumn": 27 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 9, + "endLine": 99, + "endColumn": 30, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 15, + "endLine": 99, + "endColumn": 29, + "problem": "ArrayIndexExprType", + "autofix": [ + { + "start": 2185, + "end": 2199, + "replacementText": "this.testIndex as int", + "line": 99, + "column": 15, + "endLine": 99, + "endColumn": 29 + } + ], + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 91, + "column": 2, + "endLine": 91, + "endColumn": 11, + "problem": "UIInterfaceImport", + "autofix": [ + { + "start": 603, + "end": 603, + "replacementText": "\n\nimport {\n Component,\n Link,\n} from '@kit.ArkUI';", + "line": 93, + "column": 4, + "endLine": 93, + "endColumn": 8 + } + ], + "suggest": "", + "rule": "The ArkUI interface \"Component\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 4, + "endLine": 93, + "endColumn": 8, + "problem": "UIInterfaceImport", + "autofix": [ + { + "start": 603, + "end": 603, + "replacementText": "\n\nimport {\n Component,\n Link,\n} from '@kit.ArkUI';", + "line": 93, + "column": 4, + "endLine": 93, + "endColumn": 8 + } + ], + "suggest": "", + "rule": "The ArkUI interface \"Link\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets.json b/ets2panda/linter/test/main/array_index_expr_type.ets.json index 7c6994fca35d92ffa2db91cfaa3ea41750ea162c..2302200e1df44c3fc2570b294e514e0f3637a980 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets.json +++ b/ets2panda/linter/test/main/array_index_expr_type.ets.json @@ -53,6 +53,16 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" + }, + { + "line": 96, + "column": 29, + "endLine": 96, + "endColumn": 38, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets b/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets index eb9ab9c696b2c5a13984cc2a5e64d83fb6de1b13..70fb78c3800c4408724f13f60875326f2d12a5d3 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets @@ -13,6 +13,11 @@ * limitations under the License. */ +import { + Component, + Link, +} from '@kit.ArkUI'; + function foo(index:number){ let an_array: number[] = [1.0, 2.0, 3.0] let a: number = an_array[index as int] @@ -36,8 +41,8 @@ let array: number[] = [1.0, 2.0, 3.0] const index_1: number = 1.3; let index_2: number = 1.3; let index_3: number = 1.0; -array[index_1 as int]; -array[index_2 as int]; +array[index_1]; +array[index_2]; array[index_3 as int]; let index_4: int = 2.0 array[index_4]; @@ -62,7 +67,7 @@ for (let i: int = 0.0; i < array2.length; i++) { let arr1:number[] = [1.0, 2.0, 3.0] enum TE{ AA = 1.12 - BB = 0.0 + BB = 0 } arr1[TE.AA as int]; arr1[TE.BB]; @@ -86,4 +91,18 @@ arr[d] = 1.0; let test: number = 1.0; arr[1 as int]; -arr[test as int]; \ No newline at end of file +arr[test as int]; + +@Component +struct Test { + @Link testIndex: number; + + async cateMode(testIndex: number) { + emitter.on(innerEvent, (eventData) => { + if (this.testIndex == 0.0) { + let array: number[] = [1.0, 2.0, 3.0]; + array[this.testIndex as int]; + } + }) + } +} diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.json b/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.json index 457bd6501c90d0816d5491b4ff4f56711124a894..7d6f66ccb49e10e0f838c0cf6264aefd11ac8807 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.json +++ b/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.json @@ -15,9 +15,9 @@ ], "result": [ { - "line": 22, + "line": 27, "column": 7, - "endLine": 22, + "endLine": 27, "endColumn": 25, "problem": "AnyType", "suggest": "", @@ -25,9 +25,9 @@ "severity": "ERROR" }, { - "line": 22, + "line": 27, "column": 20, - "endLine": 22, + "endLine": 27, "endColumn": 24, "problem": "ArrayIndexExprType", "suggest": "", @@ -35,9 +35,9 @@ "severity": "ERROR" }, { - "line": 23, + "line": 28, "column": 7, - "endLine": 23, + "endLine": 28, "endColumn": 28, "problem": "AnyType", "suggest": "", @@ -45,9 +45,9 @@ "severity": "ERROR" }, { - "line": 23, + "line": 28, "column": 20, - "endLine": 23, + "endLine": 28, "endColumn": 27, "problem": "ArrayIndexExprType", "suggest": "", @@ -55,9 +55,9 @@ "severity": "ERROR" }, { - "line": 24, + "line": 29, "column": 7, - "endLine": 24, + "endLine": 29, "endColumn": 30, "problem": "AnyType", "suggest": "", @@ -65,9 +65,9 @@ "severity": "ERROR" }, { - "line": 24, + "line": 29, "column": 20, - "endLine": 24, + "endLine": 29, "endColumn": 29, "problem": "ArrayIndexExprType", "suggest": "", @@ -75,9 +75,9 @@ "severity": "ERROR" }, { - "line": 25, + "line": 30, "column": 7, - "endLine": 25, + "endLine": 30, "endColumn": 25, "problem": "AnyType", "suggest": "", @@ -85,9 +85,9 @@ "severity": "ERROR" }, { - "line": 25, + "line": 30, "column": 20, - "endLine": 25, + "endLine": 30, "endColumn": 24, "problem": "ArrayIndexExprType", "suggest": "", @@ -95,9 +95,9 @@ "severity": "ERROR" }, { - "line": 26, + "line": 31, "column": 28, - "endLine": 26, + "endLine": 31, "endColumn": 28, "problem": "ArrayIndexExprType", "suggest": "", @@ -105,9 +105,9 @@ "severity": "ERROR" }, { - "line": 29, + "line": 34, "column": 19, - "endLine": 29, + "endLine": 34, "endColumn": 30, "problem": "RuntimeArrayCheck", "suggest": "", @@ -115,9 +115,29 @@ "severity": "ERROR" }, { - "line": 64, + "line": 44, + "column": 1, + "endLine": 44, + "endColumn": 15, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 1, + "endLine": 45, + "endColumn": 15, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 69, "column": 3, - "endLine": 64, + "endLine": 69, "endColumn": 12, "problem": "EnumMemberNonConstInit", "suggest": "", @@ -125,9 +145,19 @@ "severity": "ERROR" }, { - "line": 68, + "line": 70, + "column": 8, + "endLine": 70, + "endColumn": 9, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 73, "column": 1, - "endLine": 68, + "endLine": 73, "endColumn": 12, "problem": "RuntimeArrayCheck", "suggest": "", @@ -135,9 +165,9 @@ "severity": "ERROR" }, { - "line": 69, + "line": 74, "column": 1, - "endLine": 69, + "endLine": 74, "endColumn": 9, "problem": "RuntimeArrayCheck", "suggest": "", @@ -145,9 +175,9 @@ "severity": "ERROR" }, { - "line": 70, + "line": 75, "column": 1, - "endLine": 70, + "endLine": 75, "endColumn": 9, "problem": "RuntimeArrayCheck", "suggest": "", @@ -155,9 +185,9 @@ "severity": "ERROR" }, { - "line": 71, + "line": 76, "column": 1, - "endLine": 71, + "endLine": 76, "endColumn": 9, "problem": "RuntimeArrayCheck", "suggest": "", @@ -165,9 +195,9 @@ "severity": "ERROR" }, { - "line": 72, + "line": 77, "column": 1, - "endLine": 72, + "endLine": 77, "endColumn": 9, "problem": "IndexNegative", "suggest": "", @@ -175,9 +205,9 @@ "severity": "ERROR" }, { - "line": 72, + "line": 77, "column": 1, - "endLine": 72, + "endLine": 77, "endColumn": 9, "problem": "RuntimeArrayCheck", "suggest": "", @@ -185,9 +215,9 @@ "severity": "ERROR" }, { - "line": 81, + "line": 86, "column": 1, - "endLine": 81, + "endLine": 86, "endColumn": 18, "problem": "RuntimeArrayCheck", "suggest": "", @@ -195,14 +225,24 @@ "severity": "ERROR" }, { - "line": 81, + "line": 86, "column": 5, - "endLine": 81, + "endLine": 86, "endColumn": 17, "problem": "ArrayIndexExprType", "suggest": "", "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", "severity": "ERROR" + }, + { + "line": 101, + "column": 29, + "endLine": 101, + "endColumn": 38, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/common_union_member_access.ets b/ets2panda/linter/test/main/common_union_member_access.ets new file mode 100644 index 0000000000000000000000000000000000000000..716957b9505fe2df7480ed6e490cd3d1e86fc92d --- /dev/null +++ b/ets2panda/linter/test/main/common_union_member_access.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { MapKit } from './oh_modules/@ohos.util.HashMap'; + +let hashMap = new MapKit.HashMap(); +let res = hashMap.keys(); +for (let i = 0; i < hashMap.length; i++) { + let result = hashMap.hasKey(res.next().value!); + result = hashMap.hasKey(res.next().value); +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/common_union_member_access.ets.args.json b/ets2panda/linter/test/main/common_union_member_access.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..9b16bb93a4605b3465a0f919cd2f678737401555 --- /dev/null +++ b/ets2panda/linter/test/main/common_union_member_access.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/common_union_member_access.ets.arkts2.json b/ets2panda/linter/test/main/common_union_member_access.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..acb6ab32103a489516062dfbcef2c7333c48c333 --- /dev/null +++ b/ets2panda/linter/test/main/common_union_member_access.ets.arkts2.json @@ -0,0 +1,38 @@ +{ + "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": 20, + "column": 10, + "endLine": 20, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 14, + "endLine": 20, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/common_union_member_access.ets.json b/ets2panda/linter/test/main/common_union_member_access.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/common_union_member_access.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/enum_not_support_float.ets b/ets2panda/linter/test/main/enum_not_support_float.ets index 593f6c64b9c8ef4857277b4a90bac71b67df20c6..69c8157c759f0fe94e7208849f7e52e25a027558 100644 --- a/ets2panda/linter/test/main/enum_not_support_float.ets +++ b/ets2panda/linter/test/main/enum_not_support_float.ets @@ -53,3 +53,9 @@ enum ExprInits { H = '123'.length, I = 1 && 2, } + +enum Numbers14{ + RED = 1 as number, + BLUE = 2, + GREEN = -1 +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/enum_not_support_float.ets.arkts2.json b/ets2panda/linter/test/main/enum_not_support_float.ets.arkts2.json index 95b3bdaefb784e4a83ae9e14da95ab0063b71d7a..a823832fa2d4484a4b6ffe7f2a60fb012d864ff7 100644 --- a/ets2panda/linter/test/main/enum_not_support_float.ets.arkts2.json +++ b/ets2panda/linter/test/main/enum_not_support_float.ets.arkts2.json @@ -34,6 +34,16 @@ "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", "severity": "ERROR" }, + { + "line": 25, + "column": 7, + "endLine": 25, + "endColumn": 13, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 26, "column": 3, @@ -163,6 +173,46 @@ "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" + }, + { + "line": 58, + "column": 3, + "endLine": 58, + "endColumn": 20, + "problem": "EnumMemberNonConstInit", + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 9, + "endLine": 58, + "endColumn": 10, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 10, + "endLine": 59, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 12, + "endLine": 60, + "endColumn": 13, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/explicit_function_type.ets b/ets2panda/linter/test/main/explicit_function_type.ets index c42f90e3fbebdbd28ff66b836d2e4dad6853d178..065dda4586383d26dc653d73ee1afa3e0b5c03ff 100755 --- a/ets2panda/linter/test/main/explicit_function_type.ets +++ b/ets2panda/linter/test/main/explicit_function_type.ets @@ -75,8 +75,8 @@ class I24 { constructor(par: Function, par1?: string) {} } class I24_1 extends I24 { - constructor() { - super(Function) + constructor(par: Function) { + super(par) } } @@ -177,4 +177,8 @@ fn29[1](); SysApiWrapper.setTimeout = (handler: Function | string, delay?: number): number => { (handler as Function)?.(); return Math.random(); -} \ No newline at end of file +} + +new Function('return 42')(); + +Function('return 42')(); diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json b/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json old mode 100755 new mode 100644 index 34273528033e6cc174e71dd6df5e600dc2e94486..ab41a3326a9ceca4e10b9e62c529cdeed8ad5d21 --- a/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json @@ -74,16 +74,6 @@ "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", "severity": "ERROR" }, - { - "line": 79, - "column": 11, - "endLine": 79, - "endColumn": 19, - "problem": "ClassAsObjectError", - "suggest": "", - "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", - "severity": "ERROR" - }, { "line": 93, "column": 11, @@ -94,6 +84,16 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, + { + "line": 96, + "column": 17, + "endLine": 96, + "endColumn": 29, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, { "line": 118, "column": 16, @@ -353,6 +353,26 @@ "suggest": "", "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", "severity": "ERROR" + }, + { + "line": 182, + "column": 1, + "endLine": 182, + "endColumn": 26, + "problem": "ExplicitFunctionType", + "suggest": "", + "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", + "severity": "ERROR" + }, + { + "line": 184, + "column": 1, + "endLine": 184, + "endColumn": 22, + "problem": "ExplicitFunctionType", + "suggest": "", + "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", + "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json b/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json index 9512b29aac946435a720b46d28464e7f675028ab..cce8e07d1c1fab1b091c6a4f074adfc7d2b94787 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json @@ -1,6 +1,6 @@ { "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Copyright (c) 2024-2025 Huawei Device Co., Ltd.", "Licensed under the Apache License, Version 2.0 (the 'License');", "you may not use this file except in compliance with the License.", "You may obtain a copy of the License at", @@ -129,16 +129,6 @@ "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", "severity": "ERROR" }, - { - "line": 79, - "column": 11, - "endLine": 79, - "endColumn": 19, - "problem": "ClassAsObjectError", - "suggest": "", - "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", - "severity": "ERROR" - }, { "line": 93, "column": 11, @@ -147,8 +137,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2073, - "end": 2074, + "start": 2081, + "end": 2082, "replacementText": "2.0", "line": 93, "column": 11, @@ -160,6 +150,16 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, + { + "line": 96, + "column": 17, + "endLine": 96, + "endColumn": 29, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, { "line": 118, "column": 16, @@ -178,8 +178,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2550, - "end": 2551, + "start": 2558, + "end": 2559, "replacementText": "1.0", "line": 118, "column": 26, @@ -199,8 +199,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2553, - "end": 2554, + "start": 2561, + "end": 2562, "replacementText": "2.0", "line": 118, "column": 29, @@ -220,8 +220,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2556, - "end": 2557, + "start": 2564, + "end": 2565, "replacementText": "3.0", "line": 118, "column": 32, @@ -281,8 +281,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2719, - "end": 2720, + "start": 2727, + "end": 2728, "replacementText": "1.0", "line": 128, "column": 31, @@ -322,8 +322,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2768, - "end": 2769, + "start": 2776, + "end": 2777, "replacementText": "1.0", "line": 128, "column": 80, @@ -351,17 +351,6 @@ "endLine": 133, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2849, - "end": 2850, - "replacementText": "1.0", - "line": 133, - "column": 10, - "endLine": 133, - "endColumn": 11 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -374,8 +363,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 2921, - "end": 2929, + "start": 2929, + "end": 2937, "replacementText": "callback.unsafeCall", "line": 139, "column": 3, @@ -395,8 +384,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2995, - "end": 2996, + "start": 3003, + "end": 3004, "replacementText": "1.0", "line": 142, "column": 41, @@ -446,8 +435,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3458, - "end": 3462, + "start": 3466, + "end": 3470, "replacementText": "curr.unsafeCall", "line": 160, "column": 62, @@ -467,8 +456,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3463, - "end": 3467, + "start": 3471, + "end": 3475, "replacementText": "prev.unsafeCall", "line": 160, "column": 67, @@ -488,8 +477,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3586, - "end": 3588, + "start": 3594, + "end": 3596, "replacementText": "f1.unsafeCall", "line": 166, "column": 1, @@ -509,8 +498,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3656, - "end": 3663, + "start": 3664, + "end": 3671, "replacementText": "ab3.fn3.unsafeCall", "line": 172, "column": 1, @@ -530,8 +519,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3697, - "end": 3704, + "start": 3705, + "end": 3712, "replacementText": "fn29[1].unsafeCall", "line": 175, "column": 1, @@ -561,8 +550,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3796, - "end": 3819, + "start": 3804, + "end": 3827, "replacementText": "(handler as Function)?.unsafeCall", "line": 178, "column": 3, @@ -573,6 +562,26 @@ "suggest": "", "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", "severity": "ERROR" + }, + { + "line": 182, + "column": 1, + "endLine": 182, + "endColumn": 26, + "problem": "ExplicitFunctionType", + "suggest": "", + "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", + "severity": "ERROR" + }, + { + "line": 184, + "column": 1, + "endLine": 184, + "endColumn": 22, + "problem": "ExplicitFunctionType", + "suggest": "", + "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", + "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.json b/ets2panda/linter/test/main/explicit_function_type.ets.json old mode 100755 new mode 100644 index d1381869898d689771df539f100eaacd386998a0..a3424dbdf251cdce4f4e0e516879ffb8aed62018 --- a/ets2panda/linter/test/main/explicit_function_type.ets.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.json @@ -1,19 +1,19 @@ { - "copyright": [ - "Copyright (c) 2024-2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "result": [ + "copyright": [ + "Copyright (c) 2024-2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ { "line": 16, "column": 20, @@ -44,16 +44,6 @@ "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", "severity": "WARNING" }, - { - "line": 79, - "column": 11, - "endLine": 79, - "endColumn": 19, - "problem": "ClassAsObject", - "suggest": "", - "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", - "severity": "WARNING" - }, { "line": 118, "column": 16, @@ -75,4 +65,4 @@ "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets index c5ecffb429d302f3dbed81aa57b822a0e37cfc5c..10fa1ca1c824b4027df605eb10b207294e185e2c 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets @@ -75,8 +75,8 @@ class I24 { constructor(par: Function, par1?: string) {} } class I24_1 extends I24 { - constructor() { - super(Function) + constructor(par: Function) { + super(par) } } @@ -130,7 +130,7 @@ let tup38:[['arkts'|Function, 1.0|true, false], string[], Function] = [['arkts', //枚举 enum E39 { Function, - BLUE = 1.0, + BLUE = 1, YELLOW } @@ -177,4 +177,8 @@ fn29[1].unsafeCall(); SysApiWrapper.setTimeout = (handler: Function | string, delay?: number): number => { (handler as Function)?.unsafeCall(); return Math.random(); -} \ No newline at end of file +} + +new Function('return 42')(); + +Function('return 42')(); diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json index b4e8db486eeaedea242edff205286dd79e155a9f..9c5d050cc76a943c1a57c9ddbd6c9eca934470d4 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json @@ -25,13 +25,13 @@ "severity": "ERROR" }, { - "line": 79, - "column": 11, - "endLine": 79, - "endColumn": 19, - "problem": "ClassAsObjectError", + "line": 96, + "column": 17, + "endLine": 96, + "endColumn": 29, + "problem": "MethodInheritRule", "suggest": "", - "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, { @@ -114,6 +114,16 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, + { + "line": 133, + "column": 10, + "endLine": 133, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 150, "column": 16, @@ -153,6 +163,26 @@ "suggest": "", "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" + }, + { + "line": 182, + "column": 1, + "endLine": 182, + "endColumn": 26, + "problem": "ExplicitFunctionType", + "suggest": "", + "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", + "severity": "ERROR" + }, + { + "line": 184, + "column": 1, + "endLine": 184, + "endColumn": 22, + "problem": "ExplicitFunctionType", + "suggest": "", + "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type.ets b/ets2panda/linter/test/main/limit_void_type.ets index 7979014031e6df6a469accd63d0acf47bcdba847..3dc13d8696c499bade5e2c1757b85042f991f59d 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets +++ b/ets2panda/linter/test/main/limit_void_type.ets @@ -13,7 +13,7 @@ * limitations under the License. */ - +import {unionVoidVal,undefinedFooFun,func3Void,fun4undefined,fun5String} from './limit_void_type2' // Example 1: Basic function function func1(): void { } let a: void = func1(); @@ -339,4 +339,27 @@ function test3(a: number): void | boolean { function test4(a: number): void | boolean { // will return -} \ No newline at end of file +} + +let unionVoid = (()=>{ + return undefined; +})() as void; //error +function undefinedFoo(){ + return undefined; +} +function unionFoo(): undefined | boolean{ + return undefined; +} +let asVoidFun = undefinedFoo() as void; //error +let undefinedAsVoid = undefined as void; //error +let unionFooAsVoid = unionFoo() as void; //error + +function func6() { + return undefined as void; //error +} + +let exportAsVoidFun = unionVoidVal as void; +let exportUndefinedFooFun = undefinedFooFun() as void; //error +let exportfunc3Void = func3Void() as void; //error +console.log(fun5String() as void); +typeof (fun4undefined() as void) //error diff --git a/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json b/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json index ba6319381d497e482a74b53b2929a47ec46ab4b5..d5851681b3cbccba32d5112080bd44cc294ca6e8 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json @@ -144,6 +144,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 39, + "column": 26, + "endLine": 39, + "endColumn": 30, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, { "line": 39, "column": 15, @@ -534,16 +544,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 91, - "column": 15, - "endLine": 91, - "endColumn": 37, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 94, "column": 8, @@ -1723,6 +1723,116 @@ "suggest": "", "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" + }, + { + "line": 346, + "column": 9, + "endLine": 346, + "endColumn": 13, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 353, + "column": 35, + "endLine": 353, + "endColumn": 39, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 354, + "column": 36, + "endLine": 354, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 355, + "column": 36, + "endLine": 355, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 358, + "column": 23, + "endLine": 358, + "endColumn": 27, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 361, + "column": 39, + "endLine": 361, + "endColumn": 43, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 362, + "column": 50, + "endLine": 362, + "endColumn": 54, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 363, + "column": 38, + "endLine": 363, + "endColumn": 42, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 363, + "column": 23, + "endLine": 363, + "endColumn": 34, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 364, + "column": 29, + "endLine": 364, + "endColumn": 33, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 365, + "column": 28, + "endLine": 365, + "endColumn": 32, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json index c8bcf12082781c3bbe1fd5d85908724b1ec36219..6f5db8552032294b7974848e0d120ab14b44b82d 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json @@ -102,8 +102,8 @@ "problem": "FunctionExpression", "autofix": [ { - "start": 942, - "end": 963, + "start": 1040, + "end": 1061, "replacementText": "(): void => { }", "line": 29, "column": 16, @@ -155,6 +155,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 39, + "column": 26, + "endLine": 39, + "endColumn": 30, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, { "line": 39, "column": 15, @@ -173,8 +183,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 1322, - "end": 1326, + "start": 1420, + "end": 1424, "replacementText": "1000.0", "line": 41, "column": 29, @@ -204,8 +214,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 1365, - "end": 1369, + "start": 1463, + "end": 1467, "replacementText": "1000.0", "line": 42, "column": 37, @@ -485,8 +495,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2527, - "end": 2528, + "start": 2625, + "end": 2626, "replacementText": "1.0", "line": 83, "column": 19, @@ -506,8 +516,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2530, - "end": 2531, + "start": 2628, + "end": 2629, "replacementText": "2.0", "line": 83, "column": 22, @@ -527,8 +537,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2533, - "end": 2534, + "start": 2631, + "end": 2632, "replacementText": "3.0", "line": 83, "column": 25, @@ -600,16 +610,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 91, - "column": 15, - "endLine": 91, - "endColumn": 37, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 94, "column": 8, @@ -669,8 +669,8 @@ "autofix": [ { "replacementText": "GeneratedDestructArray_1", - "start": 3050, - "end": 3056, + "start": 3148, + "end": 3154, "line": 102, "column": 7, "endLine": 102, @@ -678,8 +678,8 @@ }, { "replacementText": "\nconst func = GeneratedDestructArray_1[0];\n", - "start": 3077, - "end": 3077, + "start": 3175, + "end": 3175, "line": 102, "column": 7, "endLine": 102, @@ -718,8 +718,8 @@ "problem": "ObjectTypeLiteral", "autofix": [ { - "start": 3128, - "end": 3159, + "start": 3226, + "end": 3257, "replacementText": "interface Wrapper {\n value: T;\n}", "line": 105, "column": 19, @@ -879,8 +879,8 @@ "problem": "FunctionExpression", "autofix": [ { - "start": 3757, - "end": 3783, + "start": 3855, + "end": 3881, "replacementText": "(target: any) => { }", "line": 126, "column": 10, @@ -1100,8 +1100,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 4599, - "end": 4619, + "start": 4697, + "end": 4717, "replacementText": "undefined | Promise", "line": 162, "column": 16, @@ -1109,8 +1109,8 @@ "endColumn": 36 }, { - "start": 4622, - "end": 4622, + "start": 4720, + "end": 4720, "replacementText": "\nreturn undefined;\n", "line": 162, "column": 16, @@ -1140,8 +1140,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 4686, - "end": 4699, + "start": 4784, + "end": 4797, "replacementText": "undefined | number", "line": 165, "column": 8, @@ -1149,8 +1149,8 @@ "endColumn": 21 }, { - "start": 4702, - "end": 4702, + "start": 4800, + "end": 4800, "replacementText": "\nreturn undefined;\n", "line": 165, "column": 8, @@ -1280,8 +1280,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5432, - "end": 5445, + "start": 5530, + "end": 5543, "replacementText": "string | undefined", "line": 211, "column": 29, @@ -1289,8 +1289,8 @@ "endColumn": 42 }, { - "start": 5489, - "end": 5489, + "start": 5587, + "end": 5587, "replacementText": "\nreturn undefined;\n", "line": 211, "column": 29, @@ -1320,8 +1320,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5459, - "end": 5460, + "start": 5557, + "end": 5558, "replacementText": "0.0", "line": 212, "column": 12, @@ -1341,8 +1341,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5521, - "end": 5534, + "start": 5619, + "end": 5632, "replacementText": "string | undefined", "line": 217, "column": 30, @@ -1350,8 +1350,8 @@ "endColumn": 43 }, { - "start": 5556, - "end": 5563, + "start": 5654, + "end": 5661, "replacementText": "return undefined;", "line": 217, "column": 30, @@ -1381,8 +1381,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5547, - "end": 5548, + "start": 5645, + "end": 5646, "replacementText": "0.0", "line": 218, "column": 11, @@ -1482,8 +1482,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5691, - "end": 5692, + "start": 5789, + "end": 5790, "replacementText": "1.0", "line": 226, "column": 25, @@ -1503,8 +1503,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5725, - "end": 5738, + "start": 5823, + "end": 5836, "replacementText": "string | undefined", "line": 228, "column": 31, @@ -1512,8 +1512,8 @@ "endColumn": 44 }, { - "start": 5764, - "end": 5771, + "start": 5862, + "end": 5869, "replacementText": "return undefined;", "line": 228, "column": 31, @@ -1521,8 +1521,8 @@ "endColumn": 44 }, { - "start": 5842, - "end": 5849, + "start": 5940, + "end": 5947, "replacementText": "return undefined;", "line": 228, "column": 31, @@ -1530,8 +1530,8 @@ "endColumn": 44 }, { - "start": 5854, - "end": 5854, + "start": 5952, + "end": 5952, "replacementText": "\nreturn undefined;\n", "line": 228, "column": 31, @@ -1561,8 +1561,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5754, - "end": 5756, + "start": 5852, + "end": 5854, "replacementText": "12.0", "line": 229, "column": 14, @@ -1582,8 +1582,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5792, - "end": 5794, + "start": 5890, + "end": 5892, "replacementText": "18.0", "line": 231, "column": 21, @@ -1603,8 +1603,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5894, - "end": 5907, + "start": 5992, + "end": 6005, "replacementText": "string | undefined", "line": 238, "column": 38, @@ -1612,8 +1612,8 @@ "endColumn": 51 }, { - "start": 5989, - "end": 5996, + "start": 6087, + "end": 6094, "replacementText": "return undefined;", "line": 238, "column": 38, @@ -1643,8 +1643,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6021, - "end": 6034, + "start": 6119, + "end": 6132, "replacementText": "string | undefined", "line": 246, "column": 22, @@ -1652,8 +1652,8 @@ "endColumn": 35 }, { - "start": 6062, - "end": 6062, + "start": 6160, + "end": 6160, "replacementText": "\nreturn undefined;\n", "line": 246, "column": 22, @@ -1683,8 +1683,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6099, - "end": 6112, + "start": 6197, + "end": 6210, "replacementText": "string | undefined", "line": 250, "column": 35, @@ -1692,8 +1692,8 @@ "endColumn": 48 }, { - "start": 6192, - "end": 6192, + "start": 6290, + "end": 6290, "replacementText": "\nreturn undefined;\n", "line": 250, "column": 35, @@ -1731,17 +1731,6 @@ "endLine": 252, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 6142, - "end": 6143, - "replacementText": "1.0", - "line": 252, - "column": 10, - "endLine": 252, - "endColumn": 11 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -1752,17 +1741,6 @@ "endLine": 253, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 6167, - "end": 6168, - "replacementText": "2.0", - "line": 253, - "column": 10, - "endLine": 253, - "endColumn": 11 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -1775,8 +1753,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6216, - "end": 6229, + "start": 6314, + "end": 6327, "replacementText": "string | undefined", "line": 257, "column": 22, @@ -1784,8 +1762,8 @@ "endColumn": 35 }, { - "start": 6304, - "end": 6304, + "start": 6402, + "end": 6402, "replacementText": "\nreturn undefined;\n", "line": 257, "column": 22, @@ -1835,8 +1813,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6370, - "end": 6384, + "start": 6468, + "end": 6482, "replacementText": "boolean | undefined", "line": 269, "column": 20, @@ -1844,8 +1822,8 @@ "endColumn": 34 }, { - "start": 6431, - "end": 6438, + "start": 6529, + "end": 6536, "replacementText": "return undefined;", "line": 269, "column": 20, @@ -1853,8 +1831,8 @@ "endColumn": 34 }, { - "start": 6468, - "end": 6475, + "start": 6566, + "end": 6573, "replacementText": "return undefined;", "line": 269, "column": 20, @@ -1884,8 +1862,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6399, - "end": 6400, + "start": 6497, + "end": 6498, "replacementText": "0.0", "line": 270, "column": 13, @@ -1905,8 +1883,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6501, - "end": 6515, + "start": 6599, + "end": 6613, "replacementText": "undefined | boolean", "line": 278, "column": 21, @@ -1914,8 +1892,8 @@ "endColumn": 35 }, { - "start": 6604, - "end": 6611, + "start": 6702, + "end": 6709, "replacementText": "return undefined;", "line": 278, "column": 21, @@ -1945,8 +1923,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6530, - "end": 6531, + "start": 6628, + "end": 6629, "replacementText": "0.0", "line": 279, "column": 13, @@ -1966,8 +1944,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6637, - "end": 6651, + "start": 6735, + "end": 6749, "replacementText": "undefined | boolean", "line": 287, "column": 21, @@ -1975,8 +1953,8 @@ "endColumn": 35 }, { - "start": 6698, - "end": 6705, + "start": 6796, + "end": 6803, "replacementText": "return undefined;", "line": 287, "column": 21, @@ -1984,8 +1962,8 @@ "endColumn": 35 }, { - "start": 6714, - "end": 6714, + "start": 6812, + "end": 6812, "replacementText": "\nreturn undefined;\n", "line": 287, "column": 21, @@ -2015,8 +1993,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6666, - "end": 6667, + "start": 6764, + "end": 6765, "replacementText": "0.0", "line": 288, "column": 13, @@ -2036,8 +2014,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6737, - "end": 6751, + "start": 6835, + "end": 6849, "replacementText": "undefined | boolean", "line": 294, "column": 21, @@ -2045,8 +2023,8 @@ "endColumn": 35 }, { - "start": 6798, - "end": 6805, + "start": 6896, + "end": 6903, "replacementText": "return undefined;", "line": 294, "column": 21, @@ -2076,8 +2054,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6766, - "end": 6767, + "start": 6864, + "end": 6865, "replacementText": "0.0", "line": 295, "column": 13, @@ -2097,8 +2075,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6846, - "end": 6860, + "start": 6944, + "end": 6958, "replacementText": "undefined | boolean", "line": 302, "column": 12, @@ -2106,8 +2084,8 @@ "endColumn": 26 }, { - "start": 6884, - "end": 6884, + "start": 6982, + "end": 6982, "replacementText": "\nreturn undefined;\n", "line": 302, "column": 12, @@ -2137,8 +2115,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6915, - "end": 6929, + "start": 7013, + "end": 7027, "replacementText": "boolean | undefined", "line": 307, "column": 27, @@ -2146,8 +2124,8 @@ "endColumn": 41 }, { - "start": 6970, - "end": 6977, + "start": 7068, + "end": 7075, "replacementText": "return undefined;", "line": 307, "column": 27, @@ -2155,8 +2133,8 @@ "endColumn": 41 }, { - "start": 7001, - "end": 7008, + "start": 7099, + "end": 7106, "replacementText": "return undefined;", "line": 307, "column": 27, @@ -2186,8 +2164,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6942, - "end": 6943, + "start": 7040, + "end": 7041, "replacementText": "0.0", "line": 308, "column": 11, @@ -2207,8 +2185,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7039, - "end": 7053, + "start": 7137, + "end": 7151, "replacementText": "undefined | boolean", "line": 316, "column": 28, @@ -2216,8 +2194,8 @@ "endColumn": 42 }, { - "start": 7130, - "end": 7137, + "start": 7228, + "end": 7235, "replacementText": "return undefined;", "line": 316, "column": 28, @@ -2247,8 +2225,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7066, - "end": 7067, + "start": 7164, + "end": 7165, "replacementText": "0.0", "line": 317, "column": 11, @@ -2268,8 +2246,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7168, - "end": 7182, + "start": 7266, + "end": 7280, "replacementText": "undefined | boolean", "line": 325, "column": 28, @@ -2277,8 +2255,8 @@ "endColumn": 42 }, { - "start": 7223, - "end": 7230, + "start": 7321, + "end": 7328, "replacementText": "return undefined;", "line": 325, "column": 28, @@ -2286,8 +2264,8 @@ "endColumn": 42 }, { - "start": 7235, - "end": 7235, + "start": 7333, + "end": 7333, "replacementText": "\nreturn undefined;\n", "line": 325, "column": 28, @@ -2317,8 +2295,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7195, - "end": 7196, + "start": 7293, + "end": 7294, "replacementText": "0.0", "line": 326, "column": 11, @@ -2338,8 +2316,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7265, - "end": 7279, + "start": 7363, + "end": 7377, "replacementText": "undefined | boolean", "line": 332, "column": 28, @@ -2347,8 +2325,8 @@ "endColumn": 42 }, { - "start": 7320, - "end": 7327, + "start": 7418, + "end": 7425, "replacementText": "return undefined;", "line": 332, "column": 28, @@ -2378,8 +2356,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7292, - "end": 7293, + "start": 7390, + "end": 7391, "replacementText": "0.0", "line": 333, "column": 11, @@ -2399,8 +2377,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7378, - "end": 7392, + "start": 7476, + "end": 7490, "replacementText": "undefined | boolean", "line": 340, "column": 28, @@ -2408,8 +2386,8 @@ "endColumn": 42 }, { - "start": 7412, - "end": 7412, + "start": 7510, + "end": 7510, "replacementText": "\nreturn undefined;\n", "line": 340, "column": 28, @@ -2430,6 +2408,116 @@ "suggest": "", "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" + }, + { + "line": 346, + "column": 9, + "endLine": 346, + "endColumn": 13, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 353, + "column": 35, + "endLine": 353, + "endColumn": 39, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 354, + "column": 36, + "endLine": 354, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 355, + "column": 36, + "endLine": 355, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 358, + "column": 23, + "endLine": 358, + "endColumn": 27, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 361, + "column": 39, + "endLine": 361, + "endColumn": 43, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 362, + "column": 50, + "endLine": 362, + "endColumn": 54, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 363, + "column": 38, + "endLine": 363, + "endColumn": 42, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 363, + "column": 23, + "endLine": 363, + "endColumn": 34, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 364, + "column": 29, + "endLine": 364, + "endColumn": 33, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 365, + "column": 28, + "endLine": 365, + "endColumn": 32, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets b/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets index 62243efb6d249edbb2f93496093630c17acb1888..b9a240dfe5be2337d97b90856d88d0f2edd8eac0 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets @@ -13,7 +13,7 @@ * limitations under the License. */ - +import {unionVoidVal,undefinedFooFun,func3Void,fun4undefined,fun5String} from './limit_void_type2' // Example 1: Basic function function func1(): void { } let a: void = func1(); @@ -263,8 +263,8 @@ return undefined; function getStatus(code: number): string | undefined { switch (code) { - case 1.0: return "OK"; - case 2.0: return "Warning"; + case 1: return "OK"; + case 2: return "Warning"; } return undefined; @@ -365,4 +365,27 @@ function test4(a: number): undefined | boolean { // will return return undefined; -} \ No newline at end of file +} + +let unionVoid = (()=>{ + return undefined; +})() as void; //error +function undefinedFoo(){ + return undefined; +} +function unionFoo(): undefined | boolean{ + return undefined; +} +let asVoidFun = undefinedFoo() as void; //error +let undefinedAsVoid = undefined as void; //error +let unionFooAsVoid = unionFoo() as void; //error + +function func6() { + return undefined as void; //error +} + +let exportAsVoidFun = unionVoidVal as void; +let exportUndefinedFooFun = undefinedFooFun() as void; //error +let exportfunc3Void = func3Void() as void; //error +console.log(fun5String() as void); +typeof (fun4undefined() as void) //error diff --git a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json index cef5d595cb318cefba01dc8098f4154b713ee62b..0ab5549e55155123c47cafcb9a8f2cafddd7243a 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json @@ -134,6 +134,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 39, + "column": 26, + "endLine": 39, + "endColumn": 30, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, { "line": 39, "column": 15, @@ -474,16 +484,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 91, - "column": 15, - "endLine": 91, - "endColumn": 37, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 94, "column": 8, @@ -1084,6 +1084,26 @@ "rule": "The switch expression type must be of type char, byte, short, int, long, string or enum (arkts-switch-expr)", "severity": "ERROR" }, + { + "line": 266, + "column": 10, + "endLine": 266, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 267, + "column": 10, + "endLine": 267, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 285, "column": 8, @@ -1103,6 +1123,116 @@ "suggest": "", "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" + }, + { + "line": 372, + "column": 9, + "endLine": 372, + "endColumn": 13, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 379, + "column": 35, + "endLine": 379, + "endColumn": 39, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 380, + "column": 36, + "endLine": 380, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 381, + "column": 36, + "endLine": 381, + "endColumn": 40, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 384, + "column": 23, + "endLine": 384, + "endColumn": 27, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 387, + "column": 39, + "endLine": 387, + "endColumn": 43, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 388, + "column": 50, + "endLine": 388, + "endColumn": 54, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 389, + "column": 38, + "endLine": 389, + "endColumn": 42, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 389, + "column": 23, + "endLine": 389, + "endColumn": 34, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 390, + "column": 29, + "endLine": 390, + "endColumn": 33, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 391, + "column": 28, + "endLine": 391, + "endColumn": 32, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type2.ets b/ets2panda/linter/test/main/limit_void_type2.ets new file mode 100644 index 0000000000000000000000000000000000000000..dc2727c71674f9af7c6792bed305307b620a86ce --- /dev/null +++ b/ets2panda/linter/test/main/limit_void_type2.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export let unionVoidVal = (()=>{ + return undefined; +})() as void; +export function undefinedFooFun(){ + return undefined; +} +export function func3Void(): void { } +export function fun4undefined(): undefined | boolean { } +export function fun5String(): string { + return ''; +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type2.ets.json b/ets2panda/linter/test/main/limit_void_type2.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/limit_void_type2.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/literals_as_prop_names.ets.autofix.json b/ets2panda/linter/test/main/literals_as_prop_names.ets.autofix.json index f3414d739de19184996435dcab30d7a8d61c643f..b16fee9cc94db1f161805763cff2f05a6b4230ce 100644 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets.autofix.json +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets.autofix.json @@ -89,35 +89,6 @@ "endLine": 27, "endColumn": 8, "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "Two", - "start": 849, - "end": 854, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - }, - { - "replacementText": "Two", - "start": 940, - "end": 945, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - }, - { - "replacementText": "litAsPropName.Two", - "start": 1032, - "end": 1052, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - } - ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -167,35 +138,6 @@ "endLine": 33, "endColumn": 8, "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "Two", - "start": 849, - "end": 854, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - }, - { - "replacementText": "Two", - "start": 940, - "end": 945, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - }, - { - "replacementText": "litAsPropName.Two", - "start": 1032, - "end": 1052, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - } - ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -287,35 +229,6 @@ "endLine": 38, "endColumn": 33, "problem": "PropertyAccessByIndex", - "autofix": [ - { - "replacementText": "Two", - "start": 849, - "end": 854, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - }, - { - "replacementText": "Two", - "start": 940, - "end": 945, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - }, - { - "replacementText": "litAsPropName.Two", - "start": 1032, - "end": 1052, - "line": 38, - "column": 13, - "endLine": 38, - "endColumn": 33 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", "severity": "ERROR" @@ -541,26 +454,6 @@ "endLine": 76, "endColumn": 8, "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "__2", - "start": 1739, - "end": 1744, - "line": 81, - "column": 3, - "endLine": 81, - "endColumn": 8 - }, - { - "replacementText": "__2", - "start": 1824, - "end": 1829, - "line": 81, - "column": 3, - "endLine": 81, - "endColumn": 8 - } - ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -611,26 +504,6 @@ "endLine": 81, "endColumn": 8, "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "__2", - "start": 1739, - "end": 1744, - "line": 81, - "column": 3, - "endLine": 81, - "endColumn": 8 - }, - { - "replacementText": "__2", - "start": 1824, - "end": 1829, - "line": 81, - "column": 3, - "endLine": 81, - "endColumn": 8 - } - ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -734,17 +607,6 @@ "endLine": 92, "endColumn": 10, "problem": "NumericSemantics", - "autofix": [ - { - "start": 1996, - "end": 1997, - "replacementText": "1.0", - "line": 92, - "column": 9, - "endLine": 92, - "endColumn": 10 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -776,17 +638,6 @@ "endLine": 97, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2040, - "end": 2041, - "replacementText": "1.0", - "line": 97, - "column": 10, - "endLine": 97, - "endColumn": 11 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -818,17 +669,6 @@ "endLine": 98, "endColumn": 14, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2055, - "end": 2056, - "replacementText": "1.0", - "line": 98, - "column": 13, - "endLine": 98, - "endColumn": 14 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -869,17 +709,6 @@ "endLine": 102, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2095, - "end": 2096, - "replacementText": "1.0", - "line": 102, - "column": 10, - "endLine": 102, - "endColumn": 11 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -920,17 +749,6 @@ "endLine": 103, "endColumn": 14, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2110, - "end": 2111, - "replacementText": "1.0", - "line": 103, - "column": 13, - "endLine": 103, - "endColumn": 14 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -1033,17 +851,6 @@ "endLine": 109, "endColumn": 9, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2214, - "end": 2215, - "replacementText": "1.0", - "line": 109, - "column": 8, - "endLine": 109, - "endColumn": 9 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -1075,17 +882,6 @@ "endLine": 112, "endColumn": 10, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2252, - "end": 2253, - "replacementText": "1.0", - "line": 112, - "column": 9, - "endLine": 112, - "endColumn": 10 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -1169,17 +965,6 @@ "endLine": 132, "endColumn": 15, "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "age", - "start": 2466, - "end": 2471, - "line": 132, - "column": 10, - "endLine": 132, - "endColumn": 15 - } - ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" diff --git a/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.ets b/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.ets index 6fb5cb3e0f5cb74294ebcbd803bacdd0840a12a4..735fe00359fdf4bf0ed72a5a748981a08e40dd9f 100644 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.ets +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.ets @@ -29,18 +29,18 @@ enum LiteralAsPropertyNameEnum { class LiteralAsPropertyName { public one: string = "1111111111"; private __2: string; - Two: number; + 'Two': number; } const litAsPropName: LiteralAsPropertyName = { one: "1", __2: 'two', - Two: 2.0, + 'Two': 2.0, }; console.log(litAsPropName.one); console.log(litAsPropName.__2); -console.log(litAsPropName.Two); +console.log(litAsPropName["Two"]); class LiteralAsPropertyName_fix { public one: string = "1111111111"; @@ -82,12 +82,12 @@ console.log(x_fix._2); interface litAsPropNameIface { one: string; ___2: string; - __2: number; + '__2': number; } const int: litAsPropNameIface = { one: '12321', ___2: 'weqwewq', - __2: 123.0 + '__2': 123.0 }; const imp: ExportLitAsPropName = { 1: 234.0 }; @@ -98,27 +98,27 @@ LiteralAsPropertyNameEnum.PrivateTwo; { const enum Direction { - __empty = 1.0, + __empty = 1, } } const enum Direction16 { - ___x5c = 1.0, - __x5c = 1.0, + ___x5c = 1, + __x5c = 1, } const enum Direction17 { - ___x5c = 1.0, - __x5c = 1.0, + ___x5c = 1, + __x5c = 1, } let case17: number = Direction17.___x5c let case172: number = Direction17.__x5c const enum Direction11 { -__x21x21 = 1.0, +__x21x21 = 1, } const enum Direction23 { -aaa = 1.0, +aaa = 1, } // ArkUI @Component @@ -138,7 +138,7 @@ let a:A = { age: 30.0} class B { - public age: number = 1.0 // error in arkts2 + public 'age': number = 1.0 // error in arkts2 } let obj11: Record = { diff --git a/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.json b/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.json index a180c185731eed0d9719daee26a9ec1c64f65992..61d1781a5e9357addae257c8db0e40eaf586cf17 100644 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.json +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.json @@ -14,6 +14,36 @@ "limitations under the License." ], "result": [ + { + "line": 32, + "column": 3, + "endLine": 32, + "endColumn": 8, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 3, + "endLine": 38, + "endColumn": 8, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 13, + "endLine": 43, + "endColumn": 33, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "severity": "ERROR" + }, { "line": 62, "column": 9, @@ -64,6 +94,16 @@ "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", "severity": "ERROR" }, + { + "line": 85, + "column": 3, + "endLine": 85, + "endColumn": 8, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, { "line": 87, "column": 7, @@ -74,6 +114,16 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, + { + "line": 90, + "column": 3, + "endLine": 90, + "endColumn": 8, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, { "line": 93, "column": 36, @@ -94,6 +144,86 @@ "rule": "Enum cannot get member name by member value (arkts-enum-no-props-by-index)", "severity": "ERROR" }, + { + "line": 101, + "column": 14, + "endLine": 101, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 106, + "column": 12, + "endLine": 106, + "endColumn": 13, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 107, + "column": 11, + "endLine": 107, + "endColumn": 12, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 111, + "column": 12, + "endLine": 111, + "endColumn": 13, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 112, + "column": 11, + "endLine": 112, + "endColumn": 12, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 118, + "column": 12, + "endLine": 118, + "endColumn": 13, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 121, + "column": 7, + "endLine": 121, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 141, + "column": 10, + "endLine": 141, + "endColumn": 15, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, { "line": 144, "column": 37, @@ -194,16 +324,6 @@ "rule": "Property '__2' has no initializer and is not definitely assigned in the constructor.", "severity": "ERROR" }, - { - "line": 32, - "column": 3, - "endLine": 32, - "endColumn": 6, - "problem": "StrictDiagnostic", - "suggest": "Property 'Two' has no initializer and is not definitely assigned in the constructor.", - "rule": "Property 'Two' has no initializer and is not definitely assigned in the constructor.", - "severity": "ERROR" - }, { "line": 47, "column": 11, diff --git a/ets2panda/linter/test/main/method_inheritance2.ets b/ets2panda/linter/test/main/method_inheritance2.ets new file mode 100755 index 0000000000000000000000000000000000000000..2591755adc6107122557a598b0cdbe0cb5e31d4d --- /dev/null +++ b/ets2panda/linter/test/main/method_inheritance2.ets @@ -0,0 +1,116 @@ +/* + * 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 { + a: number = 0 +} +class B { + a: number = 0 +} +class C { + a: number = 0 +} + +class D extends A{ + a: number = 0; + b: number = 1; +} + + +// T +class Base3 { + foo(obj: A | B): void { + console.log("base") + } + foo2(obj: A | B): void { + console.log("base") + } + foo3(obj: A | B | C): void { + console.log("base") + } +} +// T extends +class Derived3 extends Base3 { + foo(obj: A): void { // (arkts-method-inherit-rule) error + console.log("Derived:" + obj.a) + } + foo2(): void { // (arkts-method-inherit-rule) error + console.log("Derived:") + } + foo3(obj: A | B): void { //(arkts-method-inherit-rule) error + console.log("Derived:") + } +} + +// T interface +interface BaseI2 { + foo(obj: A | B):void; + foo2(obj: A ): void; + foo3(obj: A | B | C): void; +} + +// T implements +class DerivedI2 implements BaseI2 { + foo(obj: A): void { + console.log("Drived"); // (arkts-method-inherit-rule) error + } + foo2(): void { + console.log("Drived"); // (arkts-method-inherit-rule) error + } + foo3(obj: A | B): void { + console.log("Drived"); // (arkts-method-inherit-rule) error + } +} + +class Base5 { + public foo(): A|B { + console.log("base") + return new A(); + } + static foo2(){ + console.log("base") + // return new A(); + } + async foo3(): Promise { + console.log("base") + return new A(); + } + static foo4():void{ + console.log("base") + // return new A(); + } +} + +// extends +class Derived5 extends Base5 { + public foo(): A|B|C{ // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + + static foo2(): A{ // (arkts-method-inherit-rule) error + console.log("Derived:") + return new A(); + } + + async foo3(): Promise { // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + static foo4(): A{ // (arkts-method-inherit-rule) error + console.log("Derived:") + return new A(); + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/method_inheritance2.ets.args.json b/ets2panda/linter/test/main/method_inheritance2.ets.args.json new file mode 100755 index 0000000000000000000000000000000000000000..d8d3390ad9befeca9b595017d9eea0f5ada3d049 --- /dev/null +++ b/ets2panda/linter/test/main/method_inheritance2.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/method_inheritance2.ets.arkts2.json b/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json new file mode 100755 index 0000000000000000000000000000000000000000..30c37afc53dcc2542c42356017353b794acf9e2b --- /dev/null +++ b/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json @@ -0,0 +1,148 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 17, + "column": 15, + "endLine": 17, + "endColumn": 16, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 15, + "endLine": 20, + "endColumn": 16, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 15, + "endLine": 23, + "endColumn": 16, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 15, + "endLine": 27, + "endColumn": 16, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 15, + "endLine": 28, + "endColumn": 16, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 46, + "column": 10, + "endLine": 46, + "endColumn": 16, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 49, + "column": 3, + "endLine": 49, + "endColumn": 7, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 11, + "endLine": 52, + "endColumn": 21, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 66, + "column": 10, + "endLine": 66, + "endColumn": 16, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 3, + "endLine": 69, + "endColumn": 7, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 11, + "endLine": 72, + "endColumn": 21, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 17, + "endLine": 98, + "endColumn": 22, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 108, + "column": 17, + "endLine": 108, + "endColumn": 29, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/method_inheritance2.ets.json b/ets2panda/linter/test/main/method_inheritance2.ets.json new file mode 100755 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/method_inheritance2.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 7a82e0fd5ef7b9c8b187f58759f8167daf75872d..3bcd3fae8c67fb66bf6ee7ca66ed64c5f80504e8 100755 --- a/ets2panda/linter/test/main/no_ts_like_smart_type.ets +++ b/ets2panda/linter/test/main/no_ts_like_smart_type.ets @@ -118,4 +118,47 @@ async function taskInfo():Promise {//nopass ", name is:" + name); } } -} \ No newline at end of file +} + +class A { + f(): number| null { + return 1 + } +} + +class B { + a?:A = new A() +} +let b = new B() +if(b.a && b.a.f() !== null){ //Error + console.log('23') +} + +if (b.a.f() !== null) { //Error + console.log('warn'); +} +if (b.a?.f() !== null) { + console.log('ok'); +} +function check(obj?: A) { + if (obj.f() !== null) { //Error + console.log('warn'); + } +} +if ((b.a?.f() ?? 0) > 0) { + console.log('ok'); +} +const val = b.a.f(); //Error + + +function foo4(uri: string | number | boolean) : string { + return uri as string +} + +class AA { + public static starUrl(url: string) { + if (url?startsWith('http')) { + url = `https:/test?appid=2000?url=${foo4(url)}`; + } + } +} 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 index 679e8a5d6f08de4aa869329676411b320f252b22..7ee5337c99b6d395132c25433356e9b5bb3c1ef0 100755 --- 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 @@ -144,6 +144,16 @@ "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", "severity": "ERROR" }, + { + "line": 80, + "column": 11, + "endLine": 80, + "endColumn": 15, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, { "line": 87, "column": 16, @@ -243,6 +253,116 @@ "suggest": "", "rule": "Smart type differences (arkts-no-ts-like-smart-type)", "severity": "ERROR" + }, + { + "line": 125, + "column": 16, + "endLine": 125, + "endColumn": 17, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 133, + "column": 11, + "endLine": 133, + "endColumn": 16, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, + { + "line": 137, + "column": 5, + "endLine": 137, + "endColumn": 10, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, + { + "line": 144, + "column": 7, + "endLine": 144, + "endColumn": 12, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, + { + "line": 148, + "column": 18, + "endLine": 148, + "endColumn": 19, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 148, + "column": 23, + "endLine": 148, + "endColumn": 24, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 151, + "column": 7, + "endLine": 151, + "endColumn": 20, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 151, + "column": 13, + "endLine": 151, + "endColumn": 18, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, + { + "line": 137, + "column": 5, + "endLine": 137, + "endColumn": 8, + "problem": "StrictDiagnostic", + "suggest": "'b.a' is possibly 'undefined'.", + "rule": "'b.a' is possibly 'undefined'.", + "severity": "ERROR" + }, + { + "line": 144, + "column": 7, + "endLine": 144, + "endColumn": 10, + "problem": "StrictDiagnostic", + "suggest": "'obj' is possibly 'undefined'.", + "rule": "'obj' is possibly 'undefined'.", + "severity": "ERROR" + }, + { + "line": 151, + "column": 13, + "endLine": 151, + "endColumn": 16, + "problem": "StrictDiagnostic", + "suggest": "'b.a' is possibly 'undefined'.", + "rule": "'b.a' is possibly 'undefined'.", + "severity": "ERROR" } ] } \ No newline at end of file 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 index ca88f857e960b437dcf767c0ac40be998c8f1236..fd7351eff41090b5a7ad6ffde13531123acab287 100755 --- a/ets2panda/linter/test/main/no_ts_like_smart_type.ets.json +++ b/ets2panda/linter/test/main/no_ts_like_smart_type.ets.json @@ -13,5 +13,46 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [] + "result": [ + { + "line": 151, + "column": 7, + "endLine": 151, + "endColumn": 20, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 137, + "column": 5, + "endLine": 137, + "endColumn": 8, + "problem": "StrictDiagnostic", + "suggest": "'b.a' is possibly 'undefined'.", + "rule": "'b.a' is possibly 'undefined'.", + "severity": "ERROR" + }, + { + "line": 144, + "column": 7, + "endLine": 144, + "endColumn": 10, + "problem": "StrictDiagnostic", + "suggest": "'obj' is possibly 'undefined'.", + "rule": "'obj' is possibly 'undefined'.", + "severity": "ERROR" + }, + { + "line": 151, + "column": 13, + "endLine": 151, + "endColumn": 16, + "problem": "StrictDiagnostic", + "suggest": "'b.a' is possibly 'undefined'.", + "rule": "'b.a' is possibly 'undefined'.", + "severity": "ERROR" + } + ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json index 7c1870a30d5b0c3597686fc55bf7a7486ddd5ff9..72ddcbaa863effb8817cf4602190402e159164a8 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json @@ -1069,17 +1069,6 @@ "endLine": 112, "endColumn": 8, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2446, - "end": 2447, - "replacementText": "1.0", - "line": 112, - "column": 7, - "endLine": 112, - "endColumn": 8 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -1090,17 +1079,6 @@ "endLine": 113, "endColumn": 8, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2468, - "end": 2469, - "replacementText": "2.0", - "line": 113, - "column": 7, - "endLine": 113, - "endColumn": 8 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2208,17 +2186,6 @@ "endLine": 212, "endColumn": 14, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5206, - "end": 5207, - "replacementText": "0.0", - "line": 212, - "column": 13, - "endLine": 212, - "endColumn": 14 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2229,17 +2196,6 @@ "endLine": 213, "endColumn": 18, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5225, - "end": 5227, - "replacementText": "-1.0", - "line": 213, - "column": 17, - "endLine": 213, - "endColumn": 18 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2250,17 +2206,6 @@ "endLine": 214, "endColumn": 18, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5246, - "end": 5247, - "replacementText": "1.0", - "line": 214, - "column": 17, - "endLine": 214, - "endColumn": 18 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2271,17 +2216,6 @@ "endLine": 215, "endColumn": 18, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5266, - "end": 5267, - "replacementText": "2.0", - "line": 215, - "column": 17, - "endLine": 215, - "endColumn": 18 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2292,17 +2226,6 @@ "endLine": 216, "endColumn": 20, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5288, - "end": 5289, - "replacementText": "3.0", - "line": 216, - "column": 19, - "endLine": 216, - "endColumn": 20 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2313,17 +2236,6 @@ "endLine": 217, "endColumn": 19, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5309, - "end": 5310, - "replacementText": "4.0", - "line": 217, - "column": 18, - "endLine": 217, - "endColumn": 19 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2334,17 +2246,6 @@ "endLine": 218, "endColumn": 21, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5332, - "end": 5333, - "replacementText": "5.0", - "line": 218, - "column": 20, - "endLine": 218, - "endColumn": 21 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2355,17 +2256,6 @@ "endLine": 222, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5380, - "end": 5381, - "replacementText": "0.0", - "line": 222, - "column": 10, - "endLine": 222, - "endColumn": 11 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2376,17 +2266,6 @@ "endLine": 223, "endColumn": 12, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5394, - "end": 5395, - "replacementText": "1.0", - "line": 223, - "column": 11, - "endLine": 223, - "endColumn": 12 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2397,17 +2276,6 @@ "endLine": 224, "endColumn": 15, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5411, - "end": 5412, - "replacementText": "2.0", - "line": 224, - "column": 14, - "endLine": 224, - "endColumn": 15 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2418,17 +2286,6 @@ "endLine": 225, "endColumn": 17, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5430, - "end": 5431, - "replacementText": "3.0", - "line": 225, - "column": 16, - "endLine": 225, - "endColumn": 17 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" @@ -2439,17 +2296,6 @@ "endLine": 226, "endColumn": 15, "problem": "NumericSemantics", - "autofix": [ - { - "start": 5447, - "end": 5448, - "replacementText": "4.0", - "line": 226, - "column": 14, - "endLine": 226, - "endColumn": 15 - } - ], "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.ets b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.ets index 80c650b284f56fa61f6c586fad2815b5579f019a..43753aa4987f263c914c9445d1ddf7660eb70fb6 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.ets +++ b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.ets @@ -119,8 +119,8 @@ let g: number = an_array[] const a: number = 1.0 enum Test { - A = 1.0, // 显式赋值为 1 - B = 2.0 // 显式赋值为 2 + A = 1, // 显式赋值为 1 + B = 2 // 显式赋值为 2 } const test: number = Test.A; @@ -222,21 +222,21 @@ let a:number = 0.000; const b:number = 0.000; export enum WalletStageValue { - DEFAULT = 0.0, - SWIPE_INIT = -1.0, - SELECT_CARD = 1.0, - SWIPE_DOING = 2.0, - SWIPE_SUCCEED = 3.0, - SWIPE_FAILED = 4.0, - SWIPE_FINISHED = 5.0, + DEFAULT = 0, + SWIPE_INIT = -1, + SELECT_CARD = 1, + SWIPE_DOING = 2, + SWIPE_SUCCEED = 3, + SWIPE_FAILED = 4, + SWIPE_FINISHED = 5, } export enum AnimationStage { - INIT = 0.0, - ENTER = 1.0, - ROTATING = 2.0, - EXIT_START = 3.0, - EXIT_END = 4.0, + INIT = 0, + ENTER = 1, + ROTATING = 2, + EXIT_START = 3, + EXIT_END = 4, } class C { diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json index 29adb27a5c73651c3f5daef9d86c8c2395f63f14..09385a376c0a71f5f8ab507066c36cbb0f10a3f5 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json @@ -34,6 +34,26 @@ "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", "severity": "ERROR" }, + { + "line": 122, + "column": 7, + "endLine": 122, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 123, + "column": 7, + "endLine": 123, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 156, "column": 6, @@ -123,6 +143,126 @@ "suggest": "", "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" + }, + { + "line": 225, + "column": 13, + "endLine": 225, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 226, + "column": 17, + "endLine": 226, + "endColumn": 18, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 227, + "column": 17, + "endLine": 227, + "endColumn": 18, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 228, + "column": 17, + "endLine": 228, + "endColumn": 18, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 229, + "column": 19, + "endLine": 229, + "endColumn": 20, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 230, + "column": 18, + "endLine": 230, + "endColumn": 19, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 231, + "column": 20, + "endLine": 231, + "endColumn": 21, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 235, + "column": 10, + "endLine": 235, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 236, + "column": 11, + "endLine": 236, + "endColumn": 12, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 237, + "column": 14, + "endLine": 237, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 238, + "column": 16, + "endLine": 238, + "endColumn": 17, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 239, + "column": 14, + "endLine": 239, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json index 0cee44032a3206ca97c463973bf98fd30e6624fe..9cee3116485dd985f550b19ad95c9d6f09e67846 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json @@ -1,1329 +1,1256 @@ { - "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": 22, - "column": 5, - "endLine": 22, - "endColumn": 26, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 17, - "column": 23, - "endLine": 17, - "endColumn": 25, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 678, - "end": 680, - "replacementText": "11.0", - "line": 17, - "column": 23, - "endLine": 17, - "endColumn": 25 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 18, - "column": 11, - "endLine": 18, - "endColumn": 17, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 702, - "end": 708, - "replacementText": "b: number = 12", - "line": 18, - "column": 11, - "endLine": 18, - "endColumn": 17 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 18, - "column": 15, - "endLine": 18, - "endColumn": 17, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 706, - "end": 708, - "replacementText": "12.0", - "line": 18, - "column": 15, - "endLine": 18, - "endColumn": 17 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 19, - "column": 11, - "endLine": 19, - "endColumn": 19, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 730, - "end": 738, - "replacementText": "c: number = 13.0", - "line": 19, - "column": 11, - "endLine": 19, - "endColumn": 19 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 21, - "column": 23, - "endLine": 21, - "endColumn": 25, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 800, - "end": 802, - "replacementText": "15.0", - "line": 21, - "column": 23, - "endLine": 21, - "endColumn": 25 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 22, - "column": 22, - "endLine": 22, - "endColumn": 23, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 835, - "end": 836, - "replacementText": "1.0", - "line": 22, - "column": 22, - "endLine": 22, - "endColumn": 23 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 22, - "column": 24, - "endLine": 22, - "endColumn": 25, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 837, - "end": 838, - "replacementText": "2.0", - "line": 22, - "column": 24, - "endLine": 22, - "endColumn": 25 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 31, - "column": 5, - "endLine": 31, - "endColumn": 30, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 38, - "column": 5, - "endLine": 38, - "endColumn": 23, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 45, - "column": 5, - "endLine": 45, - "endColumn": 25, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 35, - "column": 20, - "endLine": 35, - "endColumn": 26, - "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "name", - "start": 1117, - "end": 1123, - "line": 37, - "column": 18, - "endLine": 37, - "endColumn": 24 - }, - { - "replacementText": "name", - "start": 1210, - "end": 1216, - "line": 37, - "column": 18, - "endLine": 37, - "endColumn": 24 - } - ], - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 35, - "column": 36, - "endLine": 35, - "endColumn": 37, - "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "__2", - "start": 1133, - "end": 1134, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - }, - { - "replacementText": "__2", - "start": 1224, - "end": 1225, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - }, - { - "replacementText": "x.__2", - "start": 1256, - "end": 1260, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - } - ], - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 36, - "column": 20, - "endLine": 36, - "endColumn": 26, - "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "name", - "start": 1164, - "end": 1170, - "line": 36, - "column": 20, - "endLine": 36, - "endColumn": 26 - } - ], - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 37, - "column": 18, - "endLine": 37, - "endColumn": 24, - "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "name", - "start": 1117, - "end": 1123, - "line": 37, - "column": 18, - "endLine": 37, - "endColumn": 24 - }, - { - "replacementText": "name", - "start": 1210, - "end": 1216, - "line": 37, - "column": 18, - "endLine": 37, - "endColumn": 24 - } - ], - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 37, - "column": 32, - "endLine": 37, - "endColumn": 33, - "problem": "LiteralAsPropertyName", - "autofix": [ - { - "replacementText": "__2", - "start": 1133, - "end": 1134, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - }, - { - "replacementText": "__2", - "start": 1224, - "end": 1225, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - }, - { - "replacementText": "x.__2", - "start": 1256, - "end": 1260, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - } - ], - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21, - "problem": "PropertyAccessByIndex", - "autofix": [ - { - "replacementText": "__2", - "start": 1133, - "end": 1134, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - }, - { - "replacementText": "__2", - "start": 1224, - "end": 1225, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - }, - { - "replacementText": "x.__2", - "start": 1256, - "end": 1260, - "line": 38, - "column": 17, - "endLine": 38, - "endColumn": 21 - } - ], - "suggest": "", - "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", - "severity": "ERROR" - }, - { - "line": 42, - "column": 17, - "endLine": 42, - "endColumn": 18, - "problem": "ObjectLiteralNoContextType", - "suggest": "", - "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", - "severity": "ERROR" - }, - { - "line": 42, - "column": 30, - "endLine": 42, - "endColumn": 31, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 44, - "column": 17, - "endLine": 44, - "endColumn": 19, - "problem": "NosparseArray", - "suggest": "", - "rule": "Sparse array is not supported in ArkTS1.2 (arkts-no-sparse-array)", - "severity": "ERROR" - }, - { - "line": 45, - "column": 17, - "endLine": 45, - "endColumn": 23, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 62, - "column": 13, - "endLine": 62, - "endColumn": 14, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 1792, - "end": 1793, - "replacementText": "1.0", - "line": 62, - "column": 13, - "endLine": 62, - "endColumn": 14 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 63, - "column": 13, - "endLine": 63, - "endColumn": 14, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 1808, - "end": 1809, - "replacementText": "2.0", - "line": 63, - "column": 13, - "endLine": 63, - "endColumn": 14 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 68, - "column": 28, - "endLine": 68, - "endColumn": 30, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 1885, - "end": 1887, - "replacementText": "11.0", - "line": 68, - "column": 28, - "endLine": 68, - "endColumn": 30 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 72, - "column": 5, - "endLine": 72, - "endColumn": 13, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 72, - "column": 8, - "endLine": 72, - "endColumn": 9, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 1925, - "end": 1926, - "replacementText": "1.0", - "line": 72, - "column": 8, - "endLine": 72, - "endColumn": 9 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 72, - "column": 10, - "endLine": 72, - "endColumn": 11, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 1927, - "end": 1928, - "replacementText": "2.0", - "line": 72, - "column": 10, - "endLine": 72, - "endColumn": 11 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 83, - "column": 5, - "endLine": 83, - "endColumn": 35, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 77, - "column": 19, - "endLine": 77, - "endColumn": 20, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 1990, - "end": 1991, - "replacementText": "1.0", - "line": 77, - "column": 19, - "endLine": 77, - "endColumn": 20 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 77, - "column": 21, - "endLine": 77, - "endColumn": 22, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 1992, - "end": 1993, - "replacementText": "2.0", - "line": 77, - "column": 21, - "endLine": 77, - "endColumn": 22 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 79, - "column": 21, - "endLine": 79, - "endColumn": 23, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2056, - "end": 2058, - "replacementText": "20.0", - "line": 79, - "column": 21, - "endLine": 79, - "endColumn": 23 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 79, - "column": 26, - "endLine": 79, - "endColumn": 28, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2061, - "end": 2063, - "replacementText": "21.0", - "line": 79, - "column": 26, - "endLine": 79, - "endColumn": 28 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 79, - "column": 31, - "endLine": 79, - "endColumn": 33, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2066, - "end": 2068, - "replacementText": "22.0", - "line": 79, - "column": 31, - "endLine": 79, - "endColumn": 33 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 79, - "column": 36, - "endLine": 79, - "endColumn": 38, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2071, - "end": 2073, - "replacementText": "23.0", - "line": 79, - "column": 36, - "endLine": 79, - "endColumn": 38 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 81, - "column": 24, - "endLine": 81, - "endColumn": 26, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2159, - "end": 2161, - "replacementText": "20.0", - "line": 81, - "column": 24, - "endLine": 81, - "endColumn": 26 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 86, - "column": 9, - "endLine": 86, - "endColumn": 15, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2321, - "end": 2327, - "replacementText": "e: number = 15", - "line": 86, - "column": 9, - "endLine": 86, - "endColumn": 15 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 86, - "column": 13, - "endLine": 86, - "endColumn": 15, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2325, - "end": 2327, - "replacementText": "15.0", - "line": 86, - "column": 13, - "endLine": 86, - "endColumn": 15 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 87, - "column": 9, - "endLine": 87, - "endColumn": 19, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2347, - "end": 2357, - "replacementText": "e1: number = e & 3", - "line": 87, - "column": 9, - "endLine": 87, - "endColumn": 19 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 87, - "column": 18, - "endLine": 87, - "endColumn": 19, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2356, - "end": 2357, - "replacementText": "3.0", - "line": 87, - "column": 18, - "endLine": 87, - "endColumn": 19 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 88, - "column": 9, - "endLine": 88, - "endColumn": 19, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2378, - "end": 2388, - "replacementText": "e2: number = e | 3", - "line": 88, - "column": 9, - "endLine": 88, - "endColumn": 19 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 88, - "column": 18, - "endLine": 88, - "endColumn": 19, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2387, - "end": 2388, - "replacementText": "3.0", - "line": 88, - "column": 18, - "endLine": 88, - "endColumn": 19 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 100, - "column": 5, - "endLine": 100, - "endColumn": 27, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 101, - "column": 5, - "endLine": 101, - "endColumn": 38, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 102, - "column": 5, - "endLine": 102, - "endColumn": 25, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 114, - "column": 5, - "endLine": 114, - "endColumn": 15, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 115, - "column": 5, - "endLine": 115, - "endColumn": 17, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 120, - "column": 5, - "endLine": 120, - "endColumn": 27, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 121, - "column": 5, - "endLine": 121, - "endColumn": 28, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 123, - "column": 5, - "endLine": 123, - "endColumn": 38, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 124, - "column": 5, - "endLine": 124, - "endColumn": 53, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 125, - "column": 5, - "endLine": 125, - "endColumn": 57, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 100, - "column": 25, - "endLine": 100, - "endColumn": 26, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2611, - "end": 2612, - "replacementText": "1.0", - "line": 100, - "column": 25, - "endLine": 100, - "endColumn": 26 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 101, - "column": 32, - "endLine": 101, - "endColumn": 33, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2673, - "end": 2674, - "replacementText": "1.0", - "line": 101, - "column": 32, - "endLine": 101, - "endColumn": 33 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 101, - "column": 36, - "endLine": 101, - "endColumn": 37, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2677, - "end": 2678, - "replacementText": "2.0", - "line": 101, - "column": 36, - "endLine": 101, - "endColumn": 37 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 102, - "column": 23, - "endLine": 102, - "endColumn": 24, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 2713, - "end": 2714, - "replacementText": "1.0", - "line": 102, - "column": 23, - "endLine": 102, - "endColumn": 24 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 109, - "column": 32, - "endLine": 109, - "endColumn": 60, - "problem": "GenericCallNoTypeArgs", - "suggest": "", - "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", - "severity": "ERROR" - }, - { - "line": 114, - "column": 9, - "endLine": 114, - "endColumn": 11, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3105, - "end": 3107, - "replacementText": "12.0", - "line": 114, - "column": 9, - "endLine": 114, - "endColumn": 11 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 114, - "column": 13, - "endLine": 114, - "endColumn": 15, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3109, - "end": 3111, - "replacementText": "24.0", - "line": 114, - "column": 13, - "endLine": 114, - "endColumn": 15 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 115, - "column": 15, - "endLine": 115, - "endColumn": 17, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3137, - "end": 3139, - "replacementText": "24.0", - "line": 115, - "column": 15, - "endLine": 115, - "endColumn": 17 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 120, - "column": 16, - "endLine": 120, - "endColumn": 17, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3250, - "end": 3251, - "replacementText": "8.0", - "line": 120, - "column": 16, - "endLine": 120, - "endColumn": 17 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 120, - "column": 25, - "endLine": 120, - "endColumn": 27, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3259, - "end": 3261, - "replacementText": "24.0", - "line": 120, - "column": 25, - "endLine": 120, - "endColumn": 27 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 121, - "column": 16, - "endLine": 121, - "endColumn": 17, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3288, - "end": 3289, - "replacementText": "8.0", - "line": 121, - "column": 16, - "endLine": 121, - "endColumn": 17 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 121, - "column": 26, - "endLine": 121, - "endColumn": 28, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3298, - "end": 3300, - "replacementText": "24.0", - "line": 121, - "column": 26, - "endLine": 121, - "endColumn": 28 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 123, - "column": 22, - "endLine": 123, - "endColumn": 24, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3335, - "end": 3337, - "replacementText": "12.0", - "line": 123, - "column": 22, - "endLine": 123, - "endColumn": 24 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 123, - "column": 25, - "endLine": 123, - "endColumn": 27, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3338, - "end": 3340, - "replacementText": "24.0", - "line": 123, - "column": 25, - "endLine": 123, - "endColumn": 27 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 123, - "column": 29, - "endLine": 123, - "endColumn": 30, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3342, - "end": 3343, - "replacementText": "8.0", - "line": 123, - "column": 29, - "endLine": 123, - "endColumn": 30 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 124, - "column": 37, - "endLine": 124, - "endColumn": 39, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3399, - "end": 3401, - "replacementText": "12.0", - "line": 124, - "column": 37, - "endLine": 124, - "endColumn": 39 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 124, - "column": 40, - "endLine": 124, - "endColumn": 42, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3402, - "end": 3404, - "replacementText": "24.0", - "line": 124, - "column": 40, - "endLine": 124, - "endColumn": 42 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 124, - "column": 44, - "endLine": 124, - "endColumn": 45, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3406, - "end": 3407, - "replacementText": "8.0", - "line": 124, - "column": 44, - "endLine": 124, - "endColumn": 45 - } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 125, - "column": 48, - "endLine": 125, - "endColumn": 49, - "problem": "NumericSemantics", - "autofix": [ - { - "start": 3474, - "end": 3475, - "replacementText": "8.0", - "line": 125, - "column": 48, - "endLine": 125, - "endColumn": 49 + "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": 22, + "column": 5, + "endLine": 22, + "endColumn": 26, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 23, + "endLine": 17, + "endColumn": 25, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 678, + "end": 680, + "replacementText": "11.0", + "line": 17, + "column": 23, + "endLine": 17, + "endColumn": 25 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 11, + "endLine": 18, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 702, + "end": 708, + "replacementText": "b: number = 12", + "line": 18, + "column": 11, + "endLine": 18, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 15, + "endLine": 18, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 706, + "end": 708, + "replacementText": "12.0", + "line": 18, + "column": 15, + "endLine": 18, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 11, + "endLine": 19, + "endColumn": 19, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 730, + "end": 738, + "replacementText": "c: number = 13.0", + "line": 19, + "column": 11, + "endLine": 19, + "endColumn": 19 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 23, + "endLine": 21, + "endColumn": 25, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 800, + "end": 802, + "replacementText": "15.0", + "line": 21, + "column": 23, + "endLine": 21, + "endColumn": 25 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 22, + "endLine": 22, + "endColumn": 23, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 835, + "end": 836, + "replacementText": "1.0", + "line": 22, + "column": 22, + "endLine": 22, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 24, + "endLine": 22, + "endColumn": 25, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 837, + "end": 838, + "replacementText": "2.0", + "line": 22, + "column": 24, + "endLine": 22, + "endColumn": 25 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 5, + "endLine": 31, + "endColumn": 30, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 5, + "endLine": 38, + "endColumn": 23, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 5, + "endLine": 45, + "endColumn": 25, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 20, + "endLine": 35, + "endColumn": 26, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 36, + "endLine": 35, + "endColumn": 37, + "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "__2", + "start": 1133, + "end": 1134, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + }, + { + "replacementText": "__2", + "start": 1224, + "end": 1225, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + }, + { + "replacementText": "x.__2", + "start": 1256, + "end": 1260, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + } + ], + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 20, + "endLine": 36, + "endColumn": 26, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 18, + "endLine": 37, + "endColumn": 24, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 32, + "endLine": 37, + "endColumn": 33, + "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "__2", + "start": 1133, + "end": 1134, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + }, + { + "replacementText": "__2", + "start": 1224, + "end": 1225, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + }, + { + "replacementText": "x.__2", + "start": 1256, + "end": 1260, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + } + ], + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21, + "problem": "PropertyAccessByIndex", + "autofix": [ + { + "replacementText": "__2", + "start": 1133, + "end": 1134, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + }, + { + "replacementText": "__2", + "start": 1224, + "end": 1225, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + }, + { + "replacementText": "x.__2", + "start": 1256, + "end": 1260, + "line": 38, + "column": 17, + "endLine": 38, + "endColumn": 21 + } + ], + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "severity": "ERROR" + }, + { + "line": 42, + "column": 17, + "endLine": 42, + "endColumn": 18, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 42, + "column": 30, + "endLine": 42, + "endColumn": 31, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 17, + "endLine": 44, + "endColumn": 19, + "problem": "NosparseArray", + "suggest": "", + "rule": "Sparse array is not supported in ArkTS1.2 (arkts-no-sparse-array)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 17, + "endLine": 45, + "endColumn": 23, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 13, + "endLine": 62, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 13, + "endLine": 63, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 68, + "column": 28, + "endLine": 68, + "endColumn": 30, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1885, + "end": 1887, + "replacementText": "11.0", + "line": 68, + "column": 28, + "endLine": 68, + "endColumn": 30 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 5, + "endLine": 72, + "endColumn": 13, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 8, + "endLine": 72, + "endColumn": 9, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1925, + "end": 1926, + "replacementText": "1.0", + "line": 72, + "column": 8, + "endLine": 72, + "endColumn": 9 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 10, + "endLine": 72, + "endColumn": 11, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1927, + "end": 1928, + "replacementText": "2.0", + "line": 72, + "column": 10, + "endLine": 72, + "endColumn": 11 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 83, + "column": 5, + "endLine": 83, + "endColumn": 35, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 77, + "column": 19, + "endLine": 77, + "endColumn": 20, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1990, + "end": 1991, + "replacementText": "1.0", + "line": 77, + "column": 19, + "endLine": 77, + "endColumn": 20 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 77, + "column": 21, + "endLine": 77, + "endColumn": 22, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1992, + "end": 1993, + "replacementText": "2.0", + "line": 77, + "column": 21, + "endLine": 77, + "endColumn": 22 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 79, + "column": 21, + "endLine": 79, + "endColumn": 23, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2056, + "end": 2058, + "replacementText": "20.0", + "line": 79, + "column": 21, + "endLine": 79, + "endColumn": 23 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 79, + "column": 26, + "endLine": 79, + "endColumn": 28, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2061, + "end": 2063, + "replacementText": "21.0", + "line": 79, + "column": 26, + "endLine": 79, + "endColumn": 28 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 79, + "column": 31, + "endLine": 79, + "endColumn": 33, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2066, + "end": 2068, + "replacementText": "22.0", + "line": 79, + "column": 31, + "endLine": 79, + "endColumn": 33 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 79, + "column": 36, + "endLine": 79, + "endColumn": 38, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2071, + "end": 2073, + "replacementText": "23.0", + "line": 79, + "column": 36, + "endLine": 79, + "endColumn": 38 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 24, + "endLine": 81, + "endColumn": 26, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2159, + "end": 2161, + "replacementText": "20.0", + "line": 81, + "column": 24, + "endLine": 81, + "endColumn": 26 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 86, + "column": 9, + "endLine": 86, + "endColumn": 15, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2321, + "end": 2327, + "replacementText": "e: number = 15", + "line": 86, + "column": 9, + "endLine": 86, + "endColumn": 15 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 86, + "column": 13, + "endLine": 86, + "endColumn": 15, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2325, + "end": 2327, + "replacementText": "15.0", + "line": 86, + "column": 13, + "endLine": 86, + "endColumn": 15 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 87, + "column": 9, + "endLine": 87, + "endColumn": 19, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2347, + "end": 2357, + "replacementText": "e1: number = e & 3", + "line": 87, + "column": 9, + "endLine": 87, + "endColumn": 19 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 87, + "column": 18, + "endLine": 87, + "endColumn": 19, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2356, + "end": 2357, + "replacementText": "3.0", + "line": 87, + "column": 18, + "endLine": 87, + "endColumn": 19 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 88, + "column": 9, + "endLine": 88, + "endColumn": 19, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2378, + "end": 2388, + "replacementText": "e2: number = e | 3", + "line": 88, + "column": 9, + "endLine": 88, + "endColumn": 19 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 88, + "column": 18, + "endLine": 88, + "endColumn": 19, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2387, + "end": 2388, + "replacementText": "3.0", + "line": 88, + "column": 18, + "endLine": 88, + "endColumn": 19 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 100, + "column": 5, + "endLine": 100, + "endColumn": 27, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 101, + "column": 5, + "endLine": 101, + "endColumn": 38, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 102, + "column": 5, + "endLine": 102, + "endColumn": 25, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 114, + "column": 5, + "endLine": 114, + "endColumn": 15, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 5, + "endLine": 115, + "endColumn": 17, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 120, + "column": 5, + "endLine": 120, + "endColumn": 27, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 121, + "column": 5, + "endLine": 121, + "endColumn": 28, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 123, + "column": 5, + "endLine": 123, + "endColumn": 38, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 124, + "column": 5, + "endLine": 124, + "endColumn": 53, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 57, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 100, + "column": 25, + "endLine": 100, + "endColumn": 26, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2611, + "end": 2612, + "replacementText": "1.0", + "line": 100, + "column": 25, + "endLine": 100, + "endColumn": 26 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 101, + "column": 32, + "endLine": 101, + "endColumn": 33, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2673, + "end": 2674, + "replacementText": "1.0", + "line": 101, + "column": 32, + "endLine": 101, + "endColumn": 33 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 101, + "column": 36, + "endLine": 101, + "endColumn": 37, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2677, + "end": 2678, + "replacementText": "2.0", + "line": 101, + "column": 36, + "endLine": 101, + "endColumn": 37 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 102, + "column": 23, + "endLine": 102, + "endColumn": 24, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2713, + "end": 2714, + "replacementText": "1.0", + "line": 102, + "column": 23, + "endLine": 102, + "endColumn": 24 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 109, + "column": 32, + "endLine": 109, + "endColumn": 60, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 114, + "column": 9, + "endLine": 114, + "endColumn": 11, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3105, + "end": 3107, + "replacementText": "12.0", + "line": 114, + "column": 9, + "endLine": 114, + "endColumn": 11 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 114, + "column": 13, + "endLine": 114, + "endColumn": 15, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3109, + "end": 3111, + "replacementText": "24.0", + "line": 114, + "column": 13, + "endLine": 114, + "endColumn": 15 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 15, + "endLine": 115, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3137, + "end": 3139, + "replacementText": "24.0", + "line": 115, + "column": 15, + "endLine": 115, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 120, + "column": 16, + "endLine": 120, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3250, + "end": 3251, + "replacementText": "8.0", + "line": 120, + "column": 16, + "endLine": 120, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 120, + "column": 25, + "endLine": 120, + "endColumn": 27, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3259, + "end": 3261, + "replacementText": "24.0", + "line": 120, + "column": 25, + "endLine": 120, + "endColumn": 27 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 121, + "column": 16, + "endLine": 121, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3288, + "end": 3289, + "replacementText": "8.0", + "line": 121, + "column": 16, + "endLine": 121, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 121, + "column": 26, + "endLine": 121, + "endColumn": 28, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3298, + "end": 3300, + "replacementText": "24.0", + "line": 121, + "column": 26, + "endLine": 121, + "endColumn": 28 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 123, + "column": 22, + "endLine": 123, + "endColumn": 24, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3335, + "end": 3337, + "replacementText": "12.0", + "line": 123, + "column": 22, + "endLine": 123, + "endColumn": 24 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 123, + "column": 25, + "endLine": 123, + "endColumn": 27, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3338, + "end": 3340, + "replacementText": "24.0", + "line": 123, + "column": 25, + "endLine": 123, + "endColumn": 27 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 123, + "column": 29, + "endLine": 123, + "endColumn": 30, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3342, + "end": 3343, + "replacementText": "8.0", + "line": 123, + "column": 29, + "endLine": 123, + "endColumn": 30 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 124, + "column": 37, + "endLine": 124, + "endColumn": 39, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3399, + "end": 3401, + "replacementText": "12.0", + "line": 124, + "column": 37, + "endLine": 124, + "endColumn": 39 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 124, + "column": 40, + "endLine": 124, + "endColumn": 42, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3402, + "end": 3404, + "replacementText": "24.0", + "line": 124, + "column": 40, + "endLine": 124, + "endColumn": 42 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 124, + "column": 44, + "endLine": 124, + "endColumn": 45, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3406, + "end": 3407, + "replacementText": "8.0", + "line": 124, + "column": 44, + "endLine": 124, + "endColumn": 45 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 125, + "column": 48, + "endLine": 125, + "endColumn": 49, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 3474, + "end": 3475, + "replacementText": "8.0", + "line": 125, + "column": 48, + "endLine": 125, + "endColumn": 49 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" } - ], - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - } - ] -} + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets index 06a1c158599f2e576c0ba151127a01324bb1f7ce..81211a821a8d1a9666b154b73322f20c0c5a7ffd 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets @@ -32,9 +32,9 @@ namespace NumericSemanticsDone { } namespace NoNumericSemantics { - interface X1 { name: number, __2: number} - interface X2 { name: number, _2: number} - let x: X1 = {name: 20.0, __2: 30.0} // OK + interface X1 { "name": number, __2: number} + interface X2 { "name": number, _2: number} + let x: X1 = {"name": 20.0, __2: 30.0} // OK console.log(x.__2); // OK let x_fix: X2 = {name: 20.0, _2: 20.0}; @@ -59,8 +59,8 @@ namespace NoNumericSemantics { let h: number = arr[12. as int] enum E { - A = 1.0, - B = 2.0 + A = 1, + B = 2 } } diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json index 57a7300d81f95c785f998fb774898c73ede2b227..2103eb7cf5387f30295dca218d7ff81e6a850e86 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json @@ -1,228 +1,278 @@ { - "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": 22, - "column": 5, - "endLine": 22, - "endColumn": 30, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 31, - "column": 5, - "endLine": 31, - "endColumn": 30, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 38, - "column": 5, - "endLine": 38, - "endColumn": 24, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 45, - "column": 5, - "endLine": 45, - "endColumn": 25, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 42, - "column": 17, - "endLine": 42, - "endColumn": 18, - "problem": "ObjectLiteralNoContextType", - "suggest": "", - "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", - "severity": "ERROR" - }, - { - "line": 42, - "column": 30, - "endLine": 42, - "endColumn": 31, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 44, - "column": 17, - "endLine": 44, - "endColumn": 19, - "problem": "NosparseArray", - "suggest": "", - "rule": "Sparse array is not supported in ArkTS1.2 (arkts-no-sparse-array)", - "severity": "ERROR" - }, - { - "line": 45, - "column": 17, - "endLine": 45, - "endColumn": 23, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 72, - "column": 5, - "endLine": 72, - "endColumn": 17, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 83, - "column": 5, - "endLine": 83, - "endColumn": 35, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 100, - "column": 5, - "endLine": 100, - "endColumn": 29, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 101, - "column": 5, - "endLine": 101, - "endColumn": 42, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 102, - "column": 5, - "endLine": 102, - "endColumn": 27, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 114, - "column": 5, - "endLine": 114, - "endColumn": 19, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 115, - "column": 5, - "endLine": 115, - "endColumn": 19, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 120, - "column": 5, - "endLine": 120, - "endColumn": 31, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 121, - "column": 5, - "endLine": 121, - "endColumn": 32, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 123, - "column": 5, - "endLine": 123, - "endColumn": 44, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 124, - "column": 5, - "endLine": 124, - "endColumn": 59, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 125, - "column": 5, - "endLine": 125, - "endColumn": 59, - "problem": "NonDeclarationInNamespace", - "suggest": "", - "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", - "severity": "ERROR" - }, - { - "line": 109, - "column": 32, - "endLine": 109, - "endColumn": 60, - "problem": "GenericCallNoTypeArgs", - "suggest": "", - "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", - "severity": "ERROR" - } - ] -} + "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": 22, + "column": 5, + "endLine": 22, + "endColumn": 30, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 5, + "endLine": 31, + "endColumn": 30, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 5, + "endLine": 38, + "endColumn": 24, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 5, + "endLine": 45, + "endColumn": 25, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 20, + "endLine": 35, + "endColumn": 26, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 20, + "endLine": 36, + "endColumn": 26, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 18, + "endLine": 37, + "endColumn": 24, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 42, + "column": 17, + "endLine": 42, + "endColumn": 18, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 42, + "column": 30, + "endLine": 42, + "endColumn": 31, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 17, + "endLine": 44, + "endColumn": 19, + "problem": "NosparseArray", + "suggest": "", + "rule": "Sparse array is not supported in ArkTS1.2 (arkts-no-sparse-array)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 17, + "endLine": 45, + "endColumn": 23, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 13, + "endLine": 62, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 13, + "endLine": 63, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 5, + "endLine": 72, + "endColumn": 17, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 83, + "column": 5, + "endLine": 83, + "endColumn": 35, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 100, + "column": 5, + "endLine": 100, + "endColumn": 29, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 101, + "column": 5, + "endLine": 101, + "endColumn": 42, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 102, + "column": 5, + "endLine": 102, + "endColumn": 27, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 114, + "column": 5, + "endLine": 114, + "endColumn": 19, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 5, + "endLine": 115, + "endColumn": 19, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 120, + "column": 5, + "endLine": 120, + "endColumn": 31, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 121, + "column": 5, + "endLine": 121, + "endColumn": 32, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 123, + "column": 5, + "endLine": 123, + "endColumn": 44, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 124, + "column": 5, + "endLine": 124, + "endColumn": 59, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 125, + "column": 5, + "endLine": 125, + "endColumn": 59, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", + "severity": "ERROR" + }, + { + "line": 109, + "column": 32, + "endLine": 109, + "endColumn": 60, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/object_literals_properties.ets.arkts2.json b/ets2panda/linter/test/main/object_literals_properties.ets.arkts2.json index b72ff900ba7ccd4a3199f642e70b74ee16525763..8ed64f688b1637ca397321e8a120fb5b1d0c1bba 100644 --- a/ets2panda/linter/test/main/object_literals_properties.ets.arkts2.json +++ b/ets2panda/linter/test/main/object_literals_properties.ets.arkts2.json @@ -1164,6 +1164,16 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, + { + "line": 216, + "column": 1, + "endLine": 218, + "endColumn": 2, + "problem": "MissingSuperCall", + "suggest": "", + "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", + "severity": "ERROR" + }, { "line": 219, "column": 18, @@ -1196,9 +1206,9 @@ }, { "line": 226, - "column": 16, - "endLine": 226, - "endColumn": 29, + "column": 1, + "endLine": 228, + "endColumn": 2, "problem": "MissingSuperCall", "suggest": "", "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", diff --git a/ets2panda/linter/test/main/object_literals_properties.ets.autofix.json b/ets2panda/linter/test/main/object_literals_properties.ets.autofix.json index ccf6076bdc6c00243b5abe01469d556165d4bf23..bbb319af18b8c79801bc869be8d35b1cd69507fd 100644 --- a/ets2panda/linter/test/main/object_literals_properties.ets.autofix.json +++ b/ets2panda/linter/test/main/object_literals_properties.ets.autofix.json @@ -2072,6 +2072,16 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, + { + "line": 216, + "column": 1, + "endLine": 218, + "endColumn": 2, + "problem": "MissingSuperCall", + "suggest": "", + "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", + "severity": "ERROR" + }, { "line": 219, "column": 18, @@ -2135,9 +2145,9 @@ }, { "line": 226, - "column": 16, - "endLine": 226, - "endColumn": 29, + "column": 1, + "endLine": 228, + "endColumn": 2, "problem": "MissingSuperCall", "suggest": "", "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", diff --git a/ets2panda/linter/test/main/object_literals_properties.ets.migrate.json b/ets2panda/linter/test/main/object_literals_properties.ets.migrate.json index cb4957616222487070cf53339fedcabe2157fecb..675cc2476a8a98d88b903bea26dcf8ab85279545 100644 --- a/ets2panda/linter/test/main/object_literals_properties.ets.migrate.json +++ b/ets2panda/linter/test/main/object_literals_properties.ets.migrate.json @@ -284,11 +284,21 @@ "rule": "Object literal properties can only contain name-value pairs (arkts-obj-literal-props)", "severity": "ERROR" }, + { + "line": 274, + "column": 1, + "endLine": 276, + "endColumn": 2, + "problem": "MissingSuperCall", + "suggest": "", + "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", + "severity": "ERROR" + }, { "line": 286, - "column": 16, - "endLine": 286, - "endColumn": 29, + "column": 1, + "endLine": 288, + "endColumn": 2, "problem": "MissingSuperCall", "suggest": "", "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", @@ -314,6 +324,16 @@ "rule": "Object literal properties can only contain name-value pairs (arkts-obj-literal-props)", "severity": "ERROR" }, + { + "line": 303, + "column": 1, + "endLine": 305, + "endColumn": 2, + "problem": "MissingSuperCall", + "suggest": "", + "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", + "severity": "ERROR" + }, { "line": 342, "column": 5, diff --git a/ets2panda/linter/test/main/oh_modules/@ohos.util.HashMap.d.ets b/ets2panda/linter/test/main/oh_modules/@ohos.util.HashMap.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..7a82cdb9a8309a9f9144fb675f2657b9f7022437 --- /dev/null +++ b/ets2panda/linter/test/main/oh_modules/@ohos.util.HashMap.d.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export namespace MapKit { + export class HashMap { + constructor(); + length: number; + keys(): IterableIterator; + hasKey(key: K): boolean; + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/property_access_by_index.ets.arkts2.json b/ets2panda/linter/test/main/property_access_by_index.ets.arkts2.json index 87f6a124449977e6c2fc004f7eebdec7c660b995..2247b1cc2e70af1c1a076519ab7bedee45e4528e 100644 --- a/ets2panda/linter/test/main/property_access_by_index.ets.arkts2.json +++ b/ets2panda/linter/test/main/property_access_by_index.ets.arkts2.json @@ -774,26 +774,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 108, - "column": 17, - "endLine": 108, - "endColumn": 40, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, - { - "line": 112, - "column": 15, - "endLine": 112, - "endColumn": 38, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 117, "column": 20, @@ -824,26 +804,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 118, - "column": 15, - "endLine": 118, - "endColumn": 36, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, - { - "line": 121, - "column": 13, - "endLine": 121, - "endColumn": 34, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 139, "column": 12, diff --git a/ets2panda/linter/test/main/property_access_by_index.ets.autofix.json b/ets2panda/linter/test/main/property_access_by_index.ets.autofix.json index 60ab233b30b77be02503372b5f949dd00f00d49d..3e8481358e4982d9ace28266eb547a6f83c93d2e 100644 --- a/ets2panda/linter/test/main/property_access_by_index.ets.autofix.json +++ b/ets2panda/linter/test/main/property_access_by_index.ets.autofix.json @@ -1269,26 +1269,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 108, - "column": 17, - "endLine": 108, - "endColumn": 40, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, - { - "line": 112, - "column": 15, - "endLine": 112, - "endColumn": 38, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 117, "column": 20, @@ -1319,26 +1299,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 118, - "column": 15, - "endLine": 118, - "endColumn": 36, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, - { - "line": 121, - "column": 13, - "endLine": 121, - "endColumn": 34, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 139, "column": 12, diff --git a/ets2panda/linter/test/main/property_access_by_index.ets.migrate.json b/ets2panda/linter/test/main/property_access_by_index.ets.migrate.json index e826cfc4171258174f8501541c8d9e45c2e7f6a5..e2746dde008b85a1c320af9f8162e34e82dd1c34 100644 --- a/ets2panda/linter/test/main/property_access_by_index.ets.migrate.json +++ b/ets2panda/linter/test/main/property_access_by_index.ets.migrate.json @@ -324,26 +324,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 108, - "column": 17, - "endLine": 108, - "endColumn": 40, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, - { - "line": 112, - "column": 15, - "endLine": 112, - "endColumn": 38, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 117, "column": 20, @@ -374,26 +354,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 118, - "column": 15, - "endLine": 118, - "endColumn": 36, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, - { - "line": 121, - "column": 13, - "endLine": 121, - "endColumn": 34, - "problem": "AvoidUnionTypes", - "suggest": "", - "rule": "Avoid using union types (arkts-common-union-member-access)", - "severity": "ERROR" - }, { "line": 139, "column": 12, diff --git a/ets2panda/linter/test/main/runtime_array_bound.ets b/ets2panda/linter/test/main/runtime_array_bound.ets index 94234312eb3e09ab82c8b5ff2118e6c22c06f825..934e9df563e128fa24f570286ac41e09eeb61c92 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets +++ b/ets2panda/linter/test/main/runtime_array_bound.ets @@ -280,4 +280,18 @@ function test7(config: Record, name: string) { function getValue(): string { return ''; -} \ No newline at end of file +} + +const arr: Record = {}; +let keys: string[] = Object.keys(arr); +let values: string[] = Object.values(arr); +for (let i = 0; i < keys.length; i++) { + values[i]; +} + +const arr: Map = new Map(); +let keys: string[] = Object.keys(arr); +let values: string[] = Object.values(arr); +for (let i = 0; i < keys.length; i++) { + values[i]; +} diff --git a/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json b/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json index 801d14b2604e3b3af5b0cdce8d99c706183a7cf5..ac6388b655d916b890b248e5f5950ce90459433a 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json @@ -1944,6 +1944,16 @@ "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", "severity": "ERROR" }, + { + "line": 194, + "column": 14, + "endLine": 194, + "endColumn": 24, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, { "line": 194, "column": 27, @@ -2433,6 +2443,76 @@ "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", "severity": "ERROR" + }, + { + "line": 287, + "column": 5, + "endLine": 287, + "endColumn": 42, + "problem": "ArrayTypeImmutable", + "suggest": "", + "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", + "severity": "ERROR" + }, + { + "line": 288, + "column": 10, + "endLine": 288, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 288, + "column": 14, + "endLine": 288, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 292, + "column": 34, + "endLine": 292, + "endColumn": 43, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 294, + "column": 5, + "endLine": 294, + "endColumn": 42, + "problem": "ArrayTypeImmutable", + "suggest": "", + "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", + "severity": "ERROR" + }, + { + "line": 295, + "column": 10, + "endLine": 295, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 295, + "column": 14, + "endLine": 295, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets index 62220b36c26b28d3a4ff0ffd93a86181e94d951e..31f0749e9f76421209911521934f7b62d52d0ee0 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets @@ -161,7 +161,7 @@ function foo(i:number):number{ arr1[(24)] = 23.0; arr1[+24] = 23.0; enum TE{ - AA = 12.0 + AA = 12 } arr1[TE.AA] = 12.0; @@ -280,4 +280,18 @@ function test7(config: Record, name: string) { function getValue(): string { return ''; -} \ No newline at end of file +} + +const arr: Record = {}; +let keys: string[] = Object.keys(arr); +let values: string[] = Object.values(arr); +for (let i: number = 0.0; i < keys.length; i++) { + values[i as int]; +} + +const arr: Map = new Map(); +let keys: string[] = Object.keys(arr); +let values: string[] = Object.values(arr); +for (let i: number = 0.0; i < keys.length; i++) { + values[i as int]; +} diff --git a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json index 7862ff0a076ea35016ba1529bd90eccef008a044..3d9a0f6ccc36d3b41c0f957b1f0d03fb2118363d 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json @@ -1,18 +1,18 @@ { - "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." - ], + "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": 29, @@ -164,6 +164,16 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 164, + "column": 8, + "endLine": 164, + "endColumn": 10, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 166, "column": 1, @@ -174,6 +184,16 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 194, + "column": 14, + "endLine": 194, + "endColumn": 24, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, { "line": 233, "column": 1, @@ -193,6 +213,26 @@ "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", "severity": "ERROR" + }, + { + "line": 287, + "column": 5, + "endLine": 287, + "endColumn": 42, + "problem": "ArrayTypeImmutable", + "suggest": "", + "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", + "severity": "ERROR" + }, + { + "line": 294, + "column": 5, + "endLine": 294, + "endColumn": 42, + "problem": "ArrayTypeImmutable", + "suggest": "", + "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", + "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets similarity index 100% rename from ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets rename to ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets diff --git a/ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.args.json b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.args.json similarity index 100% rename from ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.args.json rename to ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.args.json diff --git a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..dd37cd82be901a52af98be7a50ce82d1870dcb01 --- /dev/null +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json @@ -0,0 +1,118 @@ +{ + "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." + ], + "result": [ + { + "line": 18, + "column": 1, + "endLine": 22, + "endColumn": 2, + "problem": "TsOverload", + "suggest": "", + "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 10, + "endLine": 21, + "endColumn": 5, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 3, + "endLine": 27, + "endColumn": 4, + "problem": "LimitedVoidTypeFromSdk", + "suggest": "", + "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 9, + "endLine": 24, + "endColumn": 18, + "problem": "SdkAbilityAsynchronousLifecycle", + "suggest": "", + "rule": "1.2 Void cannot be combined. OnDestroy/onDisconnect (The return type of the method is now void | Promise) needs to be split into two interfaces. (sdk-ability-asynchronous-lifecycle)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 18, + "endLine": 26, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 1, + "endLine": 35, + "endColumn": 2, + "problem": "TsOverload", + "suggest": "", + "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 10, + "endLine": 34, + "endColumn": 5, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 3, + "endLine": 40, + "endColumn": 4, + "problem": "LimitedVoidTypeFromSdk", + "suggest": "", + "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 3, + "endLine": 37, + "endColumn": 12, + "problem": "SdkAbilityAsynchronousLifecycle", + "suggest": "", + "rule": "1.2 Void cannot be combined. OnDestroy/onDisconnect (The return type of the method is now void | Promise) needs to be split into two interfaces. (sdk-ability-asynchronous-lifecycle)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 18, + "endLine": 39, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.json b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.json similarity index 100% rename from ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.json rename to ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.json diff --git a/ets2panda/linter/test/main/subclass_super_call.ets b/ets2panda/linter/test/main/subclass_super_call.ets index d275725c9ced20f3df8eb301562897c1f14e3845..7e8034806431ea58a666b1a78cf468910585e6f3 100644 --- a/ets2panda/linter/test/main/subclass_super_call.ets +++ b/ets2panda/linter/test/main/subclass_super_call.ets @@ -36,4 +36,50 @@ class E extends A { // NO ERROR constructor is called } } -class F extends B {} // NO ERROR +class Base { + constructor(a?: string) {} + constructor(a: string, b:string, c?:string) {} +} + +class Foo extends Base { + constructor() { + super() + } +} + +class Bar extends Base { + constructor() { + super("foo") + } +} + +class FooTheSecond extends Base { + constructor() { + super("Foo", "Bar", "Baz") + } +} + +class FaultyBar extends Base { + constructor() { + super(12) // should error + } +} + + +class FaultyFooTheSecond extends Base { + constructor() { + super("foo", "bar", false) // should error + } +} + +class EpicFoo extends Error { + constructor() { + super() + } +} + +class EpicBar extends Error { + constructor() { + super("foo") + } +} diff --git a/ets2panda/linter/test/main/subclass_super_call.ets.args.json b/ets2panda/linter/test/main/subclass_super_call.ets.args.json index 948b846fe04969bf5ccbe8bd9dc4a18559ce0c2c..bc4d2071daf6e9354e711c3b74b6be2b56659066 100644 --- a/ets2panda/linter/test/main/subclass_super_call.ets.args.json +++ b/ets2panda/linter/test/main/subclass_super_call.ets.args.json @@ -14,6 +14,6 @@ "limitations under the License." ], "mode": { - "arkts2": "" + "arkts2": "" } } diff --git a/ets2panda/linter/test/main/subclass_super_call.ets.arkts2.json b/ets2panda/linter/test/main/subclass_super_call.ets.arkts2.json index 289a83337b8aabfabe08c43a0ade753e39dfbf7b..cb39d72e3ffed48725fc556c33893ac6281b6178 100644 --- a/ets2panda/linter/test/main/subclass_super_call.ets.arkts2.json +++ b/ets2panda/linter/test/main/subclass_super_call.ets.arkts2.json @@ -1,38 +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": 27, - "column": 9, - "endLine": 27, - "endColumn": 18, - "problem": "MissingSuperCall", - "suggest": "", - "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", - "severity": "ERROR" - }, - { - "line": 29, - "column": 9, - "endLine": 29, - "endColumn": 18, - "problem": "MissingSuperCall", - "suggest": "", - "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", - "severity": "ERROR" - } - ] -} + "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": 27, + "column": 1, + "endLine": 27, + "endColumn": 21, + "problem": "MissingSuperCall", + "suggest": "", + "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 1, + "endLine": 31, + "endColumn": 2, + "problem": "MissingSuperCall", + "suggest": "", + "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 5, + "endLine": 40, + "endColumn": 31, + "problem": "TsOverload", + "suggest": "", + "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 5, + "endLine": 41, + "endColumn": 51, + "problem": "TsOverload", + "suggest": "", + "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 1, + "endLine": 66, + "endColumn": 2, + "problem": "MissingSuperCall", + "suggest": "", + "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 15, + "endLine": 64, + "endColumn": 17, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 1, + "endLine": 73, + "endColumn": 2, + "problem": "MissingSuperCall", + "suggest": "", + "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.arkts2.json b/ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.arkts2.json deleted file mode 100644 index 6d099918006dbaec831877c173cbbeee70235071..0000000000000000000000000000000000000000 --- a/ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.arkts2.json +++ /dev/null @@ -1,148 +0,0 @@ -{ - "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." - ], - "result": [ - { - "line": 18, - "column": 1, - "endLine": 22, - "endColumn": 2, - "problem": "TsOverload", - "suggest": "", - "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", - "severity": "ERROR" - }, - { - "line": 19, - "column": 14, - "endLine": 19, - "endColumn": 21, - "problem": "ConstructorIfaceFromSdk", - "suggest": "", - "rule": "Construct signatures are not supported in interfaces.(sdk-ctor-signatures-iface)", - "severity": "ERROR" - }, - { - "line": 19, - "column": 10, - "endLine": 21, - "endColumn": 5, - "problem": "GenericCallNoTypeArgs", - "suggest": "", - "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 3, - "endLine": 27, - "endColumn": 4, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 9, - "endLine": 24, - "endColumn": 18, - "problem": "SdkAbilityAsynchronousLifecycle", - "suggest": "", - "rule": "1.2 Void cannot be combined. OnDestroy/onDisconnect (The return type of the method is now void | Promise) needs to be split into two interfaces. (sdk-ability-asynchronous-lifecycle)", - "severity": "ERROR" - }, - { - "line": 26, - "column": 12, - "endLine": 26, - "endColumn": 23, - "problem": "StructuralIdentity", - "suggest": "", - "rule": "Structural typing is not supported (arkts-no-structural-typing)", - "severity": "ERROR" - }, - { - "line": 26, - "column": 18, - "endLine": 26, - "endColumn": 22, - "problem": "NumericSemantics", - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - }, - { - "line": 31, - "column": 1, - "endLine": 35, - "endColumn": 2, - "problem": "TsOverload", - "suggest": "", - "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", - "severity": "ERROR" - }, - { - "line": 32, - "column": 14, - "endLine": 32, - "endColumn": 21, - "problem": "ConstructorIfaceFromSdk", - "suggest": "", - "rule": "Construct signatures are not supported in interfaces.(sdk-ctor-signatures-iface)", - "severity": "ERROR" - }, - { - "line": 32, - "column": 10, - "endLine": 34, - "endColumn": 5, - "problem": "GenericCallNoTypeArgs", - "suggest": "", - "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", - "severity": "ERROR" - }, - { - "line": 37, - "column": 3, - "endLine": 40, - "endColumn": 4, - "problem": "LimitedVoidTypeFromSdk", - "suggest": "", - "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", - "severity": "ERROR" - }, - { - "line": 37, - "column": 3, - "endLine": 37, - "endColumn": 12, - "problem": "SdkAbilityAsynchronousLifecycle", - "suggest": "", - "rule": "1.2 Void cannot be combined. OnDestroy/onDisconnect (The return type of the method is now void | Promise) needs to be split into two interfaces. (sdk-ability-asynchronous-lifecycle)", - "severity": "ERROR" - }, - { - "line": 39, - "column": 18, - "endLine": 39, - "endColumn": 22, - "problem": "NumericSemantics", - "suggest": "", - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "severity": "ERROR" - } - ] -}