From beddb9adb66ca34177962aa2a27fe2634a85b30d Mon Sep 17 00:00:00 2001 From: ZhongNing Date: Tue, 1 Jul 2025 20:11:59 +0800 Subject: [PATCH 01/16] fix arkts-no-ts-like-function-call Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICICWF Test scenarios: fix bug Signed-off-by: ZhongNing --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 17 +++++++++++++--- .../src/lib/utils/consts/LikeFunction.ts | 2 ++ .../test/main/explicit_function_type.ets | 6 +++++- .../explicit_function_type.ets.arkts2.json | 20 +++++++++++++++++++ .../explicit_function_type.ets.autofix.json | 20 +++++++++++++++++++ .../explicit_function_type.ets.migrate.ets | 6 +++++- .../explicit_function_type.ets.migrate.json | 20 +++++++++++++++++++ 7 files changed, 86 insertions(+), 5 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 393b46cc96..aa0b661ab7 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'; @@ -4485,10 +4485,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 { diff --git a/ets2panda/linter/src/lib/utils/consts/LikeFunction.ts b/ets2panda/linter/src/lib/utils/consts/LikeFunction.ts index 669b24fd7b..38a013ece2 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/test/main/explicit_function_type.ets b/ets2panda/linter/test/main/explicit_function_type.ets index c42f90e3fb..9896f87a36 100755 --- a/ets2panda/linter/test/main/explicit_function_type.ets +++ b/ets2panda/linter/test/main/explicit_function_type.ets @@ -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')(); \ No newline at end of file diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json b/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json index 3427352803..1bafbdd1de 100755 --- a/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json @@ -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 9512b29aac..23f1af4921 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json @@ -573,6 +573,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.migrate.ets b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets index c5ecffb429..b9ac8ffe17 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets @@ -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')(); \ No newline at end of file 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 b4e8db486e..e49a4f78fd 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json @@ -153,6 +153,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 -- Gitee From 633cee85f7349ee483989afcd4c0ebcfaacb6480 Mon Sep 17 00:00:00 2001 From: Utku Enes GURSEL Date: Wed, 2 Jul 2025 19:04:09 +0300 Subject: [PATCH 02/16] rewrite super-call checking rule Issue: ICJKKN Description: Old implementation just looked at if there is any super with args, new rule checks the types and tries to see if they are matching, also checks if there is multiple constructors. Signed-off-by: Utku Enes GURSEL --- ets2panda/linter/src/lib/FaultAttrs.ts | 2 +- ets2panda/linter/src/lib/TypeScriptLinter.ts | 268 +++++++++++++++--- .../linter/src/lib/autofixes/Autofixer.ts | 35 ++- .../src/lib/utils/consts/ArkuiImportList.ts | 70 ++--- .../linter/src/lib/utils/consts/Types.ts | 37 +++ .../lib/utils/consts/WorkloadRelatedConst.ts | 2 +- .../test/main/explicit_function_type.ets | 6 +- .../explicit_function_type.ets.arkts2.json | 12 +- .../explicit_function_type.ets.autofix.json | 74 +++-- .../test/main/explicit_function_type.ets.json | 42 ++- .../explicit_function_type.ets.migrate.ets | 6 +- .../explicit_function_type.ets.migrate.json | 12 +- ...object_literals_properties.ets.arkts2.json | 16 +- ...bject_literals_properties.ets.autofix.json | 16 +- ...bject_literals_properties.ets.migrate.json | 26 +- .../linter/test/main/subclass_super_call.ets | 48 +++- .../main/subclass_super_call.ets.args.json | 2 +- .../main/subclass_super_call.ets.arkts2.json | 142 +++++++--- 18 files changed, 574 insertions(+), 242 deletions(-) create mode 100644 ets2panda/linter/src/lib/utils/consts/Types.ts mode change 100755 => 100644 ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json mode change 100755 => 100644 ets2panda/linter/test/main/explicit_function_type.ets.json diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index faeb575025..f67ac33cb4 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 aa0b661ab7..71928baa9c 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -160,6 +160,9 @@ 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 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; @@ -8929,7 +8932,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; } @@ -8938,78 +8941,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 { diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 4a3dbb93cd..40677b33cb 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 { @@ -4917,7 +4916,10 @@ 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)}>`; @@ -4925,7 +4927,10 @@ export class Autofixer { 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[]; diff --git a/ets2panda/linter/src/lib/utils/consts/ArkuiImportList.ts b/ets2panda/linter/src/lib/utils/consts/ArkuiImportList.ts index 3beae87577..f8ab0145c5 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/Types.ts b/ets2panda/linter/src/lib/utils/consts/Types.ts new file mode 100644 index 0000000000..86abf3d58c --- /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 c0c5efc0cc..676b1fb1e7 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/explicit_function_type.ets b/ets2panda/linter/test/main/explicit_function_type.ets index 9896f87a36..065dda4586 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) } } @@ -181,4 +181,4 @@ SysApiWrapper.setTimeout = (handler: Function | string, delay?: number): number new Function('return 42')(); -Function('return 42')(); \ No newline at end of file +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 1bafbdd1de..e485c6f536 --- 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, @@ -375,4 +365,4 @@ "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 23f1af4921..b1f90097df 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, @@ -178,8 +168,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2550, - "end": 2551, + "start": 2558, + "end": 2559, "replacementText": "1.0", "line": 118, "column": 26, @@ -199,8 +189,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2553, - "end": 2554, + "start": 2561, + "end": 2562, "replacementText": "2.0", "line": 118, "column": 29, @@ -220,8 +210,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2556, - "end": 2557, + "start": 2564, + "end": 2565, "replacementText": "3.0", "line": 118, "column": 32, @@ -281,8 +271,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2719, - "end": 2720, + "start": 2727, + "end": 2728, "replacementText": "1.0", "line": 128, "column": 31, @@ -322,8 +312,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2768, - "end": 2769, + "start": 2776, + "end": 2777, "replacementText": "1.0", "line": 128, "column": 80, @@ -353,8 +343,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2849, - "end": 2850, + "start": 2857, + "end": 2858, "replacementText": "1.0", "line": 133, "column": 10, @@ -374,8 +364,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 2921, - "end": 2929, + "start": 2929, + "end": 2937, "replacementText": "callback.unsafeCall", "line": 139, "column": 3, @@ -395,8 +385,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2995, - "end": 2996, + "start": 3003, + "end": 3004, "replacementText": "1.0", "line": 142, "column": 41, @@ -446,8 +436,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3458, - "end": 3462, + "start": 3466, + "end": 3470, "replacementText": "curr.unsafeCall", "line": 160, "column": 62, @@ -467,8 +457,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3463, - "end": 3467, + "start": 3471, + "end": 3475, "replacementText": "prev.unsafeCall", "line": 160, "column": 67, @@ -488,8 +478,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3586, - "end": 3588, + "start": 3594, + "end": 3596, "replacementText": "f1.unsafeCall", "line": 166, "column": 1, @@ -509,8 +499,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3656, - "end": 3663, + "start": 3664, + "end": 3671, "replacementText": "ab3.fn3.unsafeCall", "line": 172, "column": 1, @@ -530,8 +520,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3697, - "end": 3704, + "start": 3705, + "end": 3712, "replacementText": "fn29[1].unsafeCall", "line": 175, "column": 1, @@ -561,8 +551,8 @@ "problem": "ExplicitFunctionType", "autofix": [ { - "start": 3796, - "end": 3819, + "start": 3804, + "end": 3827, "replacementText": "(handler as Function)?.unsafeCall", "line": 178, "column": 3, @@ -595,4 +585,4 @@ "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 d138186989..a3424dbdf2 --- 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 b9ac8ffe17..c993a82931 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) } } @@ -181,4 +181,4 @@ SysApiWrapper.setTimeout = (handler: Function | string, delay?: number): number new Function('return 42')(); -Function('return 42')(); \ No newline at end of file +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 e49a4f78fd..3149693834 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json @@ -24,16 +24,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": 118, "column": 16, @@ -175,4 +165,4 @@ "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 b72ff900ba..8ed64f688b 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 ccf6076bdc..bbb319af18 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 cb49576162..675cc2476a 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/subclass_super_call.ets b/ets2panda/linter/test/main/subclass_super_call.ets index d275725c9c..7e80348064 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 948b846fe0..bc4d2071da 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 289a83337b..83dc3263ef 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,108 @@ { - "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" + }, + { + "line": 77, + "column": 9, + "endLine": 77, + "endColumn": 14, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 83, + "column": 9, + "endLine": 83, + "endColumn": 14, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + } + ] } -- Gitee From 77ce7e5e9ebf30e4152f37d43c07531b89e247aa Mon Sep 17 00:00:00 2001 From: sefayilmazunal Date: Mon, 30 Jun 2025 10:07:00 +0300 Subject: [PATCH 03/16] ArrayIndexExprType false report fixed Description: ArrayIndexExprType rule array false report on index access when decimal used is fixed Issue: #ICIXZV Signed-off-by: sefayilmazunal --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 23 +- .../test/main/array_index_expr_type.ets | 2 +- .../array_index_expr_type.ets.arkts2.json | 22 +- .../array_index_expr_type.ets.autofix.json | 44 +- .../array_index_expr_type.ets.migrate.ets | 6 +- .../array_index_expr_type.ets.migrate.json | 434 +++++++++--------- .../sdk_ability_asynchronous_lifecycle.ets | 0 ...ility_asynchronous_lifecycle.ets.args.json | 0 ...ity_asynchronous_lifecycle.ets.arkts2.json | 40 +- ...dk_ability_asynchronous_lifecycle.ets.json | 0 10 files changed, 275 insertions(+), 296 deletions(-) rename ets2panda/linter/test/{ => main}/sdk_ability_asynchronous_lifecycle.ets (100%) rename ets2panda/linter/test/{ => main}/sdk_ability_asynchronous_lifecycle.ets.args.json (100%) rename ets2panda/linter/test/{ => main}/sdk_ability_asynchronous_lifecycle.ets.arkts2.json (89%) rename ets2panda/linter/test/{ => main}/sdk_ability_asynchronous_lifecycle.ets.json (100%) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 71928baa9c..aa7499efce 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -4122,7 +4122,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); @@ -4136,6 +4136,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); diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets b/ets2panda/linter/test/main/array_index_expr_type.ets index a2120f59ea..29fa54df14 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets +++ b/ets2panda/linter/test/main/array_index_expr_type.ets @@ -86,4 +86,4 @@ arr[d] = 1; let test = 1; arr[1 as number]; -arr[test as number]; \ No newline at end of file +arr[test as number]; 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 27fa37360d..947d5f6d0f 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, @@ -1065,4 +1045,4 @@ "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 a65d5f7162..4c1527739c 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, @@ -1813,4 +1771,4 @@ "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 eb9ab9c696..1e64a8c9eb 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 @@ -36,8 +36,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]; @@ -86,4 +86,4 @@ 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]; 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 457bd6501c..d05f94a3f8 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 @@ -1,208 +1,228 @@ { - "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": 7, - "endLine": 22, - "endColumn": 25, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 22, - "column": 20, - "endLine": 22, - "endColumn": 24, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 23, - "column": 7, - "endLine": 23, - "endColumn": 28, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 23, - "column": 20, - "endLine": 23, - "endColumn": 27, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 7, - "endLine": 24, - "endColumn": 30, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 20, - "endLine": 24, - "endColumn": 29, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 25, - "column": 7, - "endLine": 25, - "endColumn": 25, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 25, - "column": 20, - "endLine": 25, - "endColumn": 24, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 26, - "column": 28, - "endLine": 26, - "endColumn": 28, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 29, - "column": 19, - "endLine": 29, - "endColumn": 30, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 64, - "column": 3, - "endLine": 64, - "endColumn": 12, - "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": 68, - "column": 1, - "endLine": 68, - "endColumn": 12, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 69, - "column": 1, - "endLine": 69, - "endColumn": 9, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 70, - "column": 1, - "endLine": 70, - "endColumn": 9, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 71, - "column": 1, - "endLine": 71, - "endColumn": 9, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 72, - "column": 1, - "endLine": 72, - "endColumn": 9, - "problem": "IndexNegative", - "suggest": "", - "rule": "The index expression must be zero or positive value.(arkts-array-index-negative)", - "severity": "ERROR" - }, - { - "line": 72, - "column": 1, - "endLine": 72, - "endColumn": 9, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 81, - "column": 1, - "endLine": 81, - "endColumn": 18, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 81, - "column": 5, - "endLine": 81, - "endColumn": 17, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - } - ] -} \ No newline at end of file + "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": 7, + "endLine": 22, + "endColumn": 25, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 20, + "endLine": 22, + "endColumn": 24, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 7, + "endLine": 23, + "endColumn": 28, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 20, + "endLine": 23, + "endColumn": 27, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 7, + "endLine": 24, + "endColumn": 30, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 20, + "endLine": 24, + "endColumn": 29, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 7, + "endLine": 25, + "endColumn": 25, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 20, + "endLine": 25, + "endColumn": 24, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 28, + "endLine": 26, + "endColumn": 28, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 19, + "endLine": 29, + "endColumn": 30, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 1, + "endLine": 39, + "endColumn": 15, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 1, + "endLine": 40, + "endColumn": 15, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 3, + "endLine": 64, + "endColumn": 12, + "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": 68, + "column": 1, + "endLine": 68, + "endColumn": 12, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 1, + "endLine": 69, + "endColumn": 9, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 1, + "endLine": 70, + "endColumn": 9, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 71, + "column": 1, + "endLine": 71, + "endColumn": 9, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 1, + "endLine": 72, + "endColumn": 9, + "problem": "IndexNegative", + "suggest": "", + "rule": "The index expression must be zero or positive value.(arkts-array-index-negative)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 1, + "endLine": 72, + "endColumn": 9, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 1, + "endLine": 81, + "endColumn": 18, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 5, + "endLine": 81, + "endColumn": 17, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + } + ] +} 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/sdk_ability_asynchronous_lifecycle.ets.arkts2.json b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json similarity index 89% rename from ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.arkts2.json rename to ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json index 6d09991800..69b80b4268 100644 --- a/ets2panda/linter/test/sdk_ability_asynchronous_lifecycle.ets.arkts2.json +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json @@ -24,16 +24,6 @@ "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, @@ -44,6 +34,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 20, + "column": 25, + "endLine": 20, + "endColumn": 27, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, { "line": 24, "column": 3, @@ -94,16 +94,6 @@ "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, @@ -114,6 +104,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 33, + "column": 25, + "endLine": 33, + "endColumn": 27, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "severity": "ERROR" + }, { "line": 37, "column": 3, 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 -- Gitee From e56d7246063cc79a2a3a26ce36a4f2c2dcd30e5c Mon Sep 17 00:00:00 2001 From: ZhongNing Date: Wed, 2 Jul 2025 11:10:58 +0800 Subject: [PATCH 04/16] fix issue for arkts-numeric-semantic Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJ6IQ Test scenarios: new tests added to the linter Signed-off-by: ZhongNing --- .../linter/migration-results-statistics.json | 65 +++ ets2panda/linter/src/lib/TypeScriptLinter.ts | 36 ++ .../array_index_expr_type.ets.autofix.json | 11 - .../array_index_expr_type.ets.migrate.ets | 2 +- .../array_index_expr_type.ets.migrate.json | 442 +++++++++--------- .../enum_not_support_float.ets.arkts2.json | 10 + .../explicit_function_type.ets.autofix.json | 11 - .../explicit_function_type.ets.migrate.ets | 2 +- .../explicit_function_type.ets.migrate.json | 10 + .../main/limit_void_type.ets.autofix.json | 22 - .../test/main/limit_void_type.ets.migrate.ets | 4 +- .../main/limit_void_type.ets.migrate.json | 20 + .../literals_as_prop_names.ets.autofix.json | 77 --- .../literals_as_prop_names.ets.migrate.ets | 14 +- .../literals_as_prop_names.ets.migrate.json | 70 +++ .../main/numeric_semantics.ets.autofix.json | 154 ------ .../main/numeric_semantics.ets.migrate.ets | 28 +- .../main/numeric_semantics.ets.migrate.json | 140 ++++++ .../main/numeric_semantics2.ets.autofix.json | 22 - .../main/numeric_semantics2.ets.migrate.ets | 4 +- .../main/numeric_semantics2.ets.migrate.json | 20 + .../main/runtime_array_bound.ets.migrate.ets | 2 +- .../main/runtime_array_bound.ets.migrate.json | 10 + 23 files changed, 625 insertions(+), 551 deletions(-) create mode 100644 ets2panda/linter/migration-results-statistics.json diff --git a/ets2panda/linter/migration-results-statistics.json b/ets2panda/linter/migration-results-statistics.json new file mode 100644 index 0000000000..62225f9fa5 --- /dev/null +++ b/ets2panda/linter/migration-results-statistics.json @@ -0,0 +1,65 @@ +{ + "problems": { + "totalProblems": 25, + "arts1.1_Problems": 0, + "arts1.2_Problems": 25, + "canBeAutoFixedproblemNumbers": 0, + "needToManualFixproblemNumbers": 25 + }, + "usedTime": { + "scanTime": "1339731.90 s", + "migrationTime": "1.33 s" + }, + "eachRuleProblemsDetail": [ + { + "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", + "problemNumbers": 1, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "problemNumbers": 1, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "problemNumbers": 14, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "problemNumbers": 1, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "Object literal properties can only contain name-value pairs (arkts-obj-literal-props)", + "problemNumbers": 1, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", + "problemNumbers": 1, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "problemNumbers": 2, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "problemNumbers": 1, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "problemNumbers": 1, + "canBeAutoFixedMumbers": 0 + }, + { + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "problemNumbers": 2, + "canBeAutoFixedMumbers": 0 + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index aa7499efce..1908fccb8e 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -10333,6 +10333,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)) { @@ -10352,6 +10356,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); @@ -10362,6 +10367,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; 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 4c1527739c..a50acdd0c1 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 @@ -1278,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" 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 1e64a8c9eb..ae8f46ecc8 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 @@ -62,7 +62,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]; 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 d05f94a3f8..4e000ee28d 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 @@ -1,228 +1,218 @@ { - "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": 7, - "endLine": 22, - "endColumn": 25, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 22, - "column": 20, - "endLine": 22, - "endColumn": 24, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 23, - "column": 7, - "endLine": 23, - "endColumn": 28, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 23, - "column": 20, - "endLine": 23, - "endColumn": 27, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 7, - "endLine": 24, - "endColumn": 30, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 20, - "endLine": 24, - "endColumn": 29, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 25, - "column": 7, - "endLine": 25, - "endColumn": 25, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 25, - "column": 20, - "endLine": 25, - "endColumn": 24, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 26, - "column": 28, - "endLine": 26, - "endColumn": 28, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "severity": "ERROR" - }, - { - "line": 29, - "column": 19, - "endLine": 29, - "endColumn": 30, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 39, - "column": 1, - "endLine": 39, - "endColumn": 15, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 40, - "column": 1, - "endLine": 40, - "endColumn": 15, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 64, - "column": 3, - "endLine": 64, - "endColumn": 12, - "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": 68, - "column": 1, - "endLine": 68, - "endColumn": 12, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 69, - "column": 1, - "endLine": 69, - "endColumn": 9, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 70, - "column": 1, - "endLine": 70, - "endColumn": 9, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 71, - "column": 1, - "endLine": 71, - "endColumn": 9, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 72, - "column": 1, - "endLine": 72, - "endColumn": 9, - "problem": "IndexNegative", - "suggest": "", - "rule": "The index expression must be zero or positive value.(arkts-array-index-negative)", - "severity": "ERROR" - }, - { - "line": 72, - "column": 1, - "endLine": 72, - "endColumn": 9, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 81, - "column": 1, - "endLine": 81, - "endColumn": 18, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, - { - "line": 81, - "column": 5, - "endLine": 81, - "endColumn": 17, - "problem": "ArrayIndexExprType", - "suggest": "", - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "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": 7, + "endLine": 22, + "endColumn": 25, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 20, + "endLine": 22, + "endColumn": 24, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 7, + "endLine": 23, + "endColumn": 28, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 20, + "endLine": 23, + "endColumn": 27, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 7, + "endLine": 24, + "endColumn": 30, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 20, + "endLine": 24, + "endColumn": 29, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 7, + "endLine": 25, + "endColumn": 25, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 20, + "endLine": 25, + "endColumn": 24, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 28, + "endLine": 26, + "endColumn": 28, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 19, + "endLine": 29, + "endColumn": 30, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 3, + "endLine": 64, + "endColumn": 12, + "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": 65, + "column": 8, + "endLine": 65, + "endColumn": 9, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 68, + "column": 1, + "endLine": 68, + "endColumn": 12, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 1, + "endLine": 69, + "endColumn": 9, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 1, + "endLine": 70, + "endColumn": 9, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 71, + "column": 1, + "endLine": 71, + "endColumn": 9, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 1, + "endLine": 72, + "endColumn": 9, + "problem": "IndexNegative", + "suggest": "", + "rule": "The index expression must be zero or positive value.(arkts-array-index-negative)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 1, + "endLine": 72, + "endColumn": 9, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 1, + "endLine": 81, + "endColumn": 18, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 5, + "endLine": 81, + "endColumn": 17, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + } + ] } 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 95b3bdaefb..5ccffdf509 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, 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 b1f90097df..f78396b2f0 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json @@ -341,17 +341,6 @@ "endLine": 133, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 2857, - "end": 2858, - "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" 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 c993a82931..10fa1ca1c8 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets @@ -130,7 +130,7 @@ let tup38:[['arkts'|Function, 1.0|true, false], string[], Function] = [['arkts', //枚举 enum E39 { Function, - BLUE = 1.0, + BLUE = 1, YELLOW } 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 3149693834..d9207e63ed 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json @@ -104,6 +104,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, 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 c8bcf12082..019abd231e 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json @@ -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" 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 62243efb6d..11ff28e13d 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.ets @@ -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; 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 cef5d595cb..b9ce1e5568 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json @@ -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, 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 f3414d739d..e9fe994345 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 @@ -734,17 +734,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 +765,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 +796,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 +836,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 +876,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 +978,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 +1009,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" 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 6fb5cb3e0f..87b32a38ae 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 @@ -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 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 a180c18573..47f600fb5e 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 @@ -94,6 +94,76 @@ "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": 144, "column": 37, diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json index 7c1870a30d..72ddcbaa86 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 80c650b284..43753aa498 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 29adb27a5c..09385a376c 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 0cee44032a..0ad922ea3c 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json @@ -445,17 +445,6 @@ "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" @@ -466,17 +455,6 @@ "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" diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets index 06a1c15859..a687cd7007 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets @@ -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 57a7300d81..56d45c6a7f 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json @@ -94,6 +94,26 @@ "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, 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 62220b36c2..21a7b9b504 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; 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 7862ff0a07..2d7c3772e3 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json @@ -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, -- Gitee From 0011d1099c09e51da82d7b21bd3099336b4c46e0 Mon Sep 17 00:00:00 2001 From: ZhongNing Date: Wed, 2 Jul 2025 17:31:15 +0800 Subject: [PATCH 05/16] fix arkts-method-inherit-rule Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJC5K Test scenarios: fix bug Signed-off-by: ZhongNing --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 168 +++++++++++++++--- .../explicit_function_type.ets.arkts2.json | 10 ++ .../explicit_function_type.ets.autofix.json | 10 ++ .../explicit_function_type.ets.migrate.json | 20 +++ .../linter/test/main/method_inheritance2.ets | 116 ++++++++++++ .../main/method_inheritance2.ets.args.json | 19 ++ .../main/method_inheritance2.ets.arkts2.json | 148 +++++++++++++++ .../test/main/method_inheritance2.ets.json | 17 ++ 8 files changed, 482 insertions(+), 26 deletions(-) create mode 100755 ets2panda/linter/test/main/method_inheritance2.ets create mode 100755 ets2panda/linter/test/main/method_inheritance2.ets.args.json create mode 100755 ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json create mode 100755 ets2panda/linter/test/main/method_inheritance2.ets.json diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 1908fccb8e..f1f16bbb71 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -3304,25 +3304,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) { @@ -3330,17 +3329,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) { @@ -3350,13 +3436,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]; } /** @@ -3470,15 +3560,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)) { @@ -3487,19 +3591,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; diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json b/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json index e485c6f536..ab41a3326a 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json @@ -84,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, 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 f78396b2f0..cce8e07d1c 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json @@ -150,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, 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 d9207e63ed..1d1d698515 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json @@ -24,6 +24,26 @@ "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": 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, diff --git a/ets2panda/linter/test/main/method_inheritance2.ets b/ets2panda/linter/test/main/method_inheritance2.ets new file mode 100755 index 0000000000..2591755adc --- /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 0000000000..d8d3390ad9 --- /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 0000000000..30c37afc53 --- /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 0000000000..ca88f857e9 --- /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 -- Gitee From 6cfdbe0f8e6df688c587864a7870a48c8c8a8079 Mon Sep 17 00:00:00 2001 From: ZhongNing Date: Wed, 2 Jul 2025 17:58:23 +0800 Subject: [PATCH 06/16] Fix for LimitedVoidType Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJ9FA Test scenarios: fix bug Signed-off-by: ZhongNing --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 11 + .../linter/test/main/limit_void_type.ets | 27 +- .../test/main/limit_void_type.ets.arkts2.json | 120 +++++ .../main/limit_void_type.ets.autofix.json | 410 ++++++++++++------ .../test/main/limit_void_type.ets.migrate.ets | 27 +- .../main/limit_void_type.ets.migrate.json | 120 +++++ .../linter/test/main/limit_void_type2.ets | 26 ++ .../test/main/limit_void_type2.ets.json | 17 + 8 files changed, 620 insertions(+), 138 deletions(-) create mode 100644 ets2panda/linter/test/main/limit_void_type2.ets create mode 100644 ets2panda/linter/test/main/limit_void_type2.ets.json diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index f1f16bbb71..2f8f26a6c6 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -5424,6 +5424,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 { @@ -6482,6 +6483,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) || diff --git a/ets2panda/linter/test/main/limit_void_type.ets b/ets2panda/linter/test/main/limit_void_type.ets index 7979014031..3dc13d8696 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 ba6319381d..869dd5a745 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, @@ -1723,6 +1733,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 019abd231e..5354ed4de2 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, @@ -669,8 +679,8 @@ "autofix": [ { "replacementText": "GeneratedDestructArray_1", - "start": 3050, - "end": 3056, + "start": 3148, + "end": 3154, "line": 102, "column": 7, "endLine": 102, @@ -678,8 +688,8 @@ }, { "replacementText": "\nconst func = GeneratedDestructArray_1[0];\n", - "start": 3077, - "end": 3077, + "start": 3175, + "end": 3175, "line": 102, "column": 7, "endLine": 102, @@ -718,8 +728,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 +889,8 @@ "problem": "FunctionExpression", "autofix": [ { - "start": 3757, - "end": 3783, + "start": 3855, + "end": 3881, "replacementText": "(target: any) => { }", "line": 126, "column": 10, @@ -1100,8 +1110,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 4599, - "end": 4619, + "start": 4697, + "end": 4717, "replacementText": "undefined | Promise", "line": 162, "column": 16, @@ -1109,8 +1119,8 @@ "endColumn": 36 }, { - "start": 4622, - "end": 4622, + "start": 4720, + "end": 4720, "replacementText": "\nreturn undefined;\n", "line": 162, "column": 16, @@ -1140,8 +1150,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 4686, - "end": 4699, + "start": 4784, + "end": 4797, "replacementText": "undefined | number", "line": 165, "column": 8, @@ -1149,8 +1159,8 @@ "endColumn": 21 }, { - "start": 4702, - "end": 4702, + "start": 4800, + "end": 4800, "replacementText": "\nreturn undefined;\n", "line": 165, "column": 8, @@ -1280,8 +1290,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5432, - "end": 5445, + "start": 5530, + "end": 5543, "replacementText": "string | undefined", "line": 211, "column": 29, @@ -1289,8 +1299,8 @@ "endColumn": 42 }, { - "start": 5489, - "end": 5489, + "start": 5587, + "end": 5587, "replacementText": "\nreturn undefined;\n", "line": 211, "column": 29, @@ -1320,8 +1330,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5459, - "end": 5460, + "start": 5557, + "end": 5558, "replacementText": "0.0", "line": 212, "column": 12, @@ -1341,8 +1351,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5521, - "end": 5534, + "start": 5619, + "end": 5632, "replacementText": "string | undefined", "line": 217, "column": 30, @@ -1350,8 +1360,8 @@ "endColumn": 43 }, { - "start": 5556, - "end": 5563, + "start": 5654, + "end": 5661, "replacementText": "return undefined;", "line": 217, "column": 30, @@ -1381,8 +1391,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5547, - "end": 5548, + "start": 5645, + "end": 5646, "replacementText": "0.0", "line": 218, "column": 11, @@ -1482,8 +1492,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5691, - "end": 5692, + "start": 5789, + "end": 5790, "replacementText": "1.0", "line": 226, "column": 25, @@ -1503,8 +1513,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5725, - "end": 5738, + "start": 5823, + "end": 5836, "replacementText": "string | undefined", "line": 228, "column": 31, @@ -1512,8 +1522,8 @@ "endColumn": 44 }, { - "start": 5764, - "end": 5771, + "start": 5862, + "end": 5869, "replacementText": "return undefined;", "line": 228, "column": 31, @@ -1521,8 +1531,8 @@ "endColumn": 44 }, { - "start": 5842, - "end": 5849, + "start": 5940, + "end": 5947, "replacementText": "return undefined;", "line": 228, "column": 31, @@ -1530,8 +1540,8 @@ "endColumn": 44 }, { - "start": 5854, - "end": 5854, + "start": 5952, + "end": 5952, "replacementText": "\nreturn undefined;\n", "line": 228, "column": 31, @@ -1561,8 +1571,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5754, - "end": 5756, + "start": 5852, + "end": 5854, "replacementText": "12.0", "line": 229, "column": 14, @@ -1582,8 +1592,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 5792, - "end": 5794, + "start": 5890, + "end": 5892, "replacementText": "18.0", "line": 231, "column": 21, @@ -1603,8 +1613,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 5894, - "end": 5907, + "start": 5992, + "end": 6005, "replacementText": "string | undefined", "line": 238, "column": 38, @@ -1612,8 +1622,8 @@ "endColumn": 51 }, { - "start": 5989, - "end": 5996, + "start": 6087, + "end": 6094, "replacementText": "return undefined;", "line": 238, "column": 38, @@ -1643,8 +1653,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6021, - "end": 6034, + "start": 6119, + "end": 6132, "replacementText": "string | undefined", "line": 246, "column": 22, @@ -1652,8 +1662,8 @@ "endColumn": 35 }, { - "start": 6062, - "end": 6062, + "start": 6160, + "end": 6160, "replacementText": "\nreturn undefined;\n", "line": 246, "column": 22, @@ -1683,8 +1693,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6099, - "end": 6112, + "start": 6197, + "end": 6210, "replacementText": "string | undefined", "line": 250, "column": 35, @@ -1692,8 +1702,8 @@ "endColumn": 48 }, { - "start": 6192, - "end": 6192, + "start": 6290, + "end": 6290, "replacementText": "\nreturn undefined;\n", "line": 250, "column": 35, @@ -1731,6 +1741,17 @@ "endLine": 252, "endColumn": 11, "problem": "NumericSemantics", + "autofix": [ + { + "start": 6240, + "end": 6241, + "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" @@ -1741,6 +1762,17 @@ "endLine": 253, "endColumn": 11, "problem": "NumericSemantics", + "autofix": [ + { + "start": 6265, + "end": 6266, + "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" @@ -1753,8 +1785,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6216, - "end": 6229, + "start": 6314, + "end": 6327, "replacementText": "string | undefined", "line": 257, "column": 22, @@ -1762,8 +1794,8 @@ "endColumn": 35 }, { - "start": 6304, - "end": 6304, + "start": 6402, + "end": 6402, "replacementText": "\nreturn undefined;\n", "line": 257, "column": 22, @@ -1813,8 +1845,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6370, - "end": 6384, + "start": 6468, + "end": 6482, "replacementText": "boolean | undefined", "line": 269, "column": 20, @@ -1822,8 +1854,8 @@ "endColumn": 34 }, { - "start": 6431, - "end": 6438, + "start": 6529, + "end": 6536, "replacementText": "return undefined;", "line": 269, "column": 20, @@ -1831,8 +1863,8 @@ "endColumn": 34 }, { - "start": 6468, - "end": 6475, + "start": 6566, + "end": 6573, "replacementText": "return undefined;", "line": 269, "column": 20, @@ -1862,8 +1894,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6399, - "end": 6400, + "start": 6497, + "end": 6498, "replacementText": "0.0", "line": 270, "column": 13, @@ -1883,8 +1915,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6501, - "end": 6515, + "start": 6599, + "end": 6613, "replacementText": "undefined | boolean", "line": 278, "column": 21, @@ -1892,8 +1924,8 @@ "endColumn": 35 }, { - "start": 6604, - "end": 6611, + "start": 6702, + "end": 6709, "replacementText": "return undefined;", "line": 278, "column": 21, @@ -1923,8 +1955,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6530, - "end": 6531, + "start": 6628, + "end": 6629, "replacementText": "0.0", "line": 279, "column": 13, @@ -1944,8 +1976,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6637, - "end": 6651, + "start": 6735, + "end": 6749, "replacementText": "undefined | boolean", "line": 287, "column": 21, @@ -1953,8 +1985,8 @@ "endColumn": 35 }, { - "start": 6698, - "end": 6705, + "start": 6796, + "end": 6803, "replacementText": "return undefined;", "line": 287, "column": 21, @@ -1962,8 +1994,8 @@ "endColumn": 35 }, { - "start": 6714, - "end": 6714, + "start": 6812, + "end": 6812, "replacementText": "\nreturn undefined;\n", "line": 287, "column": 21, @@ -1993,8 +2025,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6666, - "end": 6667, + "start": 6764, + "end": 6765, "replacementText": "0.0", "line": 288, "column": 13, @@ -2014,8 +2046,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6737, - "end": 6751, + "start": 6835, + "end": 6849, "replacementText": "undefined | boolean", "line": 294, "column": 21, @@ -2023,8 +2055,8 @@ "endColumn": 35 }, { - "start": 6798, - "end": 6805, + "start": 6896, + "end": 6903, "replacementText": "return undefined;", "line": 294, "column": 21, @@ -2054,8 +2086,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6766, - "end": 6767, + "start": 6864, + "end": 6865, "replacementText": "0.0", "line": 295, "column": 13, @@ -2075,8 +2107,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6846, - "end": 6860, + "start": 6944, + "end": 6958, "replacementText": "undefined | boolean", "line": 302, "column": 12, @@ -2084,8 +2116,8 @@ "endColumn": 26 }, { - "start": 6884, - "end": 6884, + "start": 6982, + "end": 6982, "replacementText": "\nreturn undefined;\n", "line": 302, "column": 12, @@ -2115,8 +2147,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 6915, - "end": 6929, + "start": 7013, + "end": 7027, "replacementText": "boolean | undefined", "line": 307, "column": 27, @@ -2124,8 +2156,8 @@ "endColumn": 41 }, { - "start": 6970, - "end": 6977, + "start": 7068, + "end": 7075, "replacementText": "return undefined;", "line": 307, "column": 27, @@ -2133,8 +2165,8 @@ "endColumn": 41 }, { - "start": 7001, - "end": 7008, + "start": 7099, + "end": 7106, "replacementText": "return undefined;", "line": 307, "column": 27, @@ -2164,8 +2196,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 6942, - "end": 6943, + "start": 7040, + "end": 7041, "replacementText": "0.0", "line": 308, "column": 11, @@ -2185,8 +2217,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7039, - "end": 7053, + "start": 7137, + "end": 7151, "replacementText": "undefined | boolean", "line": 316, "column": 28, @@ -2194,8 +2226,8 @@ "endColumn": 42 }, { - "start": 7130, - "end": 7137, + "start": 7228, + "end": 7235, "replacementText": "return undefined;", "line": 316, "column": 28, @@ -2225,8 +2257,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7066, - "end": 7067, + "start": 7164, + "end": 7165, "replacementText": "0.0", "line": 317, "column": 11, @@ -2246,8 +2278,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7168, - "end": 7182, + "start": 7266, + "end": 7280, "replacementText": "undefined | boolean", "line": 325, "column": 28, @@ -2255,8 +2287,8 @@ "endColumn": 42 }, { - "start": 7223, - "end": 7230, + "start": 7321, + "end": 7328, "replacementText": "return undefined;", "line": 325, "column": 28, @@ -2264,8 +2296,8 @@ "endColumn": 42 }, { - "start": 7235, - "end": 7235, + "start": 7333, + "end": 7333, "replacementText": "\nreturn undefined;\n", "line": 325, "column": 28, @@ -2295,8 +2327,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7195, - "end": 7196, + "start": 7293, + "end": 7294, "replacementText": "0.0", "line": 326, "column": 11, @@ -2316,8 +2348,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7265, - "end": 7279, + "start": 7363, + "end": 7377, "replacementText": "undefined | boolean", "line": 332, "column": 28, @@ -2325,8 +2357,8 @@ "endColumn": 42 }, { - "start": 7320, - "end": 7327, + "start": 7418, + "end": 7425, "replacementText": "return undefined;", "line": 332, "column": 28, @@ -2356,8 +2388,8 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 7292, - "end": 7293, + "start": 7390, + "end": 7391, "replacementText": "0.0", "line": 333, "column": 11, @@ -2377,8 +2409,8 @@ "problem": "LimitedVoidType", "autofix": [ { - "start": 7378, - "end": 7392, + "start": 7476, + "end": 7490, "replacementText": "undefined | boolean", "line": 340, "column": 28, @@ -2386,8 +2418,8 @@ "endColumn": 42 }, { - "start": 7412, - "end": 7412, + "start": 7510, + "end": 7510, "replacementText": "\nreturn undefined;\n", "line": 340, "column": 28, @@ -2408,6 +2440,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 11ff28e13d..b9a240dfe5 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(); @@ -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 b9ce1e5568..2f527ab03a 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, @@ -1123,6 +1133,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 0000000000..dc2727c716 --- /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 0000000000..ca88f857e9 --- /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 -- Gitee From 85e1df7028e7408b9d7cdf4aea73fbf15167f4e0 Mon Sep 17 00:00:00 2001 From: zhongning Date: Thu, 3 Jul 2025 18:01:44 +0800 Subject: [PATCH 07/16] fix bug for arkts-array-index-expr-type Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJLW5 Test scenarios: fix bug Signed-off-by: zhongning --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 36 +--- .../test/main/array_index_expr_type.ets | 14 ++ .../array_index_expr_type.ets.arkts2.json | 100 ++++++++++ .../array_index_expr_type.ets.autofix.json | 188 ++++++++++++++++++ .../test/main/array_index_expr_type.ets.json | 10 + .../array_index_expr_type.ets.migrate.ets | 21 +- .../array_index_expr_type.ets.migrate.json | 78 ++++---- .../main/runtime_array_bound.ets.migrate.ets | 2 +- .../main/runtime_array_bound.ets.migrate.json | 22 +- 9 files changed, 389 insertions(+), 82 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 2f8f26a6c6..7056bbf51c 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -1537,7 +1537,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 { @@ -2080,7 +2080,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleObjectLiteralAssignmentToClass(tsBinaryExpr); this.handleAssignmentNotsLikeSmartType(tsBinaryExpr); } - + private handleNumericPublicStatic(node: ts.PropertyDeclaration): void { if (!this.options.arkts2) { return; @@ -2094,8 +2094,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); } @@ -2109,10 +2108,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 { @@ -4291,15 +4287,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' { @@ -4365,15 +4358,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); @@ -10555,7 +10539,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } if (this.isObjectPropertyAccess(accessExpr)) { - return true; + return true; } return this.isInstanceOfCheck(accessExpr.parent, accessExpr); @@ -11247,10 +11231,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; } diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets b/ets2panda/linter/test/main/array_index_expr_type.ets index 29fa54df14..3d326b6f36 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets +++ b/ets2panda/linter/test/main/array_index_expr_type.ets @@ -87,3 +87,17 @@ arr[d] = 1; let test = 1; arr[1 as number]; 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 947d5f6d0f..3154514507 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 @@ -1043,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" } ] } 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 a50acdd0c1..8aff28f188 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 @@ -1758,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" } ] } 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 7c6994fca3..2302200e1d 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 ae8f46ecc8..f3e03f2fec 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] @@ -65,7 +70,7 @@ enum TE{ BB = 0 } arr1[TE.AA as int]; -arr1[TE.BB]; +arr1[TE.BB as int]; arr1[+0]; arr1[-0]; arr1[+1]; @@ -87,3 +92,17 @@ arr[d] = 1.0; let test: number = 1.0; arr[1 as int]; 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 4e000ee28d..c64d8f557e 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,9 @@ "severity": "ERROR" }, { - "line": 64, + "line": 69, "column": 3, - "endLine": 64, + "endLine": 69, "endColumn": 12, "problem": "EnumMemberNonConstInit", "suggest": "", @@ -155,9 +155,9 @@ "severity": "ERROR" }, { - "line": 70, + "line": 75, "column": 1, - "endLine": 70, + "endLine": 75, "endColumn": 9, "problem": "RuntimeArrayCheck", "suggest": "", @@ -165,9 +165,9 @@ "severity": "ERROR" }, { - "line": 71, + "line": 76, "column": 1, - "endLine": 71, + "endLine": 76, "endColumn": 9, "problem": "RuntimeArrayCheck", "suggest": "", @@ -175,9 +175,9 @@ "severity": "ERROR" }, { - "line": 72, + "line": 77, "column": 1, - "endLine": 72, + "endLine": 77, "endColumn": 9, "problem": "IndexNegative", "suggest": "", @@ -185,9 +185,9 @@ "severity": "ERROR" }, { - "line": 72, + "line": 77, "column": 1, - "endLine": 72, + "endLine": 77, "endColumn": 9, "problem": "RuntimeArrayCheck", "suggest": "", @@ -195,9 +195,9 @@ "severity": "ERROR" }, { - "line": 81, + "line": 86, "column": 1, - "endLine": 81, + "endLine": 86, "endColumn": 18, "problem": "RuntimeArrayCheck", "suggest": "", @@ -205,14 +205,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" } ] } 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 21a7b9b504..ff21120fa3 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets @@ -163,7 +163,7 @@ arr1[+24] = 23.0; enum TE{ AA = 12 } -arr1[TE.AA] = 12.0; +arr1[TE.AA as int] = 12.0; let a: string[] = []; let b: Array = new Array(a.length); 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 2d7c3772e3..b233b0e1ce 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json @@ -164,26 +164,6 @@ "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, - "endLine": 166, - "endColumn": 12, - "problem": "RuntimeArrayCheck", - "suggest": "", - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "severity": "ERROR" - }, { "line": 233, "column": 1, @@ -205,4 +185,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file -- Gitee From 253b989c40f9a27ddb3d5777bba7053d7d64f6fc Mon Sep 17 00:00:00 2001 From: beratagaca_9a91 Date: Fri, 4 Jul 2025 16:40:06 +0300 Subject: [PATCH 08/16] fix arkts-common-union-member-access Description: test cases updated, IteratorResult check added Issue: #ICJJJ6 Signed-off-by: beratagaca_9a91 --- .../linter/migration-results-statistics.json | 65 ---- ets2panda/linter/src/lib/TypeScriptLinter.ts | 5 +- .../lib/utils/consts/ArktsWhiteApiPaths.ts | 1 + .../array_index_expr_type.ets.migrate.ets | 2 +- .../array_index_expr_type.ets.migrate.json | 34 ++- .../test/main/common_union_member_access.ets | 23 ++ .../common_union_member_access.ets.args.json | 19 ++ ...common_union_member_access.ets.arkts2.json | 38 +++ .../main/common_union_member_access.ets.json | 17 ++ .../explicit_function_type.ets.migrate.json | 12 +- .../test/main/limit_void_type.ets.arkts2.json | 10 - .../main/limit_void_type.ets.autofix.json | 32 -- .../main/limit_void_type.ets.migrate.json | 10 - .../main/oh_modules/@ohos.util.HashMap.d.ets | 23 ++ .../property_access_by_index.ets.arkts2.json | 40 --- .../property_access_by_index.ets.autofix.json | 40 --- .../property_access_by_index.ets.migrate.json | 40 --- .../main/runtime_array_bound.ets.migrate.ets | 2 +- .../main/runtime_array_bound.ets.migrate.json | 48 ++- ...ity_asynchronous_lifecycle.ets.arkts2.json | 284 +++++++++--------- 20 files changed, 326 insertions(+), 419 deletions(-) delete mode 100644 ets2panda/linter/migration-results-statistics.json create mode 100644 ets2panda/linter/test/main/common_union_member_access.ets create mode 100644 ets2panda/linter/test/main/common_union_member_access.ets.args.json create mode 100644 ets2panda/linter/test/main/common_union_member_access.ets.arkts2.json create mode 100644 ets2panda/linter/test/main/common_union_member_access.ets.json create mode 100644 ets2panda/linter/test/main/oh_modules/@ohos.util.HashMap.d.ets diff --git a/ets2panda/linter/migration-results-statistics.json b/ets2panda/linter/migration-results-statistics.json deleted file mode 100644 index 62225f9fa5..0000000000 --- a/ets2panda/linter/migration-results-statistics.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "problems": { - "totalProblems": 25, - "arts1.1_Problems": 0, - "arts1.2_Problems": 25, - "canBeAutoFixedproblemNumbers": 0, - "needToManualFixproblemNumbers": 25 - }, - "usedTime": { - "scanTime": "1339731.90 s", - "migrationTime": "1.33 s" - }, - "eachRuleProblemsDetail": [ - { - "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", - "problemNumbers": 1, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", - "problemNumbers": 1, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", - "problemNumbers": 14, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", - "problemNumbers": 1, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "Object literal properties can only contain name-value pairs (arkts-obj-literal-props)", - "problemNumbers": 1, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", - "problemNumbers": 1, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "problemNumbers": 2, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "Array bound not checked. (arkts-runtime-array-check)", - "problemNumbers": 1, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", - "problemNumbers": 1, - "canBeAutoFixedMumbers": 0 - }, - { - "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", - "problemNumbers": 2, - "canBeAutoFixedMumbers": 0 - } - ] -} \ No newline at end of file diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 7056bbf51c..9a7359cf46 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -160,6 +160,7 @@ 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'; @@ -1440,7 +1441,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; diff --git a/ets2panda/linter/src/lib/utils/consts/ArktsWhiteApiPaths.ts b/ets2panda/linter/src/lib/utils/consts/ArktsWhiteApiPaths.ts index bd6d904c93..113c4bdd79 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/test/main/array_index_expr_type.ets.migrate.ets b/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets index f3e03f2fec..70fb78c380 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 @@ -70,7 +70,7 @@ enum TE{ BB = 0 } arr1[TE.AA as int]; -arr1[TE.BB as int]; +arr1[TE.BB]; arr1[+0]; arr1[-0]; arr1[+1]; 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 c64d8f557e..7d6f66ccb4 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 @@ -114,6 +114,26 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "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, @@ -125,9 +145,9 @@ "severity": "ERROR" }, { - "line": 65, + "line": 70, "column": 8, - "endLine": 65, + "endLine": 70, "endColumn": 9, "problem": "NumericSemantics", "suggest": "", @@ -135,9 +155,9 @@ "severity": "ERROR" }, { - "line": 68, + "line": 73, "column": 1, - "endLine": 68, + "endLine": 73, "endColumn": 12, "problem": "RuntimeArrayCheck", "suggest": "", @@ -145,9 +165,9 @@ "severity": "ERROR" }, { - "line": 69, + "line": 74, "column": 1, - "endLine": 69, + "endLine": 74, "endColumn": 9, "problem": "RuntimeArrayCheck", "suggest": "", @@ -225,4 +245,4 @@ "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 0000000000..716957b950 --- /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 0000000000..9b16bb93a4 --- /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 0000000000..acb6ab3210 --- /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 0000000000..ca88f857e9 --- /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/explicit_function_type.ets.migrate.json b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json index 1d1d698515..9c5d050cc7 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.json @@ -24,16 +24,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": 96, "column": 17, @@ -195,4 +185,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file 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 869dd5a745..d5851681b3 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json @@ -544,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, 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 5354ed4de2..6f5db85520 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json @@ -610,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, @@ -1741,17 +1731,6 @@ "endLine": 252, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 6240, - "end": 6241, - "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" @@ -1762,17 +1741,6 @@ "endLine": 253, "endColumn": 11, "problem": "NumericSemantics", - "autofix": [ - { - "start": 6265, - "end": 6266, - "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" 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 2f527ab03a..0ab5549e55 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json @@ -484,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, 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 0000000000..7a82cdb9a8 --- /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 87f6a12444..2247b1cc2e 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 60ab233b30..3e8481358e 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 e826cfc417..e2746dde00 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.migrate.ets b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets index ff21120fa3..21a7b9b504 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets @@ -163,7 +163,7 @@ arr1[+24] = 23.0; enum TE{ AA = 12 } -arr1[TE.AA as int] = 12.0; +arr1[TE.AA] = 12.0; let a: string[] = []; let b: Array = new Array(a.length); 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 b233b0e1ce..eeba3042ae 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,26 @@ "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, + "endLine": 166, + "endColumn": 12, + "problem": "RuntimeArrayCheck", + "suggest": "", + "rule": "Array bound not checked. (arkts-runtime-array-check)", + "severity": "ERROR" + }, { "line": 233, "column": 1, 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 index 69b80b4268..0c4c24645e 100644 --- a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json @@ -1,148 +1,138 @@ { - "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": 20, - "column": 25, - "endLine": 20, - "endColumn": 27, - "problem": "NoTsLikeSmartType", - "suggest": "", - "rule": "Smart type differences (arkts-no-ts-like-smart-type)", - "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": 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": 33, - "column": 25, - "endLine": 33, - "endColumn": 27, - "problem": "NoTsLikeSmartType", - "suggest": "", - "rule": "Smart type differences (arkts-no-ts-like-smart-type)", - "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" - } - ] -} + "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": 20, + "column": 25, + "endLine": 20, + "endColumn": 27, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "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": 33, + "column": 25, + "endLine": 33, + "endColumn": 27, + "problem": "NoTsLikeSmartType", + "suggest": "", + "rule": "Smart type differences (arkts-no-ts-like-smart-type)", + "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 -- Gitee From 9b1e9b8277add7f043b7b355612c40e3f8c7aa1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E6=9F=A0?= Date: Wed, 2 Jul 2025 13:57:07 +0800 Subject: [PATCH 09/16] fix issue for arkts-no-number-values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJ9F5 Test scenarios: arkts-no-number-values Signed-off-by: 钟柠 --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 11 +++++ .../linter/src/lib/autofixes/Autofixer.ts | 8 ++-- .../test/main/enum_not_support_float.ets | 6 +++ .../enum_not_support_float.ets.arkts2.json | 40 +++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 9a7359cf46..4fc39e1d0d 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -4425,6 +4425,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); diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 40677b33cb..bca8d8304e 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -4908,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 @@ -4922,7 +4922,7 @@ export class Autofixer { ): 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 }]; } @@ -4941,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(', ')}>`; @@ -4972,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/test/main/enum_not_support_float.ets b/ets2panda/linter/test/main/enum_not_support_float.ets index 593f6c64b9..69c8157c75 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 5ccffdf509..a823832fa2 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 @@ -173,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 -- Gitee From 414b1a151553632e25a83ef1aac79cd7d8e8afa3 Mon Sep 17 00:00:00 2001 From: xudan16 Date: Thu, 3 Jul 2025 11:43:03 +0800 Subject: [PATCH 10/16] homecheck update arkts-as-check with numeric Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJO5V Signed-off-by: xudan16 --- .../src/checker/migration/NoTSLikeAsCheck.ts | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/ets2panda/linter/homecheck/src/checker/migration/NoTSLikeAsCheck.ts b/ets2panda/linter/homecheck/src/checker/migration/NoTSLikeAsCheck.ts index 3c7fb7450a..bd36723fa8 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) { -- Gitee From 7b441a1a108ba08203231f4fc462eb6f7df6f11a Mon Sep 17 00:00:00 2001 From: cihatfurkaneken Date: Wed, 2 Jul 2025 14:48:56 +0300 Subject: [PATCH 11/16] extend arkts-no-ts-like-smart-type rule check Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJJNU Signed-off-by: cihatfurkaneken --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 39 +++++-- .../test/main/no_ts_like_smart_type.ets | 32 ++++- .../no_ts_like_smart_type.ets.arkts2.json | 110 ++++++++++++++++++ .../test/main/no_ts_like_smart_type.ets.json | 43 ++++++- 4 files changed, 214 insertions(+), 10 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 4fc39e1d0d..d0bd933bdb 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -1257,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; } @@ -1272,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); } @@ -1295,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); @@ -10242,6 +10247,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; 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 7a82e0fd5e..b065a8c6fa 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,34 @@ 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 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 679e8a5d6f..1af1e06976 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 @@ -243,6 +243,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 ca88f857e9..fd7351eff4 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 -- Gitee From a1270f055e3692c74e4a66973f9c1885f2139ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E6=9F=A0?= Date: Thu, 3 Jul 2025 16:26:03 +0800 Subject: [PATCH 12/16] fix issue for arkts-runtime-array-check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJQCA Test scenarios: arkts-runtime-array-check Signed-off-by: 钟柠 --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 100 +++++++++++++++++- .../linter/test/main/runtime_array_bound.ets | 16 ++- .../main/runtime_array_bound.ets.arkts2.json | 70 ++++++++++++ .../main/runtime_array_bound.ets.migrate.ets | 16 ++- .../main/runtime_array_bound.ets.migrate.json | 20 ++++ 5 files changed, 219 insertions(+), 3 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index d0bd933bdb..febe88e81a 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -10564,7 +10564,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if ( this.isInMaxLengthControlledLoop(accessExpr) || TypeScriptLinter.hasDefaultValueProtection(accessExpr) || - this.isInLengthCheckedBlock(accessExpr) + this.isInLengthCheckedBlock(accessExpr) || + this.isInStandardLengthControlledLoop(accessExpr) ) { return true; } @@ -11461,6 +11462,103 @@ 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/test/main/runtime_array_bound.ets b/ets2panda/linter/test/main/runtime_array_bound.ets index 94234312eb..934e9df563 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 801d14b260..1c6c7709e3 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json @@ -2433,6 +2433,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 21a7b9b504..31f0749e9f 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.ets +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.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: 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 eeba3042ae..db095f65e8 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json @@ -203,6 +203,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 -- Gitee From 13d386a8356980c10ab9bb96d92c69fe62b40ea4 Mon Sep 17 00:00:00 2001 From: liqing-yang Date: Wed, 25 Jun 2025 10:30:52 +0800 Subject: [PATCH 13/16] object built-in method bugfix Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICHM7N Signed-off-by: liqing-yang --- .../migration/InteropBackwardDFACheck.ts | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/ets2panda/linter/homecheck/src/checker/migration/InteropBackwardDFACheck.ts b/ets2panda/linter/homecheck/src/checker/migration/InteropBackwardDFACheck.ts index 7f231f51fa..71d73b3b28 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; } -- Gitee From 648e624f3b84c8618dd21f81c85293f78b9738dd Mon Sep 17 00:00:00 2001 From: beratagaca_9a91 Date: Fri, 4 Jul 2025 16:40:06 +0300 Subject: [PATCH 14/16] fix arkts-common-union-member-access Description: test cases updated, IteratorResult check added Issue: #ICJJJ6 Signed-off-by: beratagaca_9a91 --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index febe88e81a..cf71d27add 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -165,6 +165,16 @@ import type { BaseClassConstructorInfo, ConstructorParameter, ExtendedIdentifier import { ExtendedIdentifierType } from './utils/consts/Types'; import { STRING_ERROR_LITERAL } from './utils/consts/Literals'; +interface InterfaceSymbolTypeResult { + propNames: string[]; + typeNames: string[]; + allProps: Map; +} +interface InterfaceSymbolTypePropertyNames { + propertyNames: string[]; + typeNames: string[]; +} + export class TypeScriptLinter extends BaseTypeScriptLinter { supportedStdCallApiChecker: SupportedStdCallApiChecker; -- Gitee From 1389bc9dce9e2f9384f1070e7b3610d96075d703 Mon Sep 17 00:00:00 2001 From: HuSenlin Date: Sat, 5 Jul 2025 12:01:50 +0800 Subject: [PATCH 15/16] fix the misreport of smart type for ZFB case Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICK6B6 Signed-off-by: HuSenlin --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 36 ++++++++++++------- .../test/main/no_ts_like_smart_type.ets | 13 +++++++ .../no_ts_like_smart_type.ets.arkts2.json | 10 ++++++ 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index cf71d27add..5aa5d5dc44 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -639,7 +639,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)) ); } @@ -4095,7 +4095,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) @@ -6450,7 +6450,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; } @@ -6664,10 +6664,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 ); }; @@ -6939,9 +6939,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); } @@ -10185,11 +10185,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); } @@ -11003,9 +11015,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; + }) ); }; 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 b065a8c6fa..3bcd3fae8c 100755 --- a/ets2panda/linter/test/main/no_ts_like_smart_type.ets +++ b/ets2panda/linter/test/main/no_ts_like_smart_type.ets @@ -149,3 +149,16 @@ 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 1af1e06976..7ee5337c99 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, -- Gitee From 77a2658e740d5d7ee6bc820443e249c8445c8491 Mon Sep 17 00:00:00 2001 From: muratcimen_9be2 Date: Mon, 7 Jul 2025 14:03:45 +0300 Subject: [PATCH 16/16] fix the arkts-identifier-as-prop-names Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJGOK Signed-off-by: muratcimen_9be2 --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 11 - ets2panda/linter/src/lib/utils/TsUtils.ts | 7 + .../literals_as_prop_names.ets.autofix.json | 138 - .../literals_as_prop_names.ets.migrate.ets | 12 +- .../literals_as_prop_names.ets.migrate.json | 70 +- .../main/numeric_semantics2.ets.autofix.json | 2559 ++++++++--------- .../main/numeric_semantics2.ets.migrate.ets | 6 +- .../main/numeric_semantics2.ets.migrate.json | 524 ++-- .../main/runtime_array_bound.ets.arkts2.json | 10 + .../main/runtime_array_bound.ets.migrate.json | 10 + ...ity_asynchronous_lifecycle.ets.arkts2.json | 20 - .../main/subclass_super_call.ets.arkts2.json | 22 +- 12 files changed, 1628 insertions(+), 1761 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 5aa5d5dc44..dcb878796d 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -165,16 +165,6 @@ import type { BaseClassConstructorInfo, ConstructorParameter, ExtendedIdentifier import { ExtendedIdentifierType } from './utils/consts/Types'; import { STRING_ERROR_LITERAL } from './utils/consts/Literals'; -interface InterfaceSymbolTypeResult { - propNames: string[]; - typeNames: string[]; - allProps: Map; -} -interface InterfaceSymbolTypePropertyNames { - propertyNames: string[]; - typeNames: string[]; -} - export class TypeScriptLinter extends BaseTypeScriptLinter { supportedStdCallApiChecker: SupportedStdCallApiChecker; @@ -11580,7 +11570,6 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { }); return hasOutOfBound; } - private handleCallExpressionForRepeat(node: ts.CallExpression): void { if (!this.options.arkts2) { return; diff --git a/ets2panda/linter/src/lib/utils/TsUtils.ts b/ets2panda/linter/src/lib/utils/TsUtils.ts index 479705c83f..7625adfd50 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/test/main/literals_as_prop_names.ets.autofix.json b/ets2panda/linter/test/main/literals_as_prop_names.ets.autofix.json index e9fe994345..b16fee9cc9 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" @@ -1092,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 87b32a38ae..735fe00359 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 }; @@ -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 47f600fb5e..61d1781a5e 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, @@ -164,6 +214,16 @@ "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, @@ -264,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/numeric_semantics2.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json index 0ad922ea3c..9cee311648 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json @@ -1,1307 +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", - "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 + "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 a687cd7007..81211a821a 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}; diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json index 56d45c6a7f..2103eb7cf5 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json @@ -1,248 +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": 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" - } - ] -} + "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/runtime_array_bound.ets.arkts2.json b/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json index 1c6c7709e3..ac6388b655 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, 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 db095f65e8..3d9a0f6ccc 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json @@ -184,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, 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 index 0c4c24645e..dd37cd82be 100644 --- a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json @@ -34,16 +34,6 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, - { - "line": 20, - "column": 25, - "endLine": 20, - "endColumn": 27, - "problem": "NoTsLikeSmartType", - "suggest": "", - "rule": "Smart type differences (arkts-no-ts-like-smart-type)", - "severity": "ERROR" - }, { "line": 24, "column": 3, @@ -94,16 +84,6 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, - { - "line": 33, - "column": 25, - "endLine": 33, - "endColumn": 27, - "problem": "NoTsLikeSmartType", - "suggest": "", - "rule": "Smart type differences (arkts-no-ts-like-smart-type)", - "severity": "ERROR" - }, { "line": 37, "column": 3, 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 83dc3263ef..cb39d72e3f 100644 --- a/ets2panda/linter/test/main/subclass_super_call.ets.arkts2.json +++ b/ets2panda/linter/test/main/subclass_super_call.ets.arkts2.json @@ -83,26 +83,6 @@ "suggest": "", "rule": "The subclass constructor must call the parent class's parametered constructor (arkts-subclass-must-call-super-constructor-with-args)", "severity": "ERROR" - }, - { - "line": 77, - "column": 9, - "endLine": 77, - "endColumn": 14, - "problem": "BuiltinNoCtorFunc", - "suggest": "", - "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", - "severity": "ERROR" - }, - { - "line": 83, - "column": 9, - "endLine": 83, - "endColumn": 14, - "problem": "BuiltinNoCtorFunc", - "suggest": "", - "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", - "severity": "ERROR" } ] -} +} \ No newline at end of file -- Gitee