diff --git a/ets2panda/linter/arkanalyzer/src/core/common/IRInference.ts b/ets2panda/linter/arkanalyzer/src/core/common/IRInference.ts index 9fd0a38200a833df66b5463a4156654f4f283c59..7c5158240596c8ee01086c30a209b5767d382f99 100644 --- a/ets2panda/linter/arkanalyzer/src/core/common/IRInference.ts +++ b/ets2panda/linter/arkanalyzer/src/core/common/IRInference.ts @@ -79,6 +79,7 @@ import { ValueUtil } from './ValueUtil'; import { ArkFile } from '../model/ArkFile'; import { AbstractTypeExpr, KeyofTypeExpr, TypeQueryExpr } from '../base/TypeExpr'; import { ArkBaseModel } from '../model/ArkBaseModel'; +import { SdkUtils } from './SdkUtils'; const logger = Logger.getLogger(LOG_MODULE_TYPE.ARKANALYZER, 'IRInference'); @@ -398,7 +399,11 @@ export class IRInference { } public static inferArgTypeWithSdk(sdkType: ClassType, scene: Scene, argType: Type): void { - if (!scene.getProjectSdkMap().has(sdkType.getClassSignature().getDeclaringFileSignature().getProjectName())) { + const sdkProjectName = sdkType.getClassSignature().getDeclaringFileSignature().getProjectName(); + const className = sdkType.getClassSignature().getClassName(); + + // When leftOp is local with Function annotation, the rightOp is a lambda function, which should be inferred as method later. + if (!scene.getProjectSdkMap().has(sdkProjectName) || (sdkProjectName === SdkUtils.BUILT_IN_NAME && className === 'Function')) { return; } if (argType instanceof UnionType) { diff --git a/ets2panda/linter/arkanalyzer/src/core/common/TypeInference.ts b/ets2panda/linter/arkanalyzer/src/core/common/TypeInference.ts index b5854a3205aa3483eb2b4ec8e8ea9a054d65c2fd..b2caf8ad565416adffbaf4c23ac64be609ff038a 100644 --- a/ets2panda/linter/arkanalyzer/src/core/common/TypeInference.ts +++ b/ets2panda/linter/arkanalyzer/src/core/common/TypeInference.ts @@ -288,15 +288,18 @@ export class TypeInference { ) { return; } - const fieldRef = stmtDef.inferType(arkMethod); - stmt.replaceDef(stmtDef, fieldRef); + this.processRef(stmtDef, stmt, arkMethod, false); } } - private static processRef(use: AbstractRef | ArkInstanceFieldRef, stmt: Stmt, arkMethod: ArkMethod): void { + private static processRef(use: AbstractRef | ArkInstanceFieldRef, stmt: Stmt, arkMethod: ArkMethod, replaceUse: boolean = true): void { const fieldRef = use.inferType(arkMethod); if (fieldRef instanceof ArkStaticFieldRef && stmt instanceof ArkAssignStmt) { - stmt.replaceUse(use, fieldRef); + if (replaceUse) { + stmt.replaceUse(use, fieldRef); + } else { + stmt.replaceDef(use, fieldRef); + } } else if (use instanceof ArkInstanceFieldRef && fieldRef instanceof ArkArrayRef && stmt instanceof ArkAssignStmt) { const index = fieldRef.getIndex(); if (index instanceof Constant && index.getType() instanceof StringType) { @@ -305,7 +308,11 @@ export class TypeInference { fieldRef.setIndex(local); } } - stmt.replaceUse(use, fieldRef); + if (replaceUse) { + stmt.replaceUse(use, fieldRef); + } else { + stmt.replaceDef(use, fieldRef); + } } } diff --git a/ets2panda/linter/arkanalyzer/src/core/common/ValueUtil.ts b/ets2panda/linter/arkanalyzer/src/core/common/ValueUtil.ts index fd33a451da8b10230640a43bd642442539c76f64..b2b9b6cc3ff8cc610cf42ad890f9f4080c4dc382 100644 --- a/ets2panda/linter/arkanalyzer/src/core/common/ValueUtil.ts +++ b/ets2panda/linter/arkanalyzer/src/core/common/ValueUtil.ts @@ -62,7 +62,7 @@ export class ValueUtil { public static createConst(str: string): Constant { const n = Number(str); if (!isNaN(n)) { - return this.getOrCreateNumberConst(n); + return this.getOrCreateNumberConst(str); } return new StringConstant(str); } diff --git a/ets2panda/linter/arkanalyzer/src/core/graph/Cfg.ts b/ets2panda/linter/arkanalyzer/src/core/graph/Cfg.ts index 54284012979954f1ee7fdf446e5cf3c2ea2753bb..7b1c4a6e5adc3d0341893d1ec8355cb0642f8333 100644 --- a/ets2panda/linter/arkanalyzer/src/core/graph/Cfg.ts +++ b/ets2panda/linter/arkanalyzer/src/core/graph/Cfg.ts @@ -121,6 +121,18 @@ export class Cfg { } } + public setBlocks(blocks: Set, resetStmtToBlock: boolean = true): void { + this.blocks = blocks; + if (resetStmtToBlock) { + this.stmtToBlock.clear(); + for (const block of this.blocks) { + for (const stmt of block.getStmts()) { + this.stmtToBlock.set(stmt, block); + } + } + } + } + public getBlocks(): Set { return this.blocks; } diff --git a/ets2panda/linter/arkanalyzer/src/core/graph/builder/CfgBuilder.ts b/ets2panda/linter/arkanalyzer/src/core/graph/builder/CfgBuilder.ts index 478d0a7121bc5a7753f791936c3e07bbef8e7df2..ca81f85119bbb7c16b4dcac1b22e249c768a3a30 100644 --- a/ets2panda/linter/arkanalyzer/src/core/graph/builder/CfgBuilder.ts +++ b/ets2panda/linter/arkanalyzer/src/core/graph/builder/CfgBuilder.ts @@ -1114,7 +1114,6 @@ export class CfgBuilder { arkIRTransformer ); - const currBlockId = this.blocks.length; this.linkBasicBlocks(blockBuilderToCfgBlock); this.adjustBlocks( blockBuilderToCfgBlock, @@ -1128,7 +1127,7 @@ export class CfgBuilder { const trapBuilder = new TrapBuilder(); const traps = trapBuilder.buildTraps(blockBuilderToCfgBlock, blockBuildersBeforeTry, arkIRTransformer, basicBlockSet); - const cfg = this.createCfg(blockBuilderToCfgBlock, basicBlockSet, currBlockId); + const cfg = this.createCfg(blockBuilderToCfgBlock, basicBlockSet); return { cfg, locals: arkIRTransformer.getLocals(), @@ -1239,20 +1238,11 @@ export class CfgBuilder { conditionalBuilder.rebuildBlocksContainConditionalOperator(basicBlockSet, ModelUtils.isArkUIBuilderMethod(this.declaringMethod)); } - private createCfg(blockBuilderToCfgBlock: Map, basicBlockSet: Set, prevBlockId: number): Cfg { - let currBlockId = prevBlockId; - for (const blockBuilder of this.blocks) { - if (blockBuilder.id === -1) { - blockBuilder.id = currBlockId++; - const block = blockBuilderToCfgBlock.get(blockBuilder) as BasicBlock; - block.setId(blockBuilder.id); - } - } - + private createCfg(blockBuilderToCfgBlock: Map, basicBlockSet: Set): Cfg { const cfg = new Cfg(); const startingBasicBlock = blockBuilderToCfgBlock.get(this.blocks[0])!; cfg.setStartingStmt(startingBasicBlock.getStmts()[0]); - currBlockId = 0; + let currBlockId = 0; for (const basicBlock of basicBlockSet) { basicBlock.setId(currBlockId++); cfg.addBlock(basicBlock); @@ -1260,9 +1250,45 @@ export class CfgBuilder { for (const stmt of cfg.getStmts()) { stmt.setCfg(cfg); } + this.topologicalSortBlock(cfg); return cfg; } + private topologicalSortBlock(cfg: Cfg): void { + function dfs(block: BasicBlock): void { + if (visited[block.getId()]) { + return; + } + + visited[block.getId()] = true; + result.add(block); + + for (const succ of block.getSuccessors() || []) { + dfs(succ); + } + } + + const startingBlock = cfg.getStartingBlock(); + if (!startingBlock) { + return; + } + const blocks = cfg.getBlocks(); + const visited: boolean[] = new Array(blocks.size).fill(false); + const result: Set = new Set(); + + dfs(startingBlock); + + // handle rest blocks haven't visted, which should be with no predecessorBlocks or the rest block in a block circle + for (const block of blocks) { + if (!visited[block.getId()]) { + dfs(block); + } + } + if (result.size === blocks.size) { + cfg.setBlocks(result, false); + } + } + private linkBasicBlocks(blockBuilderToCfgBlock: Map): void { for (const [blockBuilder, cfgBlock] of blockBuilderToCfgBlock) { for (const successorBlockBuilder of blockBuilder.nexts) { diff --git a/ets2panda/linter/homecheck/src/checker/migration/NumericSemanticCheck.ts b/ets2panda/linter/homecheck/src/checker/migration/NumericSemanticCheck.ts index b3b3c6d09a622dfb58e7c36f7238f9600aa5b204..f0b5433573a1a5f9051e186c2d8dd854c422d941 100644 --- a/ets2panda/linter/homecheck/src/checker/migration/NumericSemanticCheck.ts +++ b/ets2panda/linter/homecheck/src/checker/migration/NumericSemanticCheck.ts @@ -31,6 +31,7 @@ import { ArkParameterRef, ArkTypeOfExpr, ArkUnopExpr, + ArrayType, BooleanType, CallGraph, ClassSignature, @@ -39,13 +40,13 @@ import { CONSTRUCTOR_NAME, DVFGBuilder, FileSignature, + FullPosition, GlobalRef, INSTANCE_INIT_METHOD_NAME, LexicalEnvType, Local, MethodSignature, NAME_DELIMITER, - NAME_PREFIX, NamespaceSignature, NormalBinaryOperator, Scene, @@ -54,6 +55,7 @@ import { TEMP_LOCAL_PREFIX, Type, UnaryOperator, + UnionType, UnknownType, Value, } from 'arkanalyzer/lib'; @@ -62,7 +64,7 @@ import { BaseChecker, BaseMetaData } from '../BaseChecker'; import { Defects, MatcherCallback, Rule, RuleFix, Utils } from '../../Index'; import { IssueReport } from '../../model/Defects'; import { DVFG, DVFGNode } from 'arkanalyzer/lib/VFG/DVFG'; -import { CALL_DEPTH_LIMIT, getGlobalLocalsInDefaultMethod, getLineAndColumn, GlobalCallGraphHelper } from './Utils'; +import { CALL_DEPTH_LIMIT, getLineAndColumn, GlobalCallGraphHelper } from './Utils'; import { Language } from 'arkanalyzer/lib/core/model/ArkFile'; import { NullConstant, NumberConstant, StringConstant, UndefinedConstant } from 'arkanalyzer/lib/core/base/Constant'; import { @@ -74,6 +76,7 @@ import { AstTreeUtils, EnumValueType, NumberType, + ts, TupleType, UnclearReferenceType, } from 'arkanalyzer'; @@ -102,6 +105,7 @@ enum NumberCategory { enum RuleCategory { SDKIntType = 'sdk-api-num2int', NumericLiteral = 'arkts-numeric-semantic', + ArrayIndex = 'arkts-array-index-expr-type', } enum IssueReason { @@ -109,6 +113,7 @@ enum IssueReason { UsedWithOtherType = 'not-only-used-as-int-or-long', CannotFindAll = 'cannot-find-all', RelatedWithNonETS2 = 'related-with-non-ets2', + ActuallyIntConstant = 'actually-int-constant', Other = 'other', } @@ -206,14 +211,29 @@ export class NumericSemanticCheck implements BaseChecker { // 场景2:需要检查整型字面量出现的stmt,该stmt为sink点。场景2在场景1之后执行,优先让SDK调用来决定变量的类型为int、long、number,剩余的场景2处理,避免issue之间的冲突 if (target.isGenerated()) { // statInit、instInit等方法不进行检查,不主动对类属性的类型进行检查,因为类属性的使用范围很广,很难找全,仅对涉及的1/2这种进行告警,自动修复为1.0/2.0 - this.checkFieldInitializerWithDivision(target); - return; + try { + this.checkFieldInitializerWithDivision(target); + } catch (e) { + logger.error(`Error checking init method with numeric literal, method: ${target.getSignature().toString()}, error: ${e}`); + } + } else { + for (const stmt of stmts) { + try { + this.checkStmtContainsNumericLiteral(stmt); + } catch (e) { + logger.error( + `Error checking stmt with numeric literal, stmt: ${stmt.toString()}, method: ${target.getSignature().toString()}, error: ${e}` + ); + } + } } + + // 场景3:需要检查array的index,该stmt为sink点 for (const stmt of stmts) { try { - this.checkStmtContainsNumericLiteral(stmt); + this.checkArrayIndexInStmt(stmt); } catch (e) { - logger.error(`Error checking stmt with numeric literal, stmt: ${stmt.toString()}, method: ${target.getSignature().toString()}, error: ${e}`); + logger.error(`Error checking array index in stmt: ${stmt.toString()}, method: ${target.getSignature().toString()}, error: ${e}`); } } } @@ -348,6 +368,114 @@ export class NumericSemanticCheck implements BaseChecker { }); } + private checkArrayIndexInStmt(stmt: Stmt): void { + const res = new Map(); + this.callDepth = 0; + const index = this.getIndexValue(stmt); + if (index === null) { + return; + } + // 对于index为1.0、2.0这种number constant,需要告警并自动修复成1、2 + if (index instanceof NumberConstant && this.isFloatActuallyInt(index)) { + this.addIssueReport(RuleCategory.ArrayIndex, NumberCategory.number, IssueReason.ActuallyIntConstant, true, stmt, index); + return; + } + const issueReason = this.checkValueOnlyUsedAsIntLong(stmt, index, res, NumberCategory.int); + if (issueReason !== IssueReason.OnlyUsedAsIntLong) { + // 若index原先非int,则获取的数组元素应该是undefined,不可以对其进行强转int,否则对原始代码的语义有修改 + this.addIssueReport(RuleCategory.ArrayIndex, NumberCategory.number, issueReason, false, stmt, index); + } + res.forEach((issueInfo, local) => { + if (this.shouldIgnoreLocal(local)) { + return; + } + const declaringStmt = local.getDeclaringStmt(); + if (declaringStmt !== null) { + this.addIssueReport(RuleCategory.ArrayIndex, issueInfo.numberCategory, issueInfo.issueReason, true, declaringStmt, local); + } + }); + this.classFieldRes.forEach((fieldInfo, field) => { + if (fieldInfo.issueReason === IssueReason.OnlyUsedAsIntLong) { + // 如果能明确判断出field是int,则添加类型注解int,其他找不全的场景不变 + this.addIssueReport(RuleCategory.ArrayIndex, NumberCategory.int, fieldInfo.issueReason, true, undefined, undefined, field); + } + }); + } + + private getFieldRefActualArrayRef(stmt: Stmt): ArkInstanceFieldRef | null { + const fieldRef = stmt.getFieldRef(); + if (fieldRef === undefined || !(fieldRef instanceof ArkInstanceFieldRef)) { + return null; + } + const fieldBaseType = fieldRef.getBase().getType(); + if (!(fieldBaseType instanceof UnionType)) { + return null; + } + let containArray = false; + for (const t of fieldBaseType.getTypes()) { + if (t instanceof ArrayType) { + containArray = true; + break; + } + } + if (!containArray) { + return null; + } + const fieldName = fieldRef.getFieldName(); + if (fieldName === 'length') { + return null; + } + return fieldRef; + } + + private getActualIndexPosInStmt(stmt: Stmt): FullPosition { + // 处理array定义时为unionType,例如string[] | undefined,array的index访问语句被错误表示成ArkInstanceFieldRef的场景 + // 由于IR表示在此处的能力限制,此处判断unionType中包含arrayType,且fieldRef的名字非length,取第4个操作数的位置为实际index的位置 + const fieldRef = this.getFieldRefActualArrayRef(stmt); + if (!fieldRef) { + return FullPosition.DEFAULT; + } + const positions = stmt.getOperandOriginalPositions(); + if (!positions || positions.length !== 4) { + return FullPosition.DEFAULT; + } + return positions[3]; + } + + private getIndexValue(stmt: Stmt): Value | null { + // 处理stmt的uses中的array的index访问语句 + const arrayRef = stmt.getArrayRef(); + if (arrayRef !== undefined) { + return arrayRef.getIndex(); + } + + // 处理array的index访问出现在赋值语句左边的情况 + if (stmt.getDef() instanceof ArkArrayRef) { + return (stmt.getDef() as ArkArrayRef).getIndex(); + } + + // 处理array定义时为unionType,例如string[] | undefined,array的index访问语句被错误表示成ArkInstanceFieldRef的场景 + // 由于IR表示在此处的能力限制,此处判断unionType中包含arrayType,且fieldRef的名字非length,且在local或global中能找到同名的情况 + const methodBody = stmt.getCfg().getDeclaringMethod().getBody(); + if (methodBody === undefined) { + return null; + } + + const fieldRef = this.getFieldRefActualArrayRef(stmt); + if (!fieldRef) { + return null; + } + let index = methodBody.getLocals().get(fieldRef.getFieldName()); + if (index !== undefined) { + return index; + } + const global = methodBody.getUsedGlobals()?.get(fieldRef.getFieldName()); + if (global === undefined || !(global instanceof GlobalRef)) { + return null; + } + return global.getRef(); + } + private isLocalAssigned2Array(local: Local): boolean { if (!local.getName().startsWith(TEMP_LOCAL_PREFIX)) { return false; @@ -406,6 +534,10 @@ export class NumericSemanticCheck implements BaseChecker { if (s instanceof ArkAssignStmt && s.getRightOp() instanceof Local && s.getRightOp() === local) { const leftOp = s.getLeftOp(); if (leftOp instanceof Local) { + if (hasChecked.has(leftOp)) { + // 对于a = a语句,此处必须判断,否则会死循环 + return; + } this.checkAllLocalsAroundLocal(s, leftOp, hasChecked, numberCategory); } } @@ -702,6 +834,42 @@ export class NumericSemanticCheck implements BaseChecker { return constant.getValue().includes('.'); } + // 判断number constant是否为1.0、2.0这种可以转成1、2的整型形式 + private isFloatActuallyInt(constant: NumberConstant): boolean { + const parts = constant.getValue().split('.'); + if (parts.length !== 2) { + return false; + } + return /^0+$/.test(parts[1]); + } + + // 根据local的类型初步判断结果 + // 有些场景直接返回检查结果,不再继续检查,例如:类型为枚举、未知类型、与number无关的复杂类型等 + // 有些场景需要继续根据local的使用进行判断,例如:与number有关的类型等 + private checkResWithLocalType(local: Local, stmt: Stmt): IssueReason | null { + const localType = local.getType(); + if (!Utils.isNearlyNumberType(localType) && !(localType instanceof BooleanType)) { + // 对于联合类型仅包含number和null、undefined,可以认为是OK的,需要进一步根据local的使用情况进行判断 + // 对于return a || b, arkanalyzer会认为return op是boolean类型,其实是a的类型或b的类型,此处应该是number,需要正常继续解析表达式a || b + if (localType instanceof UnknownType || localType instanceof UnclearReferenceType) { + // 类型推导失败为unknownType或UnclearReferenceType + if (stmt instanceof ArkAssignStmt && stmt.getRightOp() instanceof ArkArrayRef && (stmt.getRightOp() as ArkArrayRef).getIndex() === local) { + // class field初始化为函数指针,导致匿名函数中使用到的闭包变量未识别,其类型为unknownType,需要继续进行查找 + return null; + } + return IssueReason.CannotFindAll; + } + if (localType instanceof EnumValueType) { + // local是枚举类型的值,无法改变枚举类型的定义,当做number使用 + return IssueReason.UsedWithOtherType; + } + // 剩余情况有aliasType、classType、函数指针、genericType等复杂场景,不再继续判断,直接返回UsedWithOtherType + logger.trace(`Local type is not number, local: ${local.getName()}, local type: ${local.getType().getTypeString()}`); + return IssueReason.UsedWithOtherType; + } + return null; + } + private isLocalOnlyUsedAsIntLong(stmt: Stmt, local: Local, hasChecked: Map, numberCategory: NumberCategory): IssueReason { const currentInfo = hasChecked.get(local); // hasChecked map中已有此local,若原先为int,现在为long则使用long替换,其余情况不改动,直接返回,避免死循环 @@ -712,10 +880,10 @@ export class NumericSemanticCheck implements BaseChecker { return IssueReason.OnlyUsedAsIntLong; } // 在之前的语句检测中已查找过此local并生成相应的issue,直接根据issue的内容返回结果,如果issue中是int,检查的是long,则结果为long - const currentIssue = this.getLocalIssueFromIssueList(local); + const currentIssue = this.getLocalIssueFromIssueList(local, stmt); if (currentIssue && currentIssue.fix instanceof RuleFix) { const issueReason = this.getIssueReasonFromDefectInfo(currentIssue.defect); - const issueCategory = this.getNumberCategoryFromLocalFixInfo(currentIssue.fix as RuleFix); + const issueCategory = this.getNumberCategoryFromFixInfo(currentIssue.fix as RuleFix); if (issueReason !== null && issueCategory !== null) { if (issueReason !== IssueReason.OnlyUsedAsIntLong) { hasChecked.set(local, { issueReason: issueReason, numberCategory: numberCategory }); @@ -738,24 +906,10 @@ export class NumericSemanticCheck implements BaseChecker { // 先将value加入map中,默认设置成false,避免后续递归查找阶段出现死循环,最后再根据查找结果绝对是否重新设置成true hasChecked.set(local, { issueReason: IssueReason.Other, numberCategory: numberCategory }); - // 正常情况不会走到此分支,除非类型为any、联合类型等复杂类型,或类型推导失败为unknownType,保守处理返回false,不转int - // 对于联合类型仅包含number和null、undefined,可以认为是OK的 - // 对于return a || b, arkanalyzer会认为return op是boolean类型,其实是a的类型或b的类型,此处应该是number,需要正常继续解析表达式a || b - const localType = local.getType(); - if (!Utils.isNearlyNumberType(localType) && !(localType instanceof BooleanType)) { - if (localType instanceof UnknownType || localType instanceof UnclearReferenceType) { - hasChecked.set(local, { issueReason: IssueReason.CannotFindAll, numberCategory: numberCategory }); - return IssueReason.CannotFindAll; - } - if (localType instanceof EnumValueType) { - // local是枚举类型的值,无法改变枚举类型的定义,当做number使用 - hasChecked.set(local, { issueReason: IssueReason.UsedWithOtherType, numberCategory: numberCategory }); - return IssueReason.UsedWithOtherType; - } - // 剩余情况有aliasType、classType、函数指针、genericType等复杂场景,不再继续判断,直接返回UsedWithOtherType - logger.trace(`Local type is not number, local: ${local.getName()}, local type: ${local.getType().getTypeString()}`); - hasChecked.set(local, { issueReason: IssueReason.UsedWithOtherType, numberCategory: numberCategory }); - return IssueReason.UsedWithOtherType; + const resWithLocalType = this.checkResWithLocalType(local, stmt); + if (resWithLocalType) { + hasChecked.set(local, { issueReason: resWithLocalType, numberCategory: numberCategory }); + return resWithLocalType; } let checkStmts: Stmt[] = []; @@ -763,7 +917,11 @@ export class NumericSemanticCheck implements BaseChecker { if (declaringStmt === null) { // 无定义语句的local可能来自于全局变量或import变量,需要根据import信息查找其原始local // 也可能是内层匿名类中使用到的外层函数中的变量,在内存类属性初始化时无定义语句 - const newLocal = this.getLocalFromOuterMethod(local) ?? this.getLocalFromGlobal(local, stmt) ?? this.getLocalFromImportInfo(local); + const declaringMethod = stmt.getCfg().getDeclaringMethod(); + const newLocal = + this.getLocalFromOuterMethod(local, declaringMethod) ?? + this.getLocalFromGlobal(local, declaringMethod) ?? + this.getLocalFromImportInfo(local, declaringMethod); if (newLocal === null) { // local非来自于import,确实是缺少定义语句,或者是从非1.2文件import,直接返回false,因为就算是能确认local仅当做int使用,也找不到定义语句去修改类型注解为int,所以后续检查都没有意义 logger.error(`Missing declaring stmt, local: ${local.getName()}`); @@ -798,7 +956,7 @@ export class NumericSemanticCheck implements BaseChecker { checkStmts.push(s); } }); - // usedStmts中不会记录local为leftOp的stmt,此处需要补充 + // usedStmts中不会记录local为leftOp的stmt,在此处进行补充 declaringStmt .getCfg() .getStmts() @@ -810,52 +968,50 @@ export class NumericSemanticCheck implements BaseChecker { }); for (const s of checkStmts) { - if (s instanceof ArkAssignStmt && s.getLeftOp() === local) { - const checkRightOp = this.checkValueOnlyUsedAsIntLong(s, s.getRightOp(), hasChecked, numberCategory); - if (checkRightOp !== IssueReason.OnlyUsedAsIntLong) { - hasChecked.set(local, { issueReason: checkRightOp, numberCategory: numberCategory }); - return checkRightOp; - } - continue; + const res = this.checkRelatedStmtForLocal(s, local, hasChecked, numberCategory); + if (res.issueReason !== IssueReason.OnlyUsedAsIntLong) { + hasChecked.set(local, res); + return res.issueReason; } - // 当前检查的local位于赋值语句的右边,若参与除法运算则看做double类型使用,若作为SDK入参依据SDK定义,其余运算、赋值等处理不会影响其自身从int -> number,所以不处理 - if (s instanceof ArkAssignStmt && s.getLeftOp() !== local) { - const rightOp = s.getRightOp(); - if (rightOp instanceof ArkNormalBinopExpr && rightOp.getOperator() === NormalBinaryOperator.Division) { - hasChecked.set(local, { issueReason: IssueReason.UsedWithOtherType, numberCategory: numberCategory }); - return IssueReason.UsedWithOtherType; - } - if (rightOp instanceof AbstractInvokeExpr) { - const res = this.checkLocalUsedAsSDKArg(rightOp, local, hasChecked); - if (res !== null && res.issueReason !== IssueReason.OnlyUsedAsIntLong) { - hasChecked.set(local, res); - return res.issueReason; - } - } - continue; + } + hasChecked.set(local, { issueReason: IssueReason.OnlyUsedAsIntLong, numberCategory: numberCategory }); + return IssueReason.OnlyUsedAsIntLong; + } + + private checkRelatedStmtForLocal(stmt: Stmt, local: Local, hasChecked: Map, numberCategory: NumberCategory): IssueInfo { + if (stmt instanceof ArkAssignStmt && stmt.getLeftOp() === local) { + const issueReason = this.checkValueOnlyUsedAsIntLong(stmt, stmt.getRightOp(), hasChecked, numberCategory); + return { issueReason, numberCategory }; + } + // 当前检查的local位于赋值语句的右边,若参与除法运算则看做double类型使用,若作为SDK入参依据SDK定义,其余运算、赋值等处理不会影响其自身从int -> number,所以不处理 + if (stmt instanceof ArkAssignStmt && stmt.getLeftOp() !== local) { + const rightOp = stmt.getRightOp(); + if (rightOp instanceof ArkNormalBinopExpr && rightOp.getOperator() === NormalBinaryOperator.Division) { + return { issueReason: IssueReason.UsedWithOtherType, numberCategory }; } - if (s instanceof ArkInvokeStmt) { - // 函数调用语句,local作为实参或base,除作为SDK入参之外,其余场景不会影响其值的变化,不会导致int被重新赋值为number使用 - const res = this.checkLocalUsedAsSDKArg(s.getInvokeExpr(), local, hasChecked); - if (res !== null && res.issueReason !== IssueReason.OnlyUsedAsIntLong) { - hasChecked.set(local, res); - return res.issueReason; + if (rightOp instanceof AbstractInvokeExpr) { + const res = this.checkLocalUsedAsSDKArg(rightOp, local, hasChecked); + if (res !== null) { + return res; } - continue; } - if (s instanceof ArkReturnStmt) { - // return语句,local作为返回值,不会影响其值的变化,不会导致int被重新赋值为number使用 - continue; - } - if (s instanceof ArkIfStmt) { - // 条件判断语句,local作为condition expr的op1或op2,进行二元条件判断,不会影响其值的变化,不会导致int被重新赋值为number使用 - continue; + return { issueReason: IssueReason.OnlyUsedAsIntLong, numberCategory }; + } + if (stmt instanceof ArkInvokeStmt) { + // 函数调用语句,local作为实参或base,除作为SDK入参之外,其余场景不会影响其值的变化,不会导致int被重新赋值为number使用 + const res = this.checkLocalUsedAsSDKArg(stmt.getInvokeExpr(), local, hasChecked); + if (res !== null) { + return res; } - logger.error(`Need to check new type of stmt: ${s.toString()}, method: ${s.getCfg().getDeclaringMethod().getSignature().toString()}`); - return IssueReason.Other; + return { issueReason: IssueReason.OnlyUsedAsIntLong, numberCategory }; } - hasChecked.set(local, { issueReason: IssueReason.OnlyUsedAsIntLong, numberCategory: numberCategory }); - return IssueReason.OnlyUsedAsIntLong; + if (stmt instanceof ArkReturnStmt || stmt instanceof ArkIfStmt) { + // return语句,local作为返回值,不会影响其值的变化,不会导致int被重新赋值为number使用 + // 条件判断语句,local作为condition expr的op1或op2,进行二元条件判断,不会影响其值的变化,不会导致int被重新赋值为number使用 + return { issueReason: IssueReason.OnlyUsedAsIntLong, numberCategory }; + } + logger.error(`Need to check new type of stmt: ${stmt.toString()}, method: ${stmt.getCfg().getDeclaringMethod().getSignature().toString()}`); + return { issueReason: IssueReason.Other, numberCategory }; } // 判断local是否是SDK invoke expr的入参,且其类型是int或long,否则返回null @@ -897,8 +1053,8 @@ export class NumericSemanticCheck implements BaseChecker { return null; } - private getLocalFromGlobal(local: Local, stmt: Stmt): Local | null { - const defaultMethod = stmt.getCfg().getDeclaringMethod().getDeclaringArkFile().getDefaultClass().getDefaultArkMethod(); + private getLocalFromGlobal(local: Local, method: ArkMethod): Local | null { + const defaultMethod = method.getDeclaringArkFile().getDefaultClass().getDefaultArkMethod(); if (!defaultMethod) { return null; } @@ -909,12 +1065,8 @@ export class NumericSemanticCheck implements BaseChecker { return null; } - private getLocalFromImportInfo(local: Local): Local | null { - const usedStmts = local.getUsedStmts(); - if (usedStmts.length < 1) { - return null; - } - const importInfo = usedStmts[0].getCfg().getDeclaringMethod().getDeclaringArkFile().getImportInfoBy(local.getName()); + private getLocalFromImportInfo(local: Local, method: ArkMethod): Local | null { + const importInfo = method.getDeclaringArkFile().getImportInfoBy(local.getName()); if (importInfo === undefined) { return null; } @@ -933,16 +1085,25 @@ export class NumericSemanticCheck implements BaseChecker { } // 对于method中的let obj: Obj = {aa: a}的对象字面量,其中使用到a变量为method中的local或global,当前ArkAnalyzer未能对其进行识别和表示,此处手动查找 - private getLocalFromOuterMethod(local: Local): Local | null { - const usedStmts = local.getUsedStmts(); - if (usedStmts.length < 1) { - return null; + // 对于class的field为lambda函数定义的函数指针的场景,lambda函数中使用到的外层的变量,当前ArkAnalyzer未能对其进行识别和表示,此处手动查找 + private getLocalFromOuterMethod(local: Local, method: ArkMethod): Local | null { + const outerMethod = method.getOuterMethod(); + if (outerMethod) { + const newLocal = outerMethod.getBody()?.getLocals().get(local.getName()); + if (newLocal) { + if (newLocal.getDeclaringStmt()) { + return newLocal; + } else { + return this.getLocalFromOuterMethod(newLocal, outerMethod); + } + } } - const clazz = usedStmts[0].getCfg().getDeclaringMethod().getDeclaringArkClass(); - return this.findLocalFromOuterObject(local, clazz); + + const clazz = method.getDeclaringArkClass(); + return this.findLocalFromOuterClass(local, clazz); } - private findLocalFromOuterObject(local: Local, objectClass: ArkClass): Local | null { + private findLocalFromOuterClass(local: Local, objectClass: ArkClass): Local | null { if (objectClass.getCategory() !== ClassCategory.INTERFACE && objectClass.getCategory() !== ClassCategory.OBJECT) { // 此查找仅涉及对象字面量中直接使用变量的场景,其余场景不涉及 return null; @@ -971,7 +1132,7 @@ export class NumericSemanticCheck implements BaseChecker { if (declaringStmt) { return newLocal; } - return this.getLocalFromOuterMethod(newLocal); + return this.getLocalFromOuterMethod(newLocal, outerMethod); } const globalRef = outerMethod.getBody()?.getUsedGlobals()?.get(local.getName()); if (globalRef && globalRef instanceof GlobalRef) { @@ -982,7 +1143,7 @@ export class NumericSemanticCheck implements BaseChecker { return null; } if (outerClass.isAnonymousClass()) { - return this.findLocalFromOuterObject(local, outerClass); + return this.findLocalFromOuterClass(local, outerClass); } return null; } @@ -1067,6 +1228,10 @@ export class NumericSemanticCheck implements BaseChecker { if (expr.getOperator() === UnaryOperator.Neg || expr.getOperator() === UnaryOperator.BitwiseNot) { return this.checkValueOnlyUsedAsIntLong(stmt, expr.getOp(), hasChecked, numberCategory); } + if (expr.getOperator() === UnaryOperator.LogicalNot) { + // let a = 1; let b = !a,不会导致a产生int到number的变化 + return IssueReason.OnlyUsedAsIntLong; + } logger.error(`Need to handle new type of unary operator: ${expr.getOperator().toString()}`); return IssueReason.Other; } @@ -1254,7 +1419,6 @@ export class NumericSemanticCheck implements BaseChecker { if (rightOp instanceof AbstractFieldRef) { if (this.isFieldRefMatchArkField(rightOp, field)) { if (leftOp instanceof Local && leftOp.getName().startsWith(TEMP_LOCAL_PREFIX)) { - // return this.checkTempLocalAssignByFieldRef(leftOp); return this.isLocalOnlyUsedAsIntLong(stmt, leftOp, hasChecked, numberCategory); } return IssueReason.OnlyUsedAsIntLong; @@ -1439,7 +1603,7 @@ export class NumericSemanticCheck implements BaseChecker { return null; } - private getNumberCategoryFromFieldFixInfo(fix: RuleFix): NumberCategory | null { + private getNumberCategoryFromFixInfo(fix: RuleFix): NumberCategory | null { const fixText = fix.text; let match = fix.text.match(/^([^=;]+:[^=;]+)([\s\S]*)$/); if (match === null || match.length < 2) { @@ -1457,20 +1621,6 @@ export class NumericSemanticCheck implements BaseChecker { return null; } - private getNumberCategoryFromLocalFixInfo(fix: RuleFix): NumberCategory | null { - const fixText = fix.text; - if (fixText.startsWith(`: ${NumberCategory.int}`)) { - return NumberCategory.int; - } - if (fixText.startsWith(`: ${NumberCategory.long}`)) { - return NumberCategory.long; - } - if (fixText.startsWith(`: ${NumberCategory.number}`)) { - return NumberCategory.number; - } - return null; - } - private getFieldIssueFromIssueList(field: ArkField): IssueReport | null { const position: WarnInfo = { line: field.getOriginPosition().getLineNo(), @@ -1487,12 +1637,8 @@ export class NumericSemanticCheck implements BaseChecker { return null; } - private getLocalIssueFromIssueList(local: Local): IssueReport | null { - const declaringStmt = local.getDeclaringStmt(); - if (declaringStmt === null) { - return null; - } - const position = getLineAndColumn(declaringStmt, local, true); + private getLocalIssueFromIssueList(local: Local, stmt: Stmt): IssueReport | null { + const position = getLineAndColumn(stmt, local, true); const fixKeyPrefix = position.line + '%' + position.startCol + '%' + position.endCol + '%'; for (const issue of this.issues) { if (issue.defect.fixKey.startsWith(fixKeyPrefix)) { @@ -1502,24 +1648,28 @@ export class NumericSemanticCheck implements BaseChecker { return null; } - private addIssueReport( - ruleCategory: RuleCategory, - numberCategory: NumberCategory, - reason: IssueReason, - couldAutofix: boolean, - issueStmt?: Stmt, - value?: Value, - field?: ArkField, - usedStmt?: Stmt - ): void { - const severity = this.rule.alert ?? this.metaData.severity; - let warnInfo: WarnInfo; + private getWarnInfo(field?: ArkField, issueStmt?: Stmt, value?: Value): WarnInfo | null { + let warnInfo: WarnInfo | null = null; + if (field === undefined) { if (issueStmt && value) { warnInfo = getLineAndColumn(issueStmt, value, true); + if (warnInfo.line === -1) { + // 可能是因为获取array index时,array是联合类型导致index未推导成功,checker里面额外去body里找local替换index + // 但是获取index的position信息时,需要使用原始的index去stmt中查找位置 + const actualPosition = this.getActualIndexPosInStmt(issueStmt); + const originPath = issueStmt.getCfg().getDeclaringMethod().getDeclaringArkFile().getFilePath(); + warnInfo = { + line: actualPosition.getFirstLine(), + startCol: actualPosition.getFirstCol(), + endLine: actualPosition.getLastLine(), + endCol: actualPosition.getLastCol(), + filePath: originPath, + }; + } } else { logger.error('Missing stmt or value when adding issue.'); - return; + return warnInfo; } } else { warnInfo = { @@ -1537,46 +1687,97 @@ export class NumericSemanticCheck implements BaseChecker { } else { logger.error(`failed to get position info`); } - return; + return null; } - let problem: string; - let desc: string; + return warnInfo; + } + + private getProblem(ruleCategory: RuleCategory, reason: IssueReason): string | null { + if (ruleCategory === RuleCategory.SDKIntType) { + return 'SDKIntType-' + reason; + } + if (ruleCategory === RuleCategory.NumericLiteral) { + return 'NumericLiteral-' + reason; + } + if (ruleCategory === RuleCategory.ArrayIndex) { + return 'IndexIntType-' + reason; + } + logger.error(`Have not support rule ${ruleCategory} yet.`); + return null; + } + + private getDesc( + ruleCategory: RuleCategory, + reason: IssueReason, + numberCategory: NumberCategory, + couldAutofix: boolean, + issueStmt?: Stmt, + usedStmt?: Stmt + ): string | null { if (ruleCategory === RuleCategory.SDKIntType) { - problem = 'SDKIntType-' + reason; if (reason === IssueReason.OnlyUsedAsIntLong) { if (usedStmt) { - desc = `It has relationship with the arg of SDK API in ${this.getUsedStmtDesc(usedStmt, issueStmt)} and only used as ${numberCategory}, should be defined as ${numberCategory} (${ruleCategory})`; - } else { - logger.error('Missing used stmt when getting issue description'); - return; + return `It has relationship with the arg of SDK API in ${this.getUsedStmtDesc(usedStmt, issueStmt)} and only used as ${numberCategory}, should be defined as ${numberCategory} (${ruleCategory})`; } - } else { - desc = `The arg of SDK API should be ${numberCategory} here (${ruleCategory})`; + logger.error('Missing used stmt when getting issue description'); + return null; } - } else if (ruleCategory === RuleCategory.NumericLiteral) { - problem = 'NumericLiteral-' + reason; + return `The arg of SDK API should be ${numberCategory} here (${ruleCategory})`; + } + if (ruleCategory === RuleCategory.NumericLiteral) { if (reason === IssueReason.OnlyUsedAsIntLong) { - desc = `It is used as ${NumberCategory.int} (${ruleCategory})`; - } else { - desc = `It is used as ${NumberCategory.number} (${ruleCategory})`; + return `It is used as ${NumberCategory.int} (${ruleCategory})`; } - } else { - logger.error(`Have not support rule ${ruleCategory} yet.`); + return `It is used as ${NumberCategory.number} (${ruleCategory})`; + } + if (ruleCategory === RuleCategory.ArrayIndex) { + if (reason === IssueReason.OnlyUsedAsIntLong) { + return `It is used as ${NumberCategory.int} (${ruleCategory})`; + } + if (reason === IssueReason.ActuallyIntConstant) { + return `The number constant could be changed to int constant (${ruleCategory})`; + } + if (couldAutofix) { + return `It is used as ${NumberCategory.number} (${ruleCategory})`; + } + return `The array index is used as ${NumberCategory.number}, please check if it's ok (${ruleCategory})`; + } + logger.error(`Have not support rule ${ruleCategory} yet.`); + return null; + } + + private addIssueReport( + ruleCategory: RuleCategory, + numberCategory: NumberCategory, + reason: IssueReason, + couldAutofix: boolean, + issueStmt?: Stmt, + value?: Value, + field?: ArkField, + usedStmt?: Stmt + ): void { + const severity = this.rule.alert ?? this.metaData.severity; + let warnInfo = this.getWarnInfo(field, issueStmt, value); + let problem = this.getProblem(ruleCategory, reason); + let desc = this.getDesc(ruleCategory, reason, numberCategory, couldAutofix, issueStmt, usedStmt); + if (!warnInfo || !problem || !desc) { return; } - // 添加新的issue之前需要检查一下已有issue,避免2个issue之间冲突,一个issue要改为int,一个issue要改为long + // 添加新的issue之前需要检查一下已有issue,避免重复issue,或2个issue之间冲突,一个issue要改为int,一个issue要改为long let currentIssue: IssueReport | null = null; let issueCategory: NumberCategory | null = null; if (field !== undefined) { currentIssue = this.getFieldIssueFromIssueList(field); if (currentIssue) { - issueCategory = this.getNumberCategoryFromFieldFixInfo(currentIssue.fix as RuleFix); + issueCategory = this.getNumberCategoryFromFixInfo(currentIssue.fix as RuleFix); } } else if (value instanceof Local) { - currentIssue = this.getLocalIssueFromIssueList(value); - if (currentIssue) { - issueCategory = this.getNumberCategoryFromLocalFixInfo(currentIssue.fix as RuleFix); + if (issueStmt) { + currentIssue = this.getLocalIssueFromIssueList(value, issueStmt); + if (currentIssue && currentIssue.fix) { + issueCategory = this.getNumberCategoryFromFixInfo(currentIssue.fix as RuleFix); + } } } if (currentIssue && issueCategory) { @@ -1593,6 +1794,9 @@ export class NumericSemanticCheck implements BaseChecker { // 已有的issue已经足够进行自动修复处理,无需重复添加 return; } + } else { + // 已有的issue对非int进行修改,无需重复添加 + return; } } } @@ -1612,28 +1816,47 @@ export class NumericSemanticCheck implements BaseChecker { couldAutofix ); - if (couldAutofix) { - let autofix: RuleFix | null = null; - if (ruleCategory === RuleCategory.SDKIntType) { - autofix = this.generateSDKRuleFix(warnInfo, reason, numberCategory, issueStmt, value, field); + if (!couldAutofix) { + this.issues.push(new IssueReport(defects, undefined)); + return; + } + if (ruleCategory === RuleCategory.SDKIntType) { + const autofix = this.generateSDKRuleFix(warnInfo, reason, numberCategory, issueStmt, value, field); + if (autofix === null) { + // 此规则必须修复,若autofix为null,则表示无需修复,不添加issue + return; + } else { + this.issues.push(new IssueReport(defects, autofix)); + } + return; + } + if (ruleCategory === RuleCategory.NumericLiteral) { + const autofix = this.generateNumericLiteralRuleFix(warnInfo, reason, issueStmt, value, field); + if (autofix === null) { + // 此规则必须修复,若autofix为null,则表示无需修复,不添加issue + return; + } + this.issues.push(new IssueReport(defects, autofix)); + return; + } + if (ruleCategory === RuleCategory.ArrayIndex) { + if (reason === IssueReason.ActuallyIntConstant && issueStmt && value instanceof NumberConstant) { + const autofix = this.generateIntConstantIndexRuleFix(warnInfo, issueStmt, value); if (autofix === null) { defects.fixable = false; this.issues.push(new IssueReport(defects, undefined)); } else { this.issues.push(new IssueReport(defects, autofix)); } - return; - } - if (ruleCategory === RuleCategory.NumericLiteral) { - autofix = this.generateNumericLiteralRuleFix(warnInfo, reason, issueStmt, value, field); + } else { + const autofix = this.generateNumericLiteralRuleFix(warnInfo, reason, issueStmt, value, field); if (autofix === null) { // 此规则必须修复,若autofix为null,则表示无需修复,不添加issue return; } this.issues.push(new IssueReport(defects, autofix)); } - } else { - this.issues.push(new IssueReport(defects, undefined)); + return; } } @@ -1647,69 +1870,149 @@ export class NumericSemanticCheck implements BaseChecker { return `line ${line}`; } - private generateSDKRuleFix( - warnInfo: WarnInfo, - issueReason: IssueReason, - numberCategory: NumberCategory, - stmt?: Stmt, - value?: Value, - field?: ArkField - ): RuleFix | null { + private getSourceFile(field?: ArkField, issueStmt?: Stmt): ts.SourceFile | null { let arkFile: ArkFile; if (field) { arkFile = field.getDeclaringArkClass().getDeclaringArkFile(); - } else if (stmt) { - arkFile = stmt.getCfg().getDeclaringMethod().getDeclaringArkFile(); + } else if (issueStmt) { + arkFile = issueStmt.getCfg().getDeclaringMethod().getDeclaringArkFile(); } else { logger.error('Missing both issue stmt and field when generating auto fix info.'); return null; } - const sourceFile = AstTreeUtils.getASTNode(arkFile.getName(), arkFile.getCode()); - if (field) { - // warnInfo中对于field的endCol与startCol一样,均为filed首列位置,包含修饰符位置,这里autofix采用整行替换方式进行 - const range = FixUtils.getLineRangeWithStartCol(sourceFile, warnInfo.line, warnInfo.startCol); - if (range === null) { - logger.error('Failed to getting range info of issue file when generating auto fix info.'); - return null; - } - const valueString = FixUtils.getSourceWithRange(sourceFile, range); - if (valueString === null) { + return AstTreeUtils.getASTNode(arkFile.getName(), arkFile.getCode()); + } + + private generateRuleFixForLocalDefine(sourceFile: ts.SourceFile, warnInfo: WarnInfo, numberCategory: NumberCategory): RuleFix | null { + // warnInfo中对于变量声明语句的位置信息只包括变量名,不包括变量声明时的类型注解位置 + // 此处先获取变量名后到行尾的字符串信息,判断是替换‘: number’ 或增加 ‘: int’ + const localRange = FixUtils.getRangeWithAst(sourceFile, { + startLine: warnInfo.line, + startCol: warnInfo.startCol, + endLine: warnInfo.line, + endCol: warnInfo.endCol, + }); + const restRange = FixUtils.getLineRangeWithStartCol(sourceFile, warnInfo.line, warnInfo.endCol); + if (!localRange || !restRange) { + logger.error('Failed to getting range info of issue file when generating auto fix info.'); + return null; + } + const restString = FixUtils.getSourceWithRange(sourceFile, restRange); + if (!restString) { + logger.error('Failed to getting text of the fix range info when generating auto fix info.'); + return null; + } + + // 场景1:变量或函数入参,无类型注解的场景,直接在localString后面添加': int' + if (!restString.trimStart().startsWith(':')) { + let ruleFix = new RuleFix(); + ruleFix.range = localRange; + const localString = FixUtils.getSourceWithRange(sourceFile, ruleFix.range); + if (!localString) { logger.error('Failed to getting text of the fix range info when generating auto fix info.'); return null; } - const fixedText = this.generateFixedTextForFieldDefine(valueString, numberCategory); - if (fixedText === null) { - logger.error('Failed to get fix text when generating auto fix info.'); - return null; - } - const ruleFix = new RuleFix(); - ruleFix.range = range; - ruleFix.text = fixedText; + ruleFix.text = `${localString}: ${numberCategory}`; return ruleFix; } + // 场景2:变量或函数入参,有类型注解的场景,需要将类型注解替换成新的类型 + const match = restString.match(/^(\s*:[^,)=;]+)([\s\S]*)$/); + if (match === null || match.length < 3) { + return null; + } + // 如果需要替换成number,但是已经存在类型注解number,则返回null,不需要告警和自动修复 + if (match[1].includes(numberCategory)) { + return null; + } + let ruleFix = new RuleFix(); + ruleFix.range = [localRange[0], localRange[1] + match[1].length]; + const localString = FixUtils.getSourceWithRange(sourceFile, ruleFix.range); + if (!localString) { + logger.error('Failed to getting text of the fix range info when generating auto fix info.'); + return null; + } + const parts = localString.split(':'); + if (parts.length !== 2) { + logger.error('Failed to getting text of the fix range info when generating auto fix info.'); + return null; + } + if (!parts[1].includes(NumberCategory.number)) { + // 原码含有类型注解但是其类型中不含number,无法进行替换 + return null; + } + ruleFix.text = `${parts[0].trimEnd()}: ${parts[1].trimStart().replace(NumberCategory.number, numberCategory)}`; + return ruleFix; + } + + private generateRuleFixForFieldDefine(sourceFile: ts.SourceFile, warnInfo: WarnInfo, numberCategory: NumberCategory): RuleFix | null { + // warnInfo中对于field的endCol与startCol一样,均为filed首列位置,包含修饰符位置,这里autofix采用整行替换方式进行 + const fullRange = FixUtils.getLineRangeWithStartCol(sourceFile, warnInfo.line, warnInfo.startCol); + if (fullRange === null) { + logger.error('Failed to getting range info of issue file when generating auto fix info.'); + return null; + } + const fullValueString = FixUtils.getSourceWithRange(sourceFile, fullRange); + if (fullValueString === null) { + logger.error('Failed to getting text of the fix range info when generating auto fix info.'); + return null; + } - if (issueReason === IssueReason.OnlyUsedAsIntLong) { - // warnInfo中对于变量声明语句的位置信息只包括变量名,不包括变量声明时的类型注解位置,此处获取变量名后到行尾的字符串信息,替换‘: number’ 或增加 ‘: int’ - const range = FixUtils.getLineRangeWithStartCol(sourceFile, warnInfo.line, warnInfo.endCol); - if (range === null) { - logger.error('Failed to getting range info of issue file when generating auto fix info.'); + const ruleFix = new RuleFix(); + // 场景1:对于类属性private a: number 或 private a: number = xxx, fullValueString为private开始到行尾的内容,需要替换为private a: int + let match = fullValueString.match(/^([^=;]+:[^=;]+)([\s\S]*)$/); + if (match !== null && match.length > 2) { + if (match[1].includes(numberCategory)) { + // 判断field是否已经有正确的类型注解 return null; } - const valueString = FixUtils.getSourceWithRange(sourceFile, range); - if (valueString === null) { + ruleFix.range = [fullRange[0], fullRange[0] + match[1].length]; + const originalText = FixUtils.getSourceWithRange(sourceFile, ruleFix.range); + if (!originalText) { logger.error('Failed to getting text of the fix range info when generating auto fix info.'); return null; } - const fixedText = this.generateFixedTextForVariableDefine(valueString, numberCategory); - if (fixedText === null) { - logger.error('Failed to get fix text when generating auto fix info.'); + if (!originalText.includes(NumberCategory.number)) { + // 原码含有类型注解但是其类型中不含number,无法进行替换 return null; } - const ruleFix = new RuleFix(); - ruleFix.range = range; - ruleFix.text = fixedText; + ruleFix.text = originalText.replace(NumberCategory.number, numberCategory); + return ruleFix; + } + // 场景2:对于private a = 123,originalText为private开始到行尾的内容,需要替换为private a: int = 123 + match = fullValueString.match(/^([^=;]+)([\s\S]*)$/); + if (match !== null && match.length > 2) { + ruleFix.range = [fullRange[0], fullRange[0] + match[1].trimEnd().length]; + const originalText = FixUtils.getSourceWithRange(sourceFile, ruleFix.range); + if (!originalText) { + logger.error('Failed to getting text of the fix range info when generating auto fix info.'); + return null; + } + ruleFix.text = `${originalText}: ${numberCategory}`; return ruleFix; } + // 正常情况下不会走到此处,因为field一定有类型注解或初始化值来确定其类型 + return null; + } + + private generateSDKRuleFix( + warnInfo: WarnInfo, + issueReason: IssueReason, + numberCategory: NumberCategory, + issueStmt?: Stmt, + value?: Value, + field?: ArkField + ): RuleFix | null { + const sourceFile = this.getSourceFile(field, issueStmt); + if (!sourceFile) { + return null; + } + if (field) { + return this.generateRuleFixForFieldDefine(sourceFile, warnInfo, numberCategory); + } + + if (issueReason === IssueReason.OnlyUsedAsIntLong) { + return this.generateRuleFixForLocalDefine(sourceFile, warnInfo, numberCategory); + } // 强转场景,获取到对应位置信息,在其后添加'.toInt()'或'.toLong()' let endLine = warnInfo.line; if (warnInfo.endLine !== undefined) { @@ -1773,47 +2076,46 @@ export class NumericSemanticCheck implements BaseChecker { } } + private generateIntConstantIndexRuleFix(warnInfo: WarnInfo, issueStmt: Stmt, constant: NumberConstant): RuleFix | null { + if (!this.isFloatActuallyInt(constant)) { + return null; + } + const sourceFile = this.getSourceFile(undefined, issueStmt); + if (!sourceFile) { + return null; + } + const range = FixUtils.getRangeWithAst(sourceFile, { + startLine: warnInfo.line, + startCol: warnInfo.startCol, + endLine: warnInfo.line, + endCol: warnInfo.endCol, + }); + if (range === null) { + logger.error('Failed to getting range info of issue file when generating auto fix info.'); + return null; + } + const ruleFix = new RuleFix(); + ruleFix.range = range; + const parts = constant.getValue().split('.'); + if (parts.length !== 2) { + return null; + } + ruleFix.text = parts[0]; + return ruleFix; + } + private generateNumericLiteralRuleFix(warnInfo: WarnInfo, issueReason: IssueReason, issueStmt?: Stmt, value?: Value, field?: ArkField): RuleFix | null { - let arkFile: ArkFile; - if (field) { - arkFile = field.getDeclaringArkClass().getDeclaringArkFile(); - } else if (issueStmt) { - arkFile = issueStmt.getCfg().getDeclaringMethod().getDeclaringArkFile(); - } else { - logger.error('Missing both issue stmt and field when generating auto fix info.'); + const sourceFile = this.getSourceFile(field, issueStmt); + if (!sourceFile) { return null; } - const sourceFile = AstTreeUtils.getASTNode(arkFile.getName(), arkFile.getCode()); if (field) { - // warnInfo中对于field的endCol与startCol一样,均为filed首列位置,包含修饰符位置,这里autofix采用整行替换方式进行 - const range = FixUtils.getLineRangeWithStartCol(sourceFile, warnInfo.line, warnInfo.startCol); - if (range === null) { - logger.error('Failed to getting range info of issue file when generating auto fix info.'); - return null; - } - const valueString = FixUtils.getSourceWithRange(sourceFile, range); - if (valueString === null) { - logger.error('Failed to getting text of the fix range info when generating auto fix info.'); - return null; - } - let fixedText: string | null = null; if (issueReason === IssueReason.OnlyUsedAsIntLong) { - fixedText = this.generateFixedTextForFieldDefine(valueString, NumberCategory.int); + return this.generateRuleFixForFieldDefine(sourceFile, warnInfo, NumberCategory.int); } else { - if (this.isFieldDefineAlreadyWithNumberType(valueString)) { - return null; - } - fixedText = this.generateFixedTextForFieldDefine(valueString, NumberCategory.number); + return this.generateRuleFixForFieldDefine(sourceFile, warnInfo, NumberCategory.number); } - if (fixedText === null) { - logger.error('Failed to get fix text when generating auto fix info.'); - return null; - } - const ruleFix = new RuleFix(); - ruleFix.range = range; - ruleFix.text = fixedText; - return ruleFix; } if (value instanceof NumberConstant) { @@ -1844,91 +2146,9 @@ export class NumericSemanticCheck implements BaseChecker { } // 非整型字面量 // warnInfo中对于变量声明语句的位置信息只包括变量名,不包括变量声明时的类型注解位置,此处获取变量名后到行尾的字符串信息,替换‘: number’ 或增加 ‘: int’ - const range = FixUtils.getLineRangeWithStartCol(sourceFile, warnInfo.line, warnInfo.endCol); - if (range === null) { - logger.error('Failed to getting range info of issue file when generating auto fix info.'); - return null; - } - const valueString = FixUtils.getSourceWithRange(sourceFile, range); - if (valueString === null) { - logger.error('Failed to getting text of the fix range info when generating auto fix info.'); - return null; - } - - let fixedText: string | null = null; if (issueReason === IssueReason.OnlyUsedAsIntLong) { - fixedText = this.generateFixedTextForVariableDefine(valueString, NumberCategory.int); - } else { - if (this.isVariableDefineAlreadyWithNumberType(valueString)) { - // 类型注解已经有number,无需进行自动修复 - return null; - } - fixedText = this.generateFixedTextForVariableDefine(valueString, NumberCategory.number); - } - if (fixedText === null) { - logger.error('Failed to get fix text when generating auto fix info.'); - return null; - } - const ruleFix = new RuleFix(); - ruleFix.range = range; - ruleFix.text = fixedText; - return ruleFix; - } - - private generateFixedTextForFieldDefine(originalText: string, numberCategory: NumberCategory): string | null { - // 对于类属性private a: number 或 private a, originalText为private开始到行尾的内容,需要替换为private a: int - let newTypeStr: string = numberCategory; - let match = originalText.match(/^([^=;]+:[^=;]+)([\s\S]*)$/); - if (match !== null && match.length > 2) { - return match[1].replace(NumberCategory.number, newTypeStr) + match[2]; - } - // 对于private a = 123,originalText为private开始到行尾的内容,需要替换为private a: int = 123 - match = originalText.match(/^([^=;]+)([\s\S]*)$/); - if (match !== null && match.length > 2) { - return `${match[1].trimEnd()}: ${newTypeStr} ${match[2]}`; - } - return null; - } - - private generateFixedTextForVariableDefine(originalText: string, numberCategory: NumberCategory): string | null { - // 对于let a = xxx, originalText为' = xxx,',需要替换成': int = xxx' - // 对于let a: number | null = xxx, originalText为': number | null = xxx,',需要替换成': int | null = xxx' - // 对于foo(a: number, b: string)场景, originalText为‘: number, b: string)’,需要替换为foo(a: int, b: string) - // 场景1:变量或类属性定义或函数入参,无类型注解的场景,直接在originalText前面添加': int' - let newTypeStr: string = numberCategory; - if (!originalText.trimStart().startsWith(':')) { - if (originalText.startsWith(';') || originalText.startsWith(FixUtils.getTextEof(originalText))) { - return `: ${newTypeStr}${originalText}`; - } - return `: ${newTypeStr} ${originalText.trimStart()}`; - } - // 场景2:变量或类属性定义或函数入参,有类型注解的场景 - const match = originalText.match(/^(\s*:[^,)=;]+)([\s\S]*)$/); - if (match === null || match.length < 3) { - return null; - } - const newAnnotation = match[1].replace('number', newTypeStr); - return newAnnotation + match[2]; - } - - // 传入的源码片段为变量的声明语句中紧跟变量名的部分 - // 对于let a: number | null = xxx, 为': number | null = xxx,', - private isVariableDefineAlreadyWithNumberType(sourceCode: string): boolean { - if (!sourceCode.trimStart().startsWith(':')) { - return false; - } - const match = sourceCode.match(/\s*:\s*([^,)=;]+)([\s\S]*)$/); - if (match === null || match.length < 2) { - return false; - } - return match[1].includes(NumberCategory.number); - } - - private isFieldDefineAlreadyWithNumberType(sourceCode: string): boolean { - let match = sourceCode.match(/^([^=;]+:[^=;]+)([\s\S]*)$/); - if (match === null || match.length < 2) { - return false; + return this.generateRuleFixForLocalDefine(sourceFile, warnInfo, NumberCategory.int); } - return match[1].includes(NumberCategory.number); + return this.generateRuleFixForLocalDefine(sourceFile, warnInfo, NumberCategory.number); } } diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index dc1ab4b18ff833330e09c4c6d8617fdeb143d3b5..2b4b13d6564edfbbd801189f3ee06fc38eac3be5 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -14,7 +14,6 @@ "arkts-no-function-return-this", "arkts-limited-stdlib", "arkts-no-class-add-super-prop-with-readonly", - "arkts-var-assignment-before-use", "arkts-concurrent-deprecated-apis", "arkts-no-classes-as-obj", "arkts-obj-literal-props", @@ -23,6 +22,7 @@ "arkts-optional-methods", "arkts-use-long-for-large-numeric-literal", "arkts-numeric-semantic", + "arkts-limited-tuple-index-type", "arkts-incompatible-function-types", "arkts-limited-void-type", "arkts-distinct-infinity-bitwise-inversion", @@ -34,7 +34,6 @@ "arkts-no-debugger", "arkts-no-arguments-obj", "arkts-no-tagged-templates", - "arkts-array-index-expr-type", "arkts-switch-expr", "arkts-case-expr", "arkts-array-index-negative", @@ -61,6 +60,7 @@ "arkts-limited-stdlib-no-setTransferList", "arkts-builtin-object-getOwnPropertyNames", "arkts-no-class-omit-interface-optional-prop", + "arkts-distinct-abstract-method-default-return-type", "arkts-class-no-signature-distinct-with-object-public-api", "arkts-no-sparse-array", "arkts-no-enum-prop-as-type", @@ -142,13 +142,22 @@ "arkui-buildernode-no-nestingbuildersupported", "arkui-sdk-common-deprecated-api", "arkui-sdk-common-whitelist-api", - "arkui-sdk-common-behaviorchange-api" + "arkui-sdk-common-behaviorchange-api", + "arkui-persistent-prop-serialization", + "arkui-persistent-props-serialization", + "arkui-persistencev2-connect-serialization" ], "builtin": [ "arkts-builtin-thisArgs", "arkts-builtin-symbol-iterator", "arkts-builtin-no-property-descriptor", - "arkts-builtin-cotr" + "arkts-builtin-cotr", + "arkts-builtin-new-cotr", + "arkts-builtin-uninitialized-element", + "arkts-builtin-final-class", + "arkts-builtin-narrow-types", + "arkts-builtin-disable-api", + "arkts-builtin-iterator-result-value" ], "OHMURL": [ "arkts-require-fullpath-name" diff --git a/ets2panda/linter/src/cli/LinterCLI.ts b/ets2panda/linter/src/cli/LinterCLI.ts index 447a2358d12e80890328e3fad0331113b17bb781..b0851047c3eadefc9979b370d2ba43bb22941f7b 100644 --- a/ets2panda/linter/src/cli/LinterCLI.ts +++ b/ets2panda/linter/src/cli/LinterCLI.ts @@ -128,6 +128,12 @@ async function executeHomeCheckTask(scanTaskRelatedInfo: ScanTaskRelatedInfo): P migrationTool = null; scanTaskRelatedInfo.homeCheckResult = transferIssues2ProblemInfo(result); for (const [filePath, problems] of scanTaskRelatedInfo.homeCheckResult) { + if ( + !scanTaskRelatedInfo.cmdOptions.scanWholeProjectInHomecheck && + !scanTaskRelatedInfo.cmdOptions.inputFiles.includes(filePath) + ) { + continue; + } if (!scanTaskRelatedInfo.mergedProblems.has(filePath)) { scanTaskRelatedInfo.mergedProblems.set(filePath, []); } diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 4d5245cdc2f123c5db1c9c52c19bff2eaee7e1a9..eb595308cac9c0bae430abd512ea4c59799469a3 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -90,7 +90,7 @@ cookBookTag[59] = '"delete" operator is not supported (arkts-no-delete)'; cookBookTag[60] = '"typeof" operator is allowed only in expression contexts (arkts-no-type-query)'; cookBookTag[61] = 'The bitwise inversion gives different result for "Infinity" (arkts-distinct-infinity-bitwise-inversion)'; -cookBookTag[62] = ''; +cookBookTag[62] = 'Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)'; cookBookTag[63] = ''; cookBookTag[64] = ''; cookBookTag[65] = '"instanceof" operator is partially supported (arkts-instanceof-ref-types)'; @@ -240,6 +240,8 @@ cookBookTag[185] = 'syntax for import type is disabled (arkts-import-types)'; cookBookTag[186] = '"new" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)'; cookBookTag[187] = 'function "Math.pow()" behavior for ArkTS differs from Typescript version (arkts-math-pow-standard-diff)'; +cookBookTag[188] = + 'In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)'; cookBookTag[189] = 'Numeric semantics is different for integer values (arkts-numeric-semantic)'; cookBookTag[190] = 'Stricter assignments into variables of function type (arkts-incompatible-function-types)'; cookBookTag[191] = 'ASON is not supported. (arkts-no-need-stdlib-ason)'; @@ -298,8 +300,6 @@ cookBookTag[268] = 'Direct usage of interop JS objects is not supported (arkts-i cookBookTag[269] = 'Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-expand-static-instance)'; cookBookTag[270] = 'ArkTS1.2 cannot catch a non Error instance thrown from JS code (arkts-interop-js2s-js-exception)'; -cookBookTag[271] = - 'After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)'; cookBookTag[272] = 'This API of process is obsolete in ArkTS 1.1. It\'s no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)'; cookBookTag[273] = @@ -415,10 +415,23 @@ cookBookTag[381] = 'The code block passed to stateStyles needs to be an arrow function (arkui-statestyles-block-need-arrow-func)'; cookBookTag[382] = 'Promiseconstructor only supports using resolve (undefined) (arkts-promise-with-void-type-need-undefined-as-resolve-arg)'; +cookBookTag[391] = + 'The class of the second parameter passed to the "persistProp" method must be a primitive type or Date type, or implement the "toJson" and "fromJson" methods (arkui-persistent-prop-serialization)'; +cookBookTag[392] = + 'The class of the "defaultValue" parameter in the literal passed to the "persistProps" method must be a primitive type or Date type, or implement the "toJson" and "fromJson" methods (arkui-persistent-props-serialization)'; +cookBookTag[393] = + 'When calling the "globalConnect" and "connect" methods, the parameter list of the methods needs to include "toJson" and "fromJson" (arkui-persistencev2-connect-serialization)'; cookBookTag[399] = 'ArkUI deprecated api check (arkui-no-deprecated-api)'; cookBookTag[400] = 'ArkUI sdk common deprecated api check (arkui-sdk-common-deprecated-api)'; cookBookTag[401] = 'ArkUI sdk common whitelist api check (arkui-sdk-common-whitelist-api)'; cookBookTag[402] = 'ArkUI sdk common behavior change api check (arkui-sdk-common-behaviorchange-api)'; +cookBookTag[403] = 'API is not support initial ctor signature (arkts-builtin-new-cotr)'; +cookBookTag[404] = + 'Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)'; +cookBookTag[405] = 'API is not support use class in this API (arkts-builtin-final-class)'; +cookBookTag[406] = 'Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)'; +cookBookTag[407] = 'API has been disabled (arkts-builtin-disable-api)'; +cookBookTag[408] = 'The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)'; for (let i = 0; i <= cookBookTag.length; i++) { cookBookMsg[i] = ''; diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index d52e47f4756d9fdfe24a71db39b9d9170a58f06e..d7d64f4e6731c3e9003559019352980f15ca4299 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -60,6 +60,7 @@ faultsAttrs[FaultID.UnaryArithmNotNumber] = new FaultAttributes(55); faultsAttrs[FaultID.DeleteOperator] = new FaultAttributes(59); faultsAttrs[FaultID.TypeQuery] = new FaultAttributes(60); faultsAttrs[FaultID.PrefixUnaryInfinity] = new FaultAttributes(61); +faultsAttrs[FaultID.TupleIndex] = new FaultAttributes(62); faultsAttrs[FaultID.InstanceofUnsupported] = new FaultAttributes(65); faultsAttrs[FaultID.InOperator] = new FaultAttributes(66); faultsAttrs[FaultID.DestructuringAssignment] = new FaultAttributes(69); @@ -153,6 +154,7 @@ faultsAttrs[FaultID.OptionalMethod] = new FaultAttributes(184); faultsAttrs[FaultID.ImportType] = new FaultAttributes(185); faultsAttrs[FaultID.DynamicCtorCall] = new FaultAttributes(186); faultsAttrs[FaultID.MathPow] = new FaultAttributes(187); +faultsAttrs[FaultID.InvalidAbstractOverrideReturnType] = new FaultAttributes(188); faultsAttrs[FaultID.NumericSemantics] = new FaultAttributes(189); faultsAttrs[FaultID.IncompationbleFunctionType] = new FaultAttributes(190); faultsAttrs[FaultID.LimitedStdLibNoASON] = new FaultAttributes(191); @@ -204,7 +206,6 @@ faultsAttrs[FaultID.InteropJsObjectCallStaticFunc] = new FaultAttributes(267, Pr faultsAttrs[FaultID.InteropJsObjectConditionJudgment] = new FaultAttributes(268); faultsAttrs[FaultID.InteropJsObjectExpandStaticInstance] = new FaultAttributes(269); faultsAttrs[FaultID.InteropJSFunctionInvoke] = new FaultAttributes(270); -faultsAttrs[FaultID.VariableMissingInitializer] = new FaultAttributes(271); faultsAttrs[FaultID.DeprecatedProcessApi] = new FaultAttributes(272); faultsAttrs[FaultID.NumericUnsignedShiftBehaviorChange] = new FaultAttributes(273); faultsAttrs[FaultID.MissingSuperCall] = new FaultAttributes(274); @@ -291,7 +292,16 @@ faultsAttrs[FaultID.NondecimalBigint] = new FaultAttributes(377); faultsAttrs[FaultID.UnsupportOperator] = new FaultAttributes(378); faultsAttrs[FaultID.StateStylesBlockNeedArrowFunc] = new FaultAttributes(381); faultsAttrs[FaultID.PromiseVoidNeedResolveArg] = new FaultAttributes(382); +faultsAttrs[FaultID.PersistentPropNeedImplementMethod] = new FaultAttributes(391); +faultsAttrs[FaultID.PersistentPropsNeedImplementMethod] = new FaultAttributes(392); +faultsAttrs[FaultID.PersistenceV2ConnectNeedAddParam] = new FaultAttributes(393); faultsAttrs[FaultID.NoDeprecatedApi] = new FaultAttributes(399); faultsAttrs[FaultID.SdkCommonApiDeprecated] = new FaultAttributes(400); faultsAttrs[FaultID.SdkCommonApiWhiteList] = new FaultAttributes(401); faultsAttrs[FaultID.SdkCommonApiBehaviorChange] = new FaultAttributes(402); +faultsAttrs[FaultID.BuiltinNewCtor] = new FaultAttributes(403); +faultsAttrs[FaultID.UninitializedArrayElements] = new FaultAttributes(404, ProblemSeverity.WARNING); +faultsAttrs[FaultID.BuiltinFinalClass] = new FaultAttributes(405); +faultsAttrs[FaultID.BuiltinNarrowTypes] = new FaultAttributes(406); +faultsAttrs[FaultID.BuiltinDisableApi] = new FaultAttributes(407); +faultsAttrs[FaultID.BuiltinIteratorResultValue] = new FaultAttributes(408); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index d2753c7fb5bb2837f6f6bcdb24b593be1c7bb459..eebe9aef4135256a9c5b2b7969053f719af631be 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -91,6 +91,7 @@ faultDesc[FaultID.TemplateStringType] = 'Template string type'; faultDesc[FaultID.ShorthandAmbientModuleDecl] = 'Shorthand ambient module declaration'; faultDesc[FaultID.LongNumeric] = 'Use long for big numbers'; faultDesc[FaultID.WildcardsInModuleName] = 'Wildcards in module name'; +faultDesc[FaultID.TupleIndex] = 'Non-negative integer index for tuples'; faultDesc[FaultID.UMDModuleDefinition] = 'UMD module definition'; faultDesc[FaultID.NewTarget] = '"new.target" meta-property'; faultDesc[FaultID.DefiniteAssignment] = faultDesc[FaultID.DefiniteAssignmentError] = 'Definite assignment assertion'; @@ -147,6 +148,7 @@ faultDesc[FaultID.OptionalMethod] = 'Optional method'; faultDesc[FaultID.ImportType] = 'Import type syntax'; faultDesc[FaultID.DynamicCtorCall] = 'Dynamic constructor call'; faultDesc[FaultID.MathPow] = 'Exponent call'; +faultDesc[FaultID.InvalidAbstractOverrideReturnType] = 'Missing return type on abstract method'; faultDesc[FaultID.IncompationbleFunctionType] = 'Incompationble function type'; faultDesc[FaultID.VoidOperator] = 'Void operator'; faultDesc[FaultID.ExponentOp] = 'Exponent operation'; @@ -173,7 +175,6 @@ faultDesc[FaultID.MethodOverridingField] = '"Method overriding field" to keep st faultDesc[FaultID.InteropJsObjectConditionJudgment] = 'Interop JS Object usage in a condition'; faultDesc[FaultID.InteropJsObjectExpandStaticInstance] = 'Interop JS function usage'; faultDesc[FaultID.InteropJSFunctionInvoke] = 'Interop JS function invoke'; -faultDesc[FaultID.VariableMissingInitializer] = 'Value must be assigned to variable'; faultDesc[FaultID.NotSupportTupleGenericValidation] = 'No Tuple type in Generic'; faultDesc[FaultID.DeprecatedProcessApi] = 'This process Api no longer supported in ArkTS 1.2'; faultDesc[FaultID.ExplicitFunctionType] = 'Not explicit function type'; @@ -285,3 +286,12 @@ faultDesc[FaultID.NoESObjectSupport] = 'ESObject type cannot be used'; faultDesc[FaultID.SdkCommonApiDeprecated] = 'ArkUI sdk common deprecated api check'; faultDesc[FaultID.SdkCommonApiWhiteList] = 'ArkUI sdk common whiteList api check'; faultDesc[FaultID.SdkCommonApiBehaviorChange] = 'ArkUI sdk common behavior change api check'; +faultDesc[FaultID.PersistentPropNeedImplementMethod] = 'Serialization needs class to implement the specific methods'; +faultDesc[FaultID.PersistentPropsNeedImplementMethod] = 'Serialization needs class to implement the specific methods'; +faultDesc[FaultID.PersistenceV2ConnectNeedAddParam] = 'Serialization needs class to implement the specific methods'; +faultDesc[FaultID.BuiltinNewCtor] = 'Api is not support ctor-signature in builtin'; +faultDesc[FaultID.UninitializedArrayElements] = 'Uninitialized array elements'; +faultDesc[FaultID.BuiltinFinalClass] = 'Not support use class in this APIe'; +faultDesc[FaultID.BuiltinNarrowTypes] = 'Using narrowing of types is not allowed'; +faultDesc[FaultID.BuiltinDisableApi] = 'Disable Api'; +faultDesc[FaultID.BuiltinIteratorResultValue] = 'IteratorResult.value is not supported'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index d607d731b137835c97f5cc8fd29fe9796cd46104..99bdbd2687631ae524ae1fa6b16bbb66e35439d0 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -145,6 +145,7 @@ export enum FaultID { ImportType, DynamicCtorCall, MathPow, + InvalidAbstractOverrideReturnType, VoidOperator, ExponentOp, RegularExpressionLiteral, @@ -163,6 +164,7 @@ export enum FaultID { ArrayIndexExprType, AvoidUnionTypes, NoTuplesArrays, + TupleIndex, DoubleExclaBindingNotSupported, DoubleDollarBindingNotSupported, DollarBindingNotSupported, @@ -193,7 +195,6 @@ export enum FaultID { InteropDirectAccessToTSTypes, InteropTSFunctionInvoke, InteropJSFunctionInvoke, - VariableMissingInitializer, DeprecatedProcessApi, LimitedVoidTypeFromSdk, EntryAnnotation, @@ -284,6 +285,15 @@ export enum FaultID { SdkCommonApiDeprecated, SdkCommonApiWhiteList, SdkCommonApiBehaviorChange, + PersistentPropNeedImplementMethod, + PersistentPropsNeedImplementMethod, + PersistenceV2ConnectNeedAddParam, + BuiltinNewCtor, + UninitializedArrayElements, + BuiltinFinalClass, + BuiltinNarrowTypes, + BuiltinDisableApi, + BuiltinIteratorResultValue, // this should always be last enum LAST_ID } diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 2658cb6a0d25c67bc325d128ec695ae4c4794efe..c2f34353a2db30f452eaef4924a29ee0b0c75eb1 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -65,7 +65,20 @@ import { } from './utils/consts/SendableAPI'; import { DEFAULT_COMPATIBLE_SDK_VERSION, DEFAULT_COMPATIBLE_SDK_VERSION_STAGE } from './utils/consts/VersionInfo'; import { TYPED_ARRAYS } from './utils/consts/TypedArrays'; -import { BUILTIN_CONSTRUCTORS, COLLECTION_METHODS, COLLECTION_TYPES } from './utils/consts/BuiltinWhiteList'; +import { + BuiltinProblem, + BuiltinProblemInfos, + SYMBOL_ITERATOR, + BUILTIN_CONSTRUCTORS, + COLLECTION_METHODS, + COLLECTION_TYPES, + BUILTIN_TYPE, + BUILTIN_DISABLE_CALLSIGNATURE, + GET_OWN_PROPERTY_NAMES_TEXT, + BUILTIN_CONSTRUCTOR_API_TYPE, + BUILTIN_CONSTRUCTOR_API_NAME, + BUILTIN_CALLSIGNATURE_NEWCTOR +} from './utils/consts/BuiltinWhiteList'; import { forEachNodeInSubtree } from './utils/functions/ForEachNodeInSubtree'; import { hasPredecessor } from './utils/functions/HasPredecessor'; import { isStdLibrarySymbol, isStdLibraryType } from './utils/functions/IsStdLibrary'; @@ -122,7 +135,15 @@ import { VIRTUAL_SCROLL_IDENTIFIER, BUILDERNODE_D_TS, BuilderNodeFunctionName, - NESTING_BUILDER_SUPPORTED + NESTING_BUILDER_SUPPORTED, + COMMON_TS_ETS_API_D_TS, + UI_STATE_MANAGEMENT_D_TS, + PERSIST_PROP_FUNC_NAME, + PERSIST_PROPS_FUNC_NAME, + GLOBAL_CONNECT_FUNC_NAME, + CONNECT_FUNC_NAME, + serializationTypeFlags, + serializationTypeName } from './utils/consts/ArkuiConstants'; import { arkuiImportList } from './utils/consts/ArkuiImportList'; import type { IdentifierAndArguments, ForbidenAPICheckResult } from './utils/consts/InteropAPI'; @@ -155,15 +176,15 @@ import { SDK_COMMON_FUNCTIONLIKE, SDK_COMMON_PROPERTYLIKE, SDK_COMMON_CONSTRUCTORLIKE, - SDK_COMMON_TYPEKEY + SDK_COMMON_TYPEKEY, + SDK_COMMON_TYPE } from './utils/consts/SdkCommonDeprecateWhiteList'; -import { DeprecateProblem, DEPRECATE_CHECK_KEY, DEPRECATE_UNNAMED } from './utils/consts/DeprecateWhiteList'; import { - BuiltinProblem, - SYMBOL_ITERATOR, - BUILTIN_DISABLE_CALLSIGNATURE, - GET_OWN_PROPERTY_NAMES_TEXT -} from './utils/consts/BuiltinWhiteList'; + DeprecateProblem, + DEPRECATE_CHECK_KEY, + DEPRECATE_UNNAMED, + DEPRECATE_TYPE +} from './utils/consts/DeprecateWhiteList'; import { USE_SHARED, USE_CONCURRENT, @@ -223,6 +244,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { static pathMap: Map>; static indexedTypeSet: Set; static globalApiInfo: Map>; + static builtApiInfo: Set; + static builtinNewCtorSet: Set; + static builtinFinalClassSet: Set; static deprecatedApiInfo: Set; static sdkCommonApiInfo: Set; static sdkCommonSymbotIterSet: Set; @@ -240,6 +264,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { TypeScriptLinter.nameSpaceFunctionCache = new Map>(); TypeScriptLinter.pathMap = new Map>(); TypeScriptLinter.globalApiInfo = new Map>(); + TypeScriptLinter.builtApiInfo = new Set(); + TypeScriptLinter.builtinNewCtorSet = new Set(); + TypeScriptLinter.builtinFinalClassSet = new Set(); TypeScriptLinter.deprecatedApiInfo = new Set(); TypeScriptLinter.sdkCommonApiInfo = new Set(); TypeScriptLinter.funcMap = new Map>>(); @@ -274,6 +301,12 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { case BuiltinProblem.LimitedThisArg: TypeScriptLinter.initSdkBuiltinThisArgsWhitelist(item); break; + case BuiltinProblem.BuiltinNewCtor: + TypeScriptLinter.builtinNewCtorSet.add(item); + break; + case BuiltinProblem.BuiltinFinalClass: + TypeScriptLinter.builtinFinalClassSet.add(item); + break; default: } } @@ -368,6 +401,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const list: ApiList = new ApiList(builtinWhiteList); if (list?.api_list?.length > 0) { for (const item of list.api_list) { + this.builtApiInfo.add(item); TypeScriptLinter.addGlobalApiInfosCollocetionData(item); } } @@ -1445,6 +1479,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.checkFunctionProperty(propertyAccessNode, baseExprSym, baseExprType); this.handleSdkForConstructorFuncs(propertyAccessNode); this.fixJsImportPropertyAccessExpression(node); + this.handleBuiltinIteratorResult(propertyAccessNode); } private handlePropertyAccessExpressionForUI(node: ts.PropertyAccessExpression): void { @@ -2754,45 +2789,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handlePropertyDescriptorInScenarios(tsVarDecl); this.handleSdkGlobalApi(tsVarDecl); this.handleNoDeprecatedApi(tsVarDecl); - this.handleMissingInitializer(tsVarDecl); this.checkNumericSemanticsForVariable(tsVarDecl); } - /** - * Reports an error if a `let`/`const` declaration lacks an initializer. - */ - private handleMissingInitializer(decl: ts.VariableDeclaration): void { - if (!this.options.arkts2) { - return; - } - - const list = decl.parent as ts.VariableDeclarationList; - if (!(list.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const))) { - return; - } - - // Skip for‐of/for‐in loop bindings - const parentStmt = list.parent; - if (ts.isForOfStatement(parentStmt) || ts.isForInStatement(parentStmt)) { - return; - } - - // Skip explicit function‐type declarations (they are more like methods) - if (decl.type && ts.isFunctionTypeNode(decl.type)) { - return; - } - - // Skip variables declared as void—voids are handled by a different rule - if (decl.type && decl.type.kind === ts.SyntaxKind.VoidKeyword) { - return; - } - - // If no initializer, report - if (!decl.initializer) { - this.incrementCounters(decl.name, FaultID.VariableMissingInitializer); - } - } - private checkNumericSemanticsForBinaryExpression(node: ts.BinaryExpression): void { if (!this.options.arkts2) { return; @@ -3924,6 +3923,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleLimitedVoidFunction(tsMethodDecl); this.checkVoidLifecycleReturn(tsMethodDecl); this.handleNoDeprecatedApi(tsMethodDecl); + this.checkAbstractOverrideReturnType(tsMethodDecl); } private checkObjectPublicApiMethods(node: ts.ClassDeclaration | ts.InterfaceDeclaration): void { @@ -4272,7 +4272,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!this.isTypeSameOrWider(baseParamType, derivedParamType)) { this.incrementCounters(derivedParams[i], FaultID.MethodInheritRule); - } + } } } @@ -4402,7 +4402,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } if (this.checkTypeInheritance(derivedType, baseType, false)) { - return true; + return true; } const baseTypeSet = new Set(this.flattenUnionTypes(baseType)); @@ -4438,7 +4438,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } - if(this.checkTypeInheritance(fromType, toType)) { + if (this.checkTypeInheritance(fromType, toType)) { return true; } @@ -4453,11 +4453,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { }); } - private checkTypeInheritance( - sourceType: ts.Type, - targetType: ts.Type, - isSouceTotaqrget: boolean = true - ): boolean { + private checkTypeInheritance(sourceType: ts.Type, targetType: ts.Type, isSouceTotaqrget: boolean = true): boolean { // Early return if either type lacks symbol information if (!sourceType.symbol || !targetType.symbol) { return false; @@ -4469,7 +4465,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { // Get inheritance chain and check for relationship const inheritanceChain = this.getTypeInheritanceChain(typeToGetChain); - return inheritanceChain.some(t => { + return inheritanceChain.some((t) => { return t.symbol === typeToCheck.symbol; }); } @@ -4479,12 +4475,14 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const declarations = type.symbol?.getDeclarations() || []; for (const declaration of declarations) { - if ((!ts.isClassDeclaration(declaration) && !ts.isInterfaceDeclaration(declaration)) || - !declaration.heritageClauses) { + if ( + !ts.isClassDeclaration(declaration) && !ts.isInterfaceDeclaration(declaration) || + !declaration.heritageClauses + ) { continue; } - const heritageClauses = declaration.heritageClauses.filter(clause => { + const heritageClauses = declaration.heritageClauses.filter((clause) => { return clause.token === ts.SyntaxKind.ExtendsKeyword || clause.token === ts.SyntaxKind.ImplementsKeyword; }); @@ -4997,6 +4995,10 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { ); const tsElemAccessArgType = this.tsTypeChecker.getTypeAtLocation(tsElementAccessExpr.argumentExpression); + if (this.options.arkts2 && this.tsUtils.isOrDerivedFrom(tsElemAccessBaseExprType, TsUtils.isTuple)) { + this.handleTupleIndex(tsElementAccessExpr); + } + if (this.tsUtils.hasEsObjectType(tsElementAccessExpr.expression)) { const faultId = this.options.arkts2 ? FaultID.EsValueTypeError : FaultID.EsValueType; this.incrementCounters(node, faultId); @@ -5013,6 +5015,80 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleNoDeprecatedApi(tsElementAccessExpr); } + private handleTupleIndex(expr: ts.ElementAccessExpression): void { + const value = expr.argumentExpression; + + if (this.isArgumentConstDotZero(value)) { + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + return; + } + + if (ts.isNumericLiteral(value)) { + const indexText = value.getText(); + const indexValue = Number(indexText); + const isValid = Number.isInteger(indexValue) && indexValue >= 0; + + if (!isValid) { + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + } + return; + } + + if (ts.isPrefixUnaryExpression(value)) { + const { operator, operand } = value; + const resolved = this.evaluateValueFromDeclaration(operand); + + if (typeof resolved === 'number') { + const final = operator === ts.SyntaxKind.MinusToken ? -resolved : resolved; + const isValid = Number.isInteger(final) && final >= 0; + if (!isValid) { + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + } + return; + } + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + return; + } + + const resolved = this.evaluateValueFromDeclaration(value); + if (typeof resolved === 'number') { + const isValid = Number.isInteger(resolved) && resolved >= 0; + if (!isValid) { + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + } + return; + } + + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + } + + private isArgumentConstDotZero(expr: ts.Expression): boolean { + if (ts.isNumericLiteral(expr)) { + return expr.getText().endsWith('.0'); + } + + if (ts.isPrefixUnaryExpression(expr) && ts.isNumericLiteral(expr.operand)) { + return expr.operand.getText().endsWith('.0'); + } + + if (ts.isIdentifier(expr)) { + const declaration = this.tsUtils.getDeclarationNode(expr); + if (declaration && ts.isVariableDeclaration(declaration) && declaration.initializer) { + const init = declaration.initializer; + + if (ts.isNumericLiteral(init)) { + return init.getText().endsWith('.0'); + } + + if (ts.isPrefixUnaryExpression(init) && ts.isNumericLiteral(init.operand)) { + return init.operand.getText().endsWith('.0'); + } + } + } + + return false; + } + private checkPropertyAccessByIndex( tsElementAccessExpr: ts.ElementAccessExpression, tsElemAccessBaseExprType: ts.Type, @@ -5199,14 +5275,17 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!initializer) { return null; } - - if (!ts.isNumericLiteral(initializer)) { - return null; - } - - const numericValue = Number(initializer.text); - if (!Number.isInteger(numericValue)) { - return null; + let numericValue: number | null = null; + if (ts.isNumericLiteral(initializer)) { + numericValue = Number(initializer.text); + } else if (ts.isPrefixUnaryExpression(initializer) && ts.isNumericLiteral(initializer.operand)) { + const rawValue = Number(initializer.operand.text); + numericValue = + initializer.operator === ts.SyntaxKind.MinusToken ? + -rawValue : + initializer.operator === ts.SyntaxKind.PlusToken ? + rawValue : + null; } return numericValue; @@ -5447,52 +5526,146 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } - private handleCallExpression(node: ts.Node): void { - const tsCallExpr = node as ts.CallExpression; - this.checkSdkAbilityLifecycleMonitor(tsCallExpr); - this.handleCallExpressionForUI(tsCallExpr); - this.handleBuiltinCtorCallSignature(tsCallExpr); - this.handleSdkConstructorIfaceForCallExpression(tsCallExpr); - if (this.options.arkts2 && tsCallExpr.typeArguments !== undefined) { - this.handleSdkPropertyAccessByIndex(tsCallExpr); + private handleCallExpression(callExpr: ts.CallExpression): void { + this.checkSdkAbilityLifecycleMonitor(callExpr); + this.handleCallExpressionForUI(callExpr); + this.handleBuiltinCtorCallSignature(callExpr); + this.handleSdkConstructorIfaceForCallExpression(callExpr); + if (this.options.arkts2 && callExpr.typeArguments !== undefined) { + this.handleSdkPropertyAccessByIndex(callExpr); } - const calleeSym = this.tsUtils.trueSymbolAtLocation(tsCallExpr.expression); - const callSignature = this.tsTypeChecker.getResolvedSignature(tsCallExpr); - this.handleImportCall(tsCallExpr); - this.handleRequireCall(tsCallExpr); + const calleeSym = this.tsUtils.trueSymbolAtLocation(callExpr.expression); + const callSignature = this.tsTypeChecker.getResolvedSignature(callExpr); + this.handleImportCall(callExpr); + this.handleRequireCall(callExpr); if (calleeSym !== undefined) { - this.processCalleeSym(calleeSym, tsCallExpr); + this.processCalleeSym(calleeSym, callExpr); } if (callSignature !== undefined) { if (!this.tsUtils.isLibrarySymbol(calleeSym)) { - this.handleStructIdentAndUndefinedInArgs(tsCallExpr, callSignature); - this.handleGenericCallWithNoTypeArgs(tsCallExpr, callSignature); + this.handleStructIdentAndUndefinedInArgs(callExpr, callSignature); + this.handleGenericCallWithNoTypeArgs(callExpr, callSignature); } else if (this.options.arkts2) { - this.handleGenericCallWithNoTypeArgs(tsCallExpr, callSignature); + this.handleGenericCallWithNoTypeArgs(callExpr, callSignature); } - this.handleNotsLikeSmartTypeOnCallExpression(tsCallExpr, callSignature); + this.handleNotsLikeSmartTypeOnCallExpression(callExpr, callSignature); } - this.handleInteropForCallExpression(tsCallExpr); - this.handleLibraryTypeCall(tsCallExpr); + this.handleInteropForCallExpression(callExpr); + this.handleLibraryTypeCall(callExpr); if ( - ts.isPropertyAccessExpression(tsCallExpr.expression) && - this.tsUtils.hasEsObjectType(tsCallExpr.expression.expression) + ts.isPropertyAccessExpression(callExpr.expression) && + this.tsUtils.hasEsObjectType(callExpr.expression.expression) ) { const faultId = this.options.arkts2 ? FaultID.EsValueTypeError : FaultID.EsValueType; - this.incrementCounters(node, faultId); + this.incrementCounters(callExpr, faultId); + } + this.handleLimitedVoidWithCall(callExpr); + this.fixJsImportCallExpression(callExpr); + this.handleInteropForCallJSExpression(callExpr, calleeSym, callSignature); + this.handleNoTsLikeFunctionCall(callExpr); + this.handleObjectLiteralInFunctionArgs(callExpr); + this.handleSdkGlobalApi(callExpr); + this.handleObjectLiteralAssignmentToClass(callExpr); + this.checkRestrictedAPICall(callExpr); + this.handleNoDeprecatedApi(callExpr); + this.handleFunctionReturnThisCall(callExpr); + this.handlePromiseTupleGeneric(callExpr); + this.checkArgumentTypeOfCallExpr(callExpr, callSignature); + this.handleTupleGeneric(callExpr); + } + + private checkArgumentTypeOfCallExpr(callExpr: ts.CallExpression, signature: ts.Signature | undefined): void { + if (!this.options.arkts2) { + return; + } + if (!signature) { + return; + } + + const args = callExpr.arguments; + if (args.length === 0) { + return; + } + + for (const [idx, arg] of args.entries()) { + this.isArgumentAndParameterMatch(signature, arg, idx); + } + } + + private isArgumentAndParameterMatch(signature: ts.Signature, arg: ts.Expression, idx: number): void { + if (!ts.isPropertyAccessExpression(arg)) { + return; + } + + let rootObject = arg.expression; + + while (ts.isPropertyAccessExpression(rootObject)) { + rootObject = rootObject.expression; + } + + if (rootObject.kind !== ts.SyntaxKind.ThisKeyword) { + return; + } + + const param = signature.parameters.at(idx); + if (!param) { + return; + } + const paramDecl = param.getDeclarations(); + if (!paramDecl || paramDecl.length === 0) { + return; + } + + const paramFirstDecl = paramDecl[0]; + if (!ts.isParameter(paramFirstDecl)) { + return; + } + + const paramTypeNode = paramFirstDecl.type; + const argumentType = this.tsTypeChecker.getTypeAtLocation(arg); + if (!paramTypeNode) { + return; + } + + if (!paramTypeNode) { + return; + } + + const argumentTypeString = this.tsTypeChecker.typeToString(argumentType); + if (ts.isUnionTypeNode(paramTypeNode)) { + this.checkUnionTypesMatching(arg, paramTypeNode, argumentTypeString); + } else { + this.checkSingleTypeMatching(paramTypeNode, arg, argumentTypeString); + } + } + + private checkSingleTypeMatching(paramTypeNode: ts.TypeNode, arg: ts.Node, argumentTypeString: string): void { + const paramType = this.tsTypeChecker.getTypeFromTypeNode(paramTypeNode); + const paramTypeString = this.tsTypeChecker.typeToString(paramType); + if (TsUtils.isIgnoredTypeForParameterType(paramTypeString, paramType)) { + return; + } + + if (argumentTypeString !== paramTypeString) { + this.incrementCounters(arg, FaultID.StructuralIdentity); + } + } + + private checkUnionTypesMatching(arg: ts.Node, paramTypeNode: ts.UnionTypeNode, argumentTypeString: string): void { + let notMatching = true; + for (const type of paramTypeNode.types) { + const paramType = this.tsTypeChecker.getTypeFromTypeNode(type); + const paramTypeString = this.tsTypeChecker.typeToString(paramType); + notMatching = !TsUtils.isIgnoredTypeForParameterType(paramTypeString, paramType); + + if (argumentTypeString === paramTypeString) { + notMatching = false; + } + } + + if (notMatching) { + this.incrementCounters(arg, FaultID.StructuralIdentity); } - this.handleLimitedVoidWithCall(tsCallExpr); - this.fixJsImportCallExpression(tsCallExpr); - this.handleInteropForCallJSExpression(tsCallExpr, calleeSym, callSignature); - this.handleNoTsLikeFunctionCall(tsCallExpr); - this.handleObjectLiteralInFunctionArgs(tsCallExpr); - this.handleSdkGlobalApi(tsCallExpr); - this.handleObjectLiteralAssignmentToClass(tsCallExpr); - this.checkRestrictedAPICall(tsCallExpr); - this.handleNoDeprecatedApi(tsCallExpr); - this.handleFunctionReturnThisCall(tsCallExpr); - this.handlePromiseTupleGeneric(tsCallExpr); - this.handleTupleGeneric(tsCallExpr); } private handleTupleGeneric(callExpr: ts.CallExpression): void { @@ -5529,6 +5702,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleStateStyles(node); this.handleCallExpressionForRepeat(node); this.handleNodeForWrappedBuilder(node); + this.handleCallExpressionForSerialization(node); } handleNoTsLikeFunctionCall(callExpr: ts.CallExpression): void { @@ -6311,6 +6485,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleInstantiatedJsObject(tsNewExpr, sym); this.handlePromiseNeedVoidResolve(tsNewExpr); this.handleFunctionReturnThisCall(tsNewExpr); + this.checkArrayInitialization(tsNewExpr); } handlePromiseNeedVoidResolve(newExpr: ts.NewExpression): void { @@ -7402,6 +7577,16 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } this.handleNotSupportCustomDecorators(decorator); + switch (decorator.parent.kind) { + case ts.SyntaxKind.PropertyDeclaration: + case ts.SyntaxKind.ClassDeclaration: + case ts.SyntaxKind.MethodDeclaration: + case ts.SyntaxKind.Parameter: + this.handleBuiltinDisableDecorator(decorator); + break; + default: + break; + } } private handleProvideDecorator(node: ts.Node): void { @@ -8252,6 +8437,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!this.options.arkts2) { return; } + this.handleNoDeprecatedApi(node as ts.TaggedTemplateExpression); this.incrementCounters(node, FaultID.TaggedTemplates); } @@ -10607,6 +10793,110 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return undefined; } + /** + * If a class method overrides a base-class abstract method that had no explicit return type, + * then any explicit return type other than `void` is an error. + * Also flags async overrides with no explicit annotation. + */ + private checkAbstractOverrideReturnType(method: ts.MethodDeclaration): void { + if (!this.options.arkts2) { + return; + } + + const baseClass = this.getDirectBaseClassOfGivenMethodDecl(method); + if (!baseClass) { + return; + } + + // Locate the abstract method in the inheritance chain + const methodName = method.name.getText(); + const baseMethod = this.findAbstractMethodInBaseChain(baseClass, methodName); + if (!baseMethod) { + return; + } + + // Only if base had no explicit return type + if (baseMethod.type) { + return; + } + + // If override declares a return type, and it isn't void → error + if (method.type && method.type.kind !== ts.SyntaxKind.VoidKeyword) { + const target = ts.isIdentifier(method.name) ? method.name : method; + this.incrementCounters(target, FaultID.InvalidAbstractOverrideReturnType); + + // Also catch async overrides with no explicit annotation (defaulting to Promise) + } else if (TsUtils.hasModifier(method.modifiers, ts.SyntaxKind.AsyncKeyword)) { + const target = ts.isIdentifier(method.name) ? method.name : method; + this.incrementCounters(target, FaultID.InvalidAbstractOverrideReturnType); + } + } + + /** + * Finds the direct superclass declaration for the given method's containing class. + * Returns undefined if the class has no extends clause or cannot resolve the base class. + */ + private getDirectBaseClassOfGivenMethodDecl(method: ts.MethodDeclaration): ts.ClassDeclaration | undefined { + // Must live in a class with an extends clause + const classDecl = method.parent; + if (!ts.isClassDeclaration(classDecl) || !classDecl.heritageClauses) { + return undefined; + } + + return this.getBaseClassDeclFromHeritageClause(classDecl.heritageClauses); + } + + /** + * Walks up the inheritance chain starting from `startClass` to find an abstract method + * named `methodName`. Returns the MethodDeclaration if found, otherwise `undefined`. + */ + private findAbstractMethodInBaseChain( + startClass: ts.ClassDeclaration, + methodName: string + ): ts.MethodDeclaration | undefined { + // Prevent infinite loops from circular extends + const visited = new Set(); + let current: ts.ClassDeclaration | undefined = startClass; + while (current && !visited.has(current)) { + visited.add(current); + const found = current.members.find((m) => { + return ( + ts.isMethodDeclaration(m) && + ts.isIdentifier(m.name) && + m.name.text === methodName && + TsUtils.hasModifier(m.modifiers, ts.SyntaxKind.AbstractKeyword) + ); + }) as ts.MethodDeclaration | undefined; + if (found) { + return found; + } + current = this.getBaseClassDeclFromHeritageClause(current.heritageClauses); + } + return undefined; + } + + getBaseClassDeclFromHeritageClause(clauses?: ts.NodeArray): ts.ClassDeclaration | undefined { + if (!clauses) { + return undefined; + } + + const ext = clauses.find((h) => { + return h.token === ts.SyntaxKind.ExtendsKeyword; + }); + if (!ext || ext.types.length === 0) { + return undefined; + } + + // Resolve the base-class declaration + const expr = ext.types[0].expression; + if (!ts.isIdentifier(expr)) { + return undefined; + } + + const sym = this.tsUtils.trueSymbolAtLocation(expr); + return sym?.declarations?.find(ts.isClassDeclaration); + } + /** * Checks for missing super() call in child classes that extend a parent class * with parameterized constructors. If parent class only has parameterized constructors @@ -10693,7 +10983,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { ) { continue; } - this.handleExtendCustomClassForSdkCommonApiDeprecated(extendedClassName, superCall); + this.handleExtendCustomClassForSdkApiDeprecated(extendedClassName, superCall, SDK_COMMON_TYPE); + this.handleExtendCustomClassForSdkApiDeprecated(extendedClassName, superCall, BUILTIN_TYPE); return; } @@ -10745,20 +11036,26 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { ); } - private handleExtendCustomClassForSdkCommonApiDeprecated( + private handleExtendCustomClassForSdkApiDeprecated( extendedClassName: string, - superCall: ts.CallExpression + superCall: ts.CallExpression, + apiType: string ): void { - const problemStr = TypeScriptLinter.getFaultIdSdkCommonApiInfoWithConstructorDecl(extendedClassName); + const problemStr = TypeScriptLinter.getFaultIdSdkApiInfoWithConstructorDecl(extendedClassName, apiType); if (problemStr) { const faultID = sdkCommonAllDeprecatedTypeName.has(extendedClassName) ? FaultID.SdkCommonApiDeprecated : - TypeScriptLinter.getFinalSdkFaultIdByProblem(problemStr); + TypeScriptLinter.getFinalSdkFaultIdByProblem(problemStr, apiType); + if (!faultID) { + return; + } this.incrementCounters( superCall, faultID, undefined, - TypeScriptLinter.getErrorMsgForSdkCommonApi(extendedClassName, faultID) + apiType === SDK_COMMON_TYPE ? + TypeScriptLinter.getErrorMsgForSdkCommonApi(extendedClassName, faultID) : + undefined ); } } @@ -13270,6 +13567,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { | ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.HeritageClause + | ts.TaggedTemplateExpression ): void { if (!this.options.arkts2) { return; @@ -13292,8 +13590,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.checkMethodDeclarationForDeprecatedApi(node); break; case ts.SyntaxKind.PropertyAssignment: - this.checkPropertyAssignmentForDeprecatedApi(node); - break; + case ts.SyntaxKind.TaggedTemplateExpression: case ts.SyntaxKind.NewExpression: case ts.SyntaxKind.CallExpression: case ts.SyntaxKind.BinaryExpression: @@ -13312,6 +13609,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { | ts.BinaryExpression | ts.PropertyAccessExpression | ts.ElementAccessExpression + | ts.TaggedTemplateExpression + | ts.PropertyAssignment ): void { switch (node.kind) { case ts.SyntaxKind.NewExpression: @@ -13329,6 +13628,12 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { case ts.SyntaxKind.ElementAccessExpression: this.checkSdkCommonOnElementAccess(node); break; + case ts.SyntaxKind.TaggedTemplateExpression: + this.checkTaggedTemplateExpressionForBuiltinApi(node); + break; + case ts.SyntaxKind.PropertyAssignment: + this.checkPropertyAssignmentForDeprecatedApi(node); + break; default: } } @@ -13397,24 +13702,27 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (sym) { this.hanldeSdkCommonTypeName(node, sym, sym.name, decl); } - if (decl && (ts.isInterfaceDeclaration(decl) || ts.isClassDeclaration(decl))) { + if (decl && (ts.isInterfaceDeclaration(decl) || ts.isClassDeclaration(decl) || ts.isTypeAliasDeclaration(decl))) { let parentName = decl.name ? decl.name.text : 'unnamed'; if (ts.isQualifiedName(node.typeName)) { parentName = node.typeName.getText(); + } else if (ts.isTypeAliasDeclaration(decl)) { + parentName = ''; } const deprecatedApiCheckMap = TypeScriptLinter.updateDeprecatedApiCheckMap( parentName, undefined, - undefined, + ts.isTypeAliasDeclaration(decl) ? decl.type.getText() : undefined, path.basename(decl.getSourceFile().fileName + '') ); this.processApiNodeDeprecatedApi(typeName.getText(), typeName, deprecatedApiCheckMap); + this.processApiNodeDeprecatedApi(typeName.getText(), typeName, deprecatedApiCheckMap, undefined, BUILTIN_TYPE); } } private checkNewExpressionForDeprecatedApi(node: ts.NewExpression): void { const expression = node.expression; - this.checkNewExpressionForSdkCommonApi(node); + this.checkNewExpressionForSdkApi(node); if (ts.isIdentifier(expression)) { const decl = this.tsUtils.getDeclarationNode(expression); if (decl && ts.isClassDeclaration(decl)) { @@ -13429,7 +13737,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } - private checkNewExpressionForSdkCommonApi(newExpr: ts.NewExpression): void { + private checkNewExpressionForSdkApi(newExpr: ts.NewExpression): void { const type = this.tsTypeChecker.getTypeAtLocation(newExpr.expression); const resolvedSignature = this.tsTypeChecker.getResolvedSignature(newExpr); if (!resolvedSignature) { @@ -13451,11 +13759,48 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { newExpr.expression, deprecatedApiCheckMap, undefined, - true + SDK_COMMON_TYPE ); + if (BUILTIN_CALLSIGNATURE_NEWCTOR.includes(newExpr.expression.getText())) { + this.handleNewExpressionForBuiltNewCtor(newExpr.expression, deprecatedApiCheckMap); + } else { + this.processApiNodeDeprecatedApi( + BUILTIN_CONSTRUCTOR_API_NAME, + newExpr.expression, + deprecatedApiCheckMap, + undefined, + BUILTIN_TYPE + ); + } } } + private handleNewExpressionForBuiltNewCtor( + errorNode: ts.Node, + deprecatedApiCheckMap?: Map> + ): void { + if (TypeScriptLinter.builtinNewCtorSet.size === 0 || !deprecatedApiCheckMap) { + return; + } + [...TypeScriptLinter.builtinNewCtorSet].some((item) => { + if (item.api_info.parent_api?.length <= 0) { + return false; + } + const isBuiltinNewConstruct = + BUILTIN_CONSTRUCTOR_API_TYPE.includes(item.api_info.api_type) && + item.api_info.parent_api[0].api_name === deprecatedApiCheckMap?.get(DEPRECATE_CHECK_KEY.PARENT_NAME) + '' && + path.basename(item.file_path) === deprecatedApiCheckMap?.get(DEPRECATE_CHECK_KEY.FILE_NAME) + ''; + if (isBuiltinNewConstruct) { + const problemStr = item.api_info.problem; + if (problemStr.length > 0) { + this.incrementCounters(errorNode, FaultID.BuiltinNewCtor); + } + return true; + } + return false; + }); + } + private checkHeritageClauseForDeprecatedApi(node: ts.HeritageClause): void { node.types.forEach((type) => { let expr = type.expression; @@ -13466,11 +13811,16 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { expr = type.expression.name; } const decl = this.tsUtils.getDeclarationNode(expr); - this.checkHeritageClauseForSdkCommonApiDeprecated(node, decl); + this.checkHeritageClauseForSdkApiDeprecated(node, decl, SDK_COMMON_TYPE); + this.checkHeritageClauseForSdkApiDeprecated(node, decl, BUILTIN_TYPE); }); } - private checkHeritageClauseForSdkCommonApiDeprecated(node: ts.HeritageClause, decl: ts.Node | undefined): void { + private checkHeritageClauseForSdkApiDeprecated( + node: ts.HeritageClause, + decl: ts.Node | undefined, + apiType: string + ): void { if ( decl && (ts.isClassDeclaration(decl) || ts.isInterfaceDeclaration(decl)) && @@ -13478,35 +13828,45 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { decl.name ) { const extendClassName = decl.name.text; - if (TypeScriptLinter.checkIsSameAsParenName(extendClassName)) { + const newSet = TypeScriptLinter.refactorSetWhitSameAsParenName(extendClassName, apiType); + if (newSet && newSet.size > 0) { const sourceFunlikeArrs = node.parent.members.filter(ts.isFunctionLike); const sourceProDeclArrs = node.parent.members.filter(ts.isPropertyDeclaration); - this.checkSdkCommonApiInfoWithClassMember(sourceFunlikeArrs, extendClassName, SDK_COMMON_TYPEKEY[0]); - this.checkSdkCommonApiInfoWithClassMember(sourceProDeclArrs, extendClassName, SDK_COMMON_TYPEKEY[1]); + this.checkSdkApiInfoWithClassMember(sourceFunlikeArrs, decl, SDK_COMMON_TYPEKEY[0], apiType, newSet); + this.checkSdkApiInfoWithClassMember(sourceProDeclArrs, decl, SDK_COMMON_TYPEKEY[1], apiType, newSet); } } } - private checkSdkCommonApiInfoWithClassMember( + private checkSdkApiInfoWithClassMember( sourceMembers: ts.ClassElement[] | ts.PropertyDeclaration[], - extendClassName: string, - typeKey: string + decl: ts.ClassDeclaration | ts.InterfaceDeclaration, + typeKey: string, + apiType: string, + mergedSet: Set ): void { sourceMembers.some((func) => { - const funcName = func.name?.getText(); - if (!funcName) { + if (!func.name || !decl.name) { return; } - const problemStr = TypeScriptLinter.getFaultIdSdkCommonApiInfoWithClassMember(extendClassName, funcName, typeKey); + const funcName = func.name.getText(); + const extendClassName = decl.name.text; + const problemStr = TypeScriptLinter.getFaultIdSdkApiInfoWithClassMember(decl, funcName, typeKey, mergedSet); if (problemStr) { - const faultID = sdkCommonAllDeprecatedTypeName.has(extendClassName) ? - FaultID.SdkCommonApiDeprecated : - TypeScriptLinter.getFinalSdkFaultIdByProblem(problemStr); + let faultID = TypeScriptLinter.getFinalSdkFaultIdByProblem(problemStr, apiType); + if (apiType === SDK_COMMON_TYPE) { + faultID = sdkCommonAllDeprecatedTypeName.has(extendClassName) ? FaultID.SdkCommonApiDeprecated : faultID; + } + if (!faultID) { + return; + } this.incrementCounters( func, faultID, undefined, - TypeScriptLinter.getErrorMsgForSdkCommonApi(extendClassName, faultID) + apiType === SDK_COMMON_TYPE ? + TypeScriptLinter.getErrorMsgForSdkCommonApi(extendClassName, faultID) : + undefined ); } }); @@ -13516,14 +13876,27 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const sym = this.tsUtils.trueSymbolAtLocation(node); const decl = this.tsUtils.getDeclarationNode(node); if (decl && (ts.isInterfaceDeclaration(decl) || ts.isClassDeclaration(decl))) { + const fileName = path.basename(decl.getSourceFile().fileName + ''); const deprecatedApiCheckMap = TypeScriptLinter.updateDeprecatedApiCheckMap( decl.name?.getText() + '', undefined, undefined, - path.basename(decl.getSourceFile().fileName + '') + fileName ); this.processApiNodeDeprecatedApi(node.getText(), node, deprecatedApiCheckMap); this.hanldeSdkCommonTypeName(node, sym, decl.name?.getText() + '', decl); + this.hanldeBuiltinFinalClassOnHeritageClause(node, fileName); + } + } + + private hanldeBuiltinFinalClassOnHeritageClause(node: ts.Node, fileName: string): void { + let isMatch = false; + for (const item of TypeScriptLinter.builtinFinalClassSet) { + isMatch = item.api_info.api_name === node.getText() && path.basename(item.file_path) === fileName; + if (isMatch) { + this.incrementCounters(node, FaultID.BuiltinFinalClass); + break; + } } } @@ -13582,7 +13955,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleCallExpressionBufferIndexOf(node, name, parName + '', funSymbol, decl); const deprecatedApiCheckMap = TypeScriptLinter.getDeprecatedApiCheckMapForCallExpression(decl, parName); this.reportDeprecatedApi(node, name, deprecatedApiCheckMap); - this.checkCallExpressionForSdkCommonApi(node, name, parName, !!isNeedGetResolvedSignature, deprecatedApiCheckMap); + this.checkCallExpressionForSdkApi(node, name, parName, !!isNeedGetResolvedSignature, deprecatedApiCheckMap); this.checkSpecialApiForDeprecatedApi(node, name, decl); } @@ -13602,7 +13975,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return undefined; } - private checkCallExpressionForSdkCommonApi( + private checkCallExpressionForSdkApi( node: ts.CallExpression, name: ts.Identifier, parName: string | undefined, @@ -13610,13 +13983,14 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { deprecatedApiCheckMap: Map> | undefined ): void { if (isNeedGetResolvedSignature) { - this.checkCallExpressionForSdkCommonApiWithSignature(node, name, parName); + this.checkCallExpressionForSdkApiWithSignature(node, name, parName); } else { - this.reportDeprecatedApi(node, name, deprecatedApiCheckMap, true); + this.reportDeprecatedApi(node, name, deprecatedApiCheckMap, SDK_COMMON_TYPE); + this.reportDeprecatedApi(node, name, deprecatedApiCheckMap, BUILTIN_TYPE); } } - private checkCallExpressionForSdkCommonApiWithSignature( + private checkCallExpressionForSdkApiWithSignature( node: ts.CallExpression, name: ts.Identifier, parName: string | undefined @@ -13627,44 +14001,76 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } const functionSymbol = this.getFunctionSymbol(signature.declaration); const functionDeclaration = functionSymbol?.valueDeclaration; + let returnType = this.tsTypeChecker.typeToString(signature.getReturnType()); + let isSpecialTypeForBuiltIn = false; if (!functionDeclaration) { - return; + const signatureDecl = signature.getDeclaration(); + if (signatureDecl && ts.isFunctionLike(signatureDecl) && signatureDecl.type) { + returnType = signatureDecl.type.getText(); + if (!parName && BUILTIN_CALLSIGNATURE_NEWCTOR.includes(name.text)) { + const type = this.tsTypeChecker.getTypeAtLocation(name); + parName = this.tsTypeChecker.typeToString(type); + isSpecialTypeForBuiltIn = !!parName; + } + } } - const returnType = this.tsTypeChecker.typeToString(signature.getReturnType()); + const fileName = signature.getDeclaration().getSourceFile().fileName; const deprecatedApiCheckMap = TypeScriptLinter.updateDeprecatedApiCheckMap( parName === undefined ? '' : parName + '', TypeScriptLinter.getParameterDeclarationsBySignature(signature), returnType, - path.basename(functionDeclaration.getSourceFile().fileName) + path.basename(fileName) ); - this.reportDeprecatedApi(node, name, deprecatedApiCheckMap, true); + this.reportDeprecatedApi(node, name, deprecatedApiCheckMap, SDK_COMMON_TYPE); + if (isSpecialTypeForBuiltIn) { + this.processApiNodeDeprecatedApi( + BUILTIN_CONSTRUCTOR_API_NAME, + name, + deprecatedApiCheckMap, + undefined, + BUILTIN_TYPE + ); + } else { + this.reportDeprecatedApi(node, name, deprecatedApiCheckMap, BUILTIN_TYPE); + } } private reportDeprecatedApi( node: ts.CallExpression, name: ts.Identifier, deprecatedApiCheckMap?: Map>, - isSdkCommon?: boolean + apiType?: string ): void { - const problemStr = this.getFaultIdWithMatchedDeprecatedApi(name.text, deprecatedApiCheckMap, isSdkCommon); + const problemStr = this.getFaultIdWithMatchedDeprecatedApi(name.text, deprecatedApiCheckMap, apiType); if (problemStr.length > 0) { const autofix = this.autofixer?.fixDeprecatedApiForCallExpression(node); if (autofix) { this.interfacesNeedToImport.add('getUIContext'); } - const faultID = isSdkCommon ? TypeScriptLinter.getFinalSdkFaultIdByProblem(problemStr) : FaultID.NoDeprecatedApi; + const isSdkCommon = apiType === SDK_COMMON_TYPE; + const faultID = TypeScriptLinter.getFinalSdkFaultIdByProblem(problemStr, apiType); + if (!faultID) { + return; + } this.incrementCounters( name, faultID, - isSdkCommon ? undefined : autofix, + isSdkCommon || apiType === BUILTIN_TYPE ? undefined : autofix, isSdkCommon ? TypeScriptLinter.getErrorMsgForSdkCommonApi(name.text, faultID) : undefined ); } } - private static getFinalSdkFaultIdByProblem(problem: string): number { - const sdkFaultId = SdkCommonApiProblemInfos.get(problem); - return sdkFaultId ? sdkFaultId : FaultID.SdkCommonApiWhiteList; + private static getFinalSdkFaultIdByProblem(problem: string, apiType: string | undefined): number | undefined { + let sdkFaultId: number | undefined = FaultID.NoDeprecatedApi; + if (apiType === SDK_COMMON_TYPE) { + sdkFaultId = SdkCommonApiProblemInfos.get(problem); + return sdkFaultId ? sdkFaultId : FaultID.SdkCommonApiWhiteList; + } else if (apiType === BUILTIN_TYPE) { + sdkFaultId = BuiltinProblemInfos.get(problem); + return sdkFaultId ? sdkFaultId : undefined; + } + return sdkFaultId; } private checkSpecialApiForDeprecatedApi( @@ -13763,7 +14169,14 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { expression, this.getPropertyTypeForPropertyAssignment(node, contextualType, true), undefined, - true + SDK_COMMON_TYPE + ); + this.processApiNodeDeprecatedApi( + expression.getText(), + expression, + this.getPropertyTypeForPropertyAssignment(node, contextualType), + undefined, + BUILTIN_TYPE ); } } @@ -13797,7 +14210,14 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { path.basename(decl.getSourceFile().fileName) ); this.processApiNodeDeprecatedApi(expression.text, expression, deprecatedApiCheckMap); - this.processApiNodeDeprecatedApi(expression.text, expression, deprecatedApiCheckMap, undefined, true); + this.processApiNodeDeprecatedApi( + expression.text, + expression, + deprecatedApiCheckMap, + undefined, + SDK_COMMON_TYPE + ); + this.processApiNodeDeprecatedApi(expression.text, expression, deprecatedApiCheckMap, undefined, BUILTIN_TYPE); } }); } @@ -13940,6 +14360,33 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return isFileMatch; } + private checkTaggedTemplateExpressionForBuiltinApi(node: ts.TaggedTemplateExpression): void { + const expression = node.tag; + if (ts.isPropertyAccessExpression(expression)) { + const funSymbol = this.tsUtils.trueSymbolAtLocation(expression.name); + const decl = TsUtils.getDeclaration(funSymbol); + const parName = this.tsUtils.getParentSymbolName(funSymbol); + if (decl) { + const returnType: string | undefined = this.tsTypeChecker.typeToString( + this.tsTypeChecker.getTypeAtLocation(decl) + ); + const deprecatedApiCheckMap = TypeScriptLinter.updateDeprecatedApiCheckMap( + parName === undefined ? DEPRECATE_UNNAMED : parName + '', + undefined, + expression.name.text === 'raw' ? 'string' : returnType, + path.basename(decl.getSourceFile().fileName) + ); + this.processApiNodeDeprecatedApi( + expression.name.text, + expression.name, + deprecatedApiCheckMap, + undefined, + BUILTIN_TYPE + ); + } + } + } + private checkPropertyDeclarationForDeprecatedApi(node: ts.PropertyDeclaration): void { const expression = node.name; if (ts.isIdentifier(expression)) { @@ -13952,15 +14399,19 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { errorNode: ts.Node, deprecatedApiCheckMap?: Map>, autofix?: Autofix[], - isSdkCommon?: boolean + apiType?: string ): void { - const problemStr = this.getFaultIdWithMatchedDeprecatedApi(apiName, deprecatedApiCheckMap, isSdkCommon); + const problemStr = this.getFaultIdWithMatchedDeprecatedApi(apiName, deprecatedApiCheckMap, apiType); if (problemStr.length > 0) { - const faultID = isSdkCommon ? TypeScriptLinter.getFinalSdkFaultIdByProblem(problemStr) : FaultID.NoDeprecatedApi; + const isSdkCommon = apiType === SDK_COMMON_TYPE; + const faultID = TypeScriptLinter.getFinalSdkFaultIdByProblem(problemStr, apiType); + if (!faultID) { + return; + } this.incrementCounters( errorNode, faultID, - isSdkCommon ? undefined : autofix, + isSdkCommon || apiType === BUILTIN_TYPE ? undefined : autofix, isSdkCommon ? TypeScriptLinter.getErrorMsgForSdkCommonApi(apiName, faultID) : undefined ); } @@ -13969,57 +14420,87 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { private getFaultIdWithMatchedDeprecatedApi( apiName: string, deprecatedApiCheckMap?: Map>, - isSdkCommon?: boolean + apiType?: string ): string { void this; - let setApiListItem = TypeScriptLinter.deprecatedApiInfo; - if (isSdkCommon) { - setApiListItem = TypeScriptLinter.sdkCommonApiInfo; + if (!apiType) { + apiType = DEPRECATE_TYPE; } + const setApiListItem = apiType && TypeScriptLinter.getApiListItemSetFromAllWhiteList(apiType); if (!setApiListItem || !deprecatedApiCheckMap) { return ''; } const apiNamesArr = [...setApiListItem]; + const isSpecial = apiType === SDK_COMMON_TYPE || apiType === BUILTIN_TYPE; let problem = ''; apiNamesArr.some((apiInfoItem) => { - if (apiInfoItem.api_info.parent_api?.length <= 0) { - return false; - } - let isSameApi = apiInfoItem.api_info.api_name === apiName; - isSameApi &&= TypeScriptLinter.checkParentNameUnderSdkList( - apiInfoItem, - deprecatedApiCheckMap?.get(DEPRECATE_CHECK_KEY.PARENT_NAME) + '', - isSdkCommon - ); - const return_type = this.getReturnTypeByApiInfoItem(apiInfoItem, isSdkCommon); - const actual_return_type = this.normalizeTypeString(deprecatedApiCheckMap?.get(DEPRECATE_CHECK_KEY.RETURN_TYPE)); - isSameApi &&= return_type === actual_return_type; - const api_func_args = apiInfoItem.api_info.api_func_args; - const params = deprecatedApiCheckMap?.get(DEPRECATE_CHECK_KEY.PARAM_SET); - if (api_func_args && params) { - const isParametersEqual = TypeScriptLinter.areParametersEqualForDeprecated( - api_func_args, - params as ts.NodeArray + if (!apiInfoItem.api_info.api_name && !apiName || BUILTIN_CONSTRUCTOR_API_NAME === apiName) { + problem = TypeScriptLinter.getFaultIdWithMatchedBuiltinConstructApi( + apiInfoItem, + deprecatedApiCheckMap?.get(DEPRECATE_CHECK_KEY.PARENT_NAME) + '' ); - isSameApi &&= isParametersEqual; + if (problem) { + return true; + } } + const isSameApi = this.checkIsSameApiWithSdkList(apiInfoItem, apiName, deprecatedApiCheckMap, apiType); const fileName = deprecatedApiCheckMap?.get(DEPRECATE_CHECK_KEY.FILE_NAME) + ''; const isSameFile = fileName.endsWith(path.basename(apiInfoItem.file_path)); const res = isSameApi && isSameFile; if (res) { - problem = isSdkCommon ? apiInfoItem.api_info.problem : DeprecateProblem.NoDeprecatedApi; + problem = isSpecial ? apiInfoItem.api_info.problem : DeprecateProblem.NoDeprecatedApi; } return res; }); return problem; } + private checkIsSameApiWithSdkList( + apiInfoItem: ApiListItem, + apiName: string, + deprecatedApiCheckMap: Map>, + apiType?: string + ): boolean { + let isSameApi = apiInfoItem.api_info.api_name === apiName; + isSameApi &&= TypeScriptLinter.checkParentNameUnderSdkList( + apiInfoItem, + deprecatedApiCheckMap.get(DEPRECATE_CHECK_KEY.PARENT_NAME) + '', + apiType === SDK_COMMON_TYPE || apiType === BUILTIN_TYPE + ); + const return_type = this.getReturnTypeByApiInfoItem( + apiInfoItem, + apiType === SDK_COMMON_TYPE || apiType === BUILTIN_TYPE + ); + const actual_return_type = this.normalizeTypeString(deprecatedApiCheckMap.get(DEPRECATE_CHECK_KEY.RETURN_TYPE)); + isSameApi &&= return_type === actual_return_type; + const api_func_args = apiInfoItem.api_info.api_func_args; + const params = deprecatedApiCheckMap.get(DEPRECATE_CHECK_KEY.PARAM_SET); + if (api_func_args && params) { + const isParametersEqual = TypeScriptLinter.areParametersEqualForDeprecated( + api_func_args, + params as ts.NodeArray + ); + isSameApi &&= isParametersEqual; + } + return isSameApi; + } + + private static getFaultIdWithMatchedBuiltinConstructApi(apiInfoItem: ApiListItem, parentName: string): string { + if (apiInfoItem.api_info.parent_api?.length <= 0) { + return ''; + } + const isBuiltinConstruct = + BUILTIN_CONSTRUCTOR_API_TYPE.includes(apiInfoItem.api_info.api_type) && + apiInfoItem.api_info.parent_api[0].api_name === parentName; + return isBuiltinConstruct ? apiInfoItem.api_info.problem : ''; + } + private getReturnTypeByApiInfoItem( apiInfoItem: ApiListItem, - isSdkCommon: boolean | undefined + isSpecial: boolean | undefined ): string | ts.NodeArray | undefined { let return_type = this.normalizeTypeString(apiInfoItem.api_info.method_return_type); - if (isSdkCommon) { + if (isSpecial) { return_type = apiInfoItem.api_info.method_return_type ? this.normalizeTypeString(apiInfoItem.api_info.method_return_type) : this.normalizeTypeString(apiInfoItem.api_info.api_property_type); @@ -14030,7 +14511,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { private static checkParentNameUnderSdkList( apiInfoItem: ApiListItem, sourceParentName: string, - isSdkCommon?: boolean + isSpecial?: boolean ): boolean { const parentApis = apiInfoItem.api_info.parent_api; const possibleNames: string[] = []; @@ -14038,18 +14519,18 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (primaryParentName) { possibleNames.push(primaryParentName); - if (!!isSdkCommon && parentApis.length > 1) { + if (!!isSpecial && parentApis.length > 1) { const secondaryParentName = parentApis[1]?.api_name || ''; possibleNames.push(`${secondaryParentName}.${primaryParentName}`); } } - return possibleNames.includes(sourceParentName); + return possibleNames.includes(sourceParentName) || parentApis.length === 0 && !sourceParentName; } private getPropertyTypeForPropertyAssignment( propertyAssignment: ts.PropertyAssignment, contextualType: ts.Type, - isSdkCommon?: boolean + isSpecial?: boolean ): Map> | undefined { const propertyName = propertyAssignment.name.getText(); if (contextualType.isUnion()) { @@ -14058,21 +14539,21 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { type, propertyName, propertyAssignment, - isSdkCommon + isSpecial ); if (deprecatedApiCheckMap) { return deprecatedApiCheckMap; } } } - return this.getPropertyInfoByContextualType(contextualType, propertyName, propertyAssignment, isSdkCommon); + return this.getPropertyInfoByContextualType(contextualType, propertyName, propertyAssignment, isSpecial); } private getPropertyInfoByContextualType( type: ts.Type, propertyName: string, node: ts.Node, - isSdkCommon?: boolean + isSpecial?: boolean ): Map> | undefined { const propertySymbol = type.getProperty(propertyName); if (!propertySymbol) { @@ -14087,7 +14568,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { propertyDecl.type.getText(), path.basename(propertyDecl.getSourceFile().fileName + '') ); - if (isSdkCommon) { + if (isSpecial) { this.hanldeSdkCommonTypeName(node, type.getSymbol(), type.getSymbol()?.name + '', propertyDecl); } } @@ -14350,13 +14831,27 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { ]); } - private static getFaultIdSdkCommonApiInfoWithConstructorDecl(extendClassName: string): string { - const mergedSet = TypeScriptLinter.mergeSdkCommonApiListInfo(); + private static getFaultIdSdkApiInfoWithConstructorDecl(extendClassName: string, apiType: string): string { + const mergedSet = TypeScriptLinter.getApiListItemSetFromAllWhiteList( + apiType, + apiType === SDK_COMMON_TYPE ? true : undefined + ); + if (!mergedSet) { + return ''; + } + let api_types = ['']; + if (apiType === SDK_COMMON_TYPE) { + api_types = SDK_COMMON_CONSTRUCTORLIKE; + } else if (apiType === BUILTIN_TYPE) { + api_types = BUILTIN_CONSTRUCTOR_API_TYPE; + } let problem = ''; for (const item of mergedSet) { + if (item.api_info.parent_api?.length <= 0) { + continue; + } const isCompare = - item.api_info.parent_api[0].api_name === extendClassName && - SDK_COMMON_CONSTRUCTORLIKE.includes(item.api_info.api_type); + item.api_info.parent_api[0].api_name === extendClassName && api_types.includes(item.api_info.api_type); if (isCompare) { problem = item.api_info.problem; break; @@ -14365,19 +14860,29 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return problem; } - private static getFaultIdSdkCommonApiInfoWithClassMember( - extendClassName: string, + private static getFaultIdSdkApiInfoWithClassMember( + decl: ts.ClassDeclaration | ts.InterfaceDeclaration, targetName: string, - typeKey: string + typeKey: string, + mergedSet: Set ): string { - const mergedSet = TypeScriptLinter.mergeSdkCommonApiListInfo(); + const extendClassName = decl.name?.text; + const fileName = path.basename(decl.getSourceFile().fileName); + if (!extendClassName || !fileName) { + return ''; + } const memberLike = typeKey === SDK_COMMON_TYPEKEY[0] ? SDK_COMMON_FUNCTIONLIKE : SDK_COMMON_PROPERTYLIKE; let problem = ''; + const apiFilePath = this.getApiFilePathsFromSdkList(mergedSet); for (const item of mergedSet) { + if (item.api_info.parent_api?.length <= 0) { + continue; + } const isFunLikeCompare = item.api_info.parent_api[0].api_name === extendClassName && memberLike.includes(item.api_info.api_type) && - item.api_info.api_name === targetName; + item.api_info.api_name === targetName && + apiFilePath.includes(fileName); if (isFunLikeCompare) { problem = item.api_info.problem; break; @@ -14386,15 +14891,107 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return problem; } - private static checkIsSameAsParenName(targetName: string): boolean { - let res = false; - const mergedSet = TypeScriptLinter.mergeSdkCommonApiListInfo(); + private static getApiFilePathsFromSdkList(mergedSet: Set): string[] { + const apiFilePath: string[] = []; + mergedSet.forEach((mem) => { + apiFilePath.push(path.basename(mem.file_path)); + }); + return apiFilePath; + } + + private static refactorSetWhitSameAsParenName(targetName: string, apiType: string): Set | undefined { + const mergedSet = TypeScriptLinter.getApiListItemSetFromAllWhiteList( + apiType, + apiType === SDK_COMMON_TYPE ? true : undefined + ); + if (!mergedSet) { + return undefined; + } + const newMergedSet = new Set(); for (const item of mergedSet) { + if (item.api_info.parent_api?.length <= 0) { + continue; + } if (item.api_info.parent_api[0].api_name === targetName) { - res = true; + newMergedSet.add(item); } } - return res; + return newMergedSet; + } + + private static getApiListItemSetFromAllWhiteList( + type: string, + isMergeSdkCommonApi?: boolean + ): Set | undefined { + if (type === DEPRECATE_TYPE) { + return TypeScriptLinter.deprecatedApiInfo; + } else if (type === SDK_COMMON_TYPE) { + return isMergeSdkCommonApi ? TypeScriptLinter.mergeSdkCommonApiListInfo() : TypeScriptLinter.sdkCommonApiInfo; + } else if (type === BUILTIN_TYPE) { + return TypeScriptLinter.builtApiInfo; + } + return undefined; + } + + private checkArrayInitialization(tsNewExpr: ts.NewExpression): void { + if (!this.options.arkts2) { + return; + } + if (!tsNewExpr.arguments || tsNewExpr.arguments.length !== 1) { + return; + } + const newExprType = this.tsTypeChecker.getTypeAtLocation(tsNewExpr); + const argType = this.tsTypeChecker.getTypeAtLocation(tsNewExpr.arguments[0]); + if (this.tsUtils.isGenericArrayType(newExprType) && this.tsUtils.isNumberLikeType(argType)) { + this.incrementCounters(tsNewExpr, FaultID.UninitializedArrayElements); + } + } + + private handleBuiltinIteratorResult(propAccessExpr: ts.PropertyAccessExpression): void { + if (!this.options.arkts2 || !TypeScriptLinter.builtApiInfo || propAccessExpr.name.getText() !== 'value') { + return; + } + + const type = this.tsTypeChecker.getTypeAtLocation(propAccessExpr.expression); + const aliasSymbol = type.aliasSymbol; + const declaration = aliasSymbol?.declarations?.[0]; + if (!declaration || !ts.isTypeAliasDeclaration(declaration)) { + return; + } + + const name = declaration.name.getText(); + const typeStr = declaration.type.getText(); + const fileName = declaration.getSourceFile().fileName; + this.processApiNodeDeprecatedApi( + name, + propAccessExpr, + TypeScriptLinter.updateDeprecatedApiCheckMap('', undefined, typeStr, path.basename(fileName)), + undefined, + BUILTIN_TYPE + ); + } + + private handleBuiltinDisableDecorator(decorator: ts.Decorator): void { + if (!this.options.arkts2 || !TypeScriptLinter.builtApiInfo) { + return; + } + const type = this.tsTypeChecker.getTypeAtLocation(decorator.expression); + const aliasSymbol = type.aliasSymbol; + const declaration = aliasSymbol?.declarations?.[0]; + if (!declaration || !ts.isTypeAliasDeclaration(declaration) || !ts.isFunctionLike(declaration.type)) { + return; + } + const name = declaration.name.getText(); + const params = declaration.type.parameters; + const typeStr = declaration.type.type?.getText(); + const fileName = declaration.getSourceFile().fileName; + this.processApiNodeDeprecatedApi( + name, + decorator, + TypeScriptLinter.updateDeprecatedApiCheckMap('', params, typeStr, path.basename(fileName)), + undefined, + BUILTIN_TYPE + ); } private handleUnsignedShiftOnNegative(node: ts.BinaryExpression): void { @@ -14431,4 +15028,122 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { node.right.text === '0' ); } + + private handleCallExpressionForSerialization(node: ts.CallExpression): void { + if (!this.options.arkts2) { + return; + } + + const propertyAccess = node.expression; + if (!ts.isPropertyAccessExpression(propertyAccess)) { + return; + } + + const persistentClass = propertyAccess.expression; + if (!ts.isIdentifier(persistentClass)) { + return; + } + + switch (persistentClass.getText()) { + case StorageTypeName.PersistentStorage: + if (this.isDeclInTargetFile(persistentClass, COMMON_TS_ETS_API_D_TS)) { + this.handleCallExpressionForPersistentStorage(node, propertyAccess); + } + break; + case StorageTypeName.PersistenceV2: + if (this.isDeclInTargetFile(persistentClass, UI_STATE_MANAGEMENT_D_TS)) { + this.handleCallExpressionForPersistenceV2(node, propertyAccess); + } + break; + default: + } + } + + private handleCallExpressionForPersistentStorage( + callExpr: ts.CallExpression, + propertyAccess: ts.PropertyAccessExpression + ): void { + const funcName = propertyAccess.name.getText(); + + switch (funcName) { + case PERSIST_PROP_FUNC_NAME: + if (!this.checkPersistPropForSerialization(callExpr)) { + this.incrementCounters(callExpr, FaultID.PersistentPropNeedImplementMethod); + } + break; + case PERSIST_PROPS_FUNC_NAME: + if (!this.checkPersistPropsForSerialization(callExpr)) { + this.incrementCounters(callExpr, FaultID.PersistentPropsNeedImplementMethod); + } + break; + default: + } + } + + private checkPersistPropForSerialization(callExpr: ts.CallExpression): boolean { + const arg = callExpr.arguments?.[1]; + return !arg || this.checkArgumentForSerialization(arg); + } + + private checkPersistPropsForSerialization(callExpr: ts.CallExpression): boolean { + const arg = callExpr.arguments?.[0]; + if (!arg || !ts.isArrayLiteralExpression(arg)) { + return true; + } + + const literals = arg.elements; + let serializable: boolean = true; + for (const literal of literals) { + if (!ts.isObjectLiteralExpression(literal)) { + continue; + } + const property = literal.properties?.[1]; + if (!property || !ts.isPropertyAssignment(property)) { + continue; + } + if (!this.checkArgumentForSerialization(property.initializer)) { + serializable = false; + break; + } + } + + return serializable; + } + + private checkArgumentForSerialization(arg: ts.Node): boolean { + const type = this.tsTypeChecker.getTypeAtLocation(arg); + + if (type.isUnion()) { + if ( + type.types.some((type) => { + return !this.isSpecificTypeOfSerialization(type); + }) + ) { + return false; + } + return true; + } + + return this.isSpecificTypeOfSerialization(type); + } + + private isSpecificTypeOfSerialization(type: ts.Type): boolean { + const typeName = this.tsTypeChecker.typeToString(type); + return serializationTypeFlags.has(type.flags) || serializationTypeName.has(typeName); + } + + private handleCallExpressionForPersistenceV2( + callExpr: ts.CallExpression, + propertyAccess: ts.PropertyAccessExpression + ): void { + const funcName = propertyAccess.name.getText(); + if (funcName !== GLOBAL_CONNECT_FUNC_NAME && funcName !== CONNECT_FUNC_NAME) { + return; + } + + const errorMsg = + `When calling the "${funcName}" method, the parameter list of the methods needs to include ` + + '"toJson" and "fromJson" (arkui-persistencev2-connect-serialization)'; + this.incrementCounters(callExpr, FaultID.PersistenceV2ConnectNeedAddParam, undefined, errorMsg); + } } diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 3ef2aba012eaa6e092826910b187dc0c631ba5fe..91ff39cad5048eb004ed3b31e8dd8177e508178d 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -42,7 +42,8 @@ import { PROVIDE_ALLOW_OVERRIDE_PROPERTY_NAME, NEW_PROP_DECORATOR_SUFFIX, VIRTUAL_SCROLL_IDENTIFIER, - DISABLE_VIRTUAL_SCROLL_IDENTIFIER + DISABLE_VIRTUAL_SCROLL_IDENTIFIER, + USE_STATIC_STATEMENT } from '../utils/consts/ArkuiConstants'; import { ES_VALUE } from '../utils/consts/ESObject'; import type { IncrementDecrementNodeInfo } from '../utils/consts/InteropAPI'; @@ -3693,7 +3694,7 @@ export class Autofixer { fixInterfaceImport( interfacesNeedToImport: Set, interfacesAlreadyImported: Set, - sourceFile: ts.SourceFile + file: ts.SourceFile ): Autofix[] { const importSpecifiers: ts.ImportSpecifier[] = []; interfacesNeedToImport.forEach((interfaceName) => { @@ -3710,25 +3711,33 @@ export class Autofixer { undefined ); - const leadingComments = ts.getLeadingCommentRanges(sourceFile.getFullText(), 0); + const leadingComments = ts.getLeadingCommentRanges(file.getFullText(), 0); let annotationEndLine = 0; let annotationEndPos = 0; if (leadingComments && leadingComments.length > 0) { annotationEndPos = leadingComments[leadingComments.length - 1].end; - annotationEndLine = sourceFile.getLineAndCharacterOfPosition(annotationEndPos).line; + annotationEndLine = file.getLineAndCharacterOfPosition(annotationEndPos).line; } + const stmt = file?.statements[0]; + const isUseStaticAtStart = stmt ? Autofixer.checkUseStaticAtStart(stmt) : false; + annotationEndLine = isUseStaticAtStart ? file.getLineAndCharacterOfPosition(stmt.end).line : annotationEndLine; + annotationEndPos = isUseStaticAtStart ? stmt.end : annotationEndPos; + let text = Autofixer.formatImportStatement( - this.printer.printNode(ts.EmitHint.Unspecified, importDeclaration, sourceFile) + this.printer.printNode(ts.EmitHint.Unspecified, importDeclaration, file) ); if (annotationEndPos !== 0) { - text = this.getNewLine() + this.getNewLine() + text; + text = this.getNewLine() + (isUseStaticAtStart ? '' : this.getNewLine()) + text; } - const codeStartLine = sourceFile.getLineAndCharacterOfPosition(sourceFile.getStart()).line; + const codeStartLine = isUseStaticAtStart ? + annotationEndLine + 1 : + file.getLineAndCharacterOfPosition(file.getStart()).line; for (let i = 2; i > codeStartLine - annotationEndLine; i--) { text = text + this.getNewLine(); } + return [{ start: annotationEndPos, end: annotationEndPos, replacementText: text }]; } @@ -3750,6 +3759,10 @@ export class Autofixer { }); } + private static checkUseStaticAtStart(stmt: ts.Statement): boolean { + return stmt.getText().trim().replace(/^'|'$/g, '').endsWith(USE_STATIC_STATEMENT); + } + fixStylesDecoratorGlobal( funcDecl: ts.FunctionDeclaration, calls: ts.Identifier[], @@ -4739,7 +4752,7 @@ export class Autofixer { return undefined; } - const typeArgs = Autofixer.getTypeArgumentsFromType(contextualType); + const typeArgs = this.getTypeArgumentsFromType(contextualType); if (typeArgs.length === 0) { return undefined; } @@ -5044,8 +5057,8 @@ export class Autofixer { return [{ start: identifier.getEnd(), end: identifier.getEnd(), replacementText: typeArgsText }]; } - static getTypeArgumentsFromType(type: ts.Type): ts.Type[] { - const typeReference = type as ts.TypeReference; + private getTypeArgumentsFromType(type: ts.Type): ts.Type[] { + const typeReference = this.utils.getNonNullableType(type) as ts.TypeReference; if (typeReference.typeArguments) { return [...typeReference.typeArguments]; } diff --git a/ets2panda/linter/src/lib/data/BuiltinList.json b/ets2panda/linter/src/lib/data/BuiltinList.json index 659a25bbd5685ce492cb3ced9ae386ead5fdd5ab..e2a086ed83b24b6265dcf2795b4f9a85f9c81c2d 100644 --- a/ets2panda/linter/src/lib/data/BuiltinList.json +++ b/ets2panda/linter/src/lib/data/BuiltinList.json @@ -4,13 +4,13 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 107, - "problem": "BuiltinAll", + "problem": "BuiltinNarrowTypes", "api_name": "PropertyKey", "api_type": "TypeAliasDeclaration", "api_func_args": [], "parent_api": [], "code_kind": 268, - "api_property_type": "string | number | symbol" + "method_return_type": "string | number | symbol" }, "import_path": [], "is_global": true @@ -148,7 +148,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 133, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "valueOf", "api_type": "MethodSignature", "api_optional": false, @@ -189,8 +189,8 @@ { "file_path": "lib.es5.d.ts", "api_info": { - "line": 156, - "problem": "BuiltinAll", + "line": 157, + "problem": "BuiltinDisableApi", "api_type": "CallSignature", "parent_api": [ { @@ -206,8 +206,8 @@ { "file_path": "lib.es5.d.ts", "api_info": { - "line": 157, - "problem": "BuiltinAll", + "line": 576, + "problem": "BuiltinNewCtor", "api_type": "CallSignature", "parent_api": [ { @@ -224,7 +224,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 392, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "length", "api_type": "PropertySignature", "api_optional": false, @@ -244,7 +244,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 393, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "callee", "api_type": "PropertySignature", "api_optional": false, @@ -277,6 +277,23 @@ "import_path": [], "is_global": true }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 522, + "problem": "BuiltinNewCtor", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "StringConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, { "file_path": "lib.es5.d.ts", "api_info": { @@ -294,6 +311,23 @@ "import_path": [], "is_global": true }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 539, + "problem": "BuiltinNewCtor", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "BooleanConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, { "file_path": "lib.es5.d.ts", "api_info": { @@ -311,11 +345,28 @@ "import_path": [], "is_global": true }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 576, + "problem": "BuiltinNewCtor", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "NumberConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, { "file_path": "lib.es5.d.ts", "api_info": { "line": 608, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "raw", "api_type": "PropertySignature", "api_optional": false, @@ -348,6 +399,23 @@ "import_path": [], "is_global": true }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 916, + "problem": "BuiltinNewCtor", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "DateConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, { "file_path": "lib.es5.d.ts", "api_info": { @@ -399,6 +467,23 @@ "import_path": [], "is_global": true }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 1060, + "problem": "BuiltinNewCtor", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "ErrorConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, { "file_path": "lib.es5.d.ts", "api_info": { @@ -539,7 +624,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 1188, - "problem": "BuiltinAll", + "problem": "BuiltinNarrowTypes", "api_name": "concat", "api_type": "MethodSignature", "api_optional": false, @@ -825,7 +910,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 1334, - "problem": "BuiltinAll", + "problem": "BuiltinNarrowTypes", "api_name": "concat", "api_type": "MethodSignature", "api_optional": false, @@ -1070,6 +1155,23 @@ "import_path": [], "is_global": true }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 1490, + "problem": "BuiltinNewCtor", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "ArrayConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, { "file_path": "lib.es5.d.ts", "api_info": { @@ -1194,7 +1296,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 1506, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "ClassDecorator", "api_type": "TypeAliasDeclaration", "api_func_args": [ @@ -1215,7 +1317,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 1507, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "PropertyDecorator", "api_type": "TypeAliasDeclaration", "api_func_args": [ @@ -1241,7 +1343,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 1508, - "problem": "NoPropertyDescriptor", + "problem": "BuiltinDisableApi", "api_name": "MethodDecorator", "api_type": "TypeAliasDeclaration", "api_func_args": [ @@ -1272,7 +1374,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 1509, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "ParameterDecorator", "api_type": "TypeAliasDeclaration", "api_func_args": [ @@ -1303,7 +1405,7 @@ "file_path": "lib.es5.d.ts", "api_info": { "line": 1681, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "ArrayBuffer", "api_type": "PropertySignature", "api_optional": false, @@ -3505,7 +3607,7 @@ "file_path": "lib.es2015.iterable.d.ts", "api_info": { "line": 46, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "return", "api_type": "MethodSignature", "api_optional": true, @@ -3533,7 +3635,7 @@ "file_path": "lib.es2015.iterable.d.ts", "api_info": { "line": 47, - "problem": "BuiltinAll", + "problem": "BuiltinDisableApi", "api_name": "throw", "api_type": "MethodSignature", "api_optional": true, @@ -5762,6 +5864,23 @@ "import_path": [], "is_global": true }, + { + "file_path": "lib.es2021.promise.d.ts", + "api_info": { + "line": 1, + "problem": "BuiltinNewCtor", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "AggregateErrorConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, { "file_path": "lib.es2015.core.d.ts", "api_info": { @@ -5795,6 +5914,1524 @@ }, "import_path": [], "is_global": true + }, + { + "file_path": "lib.es2021.promise.d.ts", + "api_info": { + "line": 110, + "problem": "NoPropertyDescriptor", + "api_name": "errors", + "api_type": "PropertySignature", + "api_optional": true, + "parent_api": [ + { + "api_name": "AggregateError", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "any[]" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2019.array.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinDisableApi", + "api_name": "flat", + "api_type": "MethodSignature", + "api_func_args": [ + { + "name": "this", + "type": "A", + "is_optional": false, + "has_default": false + }, + { + "name": "depth", + "type": "D", + "is_optional": true, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "Array", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "FlatArray[]", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "day", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "dayPeriod", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "era", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "hour", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "literal", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "minute", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "month", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "second", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "timeZoneName", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "weekday", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "year", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DateTimeFormatPartTypesRegistry", + "api_type": "InterfaceDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "any", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2020.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "prototype", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "DisplayNames", + "api_type": "VariableDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "DisplayNames", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2021.intl.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "prototype", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "ListFormat", + "api_type": "VariableDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "ListFormat", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 114, + "problem": "BuiltinDisableApi", + "api_name": "prototype", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "NumberFormat", + "api_type": "VariableDeclaration" + }, + { + "api_name": "Intl", + "api_type": "ModuleDeclaration" + } + ], + "api_property_type": "NumberFormat", + "code_kind": 170 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2019.array.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinDisableApi", + "api_name": "flat", + "api_type": "MethodSignature", + "api_func_args": [ + { + "name": "this", + "type": "A", + "is_optional": false, + "has_default": false + }, + { + "name": "depth", + "type": "D", + "is_optional": true, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "ReadonlyArray", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "FlatArray[]", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2019.array.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinDisableApi", + "api_name": "flatMap", + "api_type": "MethodSignature", + "api_func_args": [ + { + "name": "callback", + "type": "(this: This, value: T, index: number, array: T[]) => U | ReadonlyArray", + "is_optional": false, + "has_default": false + }, + { + "name": "thisArg", + "type": "This", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "ReadonlyArray", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "U[]", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2018.regexp.d.ts", + "api_info": { + "line": 110, + "problem": "BuiltinDisableApi", + "api_name": "groups", + "api_type": "PropertySignature", + "api_optional": true, + "parent_api": [ + { + "api_name": "RegExpExecArray", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "{[key: string]: string}" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2018.regexp.d.ts", + "api_info": { + "line": 110, + "problem": "BuiltinDisableApi", + "api_name": "groups", + "api_type": "PropertySignature", + "api_optional": true, + "parent_api": [ + { + "api_name": "RegExpMatchArray", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "{[key: string]: string}" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2019.array.d.ts", + "api_info": { + "line": 110, + "problem": "BuiltinDisableApi", + "api_name": "FlatArray", + "api_type": "TypeAliasDeclaration", + "api_optional": true, + "parent_api": [], + "code_kind": 170, + "method_return_type": "{\"done\": Arr, \"recur\": Arr extends ReadonlyArray ? FlatArray : Arr}[Depth extends -1 ? \"done\" : \"recur\"]" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.core.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinNarrowTypes", + "api_name": "isFinite", + "api_type": "MethodSignature", + "api_func_args": [ + { + "name": "number", + "type": "unknown", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "NumberConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "boolean", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.core.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinNarrowTypes", + "api_name": "isInteger", + "api_type": "MethodSignature", + "api_func_args": [ + { + "name": "number", + "type": "unknown", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "NumberConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "boolean", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.core.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinNarrowTypes", + "api_name": "isNaN", + "api_type": "MethodSignature", + "api_func_args": [ + { + "name": "number", + "type": "unknown", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "NumberConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "boolean", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.core.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinNarrowTypes", + "api_name": "isSafeInteger", + "api_type": "MethodSignature", + "api_func_args": [ + { + "name": "number", + "type": "unknown", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "NumberConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "boolean", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.reflect.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinAll", + "api_name": "get", + "api_type": "MethodDeclaration", + "api_func_args": [ + { + "name": "target", + "type": "T", + "is_optional": false, + "has_default": false + }, + { + "name": "propertyKey", + "type": "P", + "is_optional": false, + "has_default": false + }, + { + "name": "receiver", + "type": "unknown", + "is_optional": true, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "Reflect", + "api_type": "ModuleDeclaration" + } + ], + "method_return_type": "P extends keyof T ? T[P] : any", + "code_kind": 174 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.reflect.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinNarrowTypes", + "api_name": "has", + "api_type": "MethodDeclaration", + "api_func_args": [ + { + "name": "target", + "type": "object", + "is_optional": false, + "has_default": false + }, + { + "name": "propertyKey", + "type": "PropertyKey", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "Reflect", + "api_type": "ModuleDeclaration" + } + ], + "method_return_type": "boolean", + "code_kind": 174 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.reflect.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinNarrowTypes", + "api_name": "ownKeys", + "api_type": "MethodDeclaration", + "api_func_args": [ + { + "name": "target", + "type": "object", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "Reflect", + "api_type": "ModuleDeclaration" + } + ], + "method_return_type": "(string | symbol)[]", + "code_kind": 174 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.reflect.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinAll", + "api_name": "set", + "api_type": "MethodDeclaration", + "api_func_args": [ + { + "name": "target", + "type": "T", + "is_optional": false, + "has_default": false + }, + { + "name": "propertyKey", + "type": "P", + "is_optional": false, + "has_default": false + }, + { + "name": "value", + "type": "P extends keyof T ? T[P] : any", + "is_optional": false, + "has_default": false + }, + { + "name": "receiver", + "type": "any", + "is_optional": true, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "Reflect", + "api_type": "ModuleDeclaration" + } + ], + "method_return_type": "boolean", + "code_kind": 174 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.core.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinDisableApi", + "api_name": "raw", + "api_type": "MethodSignature", + "api_func_args": [ + { + "name": "template", + "type": "{ raw: readonly string[] | ArrayLike}", + "is_optional": false, + "has_default": false + }, + { + "name": "substitutions", + "type": "any[]", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "StringConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "string", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.iterable.d.ts", + "api_info": { + "line": 1, + "problem": "BuiltinDisableApi", + "api_name": "from", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "iterable", + "type": "Iterable | ArrayLike", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "ArrayConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "T[]", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 1, + "problem": "BuiltinNarrowTypes", + "api_name": "isArray", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "arg", + "type": "any", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "ArrayConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "arg is any[]", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.iterable.d.ts", + "api_info": { + "line": 1506, + "problem": "BuiltinIteratorResultValue", + "api_name": "IteratorResult", + "api_type": "TypeAliasDeclaration", + "api_func_args": [], + "parent_api": [], + "method_return_type": "IteratorYieldResult | IteratorReturnResult", + "code_kind": 268 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.iterable.d.ts", + "api_info": { + "line": 1681, + "problem": "BuiltinDisableApi", + "api_name": "done", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "IteratorReturnResult", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "true" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.iterable.d.ts", + "api_info": { + "line": 1681, + "problem": "BuiltinDisableApi", + "api_name": "value", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "IteratorReturnResult", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "TReturn" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.iterable.d.ts", + "api_info": { + "line": 1681, + "problem": "BuiltinDisableApi", + "api_name": "done", + "api_type": "PropertySignature", + "api_optional": true, + "parent_api": [ + { + "api_name": "IteratorYieldResult", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "false" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.iterable.d.ts", + "api_info": { + "line": 1681, + "problem": "BuiltinDisableApi", + "api_name": "value", + "api_type": "PropertySignature", + "api_optional": false, + "parent_api": [ + { + "api_name": "IteratorYieldResult", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "TYield" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 1244, + "problem": "BuiltinNarrowTypes", + "api_name": "isView", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "arg", + "type": "any", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "ArrayBufferConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "arg is ArrayBufferView", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 1244, + "problem": "BuiltinNarrowTypes", + "api_name": "toJSON", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "key", + "type": "any", + "is_optional": true, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "Date", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "string", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2022.error.d.ts", + "api_info": { + "line": 110, + "problem": "NoPropertyDescriptor", + "api_name": "cause", + "api_type": "PropertySignature", + "api_optional": true, + "parent_api": [ + { + "api_name": "ErrorOptions", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "unknown" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2022.error.d.ts", + "api_info": { + "line": 110, + "problem": "NoPropertyDescriptor", + "api_name": "cause", + "api_type": "PropertySignature", + "api_optional": true, + "parent_api": [ + { + "api_name": "Error", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 170, + "api_property_type": "unknown" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 1139, + "problem": "BuiltinNarrowTypes", + "api_name": "stringify", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "value", + "type": "any", + "is_optional": false, + "has_default": false + }, + { + "name": "replacer", + "type": "(this: any, key: string, value: any) => any", + "is_optional": true, + "has_default": false + }, + { + "name": "space", + "type": "string | number", + "is_optional": true, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "JSON", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "string", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 1139, + "problem": "BuiltinNarrowTypes", + "api_name": "stringify", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "value", + "type": "any", + "is_optional": false, + "has_default": false + }, + { + "name": "replacer", + "type": "(number | string)[] | null", + "is_optional": true, + "has_default": false + }, + { + "name": "space", + "type": "string | number", + "is_optional": true, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "JSON", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "string", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.object.d.ts", + "api_info": { + "line": 1139, + "problem": "BuiltinNarrowTypes", + "api_name": "entries", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "o", + "type": "{}", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "ObjectConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "[string, any][]", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2017.object.d.ts", + "api_info": { + "line": 1139, + "problem": "BuiltinNarrowTypes", + "api_name": "values", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "o", + "type": "{}", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "ObjectConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "any[]", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2019.object.d.ts", + "api_info": { + "line": 1139, + "problem": "BuiltinNarrowTypes", + "api_name": "fromEntries", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "entries", + "type": "Iterable", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "ObjectConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "{ [k: string]: T }", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 1139, + "problem": "BuiltinNarrowTypes", + "api_name": "replace", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "searchValue", + "type": "string | RegExp", + "is_optional": false, + "has_default": false + }, + { + "name": "replacer", + "type": "(substring: string, ...args: any[]) => string", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "String", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "string", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2021.string.d.ts", + "api_info": { + "line": 1139, + "problem": "BuiltinNarrowTypes", + "api_name": "replaceAll", + "api_type": "MethodSignature", + "api_optional": false, + "api_func_args": [ + { + "name": "searchValue", + "type": "string | RegExp", + "is_optional": false, + "has_default": false + }, + { + "name": "replacer", + "type": "(substring: string, ...args: any[]) => string", + "is_optional": false, + "has_default": false + } + ], + "parent_api": [ + { + "api_name": "String", + "api_type": "InterfaceDeclaration" + } + ], + "method_return_type": "string", + "code_kind": 173 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.collection.d.ts", + "api_info": { + "line": 522, + "problem": "BuiltinNoCtorFunc", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "WeakMapConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.collection.d.ts", + "api_info": { + "line": 522, + "problem": "BuiltinNewCtor", + "api_type": "CallSignature", + "parent_api": [ + { + "api_name": "WeakMapConstructor", + "api_type": "InterfaceDeclaration" + } + ], + "code_kind": 179 + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2020.bigint.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "BigInt", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "BigIntConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "DataView", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "DataViewConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "Int8Array", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "Int8ArrayConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "Int16Array", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "Int16ArrayConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "Int32Array", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "Int32ArrayConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2020.bigint.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "BigInt64Array", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "BigInt64ArrayConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "Float32Array", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "Float32ArrayConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "Float64Array", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "Float64ArrayConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "Boolean", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "BooleanConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "String", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "StringConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.collection.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "WeakMap", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "WeakMapConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2015.collection.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "WeakSet", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "WeakSetConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es2021.weakref.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "FinalizationRegistry", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "FinalizationRegistryConstructor" + }, + "import_path": [], + "is_global": true + }, + { + "file_path": "lib.es5.d.ts", + "api_info": { + "line": 126, + "problem": "BuiltinFinalClass", + "api_name": "Promise", + "api_type": "VariableDeclaration", + "api_optional": false, + "parent_api": [], + "code_kind": 260, + "api_property_type": "PromiseConstructor" + }, + "import_path": [], + "is_global": true } ] } \ No newline at end of file diff --git a/ets2panda/linter/src/lib/statistics/scan/ProblemStatisticsCommonFunction.ts b/ets2panda/linter/src/lib/statistics/scan/ProblemStatisticsCommonFunction.ts index cbe8c04e23c9a22e7096dc694535d1b8df47d34c..8ad419cb3dc502382960ff723f004ab0e71de07a 100644 --- a/ets2panda/linter/src/lib/statistics/scan/ProblemStatisticsCommonFunction.ts +++ b/ets2panda/linter/src/lib/statistics/scan/ProblemStatisticsCommonFunction.ts @@ -144,13 +144,14 @@ export async function generateScanProbelemStatisticsReport( needToManualFixproblemNumbers: statisticsReportInPutInfo.totalProblemNumbers - canBeAutoFixedproblemNumbers }; const projectFolderList = statisticsReportInPutInfo.cmdOptions.linterOptions.projectFolderList!; - const WorkLoadInfo = await getWorkLoadInfo(projectFolderList); + const workLoadInfo = await getWorkLoadInfo(projectFolderList); + workLoadInfo.calculateFixRate(problemNumbers); const statisticsReportData = getProblemStatisticsInfo( problemNumbers, statisticsReportInPutInfo.ruleToNumbersMap, statisticsReportInPutInfo.ruleToAutoFixedNumbersMap, statisticsReportInPutInfo.timeRecorder, - WorkLoadInfo + workLoadInfo ); await generateReportFile( statisticsReportInPutInfo.statisticsReportName, diff --git a/ets2panda/linter/src/lib/statistics/scan/WorkLoadInfo.ts b/ets2panda/linter/src/lib/statistics/scan/WorkLoadInfo.ts index 59135b1db29f1c9f48cc3485dd3dc05c263fb02c..0fbb9d817ccbe2ab1d976421ed9f5cd46cdce0b8 100644 --- a/ets2panda/linter/src/lib/statistics/scan/WorkLoadInfo.ts +++ b/ets2panda/linter/src/lib/statistics/scan/WorkLoadInfo.ts @@ -30,6 +30,7 @@ export class WorkLoadInfo { totalTsCodeLines = 0; totalJsonCodeLines = 0; totalXmlCodeLines = 0; + manualFixRate: string | undefined; addFloderResult(result: FloderScanResultInfo): void { this.scanFilePathList.push(result.normalizedPath); @@ -42,10 +43,10 @@ export class WorkLoadInfo { this.totalXmlCodeLines += result.xmlCodeLines; } - calculateFixRate(problemNumbers: ProblemNumbersInfo): string { + calculateFixRate(problemNumbers: ProblemNumbersInfo): void { const totalLines = this.totalArkTSCodeLines + this.totalCAndCPPCodeLines; if (totalLines <= 0) { - return '0.00%'; + this.manualFixRate = '0.00%'; } const problemCount = problemNumbers.needToManualFixproblemNumbers; @@ -53,7 +54,7 @@ export class WorkLoadInfo { (problemCount * AVERAGE_LINE_FOR_REPAIRE_RULE_COEFFICIENT * TEST_DEBUG_WORKLOAD_COEFFICIENT + this.totalNapiCodeLines * NPAI_REPAIRE_WORKLOADA_COEFFICIEN) / totalLines; - - return `${(ratio * 100).toFixed(2)}%`; + + this.manualFixRate = `${(ratio * 100).toFixed(2)}%`; } } diff --git a/ets2panda/linter/src/lib/utils/TsUtils.ts b/ets2panda/linter/src/lib/utils/TsUtils.ts index fbc408c87e9af7c1444b9687e3de92829d240512..1eea1826ef462274b8813ba8b2dd1429d51b203b 100644 --- a/ets2panda/linter/src/lib/utils/TsUtils.ts +++ b/ets2panda/linter/src/lib/utils/TsUtils.ts @@ -48,6 +48,7 @@ import { ETS_MODULE, PATH_SEPARATOR, VALID_OHM_COMPONENTS_MODULE_PATH } from './ import { EXTNAME_ETS, EXTNAME_JS, EXTNAME_D_ETS } from './consts/ExtensionName'; import { CONCAT_ARRAY, STRING_ERROR_LITERAL } from './consts/Literals'; import { INT_MIN, INT_MAX } from './consts/NumericalConstants'; +import { IGNORE_TYPE_LIST } from './consts/TypesToBeIgnored'; export const PROMISE_METHODS = new Set(['all', 'race', 'any', 'resolve', 'allSettled']); export const PROMISE_METHODS_WITH_NO_TUPLE_SUPPORT = new Set(['all', 'race', 'any', 'allSettled']); @@ -3917,4 +3918,16 @@ export class TsUtils { return (typeArguments[0].flags & ts.TypeFlags.Number) !== 0; } + + static isIgnoredTypeForParameterType(typeString: string, type: ts.Type): boolean { + if (TsUtils.isAnyType(type)) { + return true; + } + + return ( + IGNORE_TYPE_LIST.findIndex((ignored_type) => { + return typeString.includes(ignored_type); + }) !== -1 + ); + } } diff --git a/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts b/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts index 40063205dac9d0f9b4ed214aec4b8922450b3a67..5b17c7dad52474dde94fcbec64d87153541edd6d 100644 --- a/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts +++ b/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts @@ -13,6 +13,8 @@ * limitations under the License. */ +import * as ts from 'typescript'; + export const DOUBLE_DOLLAR_IDENTIFIER = '$$'; export const THIS_IDENTIFIER = 'this'; export const ATTRIBUTE_SUFFIX = 'Attribute'; @@ -42,7 +44,9 @@ export enum CustomInterfaceName { export enum StorageTypeName { LocalStorage = 'LocalStorage', - AppStorage = 'AppStorage' + AppStorage = 'AppStorage', + PersistentStorage = 'PersistentStorage', + PersistenceV2 = 'PersistenceV2' } export enum PropDecoratorName { @@ -85,6 +89,74 @@ export const skipImportDecoratorName: Set = new Set([ 'LocalStorageProp' ]); +export const serializationTypeFlags: Set = new Set([ + ts.TypeFlags.String, + ts.TypeFlags.Number, + ts.TypeFlags.Boolean, + ts.TypeFlags.StringLiteral, + ts.TypeFlags.NumberLiteral, + ts.TypeFlags.BooleanLiteral, + ts.TypeFlags.Undefined, + ts.TypeFlags.Null +]); + +export const serializationTypeName: Set = new Set([ + 'Date', + 'number', + 'boolean', + 'string', + 'undefined', + 'null', + 'Date[]', + 'number[]', + 'boolean[]', + 'string[]', + 'undefined[]', + 'null[]', + 'Set', + 'Set', + 'Set', + 'Set', + 'Set', + 'Set', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map', + 'Map' +]); + export const customLayoutFunctionName: Set = new Set(['onMeasureSize', 'onPlaceChildren']); export const ENTRY_DECORATOR_NAME = 'Entry'; @@ -104,3 +176,12 @@ export const STATE_MANAGEMENT_MODULE = '@ohos.arkui.StateManagement'; export const BUILDERNODE_D_TS = 'BuilderNode.d.ts'; export const NESTING_BUILDER_SUPPORTED = 'nestingBuilderSupported'; + +export const COMMON_TS_ETS_API_D_TS = 'common_ts_ets_api.d.ts'; +export const UI_STATE_MANAGEMENT_D_TS = '@ohos.arkui.StateManagement.d.ts'; +export const PERSIST_PROP_FUNC_NAME = 'persistProp'; +export const PERSIST_PROPS_FUNC_NAME = 'persistProps'; +export const GLOBAL_CONNECT_FUNC_NAME = 'globalConnect'; +export const CONNECT_FUNC_NAME = 'connect'; + +export const USE_STATIC_STATEMENT = 'use static'; diff --git a/ets2panda/linter/src/lib/utils/consts/BuiltinWhiteList.ts b/ets2panda/linter/src/lib/utils/consts/BuiltinWhiteList.ts index 297b5fba00b1328a2e454f5989ebef0765b9fa2f..3a2fb5e275855c9de6f40e439fc81dad240f31be 100644 --- a/ets2panda/linter/src/lib/utils/consts/BuiltinWhiteList.ts +++ b/ets2panda/linter/src/lib/utils/consts/BuiltinWhiteList.ts @@ -13,12 +13,19 @@ * limitations under the License. */ +import { FaultID } from '../../Problems'; + export enum BuiltinProblem { LimitedThisArg = 'ThisArg', SymbolIterator = 'SymbolIterator', BuiltinNoCtorFunc = 'BuiltinNoCtorFunc', BuiltinNoPropertyDescriptor = 'NoPropertyDescriptor', - MissingAttributes = 'MissingAttributes' + MissingAttributes = 'MissingAttributes', + BuiltinNewCtor = 'BuiltinNewCtor', + BuiltinFinalClass = 'BuiltinFinalClass', + BuiltinNarrowTypes = 'BuiltinNarrowTypes', + BuiltinDisableApi = 'BuiltinDisableApi', + BuiltinIteratorResultValue = 'BuiltinIteratorResultValue' } export const SYMBOL_ITERATOR: string = 'Symbol.iterator'; @@ -51,3 +58,25 @@ export const BUILTIN_CONSTRUCTORS = ['Boolean', 'Number', 'Object', 'String']; export const COLLECTION_TYPES = new Set(['Map', 'Set', 'WeakMap', 'WeakSet']); export const COLLECTION_METHODS = new Set(['add', 'delete', 'get', 'has', 'set']); + +export const BUILTIN_TYPE = 'BuiltinApi'; +export const BuiltinProblemInfos = new Map([ + [BuiltinProblem.BuiltinNoCtorFunc, FaultID.BuiltinNoCtorFunc], + [BuiltinProblem.BuiltinNoPropertyDescriptor, FaultID.NoPropertyDescriptor], + [BuiltinProblem.BuiltinNarrowTypes, FaultID.BuiltinNarrowTypes], + [BuiltinProblem.BuiltinDisableApi, FaultID.BuiltinDisableApi], + [BuiltinProblem.BuiltinIteratorResultValue, FaultID.BuiltinIteratorResultValue] +]); +export const BUILTIN_CONSTRUCTOR_API_NAME: string = 'builtin_constructor'; +export const BUILTIN_CONSTRUCTOR_API_TYPE = ['CallSignature']; +export const BUILTIN_CALLSIGNATURE_NEWCTOR = [ + 'AggregateError', + 'Array', + 'Boolean', + 'Date', + 'Error', + 'Number', + 'String', + 'WeakMap', + 'Object' +]; diff --git a/ets2panda/linter/src/lib/utils/consts/DeprecateWhiteList.ts b/ets2panda/linter/src/lib/utils/consts/DeprecateWhiteList.ts index 0cdf0e2aba745f88fd8d53e26ef0bca335c0141e..e89e671d0d7878de8495f6474f3a6427e8efb6e8 100644 --- a/ets2panda/linter/src/lib/utils/consts/DeprecateWhiteList.ts +++ b/ets2panda/linter/src/lib/utils/consts/DeprecateWhiteList.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +export const DEPRECATE_TYPE = 'DeprecatedApi'; export enum DeprecateProblem { NoDeprecatedApi = 'NoDeprecatedApi' } diff --git a/ets2panda/linter/src/lib/utils/consts/SdkCommonDeprecateWhiteList.ts b/ets2panda/linter/src/lib/utils/consts/SdkCommonDeprecateWhiteList.ts index 992e803740b7d97c39c10b48c05b2d5b40e43b84..7a6c52b469ebac9347791a88c82fedc9070439f2 100644 --- a/ets2panda/linter/src/lib/utils/consts/SdkCommonDeprecateWhiteList.ts +++ b/ets2panda/linter/src/lib/utils/consts/SdkCommonDeprecateWhiteList.ts @@ -15,6 +15,7 @@ import { FaultID } from '../../Problems'; +export const SDK_COMMON_TYPE = 'SdkCommonApi'; export const SdkCommonApiProblemInfos = new Map([ ['WhiteList', FaultID.SdkCommonApiWhiteList], ['BehaviorChange', FaultID.SdkCommonApiBehaviorChange], diff --git a/ets2panda/linter/src/lib/utils/consts/TypesToBeIgnored.ts b/ets2panda/linter/src/lib/utils/consts/TypesToBeIgnored.ts new file mode 100644 index 0000000000000000000000000000000000000000..06b56ad53c8ca0351745034ce98cf18c73b1e32d --- /dev/null +++ b/ets2panda/linter/src/lib/utils/consts/TypesToBeIgnored.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const IGNORE_TYPE_LIST: string[] = ['any[]', 'Promise', 'never', 'never[]', '{}', 'undefined[]']; diff --git a/ets2panda/linter/test/builtin/builtin_array_negative.ets b/ets2panda/linter/test/builtin/builtin_array_negative.ets new file mode 100644 index 0000000000000000000000000000000000000000..dbf1092470fb76fae8a74dda764bf6d3fd9b5351 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_array_negative.ets @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { collections } from '@kit.ArkTS'; + +let arr1 = new Array(); //BuiltinNewCtor +let arr2 = new Array(); //BuiltinNewCtor +arr1.concat(1, arr2); //BuiltinAll +Array.length; +let arr11: ReadonlyArray = new Array(); //BuiltinNewCtor +let arr22: ReadonlyArray = new Array(); //BuiltinNewCtor +arr11.concat(1, arr22); //BuiltinAll + +const isArr = Array.isArray([1]); //BuiltinAll +let arr = new Array(); //BuiltinNewCtor + +const date = new Date("August 19,1975 23:00:00 UTC");//lib.es2015.core.d.ts +const jsonDate = date.toJSON(); //BuiltinAll +new Date().toJSON(); //BuiltinAll+BuiltinNewCtor +function getDate(){ + return date; +} +getDate().toJSON(); //BuiltinAll +console.log(new Demo().localDate?.toJSON()) //BuiltinAll +const demo = new Demo(); +demo.get()?.toJSON(); //BuiltinAll +Date.toString(); +//Reflect +let a1 = new Array(1,2,3) //BuiltinNewCtor +Reflect.ownKeys(a1) //BuiltinAll + +//ArrayBufferConstructor +ArrayBuffer.isView(1); //BuiltinAll +ArrayBuffer.isView(100n); //BuiltinAll +interface ArrayBufferConstructor{} +class Demo implements ArrayBufferConstructor,Date{ + localDate:Date|undefined = undefined; + set(localDate:Date|undefined){ + localDate = new Date(); //BuiltinNewCtor + return localDate + } + get():Date|undefined{ + return this.set(this.localDate); + } + isView(arg: string): arg is ArrayBufferView { + this.localDate?.toJSON(); //BuiltinAll + } + toJSON(key?: number): string { //BuiltinAll + return ''; + } +} + +let array = new collections.Array(1, 2, 3); +let array1 = new collections.Array(4, 5, 6); +let array2 = new collections.Array(7, 8, 9); +let concatArray = array.concat(array1, array2); +let arr3: collections.Array = new collections.Array('a', 'b', 'c', 'd'); +let result: boolean = collections.Array.isArray(arr3); +console.info(result + ''); + +const uint8 = new Uint8Array([1, 2, 3]); +ArrayBuffer.isView(uint8) //BuiltinAll +const buffer = new ArrayBuffer(16); +const dataView = new DataView(buffer); +ArrayBuffer.isView(dataView) //BuiltinAll + +//sum:24 \ No newline at end of file diff --git a/ets2panda/linter/test/main/var_assignment_before_use.ets.json b/ets2panda/linter/test/builtin/builtin_array_negative.ets.args.json similarity index 33% rename from ets2panda/linter/test/main/var_assignment_before_use.ets.json rename to ets2panda/linter/test/builtin/builtin_array_negative.ets.args.json index 687dd6fe1903d7f360bcaa247ec3c6210db5f411..4dfa4f20174c5965ff0a03fe9745d4cece7b7efa 100644 --- a/ets2panda/linter/test/main/var_assignment_before_use.ets.json +++ b/ets2panda/linter/test/builtin/builtin_array_negative.ets.args.json @@ -1,68 +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." - ], - "result": [ - { - "line": 19, - "column": 10, - "endLine": 19, - "endColumn": 17, - "problem": "EsValueType", - "suggest": "", - "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", - "severity": "WARNING" - }, - { - "line": 36, - "column": 10, - "endLine": 36, - "endColumn": 14, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 40, - "column": 14, - "endLine": 40, - "endColumn": 16, - "problem": "ForInStatement", - "suggest": "", - "rule": "\"for .. in\" is not supported (arkts-no-for-in)", - "severity": "ERROR" - }, - { - "line": 49, - "column": 11, - "endLine": 51, - "endColumn": 2, - "problem": "FunctionExpression", - "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", - "severity": "ERROR" - }, - { - "line": 58, - "column": 5, - "endLine": 58, - "endColumn": 21, - "problem": "DestructuringDeclaration", - "suggest": "", - "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", - "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." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/builtin/builtin_array_negative.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_array_negative.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..86ad8dac2ff070540fee8e10d07a87a357cc8756 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_array_negative.ets.arkts2.json @@ -0,0 +1,398 @@ +{ + "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": 15, + "column": 10, + "endLine": 15, + "endColumn": 21, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 16, + "endLine": 17, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 16, + "endLine": 18, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 6, + "endLine": 19, + "endColumn": 12, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 40, + "endLine": 21, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 40, + "endLine": 22, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 7, + "endLine": 23, + "endColumn": 13, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 21, + "endLine": 25, + "endColumn": 28, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 15, + "endLine": 26, + "endColumn": 20, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 23, + "endLine": 29, + "endColumn": 29, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 12, + "endLine": 30, + "endColumn": 18, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 5, + "endLine": 30, + "endColumn": 9, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 11, + "endLine": 34, + "endColumn": 17, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 35, + "endLine": 35, + "endColumn": 41, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 13, + "endLine": 37, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 14, + "endLine": 40, + "endColumn": 19, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 1, + "endLine": 41, + "endColumn": 20, + "problem": "InteropCallReflect", + "suggest": "", + "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 9, + "endLine": 41, + "endColumn": 16, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 13, + "endLine": 44, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 13, + "endLine": 45, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 47, + "column": 46, + "endLine": 47, + "endColumn": 50, + "problem": "ExtendsExpression", + "suggest": "", + "rule": "Extends or implements expression are not supported(arkts-no-extends-expression)", + "severity": "ERROR" + }, + { + "line": 47, + "column": 7, + "endLine": 47, + "endColumn": 11, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 3, + "endLine": 61, + "endColumn": 4, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 21, + "endLine": 50, + "endColumn": 25, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 54, + "column": 21, + "endLine": 54, + "endColumn": 35, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 24, + "endLine": 56, + "endColumn": 46, + "problem": "IsOperator", + "suggest": "", + "rule": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 21, + "endLine": 57, + "endColumn": 27, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 10, + "endLine": 59, + "endColumn": 22, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 5, + "endLine": 64, + "endColumn": 43, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 17, + "endLine": 64, + "endColumn": 34, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 5, + "endLine": 65, + "endColumn": 44, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 18, + "endLine": 65, + "endColumn": 35, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 66, + "column": 5, + "endLine": 66, + "endColumn": 44, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 66, + "column": 18, + "endLine": 66, + "endColumn": 35, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 5, + "endLine": 67, + "endColumn": 47, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 68, + "column": 43, + "endLine": 68, + "endColumn": 60, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 73, + "column": 13, + "endLine": 73, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 76, + "column": 13, + "endLine": 76, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_array_negative.ets.json b/ets2panda/linter/test/builtin/builtin_array_negative.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..f96a03d6a073f3f669c25fcfa60bcd6c7e65b5c7 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_array_negative.ets.json @@ -0,0 +1,78 @@ +{ + "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": 41, + "column": 1, + "endLine": 41, + "endColumn": 20, + "problem": "InteropCallReflect", + "suggest": "", + "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 24, + "endLine": 56, + "endColumn": 46, + "problem": "IsOperator", + "suggest": "", + "rule": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 5, + "endLine": 64, + "endColumn": 43, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 5, + "endLine": 65, + "endColumn": 44, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 66, + "column": 5, + "endLine": 66, + "endColumn": 44, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 5, + "endLine": 67, + "endColumn": 47, + "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/builtin/builtin_array_positive.ets b/ets2panda/linter/test/builtin/builtin_array_positive.ets new file mode 100644 index 0000000000000000000000000000000000000000..73b998f4589d060c3a51e4409ae2d036cc9443db --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_array_positive.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { collections } from '@kit.ArkTS'; +Array.length; +const date = new Date("August 19,1975 23:00:00 UTC");//lib.es2015.core.d.ts + +let array = new collections.Array(1, 2, 3); +let array1 = new collections.Array(4, 5, 6); +let array2 = new collections.Array(7, 8, 9); +let concatArray = array.concat(array1, array2); +let arr3: collections.Array = new collections.Array('a', 'b', 'c', 'd'); +let result: boolean = collections.Array.isArray(arr3); +console.info(result + ''); diff --git a/ets2panda/linter/test/builtin/builtin_array_positive.ets.args.json b/ets2panda/linter/test/builtin/builtin_array_positive.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..4dfa4f20174c5965ff0a03fe9745d4cece7b7efa --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_array_positive.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/var_assignment_before_use.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_array_positive.ets.arkts2.json similarity index 40% rename from ets2panda/linter/test/main/var_assignment_before_use.ets.arkts2.json rename to ets2panda/linter/test/builtin/builtin_array_positive.ets.arkts2.json index f827da9ffb08b67aae99f45de2ed8eaafe9b84c2..2352209dcdc16cdebbd7ddde545ba65d43dbf1ad 100644 --- a/ets2panda/linter/test/main/var_assignment_before_use.ets.arkts2.json +++ b/ets2panda/linter/test/builtin/builtin_array_positive.ets.arkts2.json @@ -1,148 +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": 17, - "column": 5, - "endLine": 17, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 18, - "column": 5, - "endLine": 18, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 19, - "column": 5, - "endLine": 19, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 19, - "column": 10, - "endLine": 19, - "endColumn": 17, - "problem": "EsValueTypeError", - "suggest": "", - "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", - "severity": "ERROR" - }, - { - "line": 20, - "column": 7, - "endLine": 20, - "endColumn": 8, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 16, - "endLine": 24, - "endColumn": 17, - "problem": "DynamicCtorCall", - "suggest": "", - "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", - "severity": "ERROR" - }, - { - "line": 32, - "column": 8, - "endLine": 32, - "endColumn": 12, - "problem": "LimitedVoidType", - "suggest": "", - "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", - "severity": "ERROR" - }, - { - "line": 33, - "column": 11, - "endLine": 33, - "endColumn": 15, - "problem": "LimitedVoidType", - "suggest": "", - "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", - "severity": "ERROR" - }, - { - "line": 36, - "column": 10, - "endLine": 36, - "endColumn": 14, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 40, - "column": 14, - "endLine": 40, - "endColumn": 16, - "problem": "ForInStatement", - "suggest": "", - "rule": "\"for .. in\" is not supported (arkts-no-for-in)", - "severity": "ERROR" - }, - { - "line": 49, - "column": 11, - "endLine": 51, - "endColumn": 2, - "problem": "FunctionExpression", - "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", - "severity": "ERROR" - }, - { - "line": 58, - "column": 5, - "endLine": 58, - "endColumn": 21, - "problem": "DestructuringDeclaration", - "suggest": "", - "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", - "severity": "ERROR" - }, - { - "line": 29, - "column": 18, - "endLine": 29, - "endColumn": 23, - "problem": "UIInterfaceImport", - "suggest": "", - "rule": "The ArkUI interface \"Event\" should be imported before it is used (arkui-modular-interface)", - "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": 15, + "column": 10, + "endLine": 15, + "endColumn": 21, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 5, + "endLine": 19, + "endColumn": 43, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 17, + "endLine": 19, + "endColumn": 34, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 5, + "endLine": 20, + "endColumn": 44, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 18, + "endLine": 20, + "endColumn": 35, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 5, + "endLine": 21, + "endColumn": 44, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 18, + "endLine": 21, + "endColumn": 35, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 5, + "endLine": 22, + "endColumn": 47, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 43, + "endLine": 23, + "endColumn": 60, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + } + ] } \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_array_positive.ets.json b/ets2panda/linter/test/builtin/builtin_array_positive.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..e44cb0bda37d0d05d17c210929930e004c297a67 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_array_positive.ets.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 19, + "column": 5, + "endLine": 19, + "endColumn": 43, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 5, + "endLine": 20, + "endColumn": 44, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 5, + "endLine": 21, + "endColumn": 44, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 5, + "endLine": 22, + "endColumn": 47, + "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/builtin/builtin_callsignature.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_callsignature.ets.arkts2.json index 82638906838c1734e3d4c539b65ac8ad583f7425..6cdfec1941d1a2cbd4a14245402b9310ac583aa9 100644 --- a/ets2panda/linter/test/builtin/builtin_callsignature.ets.arkts2.json +++ b/ets2panda/linter/test/builtin/builtin_callsignature.ets.arkts2.json @@ -34,6 +34,16 @@ "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", "severity": "ERROR" }, + { + "line": 20, + "column": 10, + "endLine": 20, + "endColumn": 15, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 23, "column": 29, diff --git a/ets2panda/linter/test/builtin/builtin_class.ets b/ets2panda/linter/test/builtin/builtin_class.ets new file mode 100644 index 0000000000000000000000000000000000000000..49d613c0963e2054b38be468839a27c85496b270 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_class.ets @@ -0,0 +1,102 @@ +/* + * 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 MyIntArray extends Int8Array implements Int8Array{} //BuiltinFinalClass*2 +interface MyIntArray2 extends Int8Array {} //BuiltinFinalClass + +class MyBigInt1 extends BigInt implements BigInt { //BuiltinFinalClass*2 + constructor(value: bigint | string | number) { + super(value); + } + [Symbol.iterator](): IterableIterator{ //BuiltinSymbolIterator + return this; + } +} + +class MyDataView1 extends DataView implements DataView{} //BuiltinFinalClass*2 +interface MyDataView3 extends DataView {} //BuiltinFinalClass + +class MyInt16Array1 extends Int16Array implements Int16Array { //BuiltinFinalClass*2 + filter(predicate: (value: number, index: number, array: Int16Array) => number, thisArg?: number): Int16Array {//BuiltinAll + return new Int16Array; + } +} +interface MyInt16Array2 extends Int16Array{ //BuiltinFinalClass + every(predicate: (value: number, index: number, array: Int16Array) => void, thisArg?: string): void; +} +class MyInt32Array1 extends Int32Array{}//BuiltinFinalClass +class MyInt32Array2 implements Int32Array{} //BuiltinFinalClass +interface MyInt32Array3 extends Int32Array{}; //BuiltinFinalClass + +class MyBigInt64Array1 extends BigInt64Array implements BigInt64Array{}//BuiltinFinalClass*2 +interface MyBigInt64Array2 extends BigInt64Array{}//BuiltinFinalClass + +class EmptyIterator implements IterableIterator{// + next(): IteratorResult {//BuiltinAll + return { done: true, value: undefined as void as T }; + } + + [Symbol.iterator](): IterableIterator {//BuiltinSymbolIterator*2 + return this; + }} +interface EmptyIterator2 extends IterableIterator{} + +class MyFloatArray1 extends Float32Array implements Float32Array,Float64Array {} //BuiltinFinalClass*3 +interface MyFloat32Array3 extends Float32Array{} //BuiltinFinalClass +interface MyFloat64Array3 extends Float64Array{} //BuiltinFinalClass + +class MyWeak extends WeakMapimplements WeakMap,WeakSet{} //BuiltinFinalClass*3 +interface MyWeakMap3 extends WeakMap{} //BuiltinFinalClass +class MyWeakSet1 extends WeakSet{} //BuiltinFinalClass +interface MyWeakSet3 extends WeakSet{} //BuiltinFinalClass + +class MyObject extends Boolean implements Boolean,String{} //BuiltinFinalClass*3 +interface MyBoolean3 extends Boolean {} //BuiltinFinalClass +interface MyString3 extends String{} //BuiltinFinalClass +class MyFinalizationRegistry1 extends FinalizationRegistry{} //BuiltinFinalClass +class MyFinalizationRegistry2 implements FinalizationRegistry { //BuiltinFinalClass + [Symbol.toStringTag]: "FinalizationRegistry"|undefined=undefined; + register(target: object, heldValue: T, unregisterToken?: object): void {} + unregister(unregisterToken: object): void {} +} +interface MyFinalizationRegistry3 extends FinalizationRegistry{} //BuiltinFinalClass +class MyPromise1 extends Promise { + constructor(executor: (resolve: (value: T | PromiseLike) => void, reject: (reason?: number) => void) => void) { + super(executor); + } +} + +class MyPromise2 implements Promise { + then( + onfulfilled?: ((value: string) => TResult1 | PromiseLike) | null, + onrejected?: ((reason: string) => TResult2 | PromiseLike) | null + ): Promise { + return Promise.resolve() as Promise; + } + + catch( + onrejected?: ((reason: string) => TResult | PromiseLike) | null + ): Promise { + return Promise.resolve() as Promise; + } + + finally(onfinally?: (() => void) | null): Promise { + return Promise.resolve() as Promise; + } + + [Symbol.toStringTag]: string = "Promise"; +} + +interface MyPromise3 extends Promise {} diff --git a/ets2panda/linter/test/builtin/builtin_class.ets.args.json b/ets2panda/linter/test/builtin/builtin_class.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..4dfa4f20174c5965ff0a03fe9745d4cece7b7efa --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_class.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/builtin/builtin_class.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_class.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..11d39cae875aa581d22ce969828f85b9be9c6996 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_class.ets.arkts2.json @@ -0,0 +1,668 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 16, + "column": 26, + "endLine": 16, + "endColumn": 35, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 16, + "column": 7, + "endLine": 16, + "endColumn": 17, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 16, + "column": 47, + "endLine": 16, + "endColumn": 56, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 31, + "endLine": 17, + "endColumn": 40, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 25, + "endLine": 19, + "endColumn": 31, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 7, + "endLine": 19, + "endColumn": 16, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 43, + "endLine": 19, + "endColumn": 49, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 4, + "endLine": 23, + "endColumn": 19, + "problem": "BuiltinSymbolIterator", + "suggest": "", + "rule": "Using \"Symbol.iterator\" is not allowed in this API (arkts-builtin-symbol-iterator)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 27, + "endLine": 28, + "endColumn": 35, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 7, + "endLine": 28, + "endColumn": 18, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 48, + "endLine": 28, + "endColumn": 56, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 31, + "endLine": 29, + "endColumn": 39, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 29, + "endLine": 31, + "endColumn": 39, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 7, + "endLine": 31, + "endColumn": 20, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 51, + "endLine": 31, + "endColumn": 61, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 10, + "endLine": 32, + "endColumn": 80, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 82, + "endLine": 32, + "endColumn": 98, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 33, + "endLine": 36, + "endColumn": 43, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 29, + "endLine": 39, + "endColumn": 39, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 7, + "endLine": 40, + "endColumn": 20, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 32, + "endLine": 40, + "endColumn": 42, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 33, + "endLine": 41, + "endColumn": 43, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 32, + "endLine": 43, + "endColumn": 45, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 7, + "endLine": 43, + "endColumn": 23, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 57, + "endLine": 43, + "endColumn": 70, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 37, + "endLine": 44, + "endColumn": 50, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 46, + "column": 7, + "endLine": 46, + "endColumn": 20, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 47, + "column": 11, + "endLine": 47, + "endColumn": 25, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 14, + "endLine": 48, + "endColumn": 18, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 26, + "endLine": 48, + "endColumn": 31, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 46, + "endLine": 48, + "endColumn": 50, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 51, + "column": 4, + "endLine": 51, + "endColumn": 19, + "problem": "BuiltinSymbolIterator", + "suggest": "", + "rule": "Using \"Symbol.iterator\" is not allowed in this API (arkts-builtin-symbol-iterator)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 29, + "endLine": 56, + "endColumn": 41, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 7, + "endLine": 56, + "endColumn": 20, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 53, + "endLine": 56, + "endColumn": 65, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 66, + "endLine": 56, + "endColumn": 78, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 35, + "endLine": 57, + "endColumn": 47, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 35, + "endLine": 58, + "endColumn": 47, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 43, + "endLine": 60, + "endColumn": 50, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 7, + "endLine": 60, + "endColumn": 13, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 67, + "endLine": 60, + "endColumn": 74, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 81, + "endLine": 60, + "endColumn": 88, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 61, + "column": 51, + "endLine": 61, + "endColumn": 58, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 44, + "endLine": 62, + "endColumn": 51, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 48, + "endLine": 63, + "endColumn": 55, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 24, + "endLine": 65, + "endColumn": 31, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 7, + "endLine": 65, + "endColumn": 15, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 43, + "endLine": 65, + "endColumn": 50, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 51, + "endLine": 65, + "endColumn": 57, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 66, + "column": 30, + "endLine": 66, + "endColumn": 37, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 29, + "endLine": 67, + "endColumn": 35, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 68, + "column": 42, + "endLine": 68, + "endColumn": 62, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 45, + "endLine": 69, + "endColumn": 65, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 3, + "endLine": 70, + "endColumn": 23, + "problem": "ComputedPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 11, + "endLine": 70, + "endColumn": 22, + "problem": "SymbolType", + "suggest": "", + "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "severity": "ERROR" + }, + { + "line": 74, + "column": 46, + "endLine": 74, + "endColumn": 66, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 29, + "endLine": 75, + "endColumn": 36, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 32, + "endLine": 81, + "endColumn": 39, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 83, + "column": 5, + "endLine": 83, + "endColumn": 79, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 84, + "column": 5, + "endLine": 84, + "endColumn": 79, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 90, + "column": 5, + "endLine": 90, + "endColumn": 77, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 3, + "endLine": 99, + "endColumn": 23, + "problem": "ComputedPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 11, + "endLine": 99, + "endColumn": 22, + "problem": "SymbolType", + "suggest": "", + "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "severity": "ERROR" + }, + { + "line": 102, + "column": 33, + "endLine": 102, + "endColumn": 40, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 3, + "endLine": 70, + "endColumn": 23, + "problem": "StrictDiagnostic", + "suggest": "Property '[Symbol.toStringTag]' in type 'MyFinalizationRegistry2' is not assignable to the same property in base type 'FinalizationRegistry'.\n Type '\"FinalizationRegistry\" | undefined' is not assignable to type '\"FinalizationRegistry\"'.\n Type 'undefined' is not assignable to type '\"FinalizationRegistry\"'.", + "rule": "Property '[Symbol.toStringTag]' in type 'MyFinalizationRegistry2' is not assignable to the same property in base type 'FinalizationRegistry'.\n Type '\"FinalizationRegistry\" | undefined' is not assignable to type '\"FinalizationRegistry\"'.\n Type 'undefined' is not assignable to type '\"FinalizationRegistry\"'.", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_class.ets.json b/ets2panda/linter/test/builtin/builtin_class.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..93d76b46940663af5381df85cf13cfb8f4f2f164 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_class.ets.json @@ -0,0 +1,68 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 70, + "column": 3, + "endLine": 70, + "endColumn": 23, + "problem": "ComputedPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 4, + "endLine": 70, + "endColumn": 22, + "problem": "SymbolType", + "suggest": "", + "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 3, + "endLine": 99, + "endColumn": 23, + "problem": "ComputedPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 4, + "endLine": 99, + "endColumn": 22, + "problem": "SymbolType", + "suggest": "", + "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 3, + "endLine": 70, + "endColumn": 23, + "problem": "StrictDiagnostic", + "suggest": "Property '[Symbol.toStringTag]' in type 'MyFinalizationRegistry2' is not assignable to the same property in base type 'FinalizationRegistry'.\n Type '\"FinalizationRegistry\" | undefined' is not assignable to type '\"FinalizationRegistry\"'.\n Type 'undefined' is not assignable to type '\"FinalizationRegistry\"'.", + "rule": "Property '[Symbol.toStringTag]' in type 'MyFinalizationRegistry2' is not assignable to the same property in base type 'FinalizationRegistry'.\n Type '\"FinalizationRegistry\" | undefined' is not assignable to type '\"FinalizationRegistry\"'.\n Type 'undefined' is not assignable to type '\"FinalizationRegistry\"'.", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_decorator.ets b/ets2panda/linter/test/builtin/builtin_decorator.ets new file mode 100644 index 0000000000000000000000000000000000000000..68c12e679052217a3bbbe6d2fc6cd74708936c2a --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_decorator.ets @@ -0,0 +1,229 @@ +/* + * 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. + */ + +let propertyDecorator: PropertyDecorator = (ttt, yyy) => { + console.log(yyy as string); +} + +class A { + @propertyDecorator + prop = 1 +} + +let classDecorator: ClassDecorator = (target) => { return target } + +@classDecorator +class B {} + +let methodDecorator: MethodDecorator = (target, propertyKey, descriptor) => { +console.log(JSON.stringify(descriptor)); +} + +class C { + @methodDecorator + method(): void {} +} + +let paramDecorator: ParameterDecorator = (target, methodName, paramIdx) => { + console.log(methodName as string); +} + +class D { + method(@paramDecorator param: string): void {} +} + +class C implements Iterator { + a: number = 0; + b: number; + constructor (b:number) { + this.b = b; + } + next(): IteratorResult { + if (this.a >= this.b) { + return {value:undefined, done:true} + } + this.a++; + return {value:this.a, done:false} + } + return(): IteratorResult { //error + console.log("call return") + this.a = 0; + return {value:undefined, done:true} + } + throw(e:Error): IteratorResult { //error + console.error("Error: " + e); + return { value: undefined, done: true }; + } +} +let a = new C(5) +a.next() +a.return() +a.throw(new Error("test")) + + +let b = String.raw`a\nb\nc` //error + + +function f(c:TemplateStringsArray, ...values: Object[]) { + c.raw; //error +} +const c: string = "123" +f`Hello, ${c}!` + + +type T1 = number | T1[]; +let arr1: ReadonlyArray = [1, [1]]; +arr1.flat(2); //error + + +type T = number | T[]; +let arr: ReadonlyArray = [1, [1]]; +arr.flatMap((value, index, array) => { //error + return value; +}); + + +let num = new Object(); +num.valueOf(); //error + + +type T2 = number | T2[]; +let arr2: Array = [1, [1]]; +arr2.flat(2); //error + + +const str = ''; +const arr3 = Array.from(str); //error + + +let buff: ArrayBufferTypes = { + ArrayBuffer: new ArrayBuffer(10), + SharedArrayBuffer: new SharedArrayBuffer(10) +} +buff.ArrayBuffer; //error +buff.SharedArrayBuffer; + + +function fn1(iArguments: IArguments) { + Reflect.get(iArguments, Symbol.iterator); //error +} + + +function fn2(iArguments: IArguments) { + iArguments.callee; //error +} + + +function fn3(iArguments: IArguments) { + iArguments.length; //error +} + + +let o: Intl.DateTimeFormatPartTypesRegistry = { + day: undefined, //error + dayPeriod: undefined, //error + era: undefined, //error + hour: undefined, //error + literal: undefined, //error + minute: undefined, //error + month: undefined, //error + second: undefined, //error + timeZoneName: undefined, //error + weekday: undefined, //error + year: undefined, //error + unknown: undefined, + fractionalSecond: undefined +} + + +Intl.DisplayNames.prototype; //error + + +Intl.ListFormat.prototype; //error + + +Intl.NumberFormat.prototype; //error + + +const arr4 = [0, 1, 2, [3, 4]]; +let arr5: FlatArray = arr4.flat(); //error + + +let d: Object = Object(); //error + + +let d1: Object = Object({}); //error + + +const text = '2025-01-01'; +const regex = /(?\d{4})-(?\d{2})-(?\d{2})/; +const match = regex.exec(text); +console.log(match!.groups!.year); //error + + +const text1 = '2025-01-01'; +const regex1 = /(?\d{4})-(?\d{2})-(?\d{2})/; +const match1 = text1.match(regex1); +console.log(match1!.groups!.year); //error + + +class FileReader { + private lines: string[] = ["Line 1", "Line 2", "Line 3"]; + + [Symbol.iterator](): Iterator { + let index = 0; + const self = this; + + return { + next(): IteratorResult { + if (index < self.lines.length) { + return { value: self.lines[index++], done: false }; + } else { + return { value: undefined, done: true }; + } + }, + + return(): IteratorReturnResult { //error + return { done: true, value: index }; + }, + }; + } +} + + +class Counter { + private count: number = 0; + private max: number; + + constructor(max: number) { + this.max = max; + } + + [Symbol.iterator](): Iterator { + const self = this; + + return { + next(): IteratorYieldResult { //error + if (self.count < self.max) { + return { + value: self.count++, + }; + } + + return { done: false, value: -1 }; + }, + }; + } +} diff --git a/ets2panda/linter/test/builtin/builtin_decorator.ets.args.json b/ets2panda/linter/test/builtin/builtin_decorator.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..ec9992d92461d66e16b80975e33f95872c06af54 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_decorator.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/builtin/builtin_decorator.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_decorator.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..f064799fd9eb474c043f862cd11bc78c6efc8255 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_decorator.ets.arkts2.json @@ -0,0 +1,878 @@ +{ + "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": 21, + "column": 3, + "endLine": 21, + "endColumn": 21, + "problem": "DecoratorsNotSupported", + "suggest": "", + "rule": "Decorators are not supported(arkts-no-ts-decorators)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 3, + "endLine": 21, + "endColumn": 21, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 1, + "endLine": 27, + "endColumn": 16, + "problem": "DecoratorsNotSupported", + "suggest": "", + "rule": "Decorators are not supported(arkts-no-ts-decorators)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 1, + "endLine": 27, + "endColumn": 16, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 62, + "endLine": 30, + "endColumn": 72, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 18, + "endLine": 31, + "endColumn": 27, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 18, + "endLine": 31, + "endColumn": 27, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 3, + "endLine": 35, + "endColumn": 19, + "problem": "DecoratorsNotSupported", + "suggest": "", + "rule": "Decorators are not supported(arkts-no-ts-decorators)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 3, + "endLine": 35, + "endColumn": 19, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 10, + "endLine": 44, + "endColumn": 25, + "problem": "DecoratorsNotSupported", + "suggest": "", + "rule": "Decorators are not supported(arkts-no-ts-decorators)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 10, + "endLine": 44, + "endColumn": 25, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 3, + "endLine": 64, + "endColumn": 4, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 3, + "endLine": 68, + "endColumn": 4, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 53, + "column": 11, + "endLine": 53, + "endColumn": 25, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 15, + "endLine": 55, + "endColumn": 20, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 32, + "endLine": 55, + "endColumn": 36, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 13, + "endLine": 58, + "endColumn": 18, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 27, + "endLine": 58, + "endColumn": 31, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 3, + "endLine": 60, + "endColumn": 9, + "problem": "InvalidIdentifier", + "suggest": "", + "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 13, + "endLine": 60, + "endColumn": 27, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 13, + "endLine": 63, + "endColumn": 18, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 30, + "endLine": 63, + "endColumn": 34, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 3, + "endLine": 65, + "endColumn": 8, + "problem": "InvalidIdentifier", + "suggest": "", + "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 19, + "endLine": 65, + "endColumn": 33, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 14, + "endLine": 67, + "endColumn": 19, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 32, + "endLine": 67, + "endColumn": 36, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 76, + "column": 16, + "endLine": 76, + "endColumn": 19, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 76, + "column": 9, + "endLine": 76, + "endColumn": 28, + "problem": "TaggedTemplates", + "suggest": "", + "rule": "Tagged templates are not supported (arkts-no-tagged-templates)", + "severity": "ERROR" + }, + { + "line": 80, + "column": 5, + "endLine": 80, + "endColumn": 8, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 83, + "column": 1, + "endLine": 83, + "endColumn": 16, + "problem": "TaggedTemplates", + "suggest": "", + "rule": "Tagged templates are not supported (arkts-no-tagged-templates)", + "severity": "ERROR" + }, + { + "line": 88, + "column": 6, + "endLine": 88, + "endColumn": 10, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 5, + "endLine": 93, + "endColumn": 12, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 15, + "endLine": 98, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 5, + "endLine": 99, + "endColumn": 12, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 104, + "column": 6, + "endLine": 104, + "endColumn": 10, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 108, + "column": 20, + "endLine": 108, + "endColumn": 24, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 112, + "column": 3, + "endLine": 112, + "endColumn": 14, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 113, + "column": 26, + "endLine": 113, + "endColumn": 43, + "problem": "SharedArrayBufferDeprecated", + "suggest": "", + "rule": "SharedArrayBuffer is not supported (arkts-no-need-stdlib-sharedArrayBuffer)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 6, + "endLine": 115, + "endColumn": 17, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 120, + "column": 3, + "endLine": 120, + "endColumn": 44, + "problem": "InteropCallReflect", + "suggest": "", + "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", + "severity": "ERROR" + }, + { + "line": 120, + "column": 27, + "endLine": 120, + "endColumn": 42, + "problem": "BuiltinSymbolIterator", + "suggest": "", + "rule": "Using \"Symbol.iterator\" is not allowed in this API (arkts-builtin-symbol-iterator)", + "severity": "ERROR" + }, + { + "line": 125, + "column": 14, + "endLine": 125, + "endColumn": 20, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 130, + "column": 14, + "endLine": 130, + "endColumn": 20, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 135, + "column": 3, + "endLine": 135, + "endColumn": 6, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 136, + "column": 3, + "endLine": 136, + "endColumn": 12, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 137, + "column": 3, + "endLine": 137, + "endColumn": 6, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 138, + "column": 3, + "endLine": 138, + "endColumn": 7, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 139, + "column": 3, + "endLine": 139, + "endColumn": 10, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 140, + "column": 3, + "endLine": 140, + "endColumn": 9, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 141, + "column": 3, + "endLine": 141, + "endColumn": 8, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 142, + "column": 3, + "endLine": 142, + "endColumn": 9, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 143, + "column": 3, + "endLine": 143, + "endColumn": 15, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 144, + "column": 3, + "endLine": 144, + "endColumn": 10, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 145, + "column": 3, + "endLine": 145, + "endColumn": 7, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 151, + "column": 19, + "endLine": 151, + "endColumn": 28, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 151, + "column": 19, + "endLine": 151, + "endColumn": 28, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "severity": "ERROR" + }, + { + "line": 154, + "column": 17, + "endLine": 154, + "endColumn": 26, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 154, + "column": 17, + "endLine": 154, + "endColumn": 26, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "severity": "ERROR" + }, + { + "line": 157, + "column": 19, + "endLine": 157, + "endColumn": 28, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 157, + "column": 19, + "endLine": 157, + "endColumn": 28, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "severity": "ERROR" + }, + { + "line": 157, + "column": 1, + "endLine": 157, + "endColumn": 18, + "problem": "PropertyDeclOnFunction", + "suggest": "", + "rule": "Declaring properties on functions is not supported (arkts-no-func-props)", + "severity": "ERROR" + }, + { + "line": 161, + "column": 11, + "endLine": 161, + "endColumn": 20, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 161, + "column": 31, + "endLine": 161, + "endColumn": 33, + "problem": "LimitedLiteralType", + "suggest": "", + "rule": "Literal types are restricted(arkts-limited-literal-types)", + "severity": "ERROR" + }, + { + "line": 161, + "column": 42, + "endLine": 161, + "endColumn": 46, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 164, + "column": 17, + "endLine": 164, + "endColumn": 23, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 167, + "column": 18, + "endLine": 167, + "endColumn": 24, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 171, + "column": 15, + "endLine": 171, + "endColumn": 61, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + }, + { + "line": 173, + "column": 20, + "endLine": 173, + "endColumn": 26, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 177, + "column": 16, + "endLine": 177, + "endColumn": 62, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + }, + { + "line": 179, + "column": 21, + "endLine": 179, + "endColumn": 27, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 185, + "column": 4, + "endLine": 185, + "endColumn": 19, + "problem": "BuiltinSymbolIterator", + "suggest": "", + "rule": "Using \"Symbol.iterator\" is not allowed in this API (arkts-builtin-symbol-iterator)", + "severity": "ERROR" + }, + { + "line": 189, + "column": 12, + "endLine": 189, + "endColumn": 13, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 190, + "column": 15, + "endLine": 190, + "endColumn": 29, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 192, + "column": 20, + "endLine": 192, + "endColumn": 25, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 192, + "column": 38, + "endLine": 192, + "endColumn": 45, + "problem": "ArrayIndexExprType", + "suggest": "", + "rule": "The index expression must be of a numeric type (arkts-array-index-expr-type)", + "severity": "ERROR" + }, + { + "line": 192, + "column": 48, + "endLine": 192, + "endColumn": 52, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 194, + "column": 20, + "endLine": 194, + "endColumn": 25, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 194, + "column": 38, + "endLine": 194, + "endColumn": 42, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 198, + "column": 7, + "endLine": 198, + "endColumn": 13, + "problem": "InvalidIdentifier", + "suggest": "", + "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", + "severity": "ERROR" + }, + { + "line": 199, + "column": 18, + "endLine": 199, + "endColumn": 22, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 199, + "column": 30, + "endLine": 199, + "endColumn": 35, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 214, + "column": 4, + "endLine": 214, + "endColumn": 19, + "problem": "BuiltinSymbolIterator", + "suggest": "", + "rule": "Using \"Symbol.iterator\" is not allowed in this API (arkts-builtin-symbol-iterator)", + "severity": "ERROR" + }, + { + "line": 217, + "column": 12, + "endLine": 217, + "endColumn": 13, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 221, + "column": 13, + "endLine": 221, + "endColumn": 18, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 225, + "column": 18, + "endLine": 225, + "endColumn": 22, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 225, + "column": 31, + "endLine": 225, + "endColumn": 36, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_decorator.ets.json b/ets2panda/linter/test/builtin/builtin_decorator.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..653a0772bb0cbe71df761c056e3b94562ecb1921 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_decorator.ets.json @@ -0,0 +1,78 @@ +{ + "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": 120, + "column": 3, + "endLine": 120, + "endColumn": 44, + "problem": "InteropCallReflect", + "suggest": "", + "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", + "severity": "ERROR" + }, + { + "line": 151, + "column": 19, + "endLine": 151, + "endColumn": 28, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "severity": "ERROR" + }, + { + "line": 154, + "column": 17, + "endLine": 154, + "endColumn": 26, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "severity": "ERROR" + }, + { + "line": 157, + "column": 19, + "endLine": 157, + "endColumn": 28, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)", + "severity": "ERROR" + }, + { + "line": 189, + "column": 12, + "endLine": 189, + "endColumn": 13, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 217, + "column": 12, + "endLine": 217, + "endColumn": 13, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_error_negative.ets b/ets2panda/linter/test/builtin/builtin_error_negative.ets new file mode 100644 index 0000000000000000000000000000000000000000..36716c22fd73e9dfe075179dde8342964166cd14 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_error_negative.ets @@ -0,0 +1,53 @@ +/* + * 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. + */ + +let err1: AggregateError = new AggregateError([1]); //NoPropertyDescriptor +let err2: AggregateError = new AggregateError([1]); //NoPropertyDescriptor +let errors: Object[] = err2.errors; // NoPropertyDescriptor +try { + throw new Error(); //lib.es2022.error.d.ts +} catch (e) { + new Error("Connecting to database failed.", {cause: e}); +} +function get(err: AggregateError):Error { //NoPropertyDescriptor + const a = AggregateError.name; + const errr = Error() //BuiltinNoCtorFunc + return new Error; //lib.es2022.error.d.ts +} +const err3 = new AggregateError([1, "two", new Error("fail")]); //NoPropertyDescriptor +console.log(err3.errors.toString()); // NoPropertyDescriptor +console.log(err3.message); // NoPropertyDescriptor? + +const err4 = new AggregateError( //NoPropertyDescriptor + [new TypeError("invalid type"), new RangeError("out of bounds")], + "Multiple errors occurred" +); +console.log(err4.errors.length.toString()); // NoPropertyDescriptor + BuiltinAll + +function fetchData() { + try { + throw new Error("Network timeout"); //BuiltinNoCtorFunc lib.es2022.error.d.ts + } catch (e) { + return new Error("Fetch failed", { cause: e }); + } +} + +const result = fetchData(); +if (result.cause) {//NoPropertyDescriptor + console.log("Root cause:", result.cause.message); // NoPropertyDescriptor +} +console.log(err4.errors.toString()); // NoPropertyDescriptor + +//sum:18-1 \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_error_negative.ets.args.json b/ets2panda/linter/test/builtin/builtin_error_negative.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..4dfa4f20174c5965ff0a03fe9745d4cece7b7efa --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_error_negative.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/builtin/builtin_error_negative.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_error_negative.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..4b1ce86a71b4df73dff0f89817f6ac45d86a4a36 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_error_negative.ets.arkts2.json @@ -0,0 +1,238 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 16, + "column": 5, + "endLine": 16, + "endColumn": 9, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 5, + "endLine": 17, + "endColumn": 9, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 5, + "endLine": 18, + "endColumn": 35, + "problem": "ArrayTypeImmutable", + "suggest": "", + "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 24, + "endLine": 18, + "endColumn": 28, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 29, + "endLine": 18, + "endColumn": 35, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 48, + "endLine": 22, + "endColumn": 53, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 14, + "endLine": 24, + "endColumn": 17, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 16, + "endLine": 26, + "endColumn": 21, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 7, + "endLine": 29, + "endColumn": 11, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 13, + "endLine": 30, + "endColumn": 17, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 18, + "endLine": 30, + "endColumn": 24, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 13, + "endLine": 31, + "endColumn": 17, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 7, + "endLine": 33, + "endColumn": 11, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 8, + "endLine": 34, + "endColumn": 17, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 39, + "endLine": 34, + "endColumn": 49, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 13, + "endLine": 37, + "endColumn": 17, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 37, + "column": 18, + "endLine": 37, + "endColumn": 24, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 40, + "endLine": 43, + "endColumn": 45, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 12, + "endLine": 48, + "endColumn": 17, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 49, + "column": 37, + "endLine": 49, + "endColumn": 42, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 51, + "column": 13, + "endLine": 51, + "endColumn": 17, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 51, + "column": 18, + "endLine": 51, + "endColumn": 24, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_error_negative.ets.json b/ets2panda/linter/test/builtin/builtin_error_negative.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..7633c79b6aa0073a72cf8f74a66e11dac370f619 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_error_negative.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_error_positive.ets b/ets2panda/linter/test/builtin/builtin_error_positive.ets new file mode 100644 index 0000000000000000000000000000000000000000..80579bdae4ad51ed621a07a3dacf9ca06367d20d --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_error_positive.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +try { + throw new Error(); //lib.es2022.error.d.ts +} catch (e) { + new Error("Connecting to database failed."); +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_error_positive.ets.args.json b/ets2panda/linter/test/builtin/builtin_error_positive.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..4dfa4f20174c5965ff0a03fe9745d4cece7b7efa --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_error_positive.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/builtin/builtin_error_positive.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_error_positive.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_error_positive.ets.arkts2.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_error_positive.ets.json b/ets2panda/linter/test/builtin/builtin_error_positive.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..7633c79b6aa0073a72cf8f74a66e11dac370f619 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_error_positive.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_iterator_result.ets b/ets2panda/linter/test/builtin/builtin_iterator_result.ets new file mode 100644 index 0000000000000000000000000000000000000000..cbe6df9118a642183a709ba14cde9f02b56c7a34 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_iterator_result.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +let arr = new Array('a'); +let iterator = arr.entries(); +let result = iterator.next(); +result.value[0]; + +arr.entries().next().value; \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_iterator_result.ets.args.json b/ets2panda/linter/test/builtin/builtin_iterator_result.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..ec9992d92461d66e16b80975e33f95872c06af54 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_iterator_result.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/builtin/builtin_iterator_result.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_iterator_result.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..424cd6f851e3cfbe47fcada0b4e4e52faee17c2f --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_iterator_result.ets.arkts2.json @@ -0,0 +1,48 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 16, + "column": 15, + "endLine": 16, + "endColumn": 20, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 13, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 1, + "endLine": 21, + "endColumn": 27, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_iterator_result.ets.json b/ets2panda/linter/test/builtin/builtin_iterator_result.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_iterator_result.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/builtin/builtin_not_support_property_descriptor.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_not_support_property_descriptor.ets.arkts2.json index aa44c0c86ecfe9f32627a82e87583d76b21508dc..f0f3bcf5e33f33376d4504915fa317fb121feb20 100644 --- a/ets2panda/linter/test/builtin/builtin_not_support_property_descriptor.ets.arkts2.json +++ b/ets2panda/linter/test/builtin/builtin_not_support_property_descriptor.ets.arkts2.json @@ -54,6 +54,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 17, + "column": 4, + "endLine": 17, + "endColumn": 16, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 18, "column": 2, @@ -64,6 +74,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 18, + "column": 4, + "endLine": 18, + "endColumn": 14, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 19, "column": 2, @@ -74,6 +94,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 19, + "column": 4, + "endLine": 19, + "endColumn": 9, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 20, "column": 2, @@ -84,6 +114,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 20, + "column": 4, + "endLine": 20, + "endColumn": 12, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 21, "column": 2, @@ -124,6 +164,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 26, + "column": 3, + "endLine": 26, + "endColumn": 8, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 28, "column": 7, @@ -134,6 +184,36 @@ "rule": "Type of parameter must be defined explicitly (arkts-require-func-arg-type)", "severity": "ERROR" }, + { + "line": 29, + "column": 3, + "endLine": 29, + "endColumn": 13, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 3, + "endLine": 30, + "endColumn": 15, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 3, + "endLine": 31, + "endColumn": 11, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 37, "column": 1, @@ -164,6 +244,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 38, + "column": 7, + "endLine": 38, + "endColumn": 19, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 39, "column": 5, @@ -174,6 +264,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 39, + "column": 7, + "endLine": 39, + "endColumn": 17, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 40, "column": 5, @@ -184,6 +284,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 40, + "column": 7, + "endLine": 40, + "endColumn": 12, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 41, "column": 5, @@ -194,6 +304,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 41, + "column": 7, + "endLine": 41, + "endColumn": 15, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 42, "column": 5, @@ -224,6 +344,16 @@ "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", "severity": "ERROR" }, + { + "line": 47, + "column": 5, + "endLine": 47, + "endColumn": 10, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 49, "column": 9, @@ -234,6 +364,36 @@ "rule": "Type of parameter must be defined explicitly (arkts-require-func-arg-type)", "severity": "ERROR" }, + { + "line": 50, + "column": 5, + "endLine": 50, + "endColumn": 15, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 51, + "column": 5, + "endLine": 51, + "endColumn": 17, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 5, + "endLine": 52, + "endColumn": 13, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, { "line": 57, "column": 11, diff --git a/ets2panda/linter/test/builtin/builtin_object_negative.ets b/ets2panda/linter/test/builtin/builtin_object_negative.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc99adc965614c99767d18b946aa08ddf23b829f --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_object_negative.ets @@ -0,0 +1,114 @@ +/* + * 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. + */ +//NumberConstructor +const num1 = new Number('123');//BuiltinNewCtor 1 +Number('123');//BuiltinNoCtorFunc 1 +console.log(Number(undefined).toString());//BuiltinNoCtorFunc 1 +Number.isFinite(1) //BuiltinAll 1 +Number.isInteger(true) //BuiltinAll 1 +Number.isNaN(true) //BuiltinAll 1 +Number.isSafeInteger(true) //BuiltinAll 1 +isFinite(11); +//ObjectConstructor +interface Person { + name: string; + age: number; +} +const obj: Person = { + name: '', + age: 42 +}; +const a: [string, number][] = Object.entries(obj);//BuiltinAll 1 +Object.values(obj);//BuiltinAll 1 + +const entries: Map = new Map([ + ['1', '2'] +]); +const obj1 = Object.fromEntries(entries);//BuiltinAll 1 +typeof new Object();//BuiltinAll 1 + +//String +new String(undefined);//BuiltinNewCtor 1 +String('');//BuiltinNoCtorFunc 1 +const str: string = 'abc'; +str.replace('a', 'b'); +str.replaceAll('a', 'b'); +class Demo implements String{ + replaceAll1(searchValue: string | RegExp, replacer: string): string { + + } + replaceAll(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string{//BuiltinAll 1 + + } +} +//replace(searchValue: string | RegExp, replaceValue: string): string; +const text = "Hello World, World!"; +const result1 = text.replace("World", "TypeScript"); +const result2 = text.replace(/World/g, "TypeScript"); + +//replace(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; +function toUpperCaseReplacer(match: string): string { + return match.toUpperCase(); +} +text.replace('',toUpperCaseReplacer)//BuiltinAll 1 +const result4 = text.replace("world", (match) => match.toUpperCase());//BuiltinAll 1 +const result5 = text.replace("/(\w+) (\w+)/", (first, last:number) => `${last}, ${first}`);//BuiltinAll 1 +//replace(searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string): string; +//lib.es2015.symbol.wellknown.d.ts +const result6 = text.replace(/-/g, (match, offset:string) => `-${offset}-`);//BuiltinAll!! +const camelCase = text.replace(/_(\w)/g, (_, char:string) => char.toUpperCase());//BuiltinAll!! +console.log(camelCase); +const prices = { apple: 5, banana: 3 }; +function pricesChange(count:string, fruit:string){ + const price = prices[fruit as keyof typeof prices] || 0; + return `${count} ${fruit} ($${price * parseInt(count)})`; +} +const result7 = text.replaceAll(/(\d+)\s+(\w+)/g, pricesChange);//BuiltinAll 1 + +//WeakMapConstructor +interface Person1 { + age: number; +} +const key1: Person1 = {age: 12}; +const key2: Person1 = {age: 123}; +const weakMap = new WeakMap([ // 0 lib.es2015.iterable.d.ts + [key1, 'value1'], + [key2, 'value2'] +]); +//JSON +const a = JSON.stringify({x: 5, y: 6});//BuiltinAll 1 +class Test implements JSON{ + stringify(value: string, replacer?: (number | string)[] | null, space?: string | number): string{//BuiltinAll 1 + return ''; + } + str: String = ''; + get() { + return this.str; + } +} +const d = new Test(); +d.get().replaceAll('a', pricesChange);//BuiltinAll 1 + +const boolObj1 = new Boolean(true); //BuiltinNewCtor +console.log(boolObj1.valueOf()); +console.log(new Test().valueOf()); //BuiltinAll +console.log(typeof boolObj1); +const tt = new Test(); +typeof tt.valueOf; //BuiltinAll?? +const boolObj2 = new Boolean(""); //BuiltinNewCtor +const boolObj3 = new Boolean(null); //BuiltinNewCtor +const boolObj4 = new Boolean(0); //BuiltinNewCtor + +//sum:27 diff --git a/ets2panda/linter/test/builtin/builtin_object_negative.ets.args.json b/ets2panda/linter/test/builtin/builtin_object_negative.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..4dfa4f20174c5965ff0a03fe9745d4cece7b7efa --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_object_negative.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/builtin/builtin_object_negative.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_object_negative.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..533a742ee1653ab2d1e42e8c26062193c05c9da9 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_object_negative.ets.arkts2.json @@ -0,0 +1,528 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 16, + "column": 14, + "endLine": 16, + "endColumn": 31, + "problem": "CreatingPrimitiveTypes", + "suggest": "", + "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", + "severity": "ERROR" + }, + { + "line": 16, + "column": 18, + "endLine": 16, + "endColumn": 24, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 7, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 13, + "endLine": 18, + "endColumn": 19, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 8, + "endLine": 19, + "endColumn": 16, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 8, + "endLine": 20, + "endColumn": 17, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 8, + "endLine": 21, + "endColumn": 13, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 8, + "endLine": 22, + "endColumn": 21, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 7, + "endLine": 33, + "endColumn": 50, + "problem": "ArrayTypeImmutable", + "suggest": "", + "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 38, + "endLine": 33, + "endColumn": 45, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 8, + "endLine": 34, + "endColumn": 14, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 38, + "endLine": 38, + "endColumn": 3, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 21, + "endLine": 39, + "endColumn": 32, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 21, + "endLine": 39, + "endColumn": 32, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 12, + "endLine": 40, + "endColumn": 18, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 1, + "endLine": 43, + "endColumn": 22, + "problem": "CreatingPrimitiveTypes", + "suggest": "", + "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 5, + "endLine": 43, + "endColumn": 11, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 1, + "endLine": 44, + "endColumn": 7, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 7, + "endLine": 48, + "endColumn": 11, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 23, + "endLine": 48, + "endColumn": 29, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 3, + "endLine": 54, + "endColumn": 4, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 44, + "endLine": 52, + "endColumn": 99, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 83, + "endLine": 52, + "endColumn": 86, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 30, + "endLine": 59, + "endColumn": 38, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 6, + "endLine": 65, + "endColumn": 13, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 66, + "column": 22, + "endLine": 66, + "endColumn": 29, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 22, + "endLine": 67, + "endColumn": 29, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 30, + "endLine": 70, + "endColumn": 34, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + }, + { + "line": 71, + "column": 32, + "endLine": 71, + "endColumn": 40, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + }, + { + "line": 73, + "column": 16, + "endLine": 73, + "endColumn": 17, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 17, + "endLine": 75, + "endColumn": 53, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 39, + "endLine": 75, + "endColumn": 45, + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "severity": "ERROR" + }, + { + "line": 78, + "column": 22, + "endLine": 78, + "endColumn": 32, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 78, + "column": 33, + "endLine": 78, + "endColumn": 49, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + }, + { + "line": 91, + "column": 16, + "endLine": 91, + "endColumn": 25, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 91, + "column": 16, + "endLine": 91, + "endColumn": 25, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 92, + "column": 7, + "endLine": 92, + "endColumn": 11, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 3, + "endLine": 95, + "endColumn": 4, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"JSON\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 3, + "endLine": 95, + "endColumn": 4, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 13, + "endLine": 93, + "endColumn": 26, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 28, + "endLine": 93, + "endColumn": 65, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 102, + "column": 9, + "endLine": 102, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 104, + "column": 18, + "endLine": 104, + "endColumn": 35, + "problem": "CreatingPrimitiveTypes", + "suggest": "", + "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", + "severity": "ERROR" + }, + { + "line": 104, + "column": 22, + "endLine": 104, + "endColumn": 29, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 106, + "column": 24, + "endLine": 106, + "endColumn": 31, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 110, + "column": 18, + "endLine": 110, + "endColumn": 33, + "problem": "CreatingPrimitiveTypes", + "suggest": "", + "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", + "severity": "ERROR" + }, + { + "line": 110, + "column": 22, + "endLine": 110, + "endColumn": 29, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 111, + "column": 18, + "endLine": 111, + "endColumn": 35, + "problem": "CreatingPrimitiveTypes", + "suggest": "", + "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", + "severity": "ERROR" + }, + { + "line": 111, + "column": 22, + "endLine": 111, + "endColumn": 29, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 112, + "column": 18, + "endLine": 112, + "endColumn": 32, + "problem": "CreatingPrimitiveTypes", + "suggest": "", + "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", + "severity": "ERROR" + }, + { + "line": 112, + "column": 22, + "endLine": 112, + "endColumn": 29, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_object_negative.ets.json b/ets2panda/linter/test/builtin/builtin_object_negative.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..3ca8258156305d1d082ccd73ce6c961baaa5dd1e --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_object_negative.ets.json @@ -0,0 +1,68 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 39, + "column": 14, + "endLine": 39, + "endColumn": 41, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 83, + "endLine": 52, + "endColumn": 86, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 73, + "column": 16, + "endLine": 73, + "endColumn": 17, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 17, + "endLine": 75, + "endColumn": 53, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 39, + "endLine": 75, + "endColumn": 45, + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_object_positive.ets b/ets2panda/linter/test/builtin/builtin_object_positive.ets new file mode 100644 index 0000000000000000000000000000000000000000..876d5d13ce25b5f3e472ae79609f2d1e25077944 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_object_positive.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const str: string = 'abc'; +str.replace('a', 'b'); +str.replaceAll('a', 'b'); +class Demo implements String{ //BuiltinFinalClass + replaceAll1(searchValue: string | RegExp, replacer: string): string { + + } +} +//replace(searchValue: string | RegExp, replaceValue: string): string; +const text = "Hello World, World!"; +const result1 = text.replace("World", "TypeScript"); +const result2 = text.replace(/World/g, "TypeScript"); + +//lib.es2015.symbol.wellknown.d.ts +const result6 = text.replace(/-/g, (match, offset:string) => `-${offset}-`); +const camelCase = text.replace(/_(\w)/g, (_, char:string) => char.toUpperCase()); \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_object_positive.ets.args.json b/ets2panda/linter/test/builtin/builtin_object_positive.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..4dfa4f20174c5965ff0a03fe9745d4cece7b7efa --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_object_positive.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/builtin/builtin_object_positive.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_object_positive.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..86f288bc70ec99db34200378bc3c3c6f2079ebab --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_object_positive.ets.arkts2.json @@ -0,0 +1,68 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 18, + "column": 7, + "endLine": 18, + "endColumn": 11, + "problem": "InterfaceFieldNotImplemented", + "suggest": "", + "rule": "ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 23, + "endLine": 18, + "endColumn": 29, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 30, + "endLine": 26, + "endColumn": 38, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 30, + "endLine": 29, + "endColumn": 34, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 32, + "endLine": 30, + "endColumn": 40, + "problem": "RegularExpressionLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_object_positive.ets.json b/ets2panda/linter/test/builtin/builtin_object_positive.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..7633c79b6aa0073a72cf8f74a66e11dac370f619 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_object_positive.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_thisArgs.ets b/ets2panda/linter/test/builtin/builtin_thisArgs.ets index b296e847c11bc4be6bf9ca82359bef48fc1b08f3..912735bad56789edf367eca985b674b4c760f8f1 100644 --- a/ets2panda/linter/test/builtin/builtin_thisArgs.ets +++ b/ets2panda/linter/test/builtin/builtin_thisArgs.ets @@ -23,7 +23,7 @@ Class MyClass { } } -let arr: Array = new Array(1, 2, 3); +let arr: Array = new Array(1, 2, 3); //BuiltinNewCtor let a = new MyClass(2); let b = new MyClass(3); arr.filter(a.compare, a); diff --git a/ets2panda/linter/test/builtin/builtin_thisArgs.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_thisArgs.ets.arkts2.json index eb2072ee2412ac1d541393449a001a2cfddd6824..738f2b023c0a649d79bb854723ea81c0a506e9b5 100644 --- a/ets2panda/linter/test/builtin/builtin_thisArgs.ets.arkts2.json +++ b/ets2panda/linter/test/builtin/builtin_thisArgs.ets.arkts2.json @@ -24,6 +24,16 @@ "rule": "Function return type inference is limited (arkts-no-implicit-return-types)", "severity": "ERROR" }, + { + "line": 26, + "column": 30, + "endLine": 26, + "endColumn": 35, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 27, "column": 5, diff --git a/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets b/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets new file mode 100644 index 0000000000000000000000000000000000000000..50efe4e895bbc05a7fdf02535d697bc173ab054e --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ + +let arr = new Array(10); +let arr1 = new Array(10); +let arr2 = new Array(); +new Array(100); +new Array(100); +new Array([1, 2]); +new Array([1, 2]); +new Array(['1', '2']); + +function test(): number { + return 1; +} + +new Array(test()); \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.args.json b/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..66fb88f85945924e8be0e83d90123507033f4c5d --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.arkts2.json b/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..5642d5965993081bfeb2a76568c65caa6863daa3 --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.arkts2.json @@ -0,0 +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": 16, + "column": 15, + "endLine": 16, + "endColumn": 20, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 16, + "column": 11, + "endLine": 16, + "endColumn": 32, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, + { + "line": 17, + "column": 5, + "endLine": 17, + "endColumn": 25, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 16, + "endLine": 17, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 12, + "endLine": 17, + "endColumn": 25, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 17, + "column": 12, + "endLine": 17, + "endColumn": 25, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, + { + "line": 18, + "column": 5, + "endLine": 18, + "endColumn": 23, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 16, + "endLine": 18, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 12, + "endLine": 18, + "endColumn": 23, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 5, + "endLine": 19, + "endColumn": 10, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 23, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, + { + "line": 20, + "column": 5, + "endLine": 20, + "endColumn": 10, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 15, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 15, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, + { + "line": 21, + "column": 5, + "endLine": 21, + "endColumn": 10, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 1, + "endLine": 21, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 5, + "endLine": 22, + "endColumn": 10, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 5, + "endLine": 23, + "endColumn": 10, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 5, + "endLine": 29, + "endColumn": 10, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 1, + "endLine": 29, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 1, + "endLine": 29, + "endColumn": 18, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.json b/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..1de3f8f971ad906f61ac5459f333fb1993853bda --- /dev/null +++ b/ets2panda/linter/test/builtin/builtin_uninitialized_element.ets.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": 17, + "column": 5, + "endLine": 17, + "endColumn": 25, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 5, + "endLine": 18, + "endColumn": 23, + "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/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json index 1f7540062cbf194992405ac4c285d5e47f3349b0..ca88f857e960b437dcf767c0ac40be998c8f1236 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json @@ -13,36 +13,5 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [ - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 7, - "endLine": 24, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 28, - "column": 7, - "endLine": 28, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - } - ] -} + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json index 1f7540062cbf194992405ac4c285d5e47f3349b0..ca88f857e960b437dcf767c0ac40be998c8f1236 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json @@ -13,36 +13,5 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [ - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 7, - "endLine": 24, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 28, - "column": 7, - "endLine": 28, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - } - ] -} + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json index d0fa8937d5cf3976f7ea45bf092500e0acfde2b2..ca88f857e960b437dcf767c0ac40be998c8f1236 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json @@ -1,48 +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": [ - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 7, - "endLine": 24, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 28, - "column": 7, - "endLine": 28, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "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": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.arkts2.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.arkts2.json index e702358e511ed151d2a4c891a356a9313f10cc7f..afa0bcaf5dcf732ce78a8ef1918853c6df697cf4 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.arkts2.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.arkts2.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 16, - "column": 5, - "endLine": 16, - "endColumn": 13, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 16, "column": 15, @@ -64,16 +54,6 @@ "rule": "SharedArrayBuffer is not supported (arkts-no-need-stdlib-sharedArrayBuffer)", "severity": "ERROR" }, - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 22, "column": 28, diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.autofix.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.autofix.json index 07ba20c5cc5c6abbfed8c81cf5d16ff33709284f..5665081830ea79823ca1c1d8541da0634a98a623 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.autofix.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.autofix.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 16, - "column": 5, - "endLine": 16, - "endColumn": 13, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 16, "column": 15, @@ -108,16 +98,6 @@ "rule": "SharedArrayBuffer is not supported (arkts-no-need-stdlib-sharedArrayBuffer)", "severity": "ERROR" }, - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 22, "column": 28, diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.migrate.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.migrate.json index 1b71547ad7a096f21a63f5afa3255c679e904fe5..ca88f857e960b437dcf767c0ac40be998c8f1236 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.migrate.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.migrate.json @@ -1,38 +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": [ - { - "line": 16, - "column": 5, - "endLine": 16, - "endColumn": 13, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "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": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/deprecatedapi/action_sheet.ets.arkts2.json b/ets2panda/linter/test/deprecatedapi/action_sheet.ets.arkts2.json index 35e1e2cbd1c62b043020c5a8e34443b5bedb1d27..16b900fecb275857815e2044bc30597a38856edb 100644 --- a/ets2panda/linter/test/deprecatedapi/action_sheet.ets.arkts2.json +++ b/ets2panda/linter/test/deprecatedapi/action_sheet.ets.arkts2.json @@ -24,6 +24,26 @@ "rule": "ArkUI deprecated api check (arkui-no-deprecated-api)", "severity": "ERROR" }, + { + "line": 41, + "column": 45, + "endLine": 41, + "endColumn": 54, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 45, + "endLine": 41, + "endColumn": 54, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 18, "column": 2, diff --git a/ets2panda/linter/test/deprecatedapi/deprecated_api_font.ets.arkts2.json b/ets2panda/linter/test/deprecatedapi/deprecated_api_font.ets.arkts2.json index 00497d02618ba04db6d78378728574529f588c2e..38f8794a0f4157e6fcb09e20aded87e6ea6145a4 100644 --- a/ets2panda/linter/test/deprecatedapi/deprecated_api_font.ets.arkts2.json +++ b/ets2panda/linter/test/deprecatedapi/deprecated_api_font.ets.arkts2.json @@ -24,6 +24,16 @@ "rule": "ArkUI deprecated api check (arkui-no-deprecated-api)", "severity": "ERROR" }, + { + "line": 21, + "column": 33, + "endLine": 21, + "endColumn": 38, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 24, "column": 10, diff --git a/ets2panda/linter/test/interop/interop_convert_import.ets.arkts2.json b/ets2panda/linter/test/interop/interop_convert_import.ets.arkts2.json index 741e95d38a4792b37d0e5874d93400857632cd6c..cbd68cf1d7d71f186c0ba92c6e5ddbf2afc2200f 100644 --- a/ets2panda/linter/test/interop/interop_convert_import.ets.arkts2.json +++ b/ets2panda/linter/test/interop/interop_convert_import.ets.arkts2.json @@ -124,6 +124,16 @@ "rule": "Casting interop JS objects to primitive types is not allowed (arkts-interop-js2s-convert-js-type)", "severity": "ERROR" }, + { + "line": 25, + "column": 48, + "endLine": 25, + "endColumn": 53, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 25, "column": 44, diff --git a/ets2panda/linter/test/interop/interop_convert_import.ets.autofix.json b/ets2panda/linter/test/interop/interop_convert_import.ets.autofix.json index 48479f4d9e2e10b336f7f7b2a956f40b70d2951d..b2c74f81c890e63815aa167967df4cb65c677408 100644 --- a/ets2panda/linter/test/interop/interop_convert_import.ets.autofix.json +++ b/ets2panda/linter/test/interop/interop_convert_import.ets.autofix.json @@ -212,6 +212,16 @@ "rule": "Casting interop JS objects to primitive types is not allowed (arkts-interop-js2s-convert-js-type)", "severity": "ERROR" }, + { + "line": 25, + "column": 48, + "endLine": 25, + "endColumn": 53, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 25, "column": 44, diff --git a/ets2panda/linter/test/interop/interop_convert_import.ets.migrate.json b/ets2panda/linter/test/interop/interop_convert_import.ets.migrate.json index 056c6e9c99d714889e80912516123d315e05c526..a0ef85502122c5b96c3670e75428957e13c8003e 100644 --- a/ets2panda/linter/test/interop/interop_convert_import.ets.migrate.json +++ b/ets2panda/linter/test/interop/interop_convert_import.ets.migrate.json @@ -44,6 +44,16 @@ "rule": "Casting interop JS objects to primitive types is not allowed (arkts-interop-js2s-convert-js-type)", "severity": "ERROR" }, + { + "line": 25, + "column": 48, + "endLine": 25, + "endColumn": 53, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 25, "column": 44, diff --git a/ets2panda/linter/test/interop/object_built_in.ets.arkts2.json b/ets2panda/linter/test/interop/object_built_in.ets.arkts2.json index 41a2db7981e1f81b39c3f920c0609d5da79b198b..1c34bb456b52af408822f508663c0effd173cfda 100644 --- a/ets2panda/linter/test/interop/object_built_in.ets.arkts2.json +++ b/ets2panda/linter/test/interop/object_built_in.ets.arkts2.json @@ -34,6 +34,26 @@ "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", "severity": "ERROR" }, + { + "line": 21, + "column": 12, + "endLine": 21, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 12, + "endLine": 23, + "endColumn": 18, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 24, "column": 9, diff --git a/ets2panda/linter/test/interop/object_literal_constructor.ets.arkts2.json b/ets2panda/linter/test/interop/object_literal_constructor.ets.arkts2.json index b9f57ab5c027d33514863ebe58edfd7608508b03..a9680f6f23acabb1287f0678008c8eb614b548d7 100644 --- a/ets2panda/linter/test/interop/object_literal_constructor.ets.arkts2.json +++ b/ets2panda/linter/test/interop/object_literal_constructor.ets.arkts2.json @@ -124,16 +124,6 @@ "rule": "Object literal cannot be directly assigned to class with a constructor. (arkts-interop-d2s-object-literal-no-args-constructor)", "severity": "ERROR" }, - { - "line": 67, - "column": 5, - "endLine": 67, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 69, "column": 5, @@ -165,4 +155,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/reflect_built_in.ets.arkts2.json b/ets2panda/linter/test/interop/reflect_built_in.ets.arkts2.json index c76a12de83ce4d962372a140309212632aa9a21d..77b9d8ee5c57c4f5de8311e5c943730b8af5ff46 100644 --- a/ets2panda/linter/test/interop/reflect_built_in.ets.arkts2.json +++ b/ets2panda/linter/test/interop/reflect_built_in.ets.arkts2.json @@ -44,6 +44,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 20, + "column": 10, + "endLine": 20, + "endColumn": 17, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 24, "column": 5, @@ -54,6 +64,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 24, + "column": 20, + "endLine": 24, + "endColumn": 23, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 27, "column": 1, @@ -134,6 +154,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 20, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 41, "column": 1, @@ -174,6 +204,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 44, + "column": 9, + "endLine": 44, + "endColumn": 16, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 46, "column": 1, @@ -214,6 +254,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 49, + "column": 9, + "endLine": 49, + "endColumn": 16, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 51, "column": 1, @@ -254,6 +304,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 54, + "column": 9, + "endLine": 54, + "endColumn": 16, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 56, "column": 1, @@ -293,6 +353,16 @@ "suggest": "", "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" + }, + { + "line": 59, + "column": 9, + "endLine": 59, + "endColumn": 16, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json b/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json index 92f20acbdfede9eb7b2fec3e4d7127952c2938c4..88d820858d0642c2bd65fe561d5f034e00ed226f 100644 --- a/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json +++ b/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json @@ -594,16 +594,6 @@ "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", "severity": "ERROR" }, - { - "line": 195, - "column": 9, - "endLine": 195, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 195, "column": 13, @@ -644,16 +634,6 @@ "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", "severity": "ERROR" }, - { - "line": 201, - "column": 9, - "endLine": 201, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 201, "column": 12, @@ -715,4 +695,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-array-type-immutable.ets.arkts2.json b/ets2panda/linter/test/main/arkts-array-type-immutable.ets.arkts2.json index fa2a742d07d636adf0b33170b72d67de017d0548..8ef0297136e121f20ea195d5538589891b9259ce 100644 --- a/ets2panda/linter/test/main/arkts-array-type-immutable.ets.arkts2.json +++ b/ets2panda/linter/test/main/arkts-array-type-immutable.ets.arkts2.json @@ -24,16 +24,6 @@ "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", "severity": "ERROR" }, - { - "line": 22, - "column": 5, - "endLine": 22, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 23, "column": 1, @@ -64,6 +54,16 @@ "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", "severity": "ERROR" }, + { + "line": 32, + "column": 35, + "endLine": 32, + "endColumn": 40, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 36, "column": 3, @@ -334,6 +334,16 @@ "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", "severity": "ERROR" }, + { + "line": 149, + "column": 40, + "endLine": 149, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 149, "column": 36, @@ -344,6 +354,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 150, + "column": 21, + "endLine": 150, + "endColumn": 26, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 150, "column": 17, @@ -354,6 +374,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 150, + "column": 17, + "endLine": 150, + "endColumn": 29, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 151, "column": 1, @@ -374,6 +404,16 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", "severity": "ERROR" }, + { + "line": 155, + "column": 17, + "endLine": 155, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 156, "column": 1, diff --git a/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets new file mode 100644 index 0000000000000000000000000000000000000000..2b73f47073145dd72e9e8ca5fe83105805aad13b --- /dev/null +++ b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +let tuple: [number, number] = [1.0,2.0]; +tuple[-1]; +tuple[1]; +tuple[1.0]; +tuple[0.0]; +tuple[0]; +const a = 1; +tuple[a]; +tuple[-a]; +const b = -1; +tuple[b]; +tuple[-b]; +const c = 1.0; +tuple[c]; +tuple[-c]; + diff --git a/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.args.json b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..66fb88f85945924e8be0e83d90123507033f4c5d --- /dev/null +++ b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.arkts2.json b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..4c0e20620142affb03d661500c5306a9e40b77b9 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.arkts2.json @@ -0,0 +1,88 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 10, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 11, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 11, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 1, + "endLine": 24, + "endColumn": 10, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 1, + "endLine": 26, + "endColumn": 9, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 1, + "endLine": 29, + "endColumn": 9, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 1, + "endLine": 30, + "endColumn": 10, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + } + ] +} diff --git a/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.json b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..9f305c86d7ff705098b1e480818e125d5e6e3a4a --- /dev/null +++ b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} diff --git a/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json b/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json index 761207d7879c5a7964ae8d771d7e98b7458e631c..a09f343947433ef57db208477664b956b155c856 100644 --- a/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json +++ b/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json @@ -44,16 +44,6 @@ "rule": "Template string type is not supported (arkts-no-template-string-type)", "severity": "ERROR" }, - { - "line": 25, - "column": 5, - "endLine": 25, - "endColumn": 13, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 25, "column": 15, diff --git a/ets2panda/linter/test/main/arkts-primitive-type-normalization.ets.arkts2.json b/ets2panda/linter/test/main/arkts-primitive-type-normalization.ets.arkts2.json index 6265f75a79ccc7fd0a7a98317cf6ad9ed012d95b..517754f2cf1543d8cbbebd9f208dab30074c5d87 100644 --- a/ets2panda/linter/test/main/arkts-primitive-type-normalization.ets.arkts2.json +++ b/ets2panda/linter/test/main/arkts-primitive-type-normalization.ets.arkts2.json @@ -24,6 +24,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 16, + "column": 12, + "endLine": 16, + "endColumn": 18, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 17, "column": 1, @@ -34,6 +44,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 17, + "column": 5, + "endLine": 17, + "endColumn": 11, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 17, "column": 18, @@ -44,6 +64,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 17, + "column": 22, + "endLine": 17, + "endColumn": 28, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 18, "column": 5, @@ -54,6 +84,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 18, + "column": 9, + "endLine": 18, + "endColumn": 16, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 19, "column": 9, @@ -64,6 +104,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 19, + "column": 13, + "endLine": 19, + "endColumn": 19, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 20, "column": 1, @@ -74,6 +124,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 20, + "column": 5, + "endLine": 20, + "endColumn": 12, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 21, "column": 1, @@ -84,6 +144,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 21, + "column": 5, + "endLine": 21, + "endColumn": 11, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 22, "column": 1, @@ -93,6 +163,16 @@ "suggest": "", "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" + }, + { + "line": 22, + "column": 5, + "endLine": 22, + "endColumn": 11, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts_class_no_signature_public_obj_api.ets.arkts2.json b/ets2panda/linter/test/main/arkts_class_no_signature_public_obj_api.ets.arkts2.json index 0352c42e8b84238726a9aa40110aff5380fcdb20..45b2c202663e5f56cf7418b63277dfabf7ff2af3 100644 --- a/ets2panda/linter/test/main/arkts_class_no_signature_public_obj_api.ets.arkts2.json +++ b/ets2panda/linter/test/main/arkts_class_no_signature_public_obj_api.ets.arkts2.json @@ -34,6 +34,16 @@ "rule": "The signature of a method in a class/interface cannot be different from the public interface in an object. (arkts-class-no-signature-distinct-with-object-public-api)", "severity": "ERROR" }, + { + "line": 37, + "column": 27, + "endLine": 37, + "endColumn": 38, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 45, "column": 3, @@ -84,6 +94,26 @@ "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", "severity": "ERROR" }, + { + "line": 55, + "column": 21, + "endLine": 55, + "endColumn": 32, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 27, + "endLine": 63, + "endColumn": 38, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 70, "column": 3, @@ -124,6 +154,26 @@ "rule": "The signature of a method in a class/interface cannot be different from the public interface in an object. (arkts-class-no-signature-distinct-with-object-public-api)", "severity": "ERROR" }, + { + "line": 84, + "column": 21, + "endLine": 84, + "endColumn": 32, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 86, + "column": 27, + "endLine": 86, + "endColumn": 38, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 90, "column": 3, @@ -164,6 +214,16 @@ "rule": "The signature of a method in a class/interface cannot be different from the public interface in an object. (arkts-class-no-signature-distinct-with-object-public-api)", "severity": "ERROR" }, + { + "line": 95, + "column": 27, + "endLine": 95, + "endColumn": 38, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 100, "column": 3, diff --git a/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json b/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json index a3e735670a47e1abef69d029c41ae952cb0394ec..c48332a4e2db3e1e7bad7d88f8a636180c199a7d 100644 --- a/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json +++ b/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json @@ -14,6 +14,86 @@ "limitations under the License." ], "result": [ + { + "line": 27, + "column": 31, + "endLine": 27, + "endColumn": 40, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 31, + "endLine": 27, + "endColumn": 40, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 23, + "endLine": 29, + "endColumn": 32, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 23, + "endLine": 29, + "endColumn": 32, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 23, + "endLine": 31, + "endColumn": 32, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 23, + "endLine": 31, + "endColumn": 32, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 31, + "endLine": 33, + "endColumn": 40, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 31, + "endLine": 33, + "endColumn": 40, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 35, "column": 22, diff --git a/ets2panda/linter/test/main/var_assignment_before_use.ets b/ets2panda/linter/test/main/call_expression_matching_argument.ets similarity index 34% rename from ets2panda/linter/test/main/var_assignment_before_use.ets rename to ets2panda/linter/test/main/call_expression_matching_argument.ets index 35554385ce240145b93bebf7ac0c1a41ef0a99e7..08c34d7682b9a6c397ff28078f1fc35f2f4c584b 100644 --- a/ets2panda/linter/test/main/var_assignment_before_use.ets +++ b/ets2panda/linter/test/main/call_expression_matching_argument.ets @@ -13,46 +13,58 @@ * limitations under the License. */ -// Positive (should be flagged) -let a: A; // ❌ VariableMissingInitializer -let b: number[]; // ❌ VariableMissingInitializer -let c: A; // ❌ VariableMissingInitializer -const x: X; // ❌ VariableMissingInitializer +interface A { + value: string; +} + +interface Outer { + inner: A +} + +interface No { + inner: string +} -// Negative (should NOT be flagged) -// 1) Initialized declarations -let d: D = new D(); // ✅ OK -const y1: string = "hello"; // ✅ OK +class Test { + sv1: number = 1 + sv2: string = "some Value"; + sv3: boolean = true; + sv4: A = { value: "something" } + sv5: Outer = { inner: sv4 } + sv6: No = { inner: sv2 } + sv7: Array = [sv2, sv2, sv2]; -// 2) Function‐typed declarations are skipped -let add: (a: number, b: number) => number; // ✅ OK -let handler: (e: Event) => void; // ✅ OK + someMethod() { + func(this.sv2) //error + func(this.sv4) //valid + func(this.sv6.inner) // error + func(this.sv5.inner) //valid + func2(this.sv2) //valid + func2(this.sv4) //valid + func3(this.sv2) //valid + func4(this.sv2, this.sv1) //valid + func5(this.sv7) //valid + } +} -// 3) Explicit void‐typed declarations are skipped -let v: void; // ✅ OK -const v2: void; // ✅ OK -// 4) For…of and For…in loop bindings -for (let item of items) { // ✅ OK - console.log(item); +function func(param: A) { + console.log(A); } -for (let key in record) { // ✅ OK - console.log(key); +function func2(param: A | any) { + console.log(param); } -// 5) Function declarations / expressions -function foo() { // ✅ OK - return 42; +function func3(param: string | Promise) { + console.log(param); } -let bar = function() { // ✅ OK - return "hi"; -}; +function func4(param: string, param2: any[]) { + console.log(param, ...param2); +} -let baz = () => { // ✅ OK - return true; -}; +function func5(param: Array) { + param.forEach(elem => console.log(elem)) +} -// 6) Destructuring with initializer -let { x, y } = point; // ✅ OK diff --git a/ets2panda/linter/test/main/var_assignment_before_use.ets.args.json b/ets2panda/linter/test/main/call_expression_matching_argument.ets.args.json similarity index 100% rename from ets2panda/linter/test/main/var_assignment_before_use.ets.args.json rename to ets2panda/linter/test/main/call_expression_matching_argument.ets.args.json diff --git a/ets2panda/linter/test/main/call_expression_matching_argument.ets.arkts2.json b/ets2panda/linter/test/main/call_expression_matching_argument.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..00147aa39226a33dc4ae27c875ec669c70be8045 --- /dev/null +++ b/ets2panda/linter/test/main/call_expression_matching_argument.ets.arkts2.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 38, + "column": 14, + "endLine": 38, + "endColumn": 22, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 14, + "endLine": 40, + "endColumn": 28, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 27, + "endLine": 55, + "endColumn": 30, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 39, + "endLine": 63, + "endColumn": 42, + "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/call_expression_matching_argument.ets.json b/ets2panda/linter/test/main/call_expression_matching_argument.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..f864fd1cc3f376222369e712dbcee0ed60b91641 --- /dev/null +++ b/ets2panda/linter/test/main/call_expression_matching_argument.ets.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": 55, + "column": 27, + "endLine": 55, + "endColumn": 30, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 39, + "endLine": 63, + "endColumn": 42, + "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/class_as_object.ets.arkts2.json b/ets2panda/linter/test/main/class_as_object.ets.arkts2.json index ae6c793e86ab40f862ccb0bb13f800af0fcf1628..8513dde89deb0dc97de2d37e5fff1980f7290c7f 100644 --- a/ets2panda/linter/test/main/class_as_object.ets.arkts2.json +++ b/ets2panda/linter/test/main/class_as_object.ets.arkts2.json @@ -214,16 +214,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 98, - "column": 5, - "endLine": 98, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 98, "column": 8, @@ -674,6 +664,76 @@ "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", "severity": "ERROR" }, + { + "line": 171, + "column": 7, + "endLine": 171, + "endColumn": 14, + "problem": "NoPropertyDescriptor", + "suggest": "", + "rule": "Not support propertydescriptor (arkts-builtin-no-property-descriptor)", + "severity": "ERROR" + }, + { + "line": 171, + "column": 17, + "endLine": 171, + "endColumn": 31, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 172, + "column": 15, + "endLine": 172, + "endColumn": 20, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 174, + "column": 14, + "endLine": 174, + "endColumn": 21, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 175, + "column": 14, + "endLine": 175, + "endColumn": 18, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 176, + "column": 13, + "endLine": 176, + "endColumn": 18, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 179, + "column": 13, + "endLine": 179, + "endColumn": 19, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 180, "column": 7, @@ -684,6 +744,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 180, + "column": 13, + "endLine": 180, + "endColumn": 19, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 183, "column": 15, @@ -694,6 +764,16 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 184, + "column": 13, + "endLine": 184, + "endColumn": 19, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 185, "column": 13, @@ -714,6 +794,16 @@ "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", "severity": "ERROR" }, + { + "line": 192, + "column": 15, + "endLine": 192, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 193, "column": 9, @@ -733,6 +823,16 @@ "suggest": "", "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", "severity": "ERROR" + }, + { + "line": 202, + "column": 30, + "endLine": 202, + "endColumn": 36, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/collections_module.ets.arkts2.json b/ets2panda/linter/test/main/collections_module.ets.arkts2.json index 2c8d9f836573b366620263f322666423700e6f5e..e3169afb9917508130f19c1aeb3a142fd76c060a 100644 --- a/ets2panda/linter/test/main/collections_module.ets.arkts2.json +++ b/ets2panda/linter/test/main/collections_module.ets.arkts2.json @@ -94,16 +94,6 @@ "rule": "Sendable containers are not supported (arkts-no-need-stdlib-sendable-containers)", "severity": "ERROR" }, - { - "line": 32, - "column": 7, - "endLine": 32, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 32, "column": 21, @@ -134,16 +124,6 @@ "rule": "Sendable containers are not supported (arkts-no-need-stdlib-sendable-containers)", "severity": "ERROR" }, - { - "line": 36, - "column": 7, - "endLine": 36, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 40, "column": 22, diff --git a/ets2panda/linter/test/main/collections_module.ets.autofix.json b/ets2panda/linter/test/main/collections_module.ets.autofix.json index 9afdf943bad223a455585a40bfc446b1c4d2e187..717aaa4ab4898b8e68b5d54c1849f827775e990e 100644 --- a/ets2panda/linter/test/main/collections_module.ets.autofix.json +++ b/ets2panda/linter/test/main/collections_module.ets.autofix.json @@ -227,16 +227,6 @@ "rule": "Sendable containers are not supported (arkts-no-need-stdlib-sendable-containers)", "severity": "ERROR" }, - { - "line": 32, - "column": 7, - "endLine": 32, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 32, "column": 21, @@ -300,16 +290,6 @@ "rule": "Sendable containers are not supported (arkts-no-need-stdlib-sendable-containers)", "severity": "ERROR" }, - { - "line": 36, - "column": 7, - "endLine": 36, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 40, "column": 22, diff --git a/ets2panda/linter/test/main/collections_module.ets.migrate.json b/ets2panda/linter/test/main/collections_module.ets.migrate.json index 5a14ab57e1f22b27528a2071c35d9a880e9a13c7..3c02aec6ac4766ca81b71799b5371a31cb8faa38 100644 --- a/ets2panda/linter/test/main/collections_module.ets.migrate.json +++ b/ets2panda/linter/test/main/collections_module.ets.migrate.json @@ -15,23 +15,43 @@ ], "result": [ { - "line": 32, - "column": 7, - "endLine": 32, - "endColumn": 19, - "problem": "VariableMissingInitializer", + "line": 26, + "column": 43, + "endLine": 26, + "endColumn": 48, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 28, + "endLine": 28, + "endColumn": 33, + "problem": "BuiltinNewCtor", "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", "severity": "ERROR" }, { - "line": 36, - "column": 7, - "endLine": 36, - "endColumn": 19, - "problem": "VariableMissingInitializer", + "line": 30, + "column": 28, + "endLine": 30, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 43, + "endLine": 34, + "endColumn": 48, + "problem": "BuiltinNewCtor", "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", "severity": "ERROR" }, { 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 index ca88f857e960b437dcf767c0ac40be998c8f1236..72664bab13a0bfa9216b34036e0ef086bdaef43e 100644 --- a/ets2panda/linter/test/main/common_union_member_access.ets.arkts2.json +++ b/ets2panda/linter/test/main/common_union_member_access.ets.arkts2.json @@ -13,5 +13,26 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [] + "result": [ + { + "line": 21, + "column": 31, + "endLine": 21, + "endColumn": 47, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 27, + "endLine": 22, + "endColumn": 43, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + } + ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/definite_assignment.ets.arkts2.json b/ets2panda/linter/test/main/definite_assignment.ets.arkts2.json index 5a0520e0f2cdea5c1e618f551692b7b5a230c5fe..cd7c54679e12d6b274062c1e19e84b41ca2baa32 100644 --- a/ets2panda/linter/test/main/definite_assignment.ets.arkts2.json +++ b/ets2panda/linter/test/main/definite_assignment.ets.arkts2.json @@ -24,26 +24,6 @@ "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", "severity": "ERROR" }, - { - "line": 16, - "column": 5, - "endLine": 16, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 5, - "endLine": 24, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 33, "column": 3, diff --git a/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..95dd7d9c2873cde34ff08d8ac8a99a463e822fcb --- /dev/null +++ b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets @@ -0,0 +1,96 @@ +/* + * 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. + */ + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 1: Simple override, no explicit type, non-async → OK +// Base has abstract foo() (no annotation), override without annotation defaults to void +abstract class A1 { + abstract foo(); +} +class B1 extends A1 { + foo() { // ✅ no error + // … + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 2: Explicit void override → OK +abstract class A2 { + abstract foo(); +} +class B2 extends A2 { + foo(): void { // ✅ no error + // … + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 3: Non-void override → ERROR +abstract class A3 { + abstract foo(); +} +class B3 extends A3 { + foo(): number { // ❌ should flag AbstractOverrideReturnTypeNotVoid + return 42; + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 4: Async override without annotation → ERROR +// async methods default to Promise, and base foo() had no type +abstract class A4 { + abstract foo(); +} +class B4 extends A4 { + async foo() { // ❌ should flag AbstractOverrideReturnTypeNotVoid + await Promise.resolve(); + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 5: Indirect inheritance through an intermediate class +abstract class A5 { + abstract foo(); +} +class B5 extends A5 { /* no override here */ } +class C5 extends B5 { + foo(): number { // ❌ should flag — walks up to A5 + return 1; + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 6: Base declares a return type +abstract class A6 { + abstract bar(): string; // explicit annotation +} +class B6 extends A6 { + bar() { // ✅ no error (base had annotation) + return "ok"; + } +} +class C6 extends A6 { + bar(): number { // ✅ no InvalidAbstractOverrideReturnType error (this rule only applies when base had no type and derived method's type is different from void) + return 123; + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 7: Class with its own non-override method — no error +class OwnClass { + fooOwn() { // ✅ no error + return 'own'; + } +} diff --git a/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.args.json b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..bc4d2071daf6e9354e711c3b74b6be2b56659066 --- /dev/null +++ b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.arkts2.json b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..82d3a8851c2eef3a7883e03f507415a517348a4d --- /dev/null +++ b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.arkts2.json @@ -0,0 +1,88 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 23, + "column": 3, + "endLine": 23, + "endColumn": 6, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 10, + "endLine": 34, + "endColumn": 14, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 3, + "endLine": 45, + "endColumn": 6, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 9, + "endLine": 57, + "endColumn": 12, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 9, + "endLine": 57, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 3, + "endLine": 69, + "endColumn": 6, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, + { + "line": 85, + "column": 10, + "endLine": 85, + "endColumn": 16, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + } + ] +} diff --git a/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.json b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.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/es_object.ets.arkts2.json b/ets2panda/linter/test/main/es_object.ets.arkts2.json index 0fc6f0e05a18eb1908691bfb76688cfebd35f3b1..7463fcb51f18c08a7bff2481cc3428ce7794e867 100644 --- a/ets2panda/linter/test/main/es_object.ets.arkts2.json +++ b/ets2panda/linter/test/main/es_object.ets.arkts2.json @@ -34,26 +34,6 @@ "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 21, - "column": 5, - "endLine": 21, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 21, "column": 9, @@ -64,16 +44,6 @@ "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, - { - "line": 22, - "column": 5, - "endLine": 22, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 22, "column": 11, @@ -784,16 +754,6 @@ "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, - { - "line": 148, - "column": 5, - "endLine": 148, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 149, "column": 1, diff --git a/ets2panda/linter/test/main/func_inferred_type_args.ets.arkts2.json b/ets2panda/linter/test/main/func_inferred_type_args.ets.arkts2.json index 7b672d3e613fb2c39809e78a70d7e7a1b3161a68..1db059acbaa957f8e4f683d9b8768ec2460dba43 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args.ets.arkts2.json +++ b/ets2panda/linter/test/main/func_inferred_type_args.ets.arkts2.json @@ -74,16 +74,6 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, - { - "line": 56, - "column": 5, - "endLine": 56, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 56, "column": 8, @@ -224,16 +214,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 72, - "column": 7, - "endLine": 72, - "endColumn": 8, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 72, "column": 10, @@ -264,6 +244,56 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 81, + "column": 3, + "endLine": 81, + "endColumn": 10, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 82, + "column": 3, + "endLine": 82, + "endColumn": 10, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 83, + "column": 3, + "endLine": 83, + "endColumn": 10, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 84, + "column": 3, + "endLine": 84, + "endColumn": 10, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 87, + "column": 1, + "endLine": 87, + "endColumn": 8, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 89, "column": 5, @@ -274,6 +304,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 89, + "column": 16, + "endLine": 89, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 89, "column": 12, @@ -374,6 +414,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 93, + "column": 20, + "endLine": 93, + "endColumn": 27, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 93, "column": 16, @@ -725,4 +775,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets b/ets2panda/linter/test/main/func_inferred_type_args_2.ets index 43830e5da0bb5ebcc71a2d22a9aa1c7dbb308730..173fc2a7abbf7e6d13c3bfc3b1f825505d807bde 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets @@ -121,4 +121,20 @@ let subWeakSet = new SubWeakSet(); class C {} class D {} -let a: D<[C]> = new D(); \ No newline at end of file +let a: D<[C]> = new D(); + +function fun(a?:Map){ + let c:Map|undefined + if(a === undefined){ + a = new Map() + } + if(a){ + a = new Map() + } + if(c){ + c = new Map() + } + if(c === undefined){ + c = new Map() + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json index 788aaf8aaa07a8e20c9a9642e9ba0d7d01b0b6f0..b04045a8b8f2b5e51f1c7229017ab29e7c87a75b 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json @@ -24,6 +24,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 17, + "column": 28, + "endLine": 17, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 17, "column": 24, @@ -34,6 +44,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 18, + "column": 40, + "endLine": 18, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 18, "column": 36, @@ -44,6 +64,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 19, + "column": 21, + "endLine": 19, + "endColumn": 26, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 19, "column": 17, @@ -394,6 +424,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 81, + "column": 29, + "endLine": 81, + "endColumn": 34, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 81, "column": 25, @@ -404,6 +444,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 83, + "column": 9, + "endLine": 83, + "endColumn": 14, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 83, "column": 5, @@ -424,6 +474,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 97, + "column": 40, + "endLine": 97, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 97, "column": 36, @@ -434,6 +494,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 98, + "column": 55, + "endLine": 98, + "endColumn": 60, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 98, "column": 51, @@ -444,6 +514,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 99, + "column": 56, + "endLine": 99, + "endColumn": 61, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 99, "column": 52, @@ -454,6 +534,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 100, + "column": 26, + "endLine": 100, + "endColumn": 31, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 100, "column": 22, @@ -514,6 +604,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 117, + "column": 26, + "endLine": 117, + "endColumn": 33, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 119, "column": 26, @@ -524,6 +624,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 119, + "column": 26, + "endLine": 119, + "endColumn": 33, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 124, "column": 17, @@ -534,6 +644,46 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 84, "column": 2, diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json index 6d8c8403ac0826036252dd6b0bec721f33a4fc57..c75c3540332d3909a6bbb2f8d4812d04710185df 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json @@ -24,6 +24,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 17, + "column": 28, + "endLine": 17, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 17, "column": 24, @@ -34,6 +44,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 18, + "column": 40, + "endLine": 18, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 18, "column": 36, @@ -55,6 +75,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 19, + "column": 21, + "endLine": 19, + "endColumn": 26, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 19, "column": 17, @@ -570,6 +600,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 81, + "column": 29, + "endLine": 81, + "endColumn": 34, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 81, "column": 25, @@ -591,6 +631,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 83, + "column": 9, + "endLine": 83, + "endColumn": 14, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 83, "column": 5, @@ -622,6 +672,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 97, + "column": 40, + "endLine": 97, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 97, "column": 36, @@ -643,6 +703,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 98, + "column": 55, + "endLine": 98, + "endColumn": 60, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 98, "column": 51, @@ -664,6 +734,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 99, + "column": 56, + "endLine": 99, + "endColumn": 61, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 99, "column": 52, @@ -674,6 +754,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 100, + "column": 26, + "endLine": 100, + "endColumn": 31, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 100, "column": 22, @@ -756,6 +846,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 117, + "column": 26, + "endLine": 117, + "endColumn": 33, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 119, "column": 26, @@ -766,6 +866,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 119, + "column": 26, + "endLine": 119, + "endColumn": 33, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 124, "column": 17, @@ -787,6 +897,90 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3430, + "end": 3430, + "replacementText": "", + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3461, + "end": 3461, + "replacementText": "", + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3492, + "end": 3492, + "replacementText": "", + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3537, + "end": 3537, + "replacementText": "", + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 84, "column": 2, diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets index 3cfe89eaab8d03105a0c493fbe8b206f07520dff..68520df9e2244e5b6b2ca1c43a3e946ad820ccbd 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets @@ -128,4 +128,20 @@ let subWeakSet = new SubWeakSet(); class C {} class D {} -let a: D<[C]> = new D<[C]>(); \ No newline at end of file +let a: D<[C]> = new D<[C]>(); + +function fun(a?:Map){ + let c:Map|undefined + if(a === undefined){ + a = new Map() + } + if(a){ + a = new Map() + } + if(c){ + c = new Map() + } + if(c === undefined){ + c = new Map() + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json index 452d9d6225f6f7e27b5814b2af5bde4081f692cc..0012a4b9eaa78bbd3f3389adf50516710d888c7d 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json @@ -24,6 +24,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 24, + "column": 28, + "endLine": 24, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 24, "column": 24, @@ -34,6 +44,26 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 25, + "column": 40, + "endLine": 25, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 21, + "endLine": 26, + "endColumn": 26, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 28, "column": 7, @@ -234,6 +264,26 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 88, + "column": 29, + "endLine": 88, + "endColumn": 34, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 90, + "column": 9, + "endLine": 90, + "endColumn": 14, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 93, "column": 77, @@ -244,6 +294,36 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 104, + "column": 40, + "endLine": 104, + "endColumn": 45, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 105, + "column": 55, + "endLine": 105, + "endColumn": 60, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 106, + "column": 56, + "endLine": 106, + "endColumn": 61, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 106, "column": 52, @@ -254,6 +334,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 107, + "column": 26, + "endLine": 107, + "endColumn": 31, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 118, "column": 22, @@ -294,6 +384,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 124, + "column": 26, + "endLine": 124, + "endColumn": 33, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 126, "column": 26, @@ -304,6 +404,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 126, + "column": 26, + "endLine": 126, + "endColumn": 33, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 110, "column": 22, diff --git a/ets2panda/linter/test/main/interface_import_6.ets b/ets2panda/linter/test/main/interface_import_6.ets new file mode 100644 index 0000000000000000000000000000000000000000..881ce6f547293ab3c1f848db7110a638a395f6b5 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_6.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +'use static' +import { Component } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/interface_import_6.ets.args.json b/ets2panda/linter/test/main/interface_import_6.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..ef3938e967322a0c7551d84c7b6d280de94144c8 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_6.ets.args.json @@ -0,0 +1,21 @@ +{ + "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": "", + "autofix": "--arkts-2", + "migrate": "--arkts-2" + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/interface_import_6.ets.arkts2.json b/ets2panda/linter/test/main/interface_import_6.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..f1ac486b52d8c95fb776d58d1c2ece99587b9350 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_6.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": 17, + "column": 1, + "endLine": 17, + "endColumn": 40, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 2, + "endLine": 19, + "endColumn": 7, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Entry\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/interface_import_6.ets.autofix.json b/ets2panda/linter/test/main/interface_import_6.ets.autofix.json new file mode 100644 index 0000000000000000000000000000000000000000..2b63a553ae7dc31a08d2a9ee40d58b06a45934a5 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_6.ets.autofix.json @@ -0,0 +1,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": 17, + "column": 1, + "endLine": 17, + "endColumn": 40, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 2, + "endLine": 19, + "endColumn": 7, + "problem": "UIInterfaceImport", + "autofix": [ + { + "start": 617, + "end": 617, + "replacementText": "\nimport { Entry } from '@kit.ArkUI';\n", + "line": 19, + "column": 2, + "endLine": 19, + "endColumn": 7 + } + ], + "suggest": "", + "rule": "The ArkUI interface \"Entry\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/interface_import_6.ets.json b/ets2panda/linter/test/main/interface_import_6.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..0cdb08cc16ad1879ae83bcc575e2f6feb7e672d0 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_6.ets.json @@ -0,0 +1,28 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 40, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/interface_import_6.ets.migrate.ets b/ets2panda/linter/test/main/interface_import_6.ets.migrate.ets new file mode 100644 index 0000000000000000000000000000000000000000..12599d4583df8e7fe2e9943190b127aace0c7dd7 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_6.ets.migrate.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. + */ + +'use static' +import { Entry } from '@kit.ArkUI'; + +import { Component } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/interface_import_6.ets.migrate.json b/ets2panda/linter/test/main/interface_import_6.ets.migrate.json new file mode 100644 index 0000000000000000000000000000000000000000..93115465bb027e2868e67d2c0ed6c9b73278a496 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_6.ets.migrate.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": 17, + "column": 1, + "endLine": 17, + "endColumn": 36, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 40, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json b/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json index 9a3582fd08d139b5a5d589b0d38698ea15b57938..1041e601a3396c117f143ef890f32646efd22f85 100644 --- a/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json +++ b/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json @@ -714,16 +714,6 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, - { - "line": 210, - "column": 9, - "endLine": 210, - "endColumn": 15, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 214, "column": 13, 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 8466667c747191e74f37030705c68bc24c960af0..fb694d6a8054da14a38410731c1e6ef82d22697e 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json @@ -494,6 +494,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 91, + "column": 15, + "endLine": 91, + "endColumn": 37, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, { "line": 94, "column": 8, @@ -994,16 +1004,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 169, - "column": 5, - "endLine": 169, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 169, "column": 12, @@ -1014,16 +1014,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 172, - "column": 5, - "endLine": 172, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 174, "column": 22, @@ -1064,16 +1054,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 200, - "column": 5, - "endLine": 200, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 201, "column": 19, @@ -1655,4 +1635,4 @@ "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 b558bfd5f181a936ab2dafe6ce82fefcac0863eb..1d193402460bed0b8e90b42435c4de9ecb4538d0 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json @@ -505,6 +505,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 91, + "column": 15, + "endLine": 91, + "endColumn": 37, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, { "line": 94, "column": 8, @@ -1087,16 +1097,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 169, - "column": 5, - "endLine": 169, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 169, "column": 12, @@ -1107,16 +1107,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 172, - "column": 5, - "endLine": 172, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 174, "column": 22, @@ -1157,16 +1147,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 200, - "column": 5, - "endLine": 200, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 201, "column": 19, @@ -2142,4 +2122,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file 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 996008ade7e950e4a45e3687a744e28420e0c3ef..2d6fa2f24571adc48cd1d92271dcfe8a9af99d90 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json @@ -484,6 +484,16 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, + { + "line": 91, + "column": 15, + "endLine": 91, + "endColumn": 37, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, { "line": 94, "column": 8, @@ -914,16 +924,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 177, - "column": 5, - "endLine": 177, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 177, "column": 12, @@ -934,16 +934,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 180, - "column": 5, - "endLine": 180, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 182, "column": 22, @@ -984,16 +974,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 208, - "column": 5, - "endLine": 208, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 209, "column": 19, @@ -1235,4 +1215,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/limited_literal_type.ets.arkts2.json b/ets2panda/linter/test/main/limited_literal_type.ets.arkts2.json index 4137773b300901106be365ebf45414c78c086953..3570308268ac8d18a3c979c8d8e808d82ba03faf 100644 --- a/ets2panda/linter/test/main/limited_literal_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/limited_literal_type.ets.arkts2.json @@ -44,26 +44,6 @@ "rule": "Literal types are restricted(arkts-limited-literal-types)", "severity": "ERROR" }, - { - "line": 19, - "column": 5, - "endLine": 19, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 22, - "column": 5, - "endLine": 22, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 30, "column": 7, @@ -74,26 +54,6 @@ "rule": "Literal types are restricted(arkts-limited-literal-types)", "severity": "ERROR" }, - { - "line": 35, - "column": 5, - "endLine": 35, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 36, - "column": 5, - "endLine": 36, - "endColumn": 12, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 39, "column": 22, @@ -124,16 +84,6 @@ "rule": "Literal types are restricted(arkts-limited-literal-types)", "severity": "ERROR" }, - { - "line": 44, - "column": 5, - "endLine": 44, - "endColumn": 8, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 44, "column": 10, diff --git a/ets2panda/linter/test/main/limited_stdlib_api.ets.arkts2.json b/ets2panda/linter/test/main/limited_stdlib_api.ets.arkts2.json index fa489440e0296df70f76ebbd92636d339e78d54b..34029346712ccd9625235de6edec0588fd885ebe 100644 --- a/ets2panda/linter/test/main/limited_stdlib_api.ets.arkts2.json +++ b/ets2panda/linter/test/main/limited_stdlib_api.ets.arkts2.json @@ -134,6 +134,16 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", "severity": "ERROR" }, + { + "line": 62, + "column": 8, + "endLine": 62, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 62, "column": 8, @@ -294,6 +304,26 @@ "rule": "Using \"Object.getOwnPropertyNames\" is not allowed in this API (arkts-builtin-object-getOwnPropertyNames))", "severity": "ERROR" }, + { + "line": 81, + "column": 20, + "endLine": 81, + "endColumn": 26, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 82, + "column": 20, + "endLine": 82, + "endColumn": 27, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 85, "column": 1, @@ -514,6 +544,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 95, + "column": 21, + "endLine": 95, + "endColumn": 24, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 96, "column": 1, @@ -524,6 +564,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 96, + "column": 21, + "endLine": 96, + "endColumn": 24, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 97, "column": 1, @@ -554,6 +604,16 @@ "rule": "Reflect API usage is not allowed in interop calls when an \"Object\" parameter receives a class instance (arkts-interop-d2s-static-reflect-on-dynamic-instance)", "severity": "ERROR" }, + { + "line": 99, + "column": 21, + "endLine": 99, + "endColumn": 28, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 100, "column": 1, @@ -854,6 +914,26 @@ "rule": "Usage of standard library is restricted (arkts-limited-stdlib)", "severity": "ERROR" }, + { + "line": 120, + "column": 13, + "endLine": 120, + "endColumn": 19, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 123, + "column": 7, + "endLine": 123, + "endColumn": 14, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 127, "column": 12, diff --git a/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json b/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json index 54216cf950e4b8b95c35c27f168c22a3f0131ae7..bac26d04ac18a7d3d6029cdd7e6def8ffd04a4e1 100644 --- a/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json +++ b/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json @@ -94,6 +94,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 95, + "column": 16, + "endLine": 95, + "endColumn": 22, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 124, "column": 7, @@ -244,6 +254,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 266, + "column": 9, + "endLine": 266, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 271, "column": 9, @@ -254,6 +274,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 271, + "column": 9, + "endLine": 271, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 277, "column": 15, @@ -264,6 +294,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 277, + "column": 9, + "endLine": 277, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 282, "column": 15, @@ -274,6 +314,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 282, + "column": 9, + "endLine": 282, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 287, "column": 15, @@ -284,6 +334,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 287, + "column": 9, + "endLine": 287, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 292, "column": 15, @@ -294,6 +354,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 292, + "column": 9, + "endLine": 292, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 298, "column": 10, @@ -304,6 +374,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 303, + "column": 3, + "endLine": 303, + "endColumn": 6, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 309, "column": 3, @@ -334,16 +414,6 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, - { - "line": 319, - "column": 9, - "endLine": 319, - "endColumn": 11, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 324, "column": 3, @@ -354,16 +424,6 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, - { - "line": 325, - "column": 9, - "endLine": 325, - "endColumn": 11, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 330, "column": 3, @@ -374,16 +434,6 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, - { - "line": 331, - "column": 9, - "endLine": 331, - "endColumn": 11, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 336, "column": 16, @@ -445,4 +495,4 @@ "severity": "ERROR" } ] -} +} \ 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 index 4e6f89111af0dc233834d35bbdbb22355714ab36..618278e62c48397bcc8ac144a3abe2989f6a4477 100644 --- a/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json +++ b/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json @@ -1,4 +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." + ], "result": [ { "line": 46, @@ -240,6 +254,26 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 255, + "column": 9, + "endLine": 255, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, + { + "line": 258, + "column": 3, + "endLine": 258, + "endColumn": 7, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 268, "column": 10, diff --git a/ets2panda/linter/test/main/no_import_namespace_star_as_var.ets.arkts2.json b/ets2panda/linter/test/main/no_import_namespace_star_as_var.ets.arkts2.json index 6e0b7d9828c7d6793c4f9a9347c473b160783797..1266c69bfca5190fe69b7b4b806747aa9610c8d6 100644 --- a/ets2panda/linter/test/main/no_import_namespace_star_as_var.ets.arkts2.json +++ b/ets2panda/linter/test/main/no_import_namespace_star_as_var.ets.arkts2.json @@ -124,16 +124,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 34, - "column": 5, - "endLine": 34, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 35, "column": 5, diff --git a/ets2panda/linter/test/main/no_sparse_array.ets.arkts2.json b/ets2panda/linter/test/main/no_sparse_array.ets.arkts2.json index ca26b319a6ae6bda6319d1a9cf75991615a039c2..292a9e3ce5bc6d1089fdeb6b665bd91108636bac 100644 --- a/ets2panda/linter/test/main/no_sparse_array.ets.arkts2.json +++ b/ets2panda/linter/test/main/no_sparse_array.ets.arkts2.json @@ -24,6 +24,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 46, + "column": 16, + "endLine": 46, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 47, "column": 13, @@ -34,6 +44,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 47, + "column": 17, + "endLine": 47, + "endColumn": 24, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 48, "column": 12, @@ -43,6 +63,36 @@ "suggest": "", "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" + }, + { + "line": 48, + "column": 16, + "endLine": 48, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 49, + "column": 16, + "endLine": 49, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 86, + "column": 16, + "endLine": 86, + "endColumn": 23, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/no_sparse_array2.ets.arkts2.json b/ets2panda/linter/test/main/no_sparse_array2.ets.arkts2.json index acd50132f8d9a6e9530a77f34d3f6712a7a4f547..6451b27b1d10594592b9ee8a088760500444492c 100644 --- a/ets2panda/linter/test/main/no_sparse_array2.ets.arkts2.json +++ b/ets2panda/linter/test/main/no_sparse_array2.ets.arkts2.json @@ -264,6 +264,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 47, + "column": 16, + "endLine": 47, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 47, "column": 23, @@ -284,6 +294,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 48, + "column": 17, + "endLine": 48, + "endColumn": 24, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 48, "column": 25, @@ -304,6 +324,16 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 49, + "column": 16, + "endLine": 49, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 49, "column": 23, @@ -314,6 +344,16 @@ "rule": "Sparse array is not supported in ArkTS1.2 (arkts-no-sparse-array)", "severity": "ERROR" }, + { + "line": 50, + "column": 16, + "endLine": 50, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 50, "column": 23, @@ -354,6 +394,16 @@ "rule": "Sparse array is not supported in ArkTS1.2 (arkts-no-sparse-array)", "severity": "ERROR" }, + { + "line": 57, + "column": 16, + "endLine": 57, + "endColumn": 23, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 58, "column": 10, 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 3ab8448c632efcc996b3a031e65df78da866f12b..d3a7239f5d16b148279096aae18c9d58b5333d8d 100644 --- 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 @@ -114,6 +114,36 @@ "rule": "Smart type differences (arkts-no-ts-like-smart-type)", "severity": "ERROR" }, + { + "line": 93, + "column": 66, + "endLine": 93, + "endColumn": 75, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 66, + "endLine": 93, + "endColumn": 75, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 101, + "column": 54, + "endLine": 101, + "endColumn": 58, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 105, "column": 8, @@ -124,6 +154,16 @@ "rule": "Smart type differences (arkts-no-ts-like-smart-type)", "severity": "ERROR" }, + { + "line": 109, + "column": 50, + "endLine": 109, + "endColumn": 54, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 114, "column": 9, diff --git a/ets2panda/linter/test/main/no_tuples_arrays.ets.arkts2.json b/ets2panda/linter/test/main/no_tuples_arrays.ets.arkts2.json index e485672d32f23afde8a1a89d5fbea64da7451926..2928b0dcbda2b118ad4d1be81a4d1d631e8b099a 100644 --- a/ets2panda/linter/test/main/no_tuples_arrays.ets.arkts2.json +++ b/ets2panda/linter/test/main/no_tuples_arrays.ets.arkts2.json @@ -234,6 +234,26 @@ "rule": "Array and tuple are different type(arkts-no-tuples-arrays)", "severity": "ERROR" }, + { + "line": 102, + "column": 27, + "endLine": 102, + "endColumn": 36, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 102, + "column": 27, + "endLine": 102, + "endColumn": 36, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 103, "column": 16, @@ -394,6 +414,16 @@ "rule": "Array and tuple are different type(arkts-no-tuples-arrays)", "severity": "ERROR" }, + { + "line": 126, + "column": 33, + "endLine": 126, + "endColumn": 40, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 127, "column": 1, @@ -404,6 +434,16 @@ "rule": "Array and tuple are different type(arkts-no-tuples-arrays)", "severity": "ERROR" }, + { + "line": 128, + "column": 12, + "endLine": 128, + "endColumn": 16, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 128, "column": 1, @@ -414,6 +454,16 @@ "rule": "Array and tuple are different type(arkts-no-tuples-arrays)", "severity": "ERROR" }, + { + "line": 129, + "column": 12, + "endLine": 129, + "endColumn": 19, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 129, "column": 1, diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json b/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json index f7d3a8c29cdebb57512afa7766c69fbf38b777e3..9ad06d0111700544d6270aeb6495bb332b348832 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json @@ -24,16 +24,6 @@ "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", "severity": "ERROR" }, - { - "line": 57, - "column": 5, - "endLine": 57, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 92, "column": 19, @@ -144,6 +134,26 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 206, + "column": 33, + "endLine": 206, + "endColumn": 37, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 207, + "column": 33, + "endLine": 207, + "endColumn": 37, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 207, "column": 42, @@ -505,4 +515,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json index da7ce528c0d4732b9dada9fa4a6560cc55b5acf8..d9ef5529e7526267f44670cc306186743bbd979c 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json @@ -24,16 +24,6 @@ "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", "severity": "ERROR" }, - { - "line": 57, - "column": 5, - "endLine": 57, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 92, "column": 19, @@ -144,6 +134,26 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 206, + "column": 33, + "endLine": 206, + "endColumn": 37, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 207, + "column": 33, + "endLine": 207, + "endColumn": 37, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 207, "column": 42, @@ -868,4 +878,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json index 713d6b80a9f80a4a28d04d8144c139d62d844946..cf68563bf6a9491008fe543192b0e7f222a31478 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json @@ -24,16 +24,6 @@ "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", "severity": "ERROR" }, - { - "line": 67, - "column": 5, - "endLine": 67, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 102, "column": 19, @@ -144,6 +134,26 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 216, + "column": 33, + "endLine": 216, + "endColumn": 37, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, + { + "line": 217, + "column": 33, + "endLine": 217, + "endColumn": 37, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 217, "column": 42, @@ -255,4 +265,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/persist_serial_1.ets b/ets2panda/linter/test/main/persist_serial_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..72a51f4537e70825aac96c0813e56c554555ac68 --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_1.ets @@ -0,0 +1,70 @@ +/* + * 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 { PersistentStorage } from './ui_modules/common_ts_ets_api'; + +class MyClassA {} + +function MyGet1() { + if (1 > 0) { + return 1 + } else { + return 2 + } +} + +function MyGet2() { + if (1 > 0) { + return 0 + } else { + return new MyClassA() + } +} + +const a1 = new MyClassA(); +const a2 = new MyClassA(); +const myArr1: Array = new Array(1, 2); +const mySet1: Set = new Set([1, 2, 3]); +const myMap1: Map = new Map([["jack", 3], ["tom", 2]]); +const myMap2: Map = new Map([[1, a1], [2, a2]]); + +PersistentStorage.persistProp('PropA', 47); +PersistentStorage.persistProp('PropA', true); +PersistentStorage.persistProp('PropA', "Jack"); +PersistentStorage.persistProp('PropA', null); +PersistentStorage.persistProp('PropA', undefined); +PersistentStorage.persistProp('PropA', new Date()); +PersistentStorage.persistProp('PropA', a1); // error +PersistentStorage.persistProp('PropA', new MyClassA()); // error +PersistentStorage.persistProp('PropA', MyGet1()); +PersistentStorage.persistProp('PropA', MyGet2()); // error +PersistentStorage.persistProp('PropA', 1 < 0 ? 1 : new MyClassA()); // error + +PersistentStorage.persistProp('PropA', new Array(1, 2)); +PersistentStorage.persistProp('PropA', new Array("jack", "tom")); +PersistentStorage.persistProp('PropA', new Array(myArr1)); // error +PersistentStorage.persistProp('PropA', new Array(new MyClassA())); // error +PersistentStorage.persistProp('PropA', new Array(a1)); // error + +PersistentStorage.persistProp('PropA', new Set([1, 2])); +PersistentStorage.persistProp('PropA', new Set(["jack", "tom"])); +PersistentStorage.persistProp('PropA', mySet1); +PersistentStorage.persistProp('PropA', new Set([new MyClassA()])); // error +PersistentStorage.persistProp('PropA', new Set([a1])); // error + +PersistentStorage.persistProp('PropA', new Map([["jack", 3], ["tom", 2]])); +PersistentStorage.persistProp('PropA', new Map([[1, a1], [2, a2]])); // error +PersistentStorage.persistProp('PropA', myMap1); +PersistentStorage.persistProp('PropA', myMap2); // error diff --git a/ets2panda/linter/test/main/persist_serial_1.ets.args.json b/ets2panda/linter/test/main/persist_serial_1.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..ec9992d92461d66e16b80975e33f95872c06af54 --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_1.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/persist_serial_1.ets.arkts2.json b/ets2panda/linter/test/main/persist_serial_1.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..e2c1626588a608dc77132b48ce71a7f8886c763f --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_1.ets.arkts2.json @@ -0,0 +1,348 @@ +{ + "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": 38, + "column": 35, + "endLine": 38, + "endColumn": 40, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 31, + "endLine": 38, + "endColumn": 46, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 29, + "endLine": 39, + "endColumn": 47, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 37, + "endLine": 40, + "endColumn": 71, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 39, + "endLine": 41, + "endColumn": 66, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 44, + "endLine": 48, + "endColumn": 48, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 49, + "column": 1, + "endLine": 49, + "endColumn": 43, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 1, + "endLine": 50, + "endColumn": 55, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 1, + "endLine": 52, + "endColumn": 49, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 53, + "column": 1, + "endLine": 53, + "endColumn": 67, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 44, + "endLine": 55, + "endColumn": 49, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 40, + "endLine": 55, + "endColumn": 55, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 44, + "endLine": 56, + "endColumn": 49, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 40, + "endLine": 56, + "endColumn": 64, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 1, + "endLine": 57, + "endColumn": 58, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 44, + "endLine": 57, + "endColumn": 49, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 40, + "endLine": 57, + "endColumn": 57, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 1, + "endLine": 58, + "endColumn": 66, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 44, + "endLine": 58, + "endColumn": 49, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 40, + "endLine": 58, + "endColumn": 65, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 1, + "endLine": 59, + "endColumn": 54, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 44, + "endLine": 59, + "endColumn": 49, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 40, + "endLine": 59, + "endColumn": 53, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 61, + "column": 40, + "endLine": 61, + "endColumn": 55, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 40, + "endLine": 62, + "endColumn": 64, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 1, + "endLine": 64, + "endColumn": 66, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 40, + "endLine": 64, + "endColumn": 65, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 1, + "endLine": 65, + "endColumn": 54, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 40, + "endLine": 65, + "endColumn": 53, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 40, + "endLine": 67, + "endColumn": 74, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 68, + "column": 1, + "endLine": 68, + "endColumn": 68, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + }, + { + "line": 68, + "column": 40, + "endLine": 68, + "endColumn": 67, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 1, + "endLine": 70, + "endColumn": 47, + "problem": "PersistentPropNeedImplementMethod", + "suggest": "", + "rule": "The class of the second parameter passed to the \"persistProp\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-prop-serialization)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/persist_serial_1.ets.json b/ets2panda/linter/test/main/persist_serial_1.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_1.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/persist_serial_2.ets b/ets2panda/linter/test/main/persist_serial_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f0214c5673ff0dca84f14772571116851161114 --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_2.ets @@ -0,0 +1,67 @@ +/* + * 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 { PersistentStorage } from './ui_modules/common_ts_ets_api'; + +class MyClassA {} + +function MyGet1() { + if (1 > 0) { + return 1 + } else { + return 2 + } +} + +function MyGet2() { + if (1 > 0) { + return 0 + } else { + return new MyClassA() + } +} + +const a1 = new MyClassA(); +const a2 = new MyClassA(); +const myArr1: Array = new Array(1, 2); +const mySet1: Set = new Set([1, 2, 3]); +const myMap1: Map = new Map([["jack", 3], ["tom", 2]]); +const myMap2: Map = new Map([[1, a1], [2, a2]]); + +PersistentStorage.persistProps([{ key: 'highScore', defaultValue: '0' }, { key: 'wightScore', defaultValue: '1' }]); +PersistentStorage.persistProps([{ key: 'highScore', defaultValue: 0 }, { key: 'wightScore', defaultValue: 1 }]); +PersistentStorage.persistProps([{ key: 'highScore', defaultValue: false }, { key: 'wightScore', defaultValue: true }]); + +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new MyClassA() }]); // error +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: 1 < 0 ? 1 : new MyClassA() }]); // error +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: MyGet1() }]); +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: MyGet2() }]); // error + +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Array(1, 2) }]); +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Array("jack", "tom") }]); +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Array(myArr1) }]); // error +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Array(new MyClassA()) }]); // error +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Array(a1) }]); // error + +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Set([1, 2]) }]); +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Set(["jack", "tom"]) }]); +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: mySet1 }]); +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Set([new MyClassA()]) }]); // error +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Set([a1]) }]); // error + +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Map([["jack", 3], ["tom", 2]]) }]); +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: new Map([[1, a1], [2, a2]]) }]); // error +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: myMap1 }]); +PersistentStorage.persistProps([{ key: 'PropA', defaultValue: '0' }, { key: 'PropB', defaultValue: myMap2 }]); // error \ No newline at end of file diff --git a/ets2panda/linter/test/main/persist_serial_2.ets.args.json b/ets2panda/linter/test/main/persist_serial_2.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..ec9992d92461d66e16b80975e33f95872c06af54 --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_2.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/persist_serial_2.ets.arkts2.json b/ets2panda/linter/test/main/persist_serial_2.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..1c0b6ba77cbe01dcd7cdbd065529a99ac6f911b4 --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_2.ets.arkts2.json @@ -0,0 +1,328 @@ +{ + "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": 38, + "column": 35, + "endLine": 38, + "endColumn": 40, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 31, + "endLine": 38, + "endColumn": 46, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 29, + "endLine": 39, + "endColumn": 47, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 37, + "endLine": 40, + "endColumn": 71, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 39, + "endLine": 41, + "endColumn": 66, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 47, + "column": 1, + "endLine": 47, + "endColumn": 118, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 1, + "endLine": 48, + "endColumn": 130, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 1, + "endLine": 50, + "endColumn": 112, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 104, + "endLine": 52, + "endColumn": 109, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 100, + "endLine": 52, + "endColumn": 115, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 53, + "column": 104, + "endLine": 53, + "endColumn": 109, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 53, + "column": 100, + "endLine": 53, + "endColumn": 124, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 54, + "column": 1, + "endLine": 54, + "endColumn": 121, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 54, + "column": 104, + "endLine": 54, + "endColumn": 109, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 54, + "column": 100, + "endLine": 54, + "endColumn": 117, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 1, + "endLine": 55, + "endColumn": 129, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 104, + "endLine": 55, + "endColumn": 109, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 100, + "endLine": 55, + "endColumn": 125, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 1, + "endLine": 56, + "endColumn": 117, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 104, + "endLine": 56, + "endColumn": 109, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 100, + "endLine": 56, + "endColumn": 113, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 100, + "endLine": 58, + "endColumn": 115, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 100, + "endLine": 59, + "endColumn": 124, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 61, + "column": 1, + "endLine": 61, + "endColumn": 129, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 61, + "column": 100, + "endLine": 61, + "endColumn": 125, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 1, + "endLine": 62, + "endColumn": 117, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 62, + "column": 100, + "endLine": 62, + "endColumn": 113, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 100, + "endLine": 64, + "endColumn": 134, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 1, + "endLine": 65, + "endColumn": 131, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 100, + "endLine": 65, + "endColumn": 127, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 1, + "endLine": 67, + "endColumn": 110, + "problem": "PersistentPropsNeedImplementMethod", + "suggest": "", + "rule": "The class of the \"defaultValue\" parameter in the literal passed to the \"persistProps\" method must be a primitive type or Date type, or implement the \"toJson\" and \"fromJson\" methods (arkui-persistent-props-serialization)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/persist_serial_2.ets.json b/ets2panda/linter/test/main/persist_serial_2.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_2.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/persist_serial_3.ets b/ets2panda/linter/test/main/persist_serial_3.ets new file mode 100644 index 0000000000000000000000000000000000000000..f314b869406c1ed70ab17236974b8cd2cbe9b32b --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_3.ets @@ -0,0 +1,49 @@ +/* + * 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 { ConnectOptions, PersistenceV2, Type } from './ui_modules/@kit.ArkUI'; +import { contextConstant } from '@kit.AbilityKit'; + +PersistenceV2.notifyOnError((key: string, reason: string, msg: string) => {}) + +@ObservedV2 +class SampleChild { + @Trace childId: number = 0; + groupId: number = 1; +} + +@ObservedV2 +class Sample { + @Type(SampleChild) + @Trace father: SampleChild = new SampleChild(); +} + +@Entry +@ComponentV2 +struct TestCase2 { + @Local p1: Sample | undefined = PersistenceV2.globalConnect({type: Sample, defaultCreator:() => new Sample()}); // error + + @Local p2: Sample | undefined = PersistenceV2.globalConnect({type: Sample, key: 'global1', defaultCreator:() => new Sample(), areaMode: contextConstant.AreaMode.EL1}); // error + + options: ConnectOptions = {type: Sample, key: 'global2', defaultCreator:() => new Sample()}; + @Local p3: Sample | undefined = PersistenceV2.globalConnect(this.options); // error + + @Local p4: Sample | undefined = PersistenceV2.globalConnect({type: Sample, key: 'global1', defaultCreator:() => new Sample(), areaMode: 3}); // error + + @Local p5: Sample | undefined = PersistenceV2.connect(Sample, () => new Sample()); // error + + build() { + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/persist_serial_3.ets.args.json b/ets2panda/linter/test/main/persist_serial_3.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..ec9992d92461d66e16b80975e33f95872c06af54 --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_3.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/persist_serial_3.ets.arkts2.json b/ets2panda/linter/test/main/persist_serial_3.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..151971eb234021de3a50c2110398f41caac4855e --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_3.ets.arkts2.json @@ -0,0 +1,248 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 16, + "column": 41, + "endLine": 16, + "endColumn": 45, + "problem": "InvalidIdentifier", + "suggest": "", + "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 35, + "endLine": 36, + "endColumn": 113, + "problem": "PersistenceV2ConnectNeedAddParam", + "suggest": "", + "rule": "When calling the \"globalConnect\" method, the parameter list of the methods needs to include \"toJson\" and \"fromJson\" (arkui-persistencev2-connect-serialization)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 35, + "endLine": 36, + "endColumn": 113, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 35, + "endLine": 38, + "endColumn": 169, + "problem": "PersistenceV2ConnectNeedAddParam", + "suggest": "", + "rule": "When calling the \"globalConnect\" method, the parameter list of the methods needs to include \"toJson\" and \"fromJson\" (arkui-persistencev2-connect-serialization)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 35, + "endLine": 38, + "endColumn": 169, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 44, + "endLine": 40, + "endColumn": 50, + "problem": "ClassAsObjectError", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 35, + "endLine": 41, + "endColumn": 76, + "problem": "PersistenceV2ConnectNeedAddParam", + "suggest": "", + "rule": "When calling the \"globalConnect\" method, the parameter list of the methods needs to include \"toJson\" and \"fromJson\" (arkui-persistencev2-connect-serialization)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 35, + "endLine": 41, + "endColumn": 76, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 35, + "endLine": 43, + "endColumn": 142, + "problem": "PersistenceV2ConnectNeedAddParam", + "suggest": "", + "rule": "When calling the \"globalConnect\" method, the parameter list of the methods needs to include \"toJson\" and \"fromJson\" (arkui-persistencev2-connect-serialization)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 35, + "endLine": 43, + "endColumn": 142, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 35, + "endLine": 45, + "endColumn": 84, + "problem": "PersistenceV2ConnectNeedAddParam", + "suggest": "", + "rule": "When calling the \"connect\" method, the parameter list of the methods needs to include \"toJson\" and \"fromJson\" (arkui-persistencev2-connect-serialization)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 35, + "endLine": 45, + "endColumn": 84, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 2, + "endLine": 21, + "endColumn": 12, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"ObservedV2\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 4, + "endLine": 23, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Trace\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 2, + "endLine": 27, + "endColumn": 12, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"ObservedV2\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 4, + "endLine": 30, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Trace\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 2, + "endLine": 33, + "endColumn": 7, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Entry\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 2, + "endLine": 34, + "endColumn": 13, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"ComponentV2\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 4, + "endLine": 36, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Local\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 4, + "endLine": 38, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Local\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 4, + "endLine": 41, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Local\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 4, + "endLine": 43, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Local\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 4, + "endLine": 45, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Local\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/persist_serial_3.ets.json b/ets2panda/linter/test/main/persist_serial_3.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..097b66ff3c436ef1e2f9b8373703c5bb650894de --- /dev/null +++ b/ets2panda/linter/test/main/persist_serial_3.ets.json @@ -0,0 +1,28 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 40, + "column": 44, + "endLine": 40, + "endColumn": 50, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)", + "severity": "WARNING" + } + ] +} \ 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 01ea1d9c16242aaefefcd38fd73879feccc063e7..b9634f30d18a08ef975eff602844951a86e5900b 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 @@ -94,6 +94,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 57, + "column": 18, + "endLine": 57, + "endColumn": 23, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 57, "column": 14, @@ -104,6 +114,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 57, + "column": 14, + "endLine": 57, + "endColumn": 27, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 70, "column": 1, @@ -324,6 +344,36 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 108, + "column": 17, + "endLine": 108, + "endColumn": 40, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 112, + "column": 15, + "endLine": 112, + "endColumn": 38, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 15, + "endLine": 115, + "endColumn": 20, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 117, "column": 20, @@ -354,6 +404,26 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 118, + "column": 15, + "endLine": 118, + "endColumn": 36, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 121, + "column": 13, + "endLine": 121, + "endColumn": 34, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, { "line": 139, "column": 12, @@ -364,6 +434,26 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 139, + "column": 16, + "endLine": 139, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 150, + "column": 23, + "endLine": 150, + "endColumn": 29, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 159, "column": 3, 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 79d7fb7b1f8640d5b580eacbfdef091bcc8649b5..81759dc802bad675bf52dadb44e0de23ff3ea5b0 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 @@ -94,6 +94,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 57, + "column": 18, + "endLine": 57, + "endColumn": 23, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 57, "column": 14, @@ -104,6 +114,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 57, + "column": 14, + "endLine": 57, + "endColumn": 27, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 70, "column": 1, @@ -324,6 +344,36 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 108, + "column": 17, + "endLine": 108, + "endColumn": 40, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 112, + "column": 15, + "endLine": 112, + "endColumn": 38, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 15, + "endLine": 115, + "endColumn": 20, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 117, "column": 20, @@ -354,6 +404,26 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 118, + "column": 15, + "endLine": 118, + "endColumn": 36, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 121, + "column": 13, + "endLine": 121, + "endColumn": 34, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, { "line": 139, "column": 12, @@ -364,6 +434,26 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 139, + "column": 16, + "endLine": 139, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 150, + "column": 23, + "endLine": 150, + "endColumn": 29, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 159, "column": 3, 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 373804e464c11d13c7665581640e69b9d45947e8..aaf5bc6ce17f19367788bc5ab6df81d7487b8d3d 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 @@ -94,6 +94,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 57, + "column": 18, + "endLine": 57, + "endColumn": 23, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 57, "column": 14, @@ -104,6 +114,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 57, + "column": 14, + "endLine": 57, + "endColumn": 27, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 70, "column": 1, @@ -324,6 +344,36 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 108, + "column": 17, + "endLine": 108, + "endColumn": 40, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 112, + "column": 15, + "endLine": 112, + "endColumn": 38, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 15, + "endLine": 115, + "endColumn": 20, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 117, "column": 20, @@ -354,6 +404,26 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 118, + "column": 15, + "endLine": 118, + "endColumn": 36, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, + { + "line": 121, + "column": 13, + "endLine": 121, + "endColumn": 34, + "problem": "BuiltinIteratorResultValue", + "suggest": "", + "rule": "The property of IteratorResult is not supported (arkts-builtin-iterator-result-value)", + "severity": "ERROR" + }, { "line": 139, "column": 12, @@ -364,6 +434,26 @@ "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" }, + { + "line": 139, + "column": 16, + "endLine": 139, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 150, + "column": 23, + "endLine": 150, + "endColumn": 29, + "problem": "BuiltinFinalClass", + "suggest": "", + "rule": "API is not support use class in this API (arkts-builtin-final-class)", + "severity": "ERROR" + }, { "line": 159, "column": 3, diff --git a/ets2panda/linter/test/main/repeat_virtualscroll.ets.arkts2.json b/ets2panda/linter/test/main/repeat_virtualscroll.ets.arkts2.json index e9f013b0812ed03496ae9cf444db7b31a94d7dbf..b6272423c4fa316906e1100ef22d4a88842f487f 100644 --- a/ets2panda/linter/test/main/repeat_virtualscroll.ets.arkts2.json +++ b/ets2panda/linter/test/main/repeat_virtualscroll.ets.arkts2.json @@ -14,6 +14,26 @@ "limitations under the License." ], "result": [ + { + "line": 36, + "column": 62, + "endLine": 36, + "endColumn": 71, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 62, + "endLine": 36, + "endColumn": 71, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 40, "column": 9, @@ -24,6 +44,26 @@ "rule": "\"Repeat\" natively supports virtual scrolling capability in ArkTS1.2, so the default virtual scrolling should be disabled (arkui-repeat-disable-default-virtualscroll)", "severity": "ERROR" }, + { + "line": 46, + "column": 62, + "endLine": 46, + "endColumn": 71, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 46, + "column": 62, + "endLine": 46, + "endColumn": 71, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 48, "column": 9, diff --git a/ets2panda/linter/test/main/repeat_virtualscroll.ets.autofix.json b/ets2panda/linter/test/main/repeat_virtualscroll.ets.autofix.json index 50e60f2e52146a29f2fe6731eb6f74d2ce098405..b06ce8f88287a5cb6e95231d593fb3beac48a855 100644 --- a/ets2panda/linter/test/main/repeat_virtualscroll.ets.autofix.json +++ b/ets2panda/linter/test/main/repeat_virtualscroll.ets.autofix.json @@ -14,6 +14,26 @@ "limitations under the License." ], "result": [ + { + "line": 36, + "column": 62, + "endLine": 36, + "endColumn": 71, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 62, + "endLine": 36, + "endColumn": 71, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 40, "column": 9, @@ -35,6 +55,26 @@ "rule": "\"Repeat\" natively supports virtual scrolling capability in ArkTS1.2, so the default virtual scrolling should be disabled (arkui-repeat-disable-default-virtualscroll)", "severity": "ERROR" }, + { + "line": 46, + "column": 62, + "endLine": 46, + "endColumn": 71, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 46, + "column": 62, + "endLine": 46, + "endColumn": 71, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 48, "column": 9, diff --git a/ets2panda/linter/test/main/repeat_virtualscroll.ets.migrate.json b/ets2panda/linter/test/main/repeat_virtualscroll.ets.migrate.json index ca88f857e960b437dcf767c0ac40be998c8f1236..e82e1454e9345d1cc59e56980159bd2c2615ecd3 100644 --- a/ets2panda/linter/test/main/repeat_virtualscroll.ets.migrate.json +++ b/ets2panda/linter/test/main/repeat_virtualscroll.ets.migrate.json @@ -13,5 +13,46 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [] + "result": [ + { + "line": 48, + "column": 62, + "endLine": 48, + "endColumn": 71, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 62, + "endLine": 48, + "endColumn": 71, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 62, + "endLine": 58, + "endColumn": 71, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 62, + "endLine": 58, + "endColumn": 71, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "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 2c19de62ff200138450c5d7aacb002a6fce9d06e..0f96cd9029f32c2997f8b11d9e352e616c3a3334 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.arkts2.json @@ -384,6 +384,16 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 169, + "column": 28, + "endLine": 169, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 169, "column": 24, @@ -394,6 +404,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 169, + "column": 24, + "endLine": 169, + "endColumn": 43, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 185, "column": 23, @@ -434,6 +454,36 @@ "rule": "Smart type differences (arkts-no-ts-like-smart-type)", "severity": "ERROR" }, + { + "line": 219, + "column": 16, + "endLine": 219, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 220, + "column": 16, + "endLine": 220, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 220, + "column": 12, + "endLine": 220, + "endColumn": 33, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 227, "column": 1, @@ -464,6 +514,16 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 254, + "column": 28, + "endLine": 254, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 254, "column": 24, @@ -474,6 +534,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 254, + "column": 24, + "endLine": 254, + "endColumn": 43, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 266, "column": 3, @@ -484,6 +554,16 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 270, + "column": 28, + "endLine": 270, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 270, "column": 24, @@ -494,6 +574,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 270, + "column": 24, + "endLine": 270, + "endColumn": 42, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 276, "column": 7, @@ -534,6 +624,16 @@ "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", "severity": "ERROR" }, + { + "line": 299, + "column": 44, + "endLine": 299, + "endColumn": 49, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 301, "column": 23, @@ -544,6 +644,16 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 313, + "column": 36, + "endLine": 313, + "endColumn": 41, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 316, "column": 9, 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 e9b3765b05fab2f211a7df0cce9ccd71b6ee0f42..1d451093ecb32ffd7fe3840791da4059ea140f75 100644 --- a/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json +++ b/ets2panda/linter/test/main/runtime_array_bound.ets.migrate.json @@ -264,6 +264,26 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 169, + "column": 28, + "endLine": 169, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 169, + "column": 24, + "endLine": 169, + "endColumn": 51, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 194, "column": 14, @@ -274,6 +294,36 @@ "rule": "Smart type differences (arkts-no-ts-like-smart-type)", "severity": "ERROR" }, + { + "line": 219, + "column": 16, + "endLine": 219, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 220, + "column": 16, + "endLine": 220, + "endColumn": 21, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 220, + "column": 12, + "endLine": 220, + "endColumn": 33, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 227, "column": 1, @@ -304,6 +354,26 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 254, + "column": 28, + "endLine": 254, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 254, + "column": 24, + "endLine": 254, + "endColumn": 51, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 266, "column": 3, @@ -314,6 +384,26 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 270, + "column": 28, + "endLine": 270, + "endColumn": 33, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 270, + "column": 24, + "endLine": 270, + "endColumn": 50, + "problem": "UninitializedArrayElements", + "suggest": "", + "rule": "Please init elements of array before read elements. If not, there will be a runtime error. We recommend you to use Array.create(len, T) (arkts-builtin-uninitialized-element)", + "severity": "WARNING" + }, { "line": 276, "column": 7, @@ -344,6 +434,16 @@ "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", "severity": "ERROR" }, + { + "line": 299, + "column": 44, + "endLine": 299, + "endColumn": 49, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 301, "column": 23, @@ -354,6 +454,16 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 313, + "column": 36, + "endLine": 313, + "endColumn": 41, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 316, "column": 9, diff --git a/ets2panda/linter/test/main/structural_identity.ets.arkts2.json b/ets2panda/linter/test/main/structural_identity.ets.arkts2.json index 5bbd4876a8e631012c6d3f598fbd0a6e997576b9..8be66d073644657941aafc7487bf95bb9ddc7647 100644 --- a/ets2panda/linter/test/main/structural_identity.ets.arkts2.json +++ b/ets2panda/linter/test/main/structural_identity.ets.arkts2.json @@ -674,16 +674,6 @@ "rule": "Structural typing is not supported (arkts-no-structural-typing)", "severity": "ERROR" }, - { - "line": 507, - "column": 5, - "endLine": 507, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 511, "column": 1, @@ -1074,6 +1064,16 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, + { + "line": 622, + "column": 45, + "endLine": 622, + "endColumn": 49, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 626, "column": 5, @@ -1285,4 +1285,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/structural_identity_extended_inheritance.ets.arkts2.json b/ets2panda/linter/test/main/structural_identity_extended_inheritance.ets.arkts2.json index 4d493d1feddb9497f7fe883b4fd194eae390ea94..f4b9ec6f673f71b7b10f6292500d03544b9017e9 100644 --- a/ets2panda/linter/test/main/structural_identity_extended_inheritance.ets.arkts2.json +++ b/ets2panda/linter/test/main/structural_identity_extended_inheritance.ets.arkts2.json @@ -14,6 +14,16 @@ "limitations under the License." ], "result": [ + { + "line": 49, + "column": 15, + "endLine": 49, + "endColumn": 20, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 56, "column": 1, @@ -24,26 +34,6 @@ "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", "severity": "ERROR" }, - { - "line": 58, - "column": 5, - "endLine": 58, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 60, - "column": 5, - "endLine": 60, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 73, "column": 1, @@ -85,4 +75,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/swicth_expr.ets.arkts2.json b/ets2panda/linter/test/main/swicth_expr.ets.arkts2.json index 2d6e11c515f6e34d3f46255fa7b34d289dfe2338..c5a72fe0733c4592f3e91717aec57c4e928607dd 100644 --- a/ets2panda/linter/test/main/swicth_expr.ets.arkts2.json +++ b/ets2panda/linter/test/main/swicth_expr.ets.arkts2.json @@ -93,6 +93,16 @@ "suggest": "", "rule": "Primitive types are normalized with their boxed type (arkts-primitive-type-normalization)", "severity": "ERROR" + }, + { + "line": 215, + "column": 17, + "endLine": 215, + "endColumn": 23, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.arkts2.json b/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.arkts2.json index 4b786c5828e523819a2a91e7c232eb88b9dfd395..4fbd4f4e2c599fdf8d9a9d09ba9c5535b5903e57 100644 --- a/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.arkts2.json +++ b/ets2panda/linter/test/main/taskpool_deprecated_usages.ets.arkts2.json @@ -84,6 +84,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 22, + "column": 17, + "endLine": 22, + "endColumn": 22, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 24, "column": 5, diff --git a/ets2panda/linter/test/main/ts_overload.ets.arkts2.json b/ets2panda/linter/test/main/ts_overload.ets.arkts2.json index ca097aeaa44ef5e13a1c2a23dc403ec636d10ed2..8e4ea2ce665c2dcc9b00e0367e3a250bad809874 100644 --- a/ets2panda/linter/test/main/ts_overload.ets.arkts2.json +++ b/ets2panda/linter/test/main/ts_overload.ets.arkts2.json @@ -44,6 +44,16 @@ "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", "severity": "ERROR" }, + { + "line": 20, + "column": 16, + "endLine": 20, + "endColumn": 20, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 30, "column": 3, diff --git a/ets2panda/linter/test/main/ui_modules/@kit.ArkUI.d.ts b/ets2panda/linter/test/main/ui_modules/@kit.ArkUI.d.ts index cf71890e70f66a55e52e5cc7d90ca8f1207ca921..638b3a1404338d3dc8cd16d181fe002e024cbbce 100644 --- a/ets2panda/linter/test/main/ui_modules/@kit.ArkUI.d.ts +++ b/ets2panda/linter/test/main/ui_modules/@kit.ArkUI.d.ts @@ -14,4 +14,5 @@ */ import { BuilderNode } from './@ohos.arkui.node'; -export { BuilderNode }; \ No newline at end of file +import { PersistenceV2 } from './@ohos.arkui.StateManagement'; +export { BuilderNode, PersistenceV2 }; \ No newline at end of file diff --git a/ets2panda/linter/test/main/ui_modules/@ohos.arkui.StateManagement.d.ts b/ets2panda/linter/test/main/ui_modules/@ohos.arkui.StateManagement.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3ba4dbfcb73b09a4e861b21440ed15c3af639ff7 --- /dev/null +++ b/ets2panda/linter/test/main/ui_modules/@ohos.arkui.StateManagement.d.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export declare class PersistenceV2 extends AppStorageV2{ + static globalConnect(): void; +} + +declare class AppStorageV2 { + static connect(): void; +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/ui_modules/common_ts_ets_api.d.ts b/ets2panda/linter/test/main/ui_modules/common_ts_ets_api.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..2634f5bd9faa4449476f8844e42819c4eaaf1876 --- /dev/null +++ b/ets2panda/linter/test/main/ui_modules/common_ts_ets_api.d.ts @@ -0,0 +1,19 @@ +/* + * 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 declare class PersistentStorage { + static persistProp(): void; + static PersistProps(): void; +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/worker_module.ets.arkts2.json b/ets2panda/linter/test/main/worker_module.ets.arkts2.json index d01b01f98e49498ef40e0df91bab289d73bf0626..535d022afdc58f18c353c35b8ca2d43213f138e0 100644 --- a/ets2panda/linter/test/main/worker_module.ets.arkts2.json +++ b/ets2panda/linter/test/main/worker_module.ets.arkts2.json @@ -114,16 +114,6 @@ "rule": "Worker are not supported(arkts-no-need-stdlib-worker)", "severity": "ERROR" }, - { - "line": 34, - "column": 7, - "endLine": 34, - "endColumn": 14, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 34, "column": 16, @@ -153,16 +143,6 @@ "suggest": "", "rule": "Worker are not supported(arkts-no-need-stdlib-worker)", "severity": "ERROR" - }, - { - "line": 38, - "column": 7, - "endLine": 38, - "endColumn": 14, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/rules/rule207.ets.arkts2.json b/ets2panda/linter/test/rules/rule207.ets.arkts2.json index d286d0d82d01fafb0634e4ab2d6139d71e5f16f5..0b4e1a641512592fd533d01e2f4b9ae0cacbbe09 100644 --- a/ets2panda/linter/test/rules/rule207.ets.arkts2.json +++ b/ets2panda/linter/test/rules/rule207.ets.arkts2.json @@ -54,6 +54,16 @@ "rule": "Special arguments object inside functions are not supported (arkts-no-arguments-obj)", "severity": "ERROR" }, + { + "line": 25, + "column": 35, + "endLine": 25, + "endColumn": 41, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 25, "column": 25, @@ -84,6 +94,16 @@ "rule": "Special arguments object inside functions are not supported (arkts-no-arguments-obj)", "severity": "ERROR" }, + { + "line": 31, + "column": 51, + "endLine": 31, + "endColumn": 57, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 31, "column": 41, @@ -224,6 +244,16 @@ "rule": "Special arguments object inside functions are not supported (arkts-no-arguments-obj)", "severity": "ERROR" }, + { + "line": 57, + "column": 19, + "endLine": 57, + "endColumn": 25, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 57, "column": 9, diff --git a/ets2panda/linter/test/rules/rule37.ets.arkts2.json b/ets2panda/linter/test/rules/rule37.ets.arkts2.json index e07b57d6dfb8725687fadcdc4937e02927228535..907deb012b6b900ad51bd985b8f9ab319d1d4159 100644 --- a/ets2panda/linter/test/rules/rule37.ets.arkts2.json +++ b/ets2panda/linter/test/rules/rule37.ets.arkts2.json @@ -24,6 +24,16 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 18, + "column": 27, + "endLine": 18, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 20, "column": 17, @@ -34,6 +44,16 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 21, + "column": 29, + "endLine": 21, + "endColumn": 35, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 23, "column": 23, @@ -44,6 +64,26 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 25, + "column": 27, + "endLine": 25, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 27, + "endLine": 27, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 27, "column": 34, @@ -54,6 +94,26 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 29, + "column": 27, + "endLine": 29, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 38, + "endLine": 29, + "endColumn": 44, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 31, "column": 23, @@ -64,6 +124,16 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 33, + "column": 28, + "endLine": 33, + "endColumn": 34, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 36, "column": 44, @@ -84,6 +154,16 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 40, + "column": 32, + "endLine": 40, + "endColumn": 38, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 43, "column": 22, @@ -94,6 +174,16 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 47, + "column": 34, + "endLine": 47, + "endColumn": 40, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 51, "column": 22, @@ -104,6 +194,16 @@ "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 55, + "column": 34, + "endLine": 55, + "endColumn": 40, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 59, "column": 17, diff --git a/ets2panda/linter/test/rules/rule37.ets.autofix.json b/ets2panda/linter/test/rules/rule37.ets.autofix.json index 3cad91ca09415031931a0886e1e44b09b2ec7132..73acc1da3e5a42d10a16607463fa4bce4ceb6e5e 100644 --- a/ets2panda/linter/test/rules/rule37.ets.autofix.json +++ b/ets2panda/linter/test/rules/rule37.ets.autofix.json @@ -24,13 +24,27 @@ { "start": 631, "end": 637, - "replacementText": "new RegExp(\"bc*d\")" + "replacementText": "new RegExp(\"bc*d\")", + "line": 16, + "column": 22, + "endLine": 16, + "endColumn": 28 } ], "suggest": "", "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 18, + "column": 27, + "endLine": 18, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 20, "column": 17, @@ -41,13 +55,27 @@ { "start": 699, "end": 764, - "replacementText": "new RegExp(\"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\\\\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$\")" + "replacementText": "new RegExp(\"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\\\\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$\")", + "line": 20, + "column": 17, + "endLine": 20, + "endColumn": 82 } ], "suggest": "", "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 21, + "column": 29, + "endLine": 21, + "endColumn": 35, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 23, "column": 23, @@ -58,13 +86,37 @@ { "start": 892, "end": 900, - "replacementText": "new RegExp(\"bc*d\", \"ig\")" + "replacementText": "new RegExp(\"bc*d\", \"ig\")", + "line": 23, + "column": 23, + "endLine": 23, + "endColumn": 31 } ], "suggest": "", "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 25, + "column": 27, + "endLine": 25, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 27, + "endLine": 27, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 27, "column": 34, @@ -75,13 +127,37 @@ { "start": 985, "end": 992, - "replacementText": "new RegExp(\"bc*d\", \"i\")" + "replacementText": "new RegExp(\"bc*d\", \"i\")", + "line": 27, + "column": 34, + "endLine": 27, + "endColumn": 41 } ], "suggest": "", "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 29, + "column": 27, + "endLine": 29, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 38, + "endLine": 29, + "endColumn": 44, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 31, "column": 23, @@ -92,13 +168,27 @@ { "start": 1088, "end": 1093, - "replacementText": "new RegExp(\"a\\\\\\\\\")" + "replacementText": "new RegExp(\"a\\\\\\\\\")", + "line": 31, + "column": 23, + "endLine": 31, + "endColumn": 28 } ], "suggest": "", "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 33, + "column": 28, + "endLine": 33, + "endColumn": 34, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 36, "column": 44, @@ -109,7 +199,11 @@ { "start": 1195, "end": 1201, - "replacementText": "new RegExp(\"bc*d\")" + "replacementText": "new RegExp(\"bc*d\")", + "line": 36, + "column": 44, + "endLine": 36, + "endColumn": 50 } ], "suggest": "", @@ -126,13 +220,27 @@ { "start": 1239, "end": 1304, - "replacementText": "new RegExp(\"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\\\\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$\")" + "replacementText": "new RegExp(\"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\\\\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$\")", + "line": 38, + "column": 36, + "endLine": 38, + "endColumn": 101 } ], "suggest": "", "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 40, + "column": 32, + "endLine": 40, + "endColumn": 38, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 43, "column": 22, @@ -143,13 +251,27 @@ { "start": 1410, "end": 1416, - "replacementText": "new RegExp(\"bc*d\")" + "replacementText": "new RegExp(\"bc*d\")", + "line": 43, + "column": 22, + "endLine": 43, + "endColumn": 28 } ], "suggest": "", "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 47, + "column": 34, + "endLine": 47, + "endColumn": 40, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 51, "column": 22, @@ -160,13 +282,27 @@ { "start": 1557, "end": 1563, - "replacementText": "new RegExp(\"bc*d\")" + "replacementText": "new RegExp(\"bc*d\")", + "line": 51, + "column": 22, + "endLine": 51, + "endColumn": 28 } ], "suggest": "", "rule": "RegExp literals are not supported (arkts-no-regexp-literals)", "severity": "ERROR" }, + { + "line": 55, + "column": 34, + "endLine": 55, + "endColumn": 40, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, { "line": 59, "column": 17, @@ -177,7 +313,11 @@ { "start": 1694, "end": 1759, - "replacementText": "new RegExp(\"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\\\\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$\")" + "replacementText": "new RegExp(\"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\\\\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$\")", + "line": 59, + "column": 17, + "endLine": 59, + "endColumn": 82 } ], "suggest": "", @@ -194,7 +334,11 @@ { "start": 1799, "end": 1864, - "replacementText": "new RegExp(\"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\\\\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$\")" + "replacementText": "new RegExp(\"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\\\\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$\")", + "line": 63, + "column": 28, + "endLine": 63, + "endColumn": 93 } ], "suggest": "", @@ -211,7 +355,11 @@ { "start": 1890, "end": 1904, - "replacementText": "new RegExp(\"ab*c\")" + "replacementText": "new RegExp(\"ab*c\")", + "line": 65, + "column": 24, + "endLine": 65, + "endColumn": 38 } ], "suggest": "", @@ -228,7 +376,11 @@ { "start": 1929, "end": 1947, - "replacementText": "new RegExp(\"ab*c\", \"i\")" + "replacementText": "new RegExp(\"ab*c\", \"i\")", + "line": 67, + "column": 24, + "endLine": 67, + "endColumn": 42 } ], "suggest": "", @@ -245,7 +397,11 @@ { "start": 1968, "end": 1992, - "replacementText": "new RegExp('dawfgr' + '12345')" + "replacementText": "new RegExp('dawfgr' + '12345')", + "line": 69, + "column": 20, + "endLine": 69, + "endColumn": 44 } ], "suggest": "", @@ -262,7 +418,11 @@ { "start": 2013, "end": 2169, - "replacementText": "new RegExp('.∗?(?:(?:元宵|三八|妇女|母亲|父亲|七夕|重阳|情人|儿童|六一' + '|愚人|复活|青年|护士|建军|教师|建党|万圣|感恩|秘书|七一|五四|八一|腊八|光棍|植树|中元)节|除夕|大年三十|大年30|七夕' + '|平安夜|六一|七一|五四|八一|三八|腊八|双十一|双十二).∗')" + "replacementText": "new RegExp('.∗?(?:(?:元宵|三八|妇女|母亲|父亲|七夕|重阳|情人|儿童|六一' + '|愚人|复活|青年|护士|建军|教师|建党|万圣|感恩|秘书|七一|五四|八一|腊八|光棍|植树|中元)节|除夕|大年三十|大年30|七夕' + '|平安夜|六一|七一|五四|八一|三八|腊八|双十一|双十二).∗')", + "line": 71, + "column": 20, + "endLine": 71, + "endColumn": 176 } ], "suggest": "", @@ -279,7 +439,11 @@ { "start": 2195, "end": 2227, - "replacementText": "new RegExp('dawfgr'.concat('12345'))" + "replacementText": "new RegExp('dawfgr'.concat('12345'))", + "line": 73, + "column": 24, + "endLine": 73, + "endColumn": 56 } ], "suggest": "", @@ -296,7 +460,11 @@ { "start": 2250, "end": 2282, - "replacementText": "new RegExp('dawfgr' + '12345' + '789')" + "replacementText": "new RegExp('dawfgr' + '12345' + '789')", + "line": 75, + "column": 21, + "endLine": 75, + "endColumn": 53 } ], "suggest": "", diff --git a/ets2panda/linter/test/rules/rule37.ets.migrate.json b/ets2panda/linter/test/rules/rule37.ets.migrate.json index ca88f857e960b437dcf767c0ac40be998c8f1236..37f9ac92510e701122490aa80c5e2dad68676e68 100644 --- a/ets2panda/linter/test/rules/rule37.ets.migrate.json +++ b/ets2panda/linter/test/rules/rule37.ets.migrate.json @@ -13,5 +13,276 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [] + "result": [ + { + "line": 16, + "column": 26, + "endLine": 16, + "endColumn": 32, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 27, + "endLine": 18, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 21, + "endLine": 20, + "endColumn": 27, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 29, + "endLine": 21, + "endColumn": 35, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 27, + "endLine": 23, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 27, + "endLine": 25, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 27, + "endLine": 27, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 38, + "endLine": 27, + "endColumn": 44, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 27, + "endLine": 29, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 38, + "endLine": 29, + "endColumn": 44, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 31, + "column": 27, + "endLine": 31, + "endColumn": 33, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 28, + "endLine": 33, + "endColumn": 34, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 36, + "column": 48, + "endLine": 36, + "endColumn": 54, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 40, + "endLine": 38, + "endColumn": 46, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 40, + "column": 32, + "endLine": 40, + "endColumn": 38, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 26, + "endLine": 43, + "endColumn": 32, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 47, + "column": 34, + "endLine": 47, + "endColumn": 40, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 51, + "column": 26, + "endLine": 51, + "endColumn": 32, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 34, + "endLine": 55, + "endColumn": 40, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 21, + "endLine": 59, + "endColumn": 27, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 32, + "endLine": 63, + "endColumn": 38, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 28, + "endLine": 65, + "endColumn": 34, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 28, + "endLine": 67, + "endColumn": 34, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 24, + "endLine": 69, + "endColumn": 30, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 71, + "column": 24, + "endLine": 71, + "endColumn": 30, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 73, + "column": 28, + "endLine": 73, + "endColumn": 34, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 25, + "endLine": 75, + "endColumn": 31, + "problem": "BuiltinNoCtorFunc", + "suggest": "", + "rule": "API is not support ctor signature and func (arkts-builtin-cotr)", + "severity": "ERROR" + } + ] } \ No newline at end of file diff --git a/ets2panda/linter/test/sdkcommonapi/sdk_url.ets b/ets2panda/linter/test/sdkcommonapi/sdk_url.ets index 2a2f5e1d0d953a858df25dab88b0049af15bb659..e9a14fb8067d3301f6948c9ac3bb8cce9888b27e 100644 --- a/ets2panda/linter/test/sdkcommonapi/sdk_url.ets +++ b/ets2panda/linter/test/sdkcommonapi/sdk_url.ets @@ -30,7 +30,7 @@ paramsObject2.delete('fod');//error let searchParamsObject1 = new url.URLSearchParams("keyName1=valueName1&keyName2=valueName2");//error let iter: Iterable = searchParamsObject1.entries();//error -let pairs = Array.from(iter); +let pairs = Array.from(iter); //BuiltinAll for (let pair of pairs) { // Show keyName/valueName pairs console.log(pair[0]+ ', '+ pair[1]); } @@ -53,7 +53,7 @@ let paramsObject4 = new url.URLSearchParams(urlObject2.search.slice(1));//error* paramsObject4.has('bard') === true;//error let searchParamsObject2 = new url.URLSearchParams("key1=value1&key2=value2"); //error -let keys = Array.from(searchParamsObject2.keys());//error +let keys = Array.from(searchParamsObject2.keys());//error+BuiltinAll for (let key of keys) { console.log(key); } @@ -71,7 +71,7 @@ params.append('fod', '3');//error console.log(params.toString()); //error let searchParams = new url.URLSearchParams("key1=value1&key2=value2");//error -let values = Array.from(searchParams.values());//error +let values = Array.from(searchParams.values());//error+BuiltinAll for (let value of values) { console.log(value); } //sum:40 \ No newline at end of file diff --git a/ets2panda/linter/test/sdkcommonapi/sdk_url.ets.arkts2.json b/ets2panda/linter/test/sdkcommonapi/sdk_url.ets.arkts2.json index a8458bc115b17f865194c5bf0212a50ab7ba36de..d538bc711d7d538c83d6ac3fa59ea70bfc51d519 100644 --- a/ets2panda/linter/test/sdkcommonapi/sdk_url.ets.arkts2.json +++ b/ets2panda/linter/test/sdkcommonapi/sdk_url.ets.arkts2.json @@ -134,6 +134,16 @@ "rule": "The \"url.URLSearchParams\" in SDK is no longer supported.(sdk-method-not-supported)", "severity": "ERROR" }, + { + "line": 33, + "column": 19, + "endLine": 33, + "endColumn": 23, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 35, "column": 15, @@ -304,6 +314,16 @@ "rule": "The \"URLSearchParams\" in SDK is no longer supported.(sdk-method-not-supported)", "severity": "ERROR" }, + { + "line": 56, + "column": 18, + "endLine": 56, + "endColumn": 22, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 56, "column": 43, @@ -424,6 +444,16 @@ "rule": "The \"URLSearchParams\" in SDK is no longer supported.(sdk-method-not-supported)", "severity": "ERROR" }, + { + "line": 74, + "column": 20, + "endLine": 74, + "endColumn": 24, + "problem": "BuiltinDisableApi", + "suggest": "", + "rule": "API has been disabled (arkts-builtin-disable-api)", + "severity": "ERROR" + }, { "line": 74, "column": 38, diff --git a/ets2panda/linter/test/sdkcommonapi/sdk_xml.ets.arkts2.json b/ets2panda/linter/test/sdkcommonapi/sdk_xml.ets.arkts2.json index f3ac4e12f2f009d6952bcef9e31b98721235e12e..84f3263b20862fcbb5d399ddb03190fe0a30c69e 100644 --- a/ets2panda/linter/test/sdkcommonapi/sdk_xml.ets.arkts2.json +++ b/ets2panda/linter/test/sdkcommonapi/sdk_xml.ets.arkts2.json @@ -154,6 +154,26 @@ "rule": "The \"ConvertOptions\" in SDK is no longer supported.(sdk-method-not-supported)", "severity": "ERROR" }, + { + "line": 32, + "column": 19, + "endLine": 32, + "endColumn": 28, + "problem": "SdkCommonApiWhiteList", + "suggest": "", + "rule": "The \"stringify\" in SDK is no longer supported.(sdk-method-not-supported)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 19, + "endLine": 32, + "endColumn": 28, + "problem": "BuiltinNarrowTypes", + "suggest": "", + "rule": "Using narrowing of types is not allowed in this API (arkts-builtin-narrow-types)", + "severity": "ERROR" + }, { "line": 32, "column": 34, @@ -364,16 +384,6 @@ "rule": "The \"ConvertOptions\" in SDK is no longer supported.(sdk-method-not-supported)", "severity": "ERROR" }, - { - "line": 54, - "column": 5, - "endLine": 54, - "endColumn": 8, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 54, "column": 9, diff --git a/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json b/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json index 709ee01e70540366d5ca3a1c8af8f9663e9eb62f..250fb9600ab36002fb381ff2873132546af54e73 100644 --- a/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json +++ b/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json @@ -64,6 +64,16 @@ "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", "severity": "ERROR" }, + { + "line": 22, + "column": 44, + "endLine": 22, + "endColumn": 49, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, { "line": 22, "column": 40, @@ -154,16 +164,6 @@ "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", "severity": "ERROR" }, - { - "line": 52, - "column": 5, - "endLine": 52, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 53, "column": 18,