diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 17e696930bad3bcaa73cee91459fd3fade113e20..8d1a73d1148128771c29591b4f1fc698d533d1ab 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -21,7 +21,10 @@ import type { Autofix } from './autofixes/Autofixer'; import { Autofixer } from './autofixes/Autofixer'; import { PROMISE_METHODS, SYMBOL, SYMBOL_CONSTRUCTOR, TsUtils } from './utils/TsUtils'; import { FUNCTION_HAS_NO_RETURN_ERROR_CODE } from './utils/consts/FunctionHasNoReturnErrorCode'; -import { LIMITED_STANDARD_UTILITY_TYPES } from './utils/consts/LimitedStandardUtilityTypes'; +import { + LIMITED_STANDARD_UTILITY_TYPES, + LIMITED_STANDARD_UTILITY_TYPES2 +} from './utils/consts/LimitedStandardUtilityTypes'; import { LIKE_FUNCTION, LIKE_FUNCTION_CONSTRUCTOR } from './utils/consts/LikeFunction'; import { METHOD_DECLARATION } from './utils/consts/MethodDeclaration'; import { METHOD_SIGNATURE } from './utils/consts/MethodSignature'; @@ -1321,10 +1324,6 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const exprSym = this.tsUtils.trueSymbolAtLocation(propertyAccessNode); const baseExprSym = this.tsUtils.trueSymbolAtLocation(propertyAccessNode.expression); const baseExprType = this.tsTypeChecker.getTypeAtLocation(propertyAccessNode.expression); - this.handleTsInterop(propertyAccessNode, () => { - const type = this.tsTypeChecker.getTypeAtLocation(propertyAccessNode.expression); - this.checkUsageOfTsTypes(type, propertyAccessNode.expression); - }); this.propertyAccessExpressionForInterop(propertyAccessNode); if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); @@ -1491,12 +1490,195 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { TsUtils.isAnyType(baseType) || TsUtils.isUnknownType(baseType) || this.tsUtils.isStdFunctionType(baseType) || - typeString === 'symbol' + typeString === 'symbol' || + this.isMixedEnum(baseType) || + this.isSpecialType(baseType, node) || + this.isStdUtilityTools(node) ) { this.incrementCounters(node, FaultID.InteropDirectAccessToTSTypes); } } + private isSpecialType(baseType: ts.Type, node: ts.Node): boolean { + const baseTypeStr = this.tsTypeChecker.typeToString(baseType); + if (TypeScriptLinter.extractKeyofFromString(baseTypeStr)) { + return true; + } + let symbol = baseType.getSymbol(); + if (!symbol) { + symbol = this.tsUtils.trueSymbolAtLocation(node); + } + const decl = TsUtils.getDeclaration(symbol); + if (!decl) { + return false; + } + if ( + ts.isTypeAliasDeclaration(decl) && this.checkSpecialTypeNode(decl.type, true) || + this.checkSpecialTypeNode(decl, true) + ) { + return true; + } + + if (this.isObjectLiteralExpression(decl)) { + return true; + } + + if (ts.isFunctionLike(decl)) { + if (decl.type && this.checkIsTypeLiteral(decl.type)) { + return true; + } + const isObjectLiteralExpression = decl.parameters.some((param) => { + return param.type && this.checkIsTypeLiteral(param.type); + }); + if (isObjectLiteralExpression) { + return true; + } + if (TypeScriptLinter.hasObjectLiteralReturn(decl as ts.FunctionLikeDeclaration)) { + return true; + } + } + + return false; + } + + private isMixedEnum(type: ts.Type): boolean { + const symbol = type.getSymbol(); + if (!symbol) { + return false; + } + + const declarations = symbol.getDeclarations(); + if (!declarations) { + return false; + } + + for (const decl of declarations) { + if (ts.isEnumDeclaration(decl)) { + const initializerTypes = new Set(); + + for (const member of decl.members) { + if (member.initializer) { + const memberType = this.tsTypeChecker.getTypeAtLocation(member.initializer); + const baseTypeStr = this.tsTypeChecker.typeToString( + this.tsTypeChecker.getBaseTypeOfLiteralType(memberType) + ); + initializerTypes.add(baseTypeStr); + } + } + + if (initializerTypes.size > 1) { + return true; + } + } + } + + return false; + } + + private isStdUtilityTools(node: ts.Node): boolean { + const symbol = this.tsUtils.trueSymbolAtLocation(node); + const decl = TsUtils.getDeclaration(symbol); + if (!decl) { + return false; + } + let isStdUtilityType = false; + const utils = this.tsUtils; + function traverse(node: ts.Node): void { + if (isStdUtilityType) { + return; + } + if (ts.isTypeReferenceNode(node) || ts.isExpressionWithTypeArguments(node)) { + let typeName = ''; + if (ts.isTypeReferenceNode(node)) { + typeName = utils.entityNameToString(node.typeName); + } else { + typeName = node.expression.getText(); + } + isStdUtilityType = !!( + LIMITED_STANDARD_UTILITY_TYPES2.includes(typeName) && + node.typeArguments && + node.typeArguments.length > 0 + ); + } + node.forEachChild(traverse); + } + traverse(decl); + return isStdUtilityType; + } + + private checkIsTypeLiteral(node: ts.Node): boolean { + if (ts.isUnionTypeNode(node) || ts.isIntersectionTypeNode(node)) { + return node.types.some((typeNode) => { + return this.checkIsTypeLiteralWithTypeNodes(typeNode); + }); + } + + return this.checkIsTypeLiteralWithTypeNodes(node); + } + + private checkIsTypeLiteralWithTypeNodes(node: ts.Node): boolean { + if (ts.isTypeLiteralNode(node) && node.members.length > 0) { + return true; + } + + if (ts.isTypeReferenceNode(node) && node.typeName) { + const typeDecl = this.tsUtils.getDeclarationNode(node.typeName); + return ( + typeDecl !== undefined && ts.isTypeAliasDeclaration(typeDecl) && this.checkSpecialTypeNode(typeDecl.type, false) + ); + } + + return false; + } + + private checkSpecialTypeNode(typeNode: ts.Node, isNeedCheckIsTypeLiteral: boolean): boolean { + let specialType = + ts.isIndexedAccessTypeNode(typeNode) || + ts.isConditionalTypeNode(typeNode) || + ts.isFunctionTypeNode(typeNode) || + ts.isMappedTypeNode(typeNode) || + ts.isTemplateLiteralTypeNode(typeNode); + if (isNeedCheckIsTypeLiteral) { + specialType ||= this.checkIsTypeLiteral(typeNode); + } + return specialType; + } + + private isObjectLiteralExpression(decl: ts.Node): boolean { + const isVariableWithInitializer = + ts.isVariableDeclaration(decl) && decl.initializer && ts.isObjectLiteralExpression(decl.initializer); + + const isVariableWithTypeLiteral = ts.isVariableDeclaration(decl) && decl.type && this.checkIsTypeLiteral(decl.type); + const isObjectLiteralExpression = + ts.isObjectLiteralExpression(decl) || + this.checkIsTypeLiteral(decl) || + isVariableWithInitializer || + isVariableWithTypeLiteral; + return !!isObjectLiteralExpression; + } + + private static hasObjectLiteralReturn(funcNode: ts.FunctionLikeDeclaration): boolean { + let found = false; + function visit(node: ts.Node): void { + if (found) { + return; + } + + if (ts.isReturnStatement(node) && node.expression && ts.isObjectLiteralExpression(node.expression)) { + found = true; + return; + } + + ts.forEachChild(node, visit); + } + visit(funcNode); + return found; + } + + private static extractKeyofFromString(typeString: string): boolean { + return (/\bkeyof\b/).test(typeString); + } + checkUnionTypes(propertyAccessNode: ts.PropertyAccessExpression): void { if (!this.options.arkts2) { return; @@ -4197,10 +4379,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { const tsIdentifier = node; this.handleTsInterop(tsIdentifier, () => { const parent = tsIdentifier.parent; - if (ts.isPropertyAccessExpression(parent) || ts.isImportSpecifier(parent)) { + if (ts.isImportSpecifier(parent)) { return; } - const type = this.tsTypeChecker.getTypeAtLocation(tsIdentifier); this.checkUsageOfTsTypes(type, tsIdentifier); }); diff --git a/ets2panda/linter/src/lib/utils/consts/LimitedStandardUtilityTypes.ts b/ets2panda/linter/src/lib/utils/consts/LimitedStandardUtilityTypes.ts index 04f651d08023de840edbffdca60cdda456b7a534..fe772501207fdd19343441d3dd08b248eb152a5f 100644 --- a/ets2panda/linter/src/lib/utils/consts/LimitedStandardUtilityTypes.ts +++ b/ets2panda/linter/src/lib/utils/consts/LimitedStandardUtilityTypes.ts @@ -32,3 +32,24 @@ export const LIMITED_STANDARD_UTILITY_TYPES = [ 'Pick', 'Awaited' ]; + +export const LIMITED_STANDARD_UTILITY_TYPES2 = [ + 'Uncapitalize', + 'Capitalize', + 'Lowercase', + 'Uppercase', + 'ThisType', + 'OmitThisParameter', + 'ThisParameterType', + 'InstanceType', + 'ReturnType', + 'ConstructorParameters', + 'Parameters', + 'NonNullable', + 'Extract', + 'Exclude', + 'Omit', + 'Pick', + 'Awaited', + 'NoInfer' +]; diff --git a/ets2panda/linter/test/interop/ignore_files/unique_types2.ts b/ets2panda/linter/test/interop/ignore_files/unique_types2.ts new file mode 100644 index 0000000000000000000000000000000000000000..e915e9bb10b8a7abf3f4fdae9f26467d37d00f80 --- /dev/null +++ b/ets2panda/linter/test/interop/ignore_files/unique_types2.ts @@ -0,0 +1,268 @@ +/* + * 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. + */ + +// any +let any_var: any = 10; +any_var = "string"; +export { any_var } + +// unknown +export let unknown_var: unknown = 10; + +// Symbol +export let symbol_var: symbol = Symbol("description"); + +// Function +export let function_var: Function = function () { + console.log("Hello, World!"); + return true; +}; + +// objectLiteral +export let objectLiteral_var: { x: number, y: string } = { x: 10, y: "hello" }; +export let objectLiteral_var2 = { x: 10, y: "hello" }; +export let objectLiteral_var3:{}; +export let objectLiteral_var32={}; +export let objectLiteral_var4 = { x: 1 }; +export function objectLiteral_var5() { + return { x: 1 }; +} +export function objectLiteral_var51(aa:{}):{}{ + return { x: 1 }; +} + +export class objectLiteral_var6 { + get() { return { a: '1' }; } + get2():{} { return {}; } + get3() { return {}; } + get4():{}|undefined {return; } + get1(): { x: number }|undefined { + return; + } + set(aa: { x: 1 }) { } + set3(aa: {}) { } + set1(aa: { x: 1 }|boolean) { } + set2(aa: { x: 1,y: string }|boolean,bb:string) { } +} +// enum +export enum enum_var { + a = 0, + b = '1', +} + +// function type +export type func_type = (arg: number) => string; +export type func_type2 = {(arg: number): string}; + +// Construct signature +export let constructor_type: { new(name: string): { name: string } } = class { + constructor(public name: string) { } +}; + +// Index Signature +let objIndexSignature_var: { [index: number]: string } = {}; +objIndexSignature_var[0] = "zero"; +objIndexSignature_var[1] = "one"; +export { objIndexSignature_var } + +// Intersection +interface TypeA { + a: number; +} +interface TypeB { + b: string; +} + +export let Intersection_obj: TypeA & TypeB = { a: 10, b: "hello" }; + +// keyof +export interface X { + a: number; + b: string; +} + +export type KeyOf_Type = keyof X; +export let de: KeyOf_Type; +export let key: keyof X; +export function keyFuns(){ + return key; +} +export class Keys{ + keys:keyof X; + set(x:keyof X|undefined){} + get():keyof X|void{} + get1(){ return this.keys} +} + +// typeof +let p = { x: 1, y: "" }; +export let typeOf_type = typeof p; +export let typeOf_type1: typeof p; +// let q: typeof p = { x: 2, y: "world" }; + +export let user = { name: "John", age: 25 }; + +export type SomeType = { + name: string, +} +//indexed access: type[index]。 +const MyArray = [{ name: "Alice", age: 15 }] +export type Person = typeof MyArray[number] +export let Person1 = MyArray[0] +type StringArray = string[]; +export type ElementType = StringArray[number]; +type Demo = { + id: number; + name: string; + address: { city: string; }; +}; +type NameType = Demo["name"]; +type CityType = Demo["address"]["city"]; +export type NameOrAddress =Demo["name" | "address"]; +export function getInfo(name:NameType){ + return name as CityType; +} +type Tuple = [string, number, boolean]; +type FirstElement = Tuple[0]; +type LastElement = Tuple[2]; +export class IndexAccess{ + par:Person; + set(city:CityType,NameOrAddr:NameOrAddress){} + get(name:NameType):Tuple|FirstElement|LastElement{ + return getInfo(name); + } +} +type UserKeys = keyof Demo; +export type UserValueTypes = Demo[UserKeys]; + +//Template Literal Types:${T}${U}... +type UnionString = "A" | "B"; +export type TemplateLiteralType =` ${UnionString}_id`; +type Direction = "up" | "down" | "left" | "right"; +type Action = "move" | "rotate"; +export type Commands = `${Action}_${Direction}`; +type PropEventNames = `${T}Changed`; +export type NameChanged = PropEventNames<"name">; +type Colors1 = "red" | "blue"; +type Sizes = "small" | "large"; +export type Variants = `${Colors1}_${Sizes}`; +type IsString = T extends string ? true : false; +export type Check = `${T}` extends string ? true : false; +export function testTemplateLiteralType(bb:Commands){ + let a :PropEventNames<"name">; +} + +export let objectLiteralType: SomeType; +export let mixedEnumType: X; +export let intersectionType: SomeType & X; +export let templateLiteralType: TemplateLiteralType|undefined; + +export function tsFunction() { }; +export let stringType: string; +export class Test{ + returnStr(){ + return stringType; + } +} +//conditional types:T extends U ? X : Y +type ExtractNumber = T extends number ? T : never; +export type NumbersOnly = ExtractNumber; +export type ReturnVal any> = + T extends (...args: any[]) => infer R ? R : never; +export type Num = ReturnVal<() => number>; + +//mapped types:{[K in KeyType]: TypeExpression} +type Readonly = { + readonly [K in keyof T]: T[K]; +}; +export type ReadonlyUser = Readonly; +export type Partial = { + [K in keyof T]?: T[K]; +}; +export type OptionalUser = Partial; +type Original = { + [key: string]: number; + name: string; +}; +export type Mapped = { + [K in keyof Original]: Original[K]; +}; + +export let sumType: { [index: number]: string ,temp:TemplateLiteralType,index:UserValueTypes} ; +//tool +type User = { + name: string; + age: number; + email: string; +}; +type Colors = 'red' | 'blue' | 'green' | 'yellow'; +// Pick +export type NameAndEmail = Pick; +// Omit +export type WithoutEmail = Omit; +// Exclude +export type PrimaryColors = Exclude; +// Extract +type Values = string | number | boolean | null; +export type PrimitiveValues = Extract; +// NonNullable +type Data = string | null | undefined; +export type CleanData = NonNullable; +// Parameters +function add(a: number, b: string): void { } +export type AddParams = Parameters; +// ConstructorParameters +class Per { + constructor(name: string, age: number) { } +} +export type PerParams = ConstructorParameters; +// ReturnType +function createUser(): { id: number; name: string } { + return { id: 1, name: 'Alice' }; +} +export type UserType = ReturnType; +// InstanceType +class Point { + x: number; + y: number; +} +export type PointInstance = InstanceType; +// NoInfer +type NoInfer = [T][T extends any ? 0 : never]; +export function identity(x: T, y: NoInfer): T { + return x; +} +// ThisParameterType +type getThis = (this: { name: string }) => void; +export type thisParameterType = ThisParameterType; +// OmitThisParameter +type GetThis = (this: { name: string }, x: number) => void; +export type WithoutThis = OmitThisParameter; +// ThisType +export type ClassThisType = ThisType<{ + getName(): string; +}>; +// Uppercase +type Greeting = 'hello'; +export type ShoutGreeting = Uppercase; +// Lowercase +export type QuietGreeting = Lowercase; +// Capitalize +export type CapitalizedWord = Capitalize; +// Uncapitalize +export type UncapitalizedWord = Uncapitalize; +export function getCapitalize(): Capitalize { + return 'Hello'; +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unique_types.ets.arkts2.json b/ets2panda/linter/test/interop/unique_types.ets.arkts2.json index 3f87d2a6a43c4ef31f9b8c3f266ea1db2dee1bd4..ad93ff0af7b8299c75bcd115e8855c4864cfffb3 100644 --- a/ets2panda/linter/test/interop/unique_types.ets.arkts2.json +++ b/ets2panda/linter/test/interop/unique_types.ets.arkts2.json @@ -64,6 +64,16 @@ "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", "severity": "ERROR" }, + { + "line": 75, + "column": 1, + "endLine": 75, + "endColumn": 9, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, { "line": 75, "column": 16, diff --git a/ets2panda/linter/test/interop/unique_types.ets.autofix.json b/ets2panda/linter/test/interop/unique_types.ets.autofix.json index 3cce68fecd036b141897b44f2e90344630de6550..203ab57067c1c62fe267b24574d87c2363f5f097 100644 --- a/ets2panda/linter/test/interop/unique_types.ets.autofix.json +++ b/ets2panda/linter/test/interop/unique_types.ets.autofix.json @@ -75,6 +75,16 @@ "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", "severity": "ERROR" }, + { + "line": 75, + "column": 1, + "endLine": 75, + "endColumn": 9, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, { "line": 75, "column": 16, diff --git a/ets2panda/linter/test/interop/unique_types.ets.migrate.json b/ets2panda/linter/test/interop/unique_types.ets.migrate.json index c5e5bd52294413eeb045dbe8cf23bcd7ea75b084..3eb75a8fe4df6211f5934d4e04459e0469c9770a 100644 --- a/ets2panda/linter/test/interop/unique_types.ets.migrate.json +++ b/ets2panda/linter/test/interop/unique_types.ets.migrate.json @@ -44,6 +44,26 @@ "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", "severity": "ERROR" }, + { + "line": 72, + "column": 1, + "endLine": 72, + "endColumn": 13, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 1, + "endLine": 75, + "endColumn": 9, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, { "line": 78, "column": 7, diff --git a/ets2panda/linter/test/interop/unique_types2.ets b/ets2panda/linter/test/interop/unique_types2.ets new file mode 100644 index 0000000000000000000000000000000000000000..245729ec2cf9007e5ad193d6de5ad53c30acb744 --- /dev/null +++ b/ets2panda/linter/test/interop/unique_types2.ets @@ -0,0 +1,120 @@ +/* + * 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 { + NameAndEmail, + WithoutEmail, + PrimaryColors, + PrimitiveValues, + CleanData, + AddParams, + PerParams, + UserType, + PointInstance, + identity, + thisParameterType, + WithoutThis, + ClassThisType, + ShoutGreeting, + QuietGreeting, + CapitalizedWord, + UncapitalizedWord, + getCapitalize +} from './ignore_files/unique_types2'; + +//tools +const res :ShoutGreeting = 'HELLO'; //error + +const withoutThis: WithoutThis = {name: 'aaa'}; //error +class AA{ + private email:WithoutEmail={name:'1',age:10}; //error + set(color:PrimaryColors){ //error + } + get():PrimitiveValues|undefined{ //error + this.email as thisParameterType //error + const cc:ClassThisType = {} //error + return ; + } +} +function test(user:UserType,point:PointInstance,per:PerParams){} //error*3 +@Entry +@Component +struct MyComponent { + // 1. Pick/Omit 示例 + @State user: NameAndEmail = { name: 'Alice', email: 'alice@example.com' }; //error + @State partialUser: WithoutEmail = { name: 'Bob', age: 30 }; //error + + // 2. Exclude/Extract 示例 + @State primaryColor: PrimaryColors = 'red'; //error + @State primitiveValue: PrimitiveValues = true; //error + + // 3. NonNullable 示例 + @State validData: CleanData = 'valid'; //error + + // 4. Parameters/ConstructorParameters 示例 + private handleParams = (params: AddParams) => { //error + } + + // 5. ReturnType/InstanceType 示例 + @State userData: UserType = { id: 1, name: 'Charlie' }; //error + private point: PointInstance = { x: 10, y: 20 }; //error + + // 6. NoInfer 示例 + private useIdentity = () => { + const numResult = identity(123, 456); //error + // const errorResult = identity(123, 'abc'); //error + console.log('Identity result:', numResult); + } + + // 7. ThisParameterType/OmitThisParameter 示例 + private thisContext: thisParameterType = { name: 'Context' }; //error + private noThisFunc: WithoutThis = (x) => { //error + console.log('Without this:', x); + } + + // 8. 字符串工具类型示例 + @State shout: ShoutGreeting = 'HELLO'; //error + @State quiet: QuietGreeting = 'hello'; //error + @State capitalized: CapitalizedWord = 'Hello'; //error + @State uncapitalized: UncapitalizedWord = 'hello'; //error + + // 9. getCapitalize 函数 + computedWord= getCapitalize(); //error + + build() { + Column() { + // 显示用户信息 + Text(`Name: ${this.user.name}`) + Text(`Email: ${this.user.email}`) + + // 显示颜色和值 + Text(`Primary Color: ${this.primaryColor}`) + Text(`Primitive Value: ${this.primitiveValue}`) + + // 显示字符串转换结果 + Text(`Shout: ${this.shout}`) + Text(`Quiet: ${this.quiet}`) + Text(`Capitalized: ${this.capitalized}`) + Text(`Computed: ${this.computedWord}`) + + // 按钮触发函数 + Button('Call Identity') + .onClick(this.useIdentity) + + Button('Submit Parameters') + .onClick(() => this.handleParams([123, 'test'])) + } + .width('100%') + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unique_types2.ets.args.json b/ets2panda/linter/test/interop/unique_types2.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..bc4d2071daf6e9354e711c3b74b6be2b56659066 --- /dev/null +++ b/ets2panda/linter/test/interop/unique_types2.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/interop/unique_types2.ets.arkts2.json b/ets2panda/linter/test/interop/unique_types2.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..2ff6a935c471b27421e63a39e6fb72f51cf3d8fc --- /dev/null +++ b/ets2panda/linter/test/interop/unique_types2.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": 37, + "column": 12, + "endLine": 37, + "endColumn": 25, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 20, + "endLine": 39, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 34, + "endLine": 39, + "endColumn": 35, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 19, + "endLine": 41, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 32, + "endLine": 41, + "endColumn": 33, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 46, + "endLine": 41, + "endColumn": 48, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 42, + "column": 15, + "endLine": 42, + "endColumn": 28, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 11, + "endLine": 44, + "endColumn": 26, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 21, + "endLine": 45, + "endColumn": 38, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 46, + "column": 16, + "endLine": 46, + "endColumn": 29, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 20, + "endLine": 50, + "endColumn": 28, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 35, + "endLine": 50, + "endColumn": 48, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 50, + "column": 53, + "endLine": 50, + "endColumn": 62, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 16, + "endLine": 55, + "endColumn": 28, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 31, + "endLine": 55, + "endColumn": 32, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 23, + "endLine": 56, + "endColumn": 35, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 38, + "endLine": 56, + "endColumn": 39, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 58, + "endLine": 56, + "endColumn": 60, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 24, + "endLine": 59, + "endColumn": 37, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 26, + "endLine": 60, + "endColumn": 41, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 21, + "endLine": 63, + "endColumn": 30, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 66, + "column": 35, + "endLine": 66, + "endColumn": 44, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 20, + "endLine": 70, + "endColumn": 28, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 31, + "endLine": 70, + "endColumn": 32, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 37, + "endLine": 70, + "endColumn": 38, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 71, + "column": 18, + "endLine": 71, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 71, + "column": 39, + "endLine": 71, + "endColumn": 41, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 71, + "column": 46, + "endLine": 71, + "endColumn": 48, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 11, + "endLine": 75, + "endColumn": 41, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 23, + "endLine": 75, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 32, + "endLine": 75, + "endColumn": 35, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 37, + "endLine": 75, + "endColumn": 40, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 24, + "endLine": 81, + "endColumn": 41, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 44, + "endLine": 81, + "endColumn": 45, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 82, + "column": 23, + "endLine": 82, + "endColumn": 34, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 87, + "column": 17, + "endLine": 87, + "endColumn": 30, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 88, + "column": 17, + "endLine": 88, + "endColumn": 30, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 89, + "column": 23, + "endLine": 89, + "endColumn": 38, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 90, + "column": 25, + "endLine": 90, + "endColumn": 42, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 17, + "endLine": 93, + "endColumn": 30, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 116, + "column": 18, + "endLine": 116, + "endColumn": 56, + "problem": "LimitedReturnTypeInference", + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)", + "severity": "ERROR" + }, + { + "line": 116, + "column": 43, + "endLine": 116, + "endColumn": 46, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 51, + "column": 2, + "endLine": 51, + "endColumn": 7, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Entry\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 52, + "column": 2, + "endLine": 52, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Component\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 4, + "endLine": 55, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 4, + "endLine": 56, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 4, + "endLine": 59, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 4, + "endLine": 60, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 4, + "endLine": 63, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 4, + "endLine": 70, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 87, + "column": 4, + "endLine": 87, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 88, + "column": 4, + "endLine": 88, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 89, + "column": 4, + "endLine": 89, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 90, + "column": 4, + "endLine": 90, + "endColumn": 9, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"State\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 96, + "column": 5, + "endLine": 96, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Column\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 7, + "endLine": 98, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Text\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 7, + "endLine": 99, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Text\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 102, + "column": 7, + "endLine": 102, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Text\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 103, + "column": 7, + "endLine": 103, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Text\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 106, + "column": 7, + "endLine": 106, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Text\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 107, + "column": 7, + "endLine": 107, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Text\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 108, + "column": 7, + "endLine": 108, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Text\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 109, + "column": 7, + "endLine": 109, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Text\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 112, + "column": 7, + "endLine": 112, + "endColumn": 13, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Button\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 7, + "endLine": 115, + "endColumn": 13, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Button\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unique_types2.ets.json b/ets2panda/linter/test/interop/unique_types2.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ee4603f669d4004aed50443f8205fcf73b955ba3 --- /dev/null +++ b/ets2panda/linter/test/interop/unique_types2.ets.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": 39, + "column": 34, + "endLine": 39, + "endColumn": 35, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 32, + "endLine": 41, + "endColumn": 33, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 31, + "endLine": 55, + "endColumn": 32, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 56, + "column": 38, + "endLine": 56, + "endColumn": 39, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 31, + "endLine": 70, + "endColumn": 32, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 44, + "endLine": 81, + "endColumn": 45, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 116, + "column": 18, + "endLine": 116, + "endColumn": 56, + "problem": "LimitedReturnTypeInference", + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unique_types3.ets b/ets2panda/linter/test/interop/unique_types3.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e80761e144ed99290aa56d7c7bfa9ebce63aeee --- /dev/null +++ b/ets2panda/linter/test/interop/unique_types3.ets @@ -0,0 +1,214 @@ +/* + * 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 { + any_var, + symbol_var, + user, + unknown_var, + function_var, + func_type2, + objectLiteral_var, + objectLiteral_var2, + objectLiteral_var3, + objectLiteral_var32, + objectLiteral_var4, + objectLiteral_var5, + objectLiteral_var51, + objectLiteral_var6, + enum_var, + func_type, + constructor_type, + objIndexSignature_var, + Intersection_obj, + KeyOf_Type, + de, + key, + keyFuns, + Keys, + SomeType, + Person, + Person1, + ElementType, + NameOrAddress, + getInfo, + IndexAccess, + UserValueTypes, + stringType, + NumbersOnly, + ReturnVal, + Num, + typeOf_type, + typeOf_type1, + templateLiteralType, + TemplateLiteralType, + NameChanged, + testTemplateLiteralType, + Test, + ReadonlyUser, + Partial, + OptionalUser, + Mapped, + sumType +} from "./ignore_files/unique_types2" + +class TestHelper { + test(arg0: () => boolean, arg1: string) { + throw new Error("Method not implemented."); + } + constructor(name: string) { + } +} +export function test_unique_type(testCaseRet: Array) { + let test_helper = new TestHelper("TEST_UNIQUE_TYPE"); + + test_helper.test(() => { + return typeof any_var === 'object' //error + }, "any_var ") + + test_helper.test(() => { + return typeof unknown_var === 'number' //error + }, "unknown_var ") + + test_helper.test(() => { + return typeof symbol_var === 'object' //error + }, "symbol_var ") + + test_helper.test(() => { + return function_var() === true //error + }, "function_var ") + + test_helper.test(() => { + return enum_var.a === 0 //error + }, "enum_var ") + + test_helper.test(() => { + const res = new objectLiteral_var6().set({}); //error + const res2 = new objectLiteral_var6().set1(true); //error + const res3 = new objectLiteral_var6().set2({},true); //error + const res3 = new objectLiteral_var6().set3(); + return typeof res === 'object' + }, "objectLiteral_var7 ") + + test_helper.test(() => { + const res = new objectLiteral_var6().get(); //error + const res2 = new objectLiteral_var6().get1(); //error + const res3 = new objectLiteral_var6().get2(); //error + const res4 = new objectLiteral_var6().get3(); //error + const res5 = new objectLiteral_var6().get4(); + return typeof res === 'object' + }, "objectLiteral_var6 ") + + test_helper.test(() => { + typeof objectLiteral_var2 === 'object' //error + typeof objectLiteral_var3 === 'object' + typeof objectLiteral_var32 === 'object' //error + typeof objectLiteral_var4 === 'object' //error + typeof objectLiteral_var5 === 'object' //error + typeof objectLiteral_var51 === 'object' //error + return typeof objectLiteral_var === 'object' //error + }, "objectLiteral_var ") + + test_helper.test(() => { + console.log(typeOf_type) + console.log(typeOf_type1+'') //error + return typeof user === 'object' //error + }, "typeof") + + test_helper.test(() => { + let fun: func_type = (arg: number) => { //error + return arg.toString(); + }; + let fun2: func_type2 = (arg: number) => { //error + }; + return fun2(1) === '111' + }, "func_type ") + + test_helper.test(() => { + return typeof user === 'object' //error + }, "user ") + + test_helper.test(() => { + // const aa = '' as SomeType; + return typeof ('object' as SomeType) === 'object' //error + }, "SomeType ") + + + test_helper.test(() => { + return objIndexSignature_var[0] === "zero" //error + }, "objIndexSignature_var ") + + test_helper.test(() => { + return Intersection_obj.a === 10 && Intersection_obj.b === 'hello' //error*2 + }, "Intersection_obj ") + + test_helper.test(() => { + let keyof_var1: KeyOf_Type = 'a'; //error + let kk = de; //error + console.log(key) //error + keyFuns(); //error + const keys = new Keys(); + keys.set(undefined); //error + new Keys().get(); //error + keys.get1(); //error + return keyof_var1 === 'a' + }, "KeyOf_Type ") + + test_helper.test(() => { + let a :Person= {name:'a',age:1}; //error + a=Person1; //error + const b = 'a' as ElementType; //error + getInfo(b) as NameOrAddress; //error*2 + typeof new IndexAccess().par; //error + const indexAcc = new IndexAccess(); + indexAcc.set('',''); //error + indexAcc.get(''); //error + let c = '' as UserValueTypes //error + return typeof a === 'object' + }, "indexed access type") + + test_helper.test(() => { + new Test().returnStr(); //error? + return typeof stringType === 'object' //error? + }, "stringType ") + + test_helper.test(() => { + const c:NumbersOnly|undefined = undefined; //error + let d:ReturnVal = c as Num; //error*2 + return typeof c === 'boolean' + }, "conditional types ") + + test_helper.test(() => { + const c:ReadonlyUser|OptionalUser|undefined = undefined; //error*2 + let d:Mapped|boolean = false; //error + let e : Partial; //error + return typeof c === 'boolean' + }, "mapped types ") + + test_helper.test(() => { + const res: NameChanged = testTemplateLiteralType(''); //error*2 + let b :TemplateLiteralType; //error + return typeof templateLiteralType !== "undefined" //error + }, "templateLiteralType ") + + test_helper.test(() => { + let instance = new constructor_type("Alice"); //error + return instance.name === 'Alice' + }, "constructor_type ") + + test_helper.test(() => { + return typeof sumType !== "undefined" //error + }, "sumType ") + +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unique_types3.ets.args.json b/ets2panda/linter/test/interop/unique_types3.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..bc4d2071daf6e9354e711c3b74b6be2b56659066 --- /dev/null +++ b/ets2panda/linter/test/interop/unique_types3.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/interop/unique_types3.ets.arkts2.json b/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..aabbdb78be04ab1345c2781a79d78fefb24ae10e --- /dev/null +++ b/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json @@ -0,0 +1,738 @@ +{ + "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": 77, + "column": 19, + "endLine": 77, + "endColumn": 26, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 81, + "column": 19, + "endLine": 81, + "endColumn": 30, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 85, + "column": 19, + "endLine": 85, + "endColumn": 29, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 89, + "column": 12, + "endLine": 89, + "endColumn": 24, + "problem": "ExplicitFunctionType", + "suggest": "", + "rule": "The function type should be explicit (arkts-no-ts-like-function-call)", + "severity": "ERROR" + }, + { + "line": 89, + "column": 12, + "endLine": 89, + "endColumn": 24, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 12, + "endLine": 93, + "endColumn": 20, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 93, + "column": 27, + "endLine": 93, + "endColumn": 28, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 97, + "column": 17, + "endLine": 97, + "endColumn": 49, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 97, + "column": 42, + "endLine": 97, + "endColumn": 45, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 97, + "column": 46, + "endLine": 97, + "endColumn": 47, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 18, + "endLine": 98, + "endColumn": 53, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 98, + "column": 43, + "endLine": 98, + "endColumn": 47, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 18, + "endLine": 99, + "endColumn": 56, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 43, + "endLine": 99, + "endColumn": 47, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 48, + "endLine": 99, + "endColumn": 49, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 100, + "column": 18, + "endLine": 100, + "endColumn": 49, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 105, + "column": 42, + "endLine": 105, + "endColumn": 45, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 106, + "column": 43, + "endLine": 106, + "endColumn": 47, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 107, + "column": 43, + "endLine": 107, + "endColumn": 47, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 108, + "column": 43, + "endLine": 108, + "endColumn": 47, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 114, + "column": 12, + "endLine": 114, + "endColumn": 30, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 116, + "column": 12, + "endLine": 116, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 117, + "column": 12, + "endLine": 117, + "endColumn": 30, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 118, + "column": 12, + "endLine": 118, + "endColumn": 30, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 119, + "column": 12, + "endLine": 119, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 120, + "column": 19, + "endLine": 120, + "endColumn": 36, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 125, + "column": 17, + "endLine": 125, + "endColumn": 29, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 126, + "column": 19, + "endLine": 126, + "endColumn": 23, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 130, + "column": 14, + "endLine": 130, + "endColumn": 23, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 133, + "column": 15, + "endLine": 133, + "endColumn": 25, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 135, + "column": 17, + "endLine": 135, + "endColumn": 18, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 139, + "column": 19, + "endLine": 139, + "endColumn": 23, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 144, + "column": 32, + "endLine": 144, + "endColumn": 40, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 149, + "column": 12, + "endLine": 149, + "endColumn": 36, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "severity": "ERROR" + }, + { + "line": 149, + "column": 12, + "endLine": 149, + "endColumn": 33, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 153, + "column": 12, + "endLine": 153, + "endColumn": 28, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 153, + "column": 35, + "endLine": 153, + "endColumn": 37, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 153, + "column": 41, + "endLine": 153, + "endColumn": 57, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 157, + "column": 21, + "endLine": 157, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 158, + "column": 14, + "endLine": 158, + "endColumn": 16, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 159, + "column": 17, + "endLine": 159, + "endColumn": 20, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 160, + "column": 5, + "endLine": 160, + "endColumn": 12, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 162, + "column": 10, + "endLine": 162, + "endColumn": 13, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 163, + "column": 16, + "endLine": 163, + "endColumn": 19, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 164, + "column": 10, + "endLine": 164, + "endColumn": 14, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 169, + "column": 12, + "endLine": 169, + "endColumn": 18, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 169, + "column": 20, + "endLine": 169, + "endColumn": 21, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 169, + "column": 34, + "endLine": 169, + "endColumn": 35, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 170, + "column": 7, + "endLine": 170, + "endColumn": 14, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 171, + "column": 22, + "endLine": 171, + "endColumn": 33, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 172, + "column": 5, + "endLine": 172, + "endColumn": 12, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 172, + "column": 19, + "endLine": 172, + "endColumn": 32, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 173, + "column": 30, + "endLine": 173, + "endColumn": 33, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 175, + "column": 14, + "endLine": 175, + "endColumn": 17, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 176, + "column": 14, + "endLine": 176, + "endColumn": 17, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 177, + "column": 19, + "endLine": 177, + "endColumn": 33, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 187, + "column": 13, + "endLine": 187, + "endColumn": 24, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 188, + "column": 11, + "endLine": 188, + "endColumn": 20, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 188, + "column": 28, + "endLine": 188, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 193, + "column": 13, + "endLine": 193, + "endColumn": 25, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 193, + "column": 26, + "endLine": 193, + "endColumn": 38, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 194, + "column": 11, + "endLine": 194, + "endColumn": 17, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 195, + "column": 13, + "endLine": 195, + "endColumn": 20, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 200, + "column": 16, + "endLine": 200, + "endColumn": 27, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 200, + "column": 30, + "endLine": 200, + "endColumn": 57, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 200, + "column": 30, + "endLine": 200, + "endColumn": 53, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 201, + "column": 12, + "endLine": 201, + "endColumn": 31, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 202, + "column": 19, + "endLine": 202, + "endColumn": 38, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 206, + "column": 24, + "endLine": 206, + "endColumn": 40, + "problem": "DynamicCtorCall", + "suggest": "", + "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", + "severity": "ERROR" + }, + { + "line": 206, + "column": 24, + "endLine": 206, + "endColumn": 40, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 211, + "column": 19, + "endLine": 211, + "endColumn": 26, + "problem": "InteropDirectAccessToTSTypes", + "suggest": "", + "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", + "severity": "ERROR" + }, + { + "line": 188, + "column": 23, + "endLine": 188, + "endColumn": 31, + "problem": "StrictDiagnostic", + "suggest": "Conversion of type 'undefined' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.", + "rule": "Conversion of type 'undefined' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unique_types3.ets.json b/ets2panda/linter/test/interop/unique_types3.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ba08ebc2873f575bc7978e7ac86eff69ea2a415b --- /dev/null +++ b/ets2panda/linter/test/interop/unique_types3.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": 97, + "column": 46, + "endLine": 97, + "endColumn": 47, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 99, + "column": 48, + "endLine": 99, + "endColumn": 49, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 149, + "column": 12, + "endLine": 149, + "endColumn": 36, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", + "severity": "ERROR" + }, + { + "line": 169, + "column": 20, + "endLine": 169, + "endColumn": 21, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)", + "severity": "ERROR" + }, + { + "line": 188, + "column": 23, + "endLine": 188, + "endColumn": 31, + "problem": "StrictDiagnostic", + "suggest": "Conversion of type 'undefined' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.", + "rule": "Conversion of type 'undefined' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.", + "severity": "ERROR" + } + ] +} \ No newline at end of file