From c6d016bb6997f10c36f6c530256c962aa5a7c68c Mon Sep 17 00:00:00 2001 From: mmorozov Date: Thu, 21 Mar 2024 12:40:41 +0300 Subject: [PATCH 1/5] [ArkTS Linter] Add rule for sendable assignment Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9BJAM Tests: Tests for new rule were added Signed-off-by: mmorozov --- ets2panda/linter/lib/CookBookMsg.ts | 1 + ets2panda/linter/lib/FaultAttrs.ts | 1 + ets2panda/linter/lib/FaultDesc.ts | 1 + ets2panda/linter/lib/Problems.ts | 1 + ets2panda/linter/lib/TypeScriptLinter.ts | 15 ++++- ets2panda/linter/test_rules/rule155.ts | 31 ++++++++++ .../linter/test_rules/rule155.ts.autofix.skip | 14 +++++ ets2panda/linter/test_rules/rule155.ts.json | 58 +++++++++++++++++++ 8 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 ets2panda/linter/test_rules/rule155.ts create mode 100644 ets2panda/linter/test_rules/rule155.ts.autofix.skip create mode 100644 ets2panda/linter/test_rules/rule155.ts.json diff --git a/ets2panda/linter/lib/CookBookMsg.ts b/ets2panda/linter/lib/CookBookMsg.ts index b76ff8f1..69e2bae7 100644 --- a/ets2panda/linter/lib/CookBookMsg.ts +++ b/ets2panda/linter/lib/CookBookMsg.ts @@ -178,3 +178,4 @@ cookBookTag[150] = '"import" statements after other statements are not allowed ( cookBookTag[151] = 'Usage of "ESObject" type is restricted (arkts-limited-esobj)'; cookBookTag[152] = '"Function.apply", "Function.call" are not supported (arkts-no-func-apply-call)'; cookBookTag[153] = 'The inheritance for "Sendable" classes is limited (arkts-sendable-class-inheritance)'; +cookBookTag[155] = 'Definite assignment assertion in not allowed in "Sendable" classes (arkts-sendable-definite-assignment)'; diff --git a/ets2panda/linter/lib/FaultAttrs.ts b/ets2panda/linter/lib/FaultAttrs.ts index 3bdb392b..138856ca 100644 --- a/ets2panda/linter/lib/FaultAttrs.ts +++ b/ets2panda/linter/lib/FaultAttrs.ts @@ -106,3 +106,4 @@ faultsAttrs[FaultID.ImportAfterStatement] = new FaultAttributes(150); faultsAttrs[FaultID.EsObjectType] = new FaultAttributes(151, ProblemSeverity.WARNING); faultsAttrs[FaultID.FunctionApplyCall] = new FaultAttributes(152); faultsAttrs[FaultID.SendableClassInheritance] = new FaultAttributes(153); +faultsAttrs[FaultID.SendableDefiniteAssignment] = new FaultAttributes(155); diff --git a/ets2panda/linter/lib/FaultDesc.ts b/ets2panda/linter/lib/FaultDesc.ts index 073be58d..cd233099 100644 --- a/ets2panda/linter/lib/FaultDesc.ts +++ b/ets2panda/linter/lib/FaultDesc.ts @@ -98,3 +98,4 @@ faultDesc[FaultID.StrictDiagnostic] = 'Strict diagnostic'; faultDesc[FaultID.ImportAfterStatement] = 'Import declaration after other declaration or statement'; faultDesc[FaultID.EsObjectType] = 'Restricted "ESObject" type'; faultDesc[FaultID.SendableClassInheritance] = 'Sendable class inheritance'; +faultDesc[FaultID.SendableDefiniteAssignment] = 'Use of definite assignment assertion in "Sendable" class'; diff --git a/ets2panda/linter/lib/Problems.ts b/ets2panda/linter/lib/Problems.ts index c8f528dd..5e5e15b7 100644 --- a/ets2panda/linter/lib/Problems.ts +++ b/ets2panda/linter/lib/Problems.ts @@ -95,6 +95,7 @@ export enum FaultID { ImportAfterStatement, EsObjectType, SendableClassInheritance, + SendableDefiniteAssignment, // this should always be last enum LAST_ID } diff --git a/ets2panda/linter/lib/TypeScriptLinter.ts b/ets2panda/linter/lib/TypeScriptLinter.ts index fc9e36de..db7678c1 100644 --- a/ets2panda/linter/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/lib/TypeScriptLinter.ts @@ -1328,7 +1328,7 @@ export class TypeScriptLinter { } const isSendableBaseType = TsUtils.isSendableType(tsExprType); - if (isSendableClass && !isSendableBaseType || !isSendableClass && isSendableBaseType) { + if (isSendableClass !== isSendableBaseType) { this.incrementCounters(tsTypeExpr, FaultID.SendableClassInheritance); } } @@ -2068,9 +2068,18 @@ export class TypeScriptLinter { } private handleDefiniteAssignmentAssertion(decl: ts.VariableDeclaration | ts.PropertyDeclaration): void { - if (decl.exclamationToken !== undefined) { - this.incrementCounters(decl, FaultID.DefiniteAssignment); + if (decl.exclamationToken === undefined) { + return; + } + + if (decl.kind === ts.SyntaxKind.PropertyDeclaration) { + const parentDecl = decl.parent; + if (parentDecl.kind === ts.SyntaxKind.ClassDeclaration && TsUtils.hasSendableDecorator(parentDecl)) { + this.incrementCounters(decl, FaultID.SendableDefiniteAssignment); + return; + } } + this.incrementCounters(decl, FaultID.DefiniteAssignment); } private readonly validatedTypesSet = new Set(); diff --git a/ets2panda/linter/test_rules/rule155.ts b/ets2panda/linter/test_rules/rule155.ts new file mode 100644 index 00000000..a24fcc6e --- /dev/null +++ b/ets2panda/linter/test_rules/rule155.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Sendable +class A{ + a: number; + b: number = 1; + c!: number; + d!: number = 1; + e?: number; +} + +class B{ + a: number; + b: number = 1; + c!: number; + d!: number = 1; + e?: number; +} diff --git a/ets2panda/linter/test_rules/rule155.ts.autofix.skip b/ets2panda/linter/test_rules/rule155.ts.autofix.skip new file mode 100644 index 00000000..83ec646e --- /dev/null +++ b/ets2panda/linter/test_rules/rule155.ts.autofix.skip @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/ets2panda/linter/test_rules/rule155.ts.json b/ets2panda/linter/test_rules/rule155.ts.json new file mode 100644 index 00000000..e12f9414 --- /dev/null +++ b/ets2panda/linter/test_rules/rule155.ts.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 20, + "column": 5, + "problem": "SendableDefiniteAssignment", + "rule": "Definite assignment assertion in not allowed in \"Sendable\" classes (arkts-sendable-definite-assignment)" + }, + { + "line": 21, + "column": 5, + "problem": "SendableDefiniteAssignment", + "rule": "Definite assignment assertion in not allowed in \"Sendable\" classes (arkts-sendable-definite-assignment)" + }, + { + "line": 28, + "column": 5, + "problem": "DefiniteAssignment", + "suggest": "", + "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)" + }, + { + "line": 29, + "column": 5, + "problem": "DefiniteAssignment", + "suggest": "", + "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)" + }, + { + "line": 18, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Property 'a' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'a' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 26, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Property 'a' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'a' has no initializer and is not definitely assigned in the constructor." + } + ] +} \ No newline at end of file -- Gitee From c7f355411e2d9aec7a2d35ee4451f1cb8c02f6e0 Mon Sep 17 00:00:00 2001 From: chenyiyuan Date: Sat, 23 Mar 2024 02:25:01 +0000 Subject: [PATCH 2/5] [ArkTS Linter] Implement `arkts-sendable-class-property` rules Signed-off-by: chenyiyuan Change-Id: If615e4a60bf35a11c56c3210f560e22849f7b599 Mode Change: TypeChecker is used to identify the attribute type Signed-off-by: chenyiyuan Change-Id: Icd8a0b836c576345a515503ad7de3d3a22525e1e [ArkTS Linter] Implement arkts-sendable-generic-types rules Signed-off-by: chenyiyuan Change-Id: I4ad9e267279d2ab705ede61ba007f8646ba6dda3 [ArkTS Linter] Implement `arkts-sendable-as-expr` rules Signed-off-by: chenyiyuan Change-Id: Ifd49a6eece8bdb4973ea928ae994e58b1b5a28cf [ArkTS Linter] Implement `arkts-sendable-class-decorator` rules Signed-off-by: chenyiyuan Change-Id: I494db10a51be6b88d276f347a93a223e0dc9d390 fix problems in comments Signed-off-by: chenyiyuan Change-Id: Ib763677e602291ec063b46a0038fae206e9abe52 --- ets2panda/linter/lib/CookBookMsg.ts | 4 + ets2panda/linter/lib/FaultAttrs.ts | 4 + ets2panda/linter/lib/FaultDesc.ts | 4 + ets2panda/linter/lib/Problems.ts | 4 + ets2panda/linter/lib/TypeScriptLinter.ts | 65 ++++++++- ets2panda/linter/lib/utils/TsUtils.ts | 64 ++++++++- ets2panda/linter/test/sendable_as_expr.ts | 27 ++++ .../test/sendable_as_expr.ts.autofix.json | 32 +++++ .../linter/test/sendable_as_expr.ts.json | 30 ++++ .../linter/test/sendable_class_decorator.ts | 56 ++++++++ .../sendable_class_decorator.ts.autofix.json | 76 ++++++++++ .../test/sendable_class_decorator.ts.json | 68 +++++++++ .../linter/test/sendable_class_property.ts | 38 +++++ .../sendable_class_property.ts.autofix.json | 133 ++++++++++++++++++ .../test/sendable_class_property.ts.json | 118 ++++++++++++++++ .../linter/test/sendable_generic_types.ts | 34 +++++ .../sendable_generic_types.ts.autofix.json | 86 +++++++++++ .../test/sendable_generic_types.ts.json | 77 ++++++++++ 18 files changed, 915 insertions(+), 5 deletions(-) create mode 100644 ets2panda/linter/test/sendable_as_expr.ts create mode 100644 ets2panda/linter/test/sendable_as_expr.ts.autofix.json create mode 100644 ets2panda/linter/test/sendable_as_expr.ts.json create mode 100644 ets2panda/linter/test/sendable_class_decorator.ts create mode 100644 ets2panda/linter/test/sendable_class_decorator.ts.autofix.json create mode 100644 ets2panda/linter/test/sendable_class_decorator.ts.json create mode 100644 ets2panda/linter/test/sendable_class_property.ts create mode 100644 ets2panda/linter/test/sendable_class_property.ts.autofix.json create mode 100644 ets2panda/linter/test/sendable_class_property.ts.json create mode 100644 ets2panda/linter/test/sendable_generic_types.ts create mode 100644 ets2panda/linter/test/sendable_generic_types.ts.autofix.json create mode 100644 ets2panda/linter/test/sendable_generic_types.ts.json diff --git a/ets2panda/linter/lib/CookBookMsg.ts b/ets2panda/linter/lib/CookBookMsg.ts index 69e2bae7..c087019d 100644 --- a/ets2panda/linter/lib/CookBookMsg.ts +++ b/ets2panda/linter/lib/CookBookMsg.ts @@ -178,4 +178,8 @@ cookBookTag[150] = '"import" statements after other statements are not allowed ( cookBookTag[151] = 'Usage of "ESObject" type is restricted (arkts-limited-esobj)'; cookBookTag[152] = '"Function.apply", "Function.call" are not supported (arkts-no-func-apply-call)'; cookBookTag[153] = 'The inheritance for "Sendable" classes is limited (arkts-sendable-class-inheritance)'; +cookBookTag[154] = 'Properties in "Sendable" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)'; cookBookTag[155] = 'Definite assignment assertion in not allowed in "Sendable" classes (arkts-sendable-definite-assignment)'; +cookBookTag[156] = 'Only "Sendable" data types are allowed as type arguments of generic "Sendable" type (arkts-sendable-generic-types)'; +cookBookTag[157] = 'Non-sendable data can not be cast to "Sendable" data (arkts-sendable-as-expr)'; +cookBookTag[158] = 'No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)'; diff --git a/ets2panda/linter/lib/FaultAttrs.ts b/ets2panda/linter/lib/FaultAttrs.ts index 138856ca..86b220bc 100644 --- a/ets2panda/linter/lib/FaultAttrs.ts +++ b/ets2panda/linter/lib/FaultAttrs.ts @@ -106,4 +106,8 @@ faultsAttrs[FaultID.ImportAfterStatement] = new FaultAttributes(150); faultsAttrs[FaultID.EsObjectType] = new FaultAttributes(151, ProblemSeverity.WARNING); faultsAttrs[FaultID.FunctionApplyCall] = new FaultAttributes(152); faultsAttrs[FaultID.SendableClassInheritance] = new FaultAttributes(153); +faultsAttrs[FaultID.SendablePropType] = new FaultAttributes(154); faultsAttrs[FaultID.SendableDefiniteAssignment] = new FaultAttributes(155); +faultsAttrs[FaultID.SendableGenericTypes] = new FaultAttributes(156); +faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(157); +faultsAttrs[FaultID.SendableClassDecorator] = new FaultAttributes(158); diff --git a/ets2panda/linter/lib/FaultDesc.ts b/ets2panda/linter/lib/FaultDesc.ts index cd233099..098ab319 100644 --- a/ets2panda/linter/lib/FaultDesc.ts +++ b/ets2panda/linter/lib/FaultDesc.ts @@ -98,4 +98,8 @@ faultDesc[FaultID.StrictDiagnostic] = 'Strict diagnostic'; faultDesc[FaultID.ImportAfterStatement] = 'Import declaration after other declaration or statement'; faultDesc[FaultID.EsObjectType] = 'Restricted "ESObject" type'; faultDesc[FaultID.SendableClassInheritance] = 'Sendable class inheritance'; +faultDesc[FaultID.SendablePropType] = 'Sendable class property'; faultDesc[FaultID.SendableDefiniteAssignment] = 'Use of definite assignment assertion in "Sendable" class'; +faultDesc[FaultID.SendableGenericTypes] = 'Sendable generic types'; +faultDesc[FaultID.SendableAsExpr] = 'Sendable as expr'; +faultDesc[FaultID.SendableClassDecorator] = 'Sendable class decorator'; diff --git a/ets2panda/linter/lib/Problems.ts b/ets2panda/linter/lib/Problems.ts index 5e5e15b7..0595319e 100644 --- a/ets2panda/linter/lib/Problems.ts +++ b/ets2panda/linter/lib/Problems.ts @@ -95,7 +95,11 @@ export enum FaultID { ImportAfterStatement, EsObjectType, SendableClassInheritance, + SendablePropType, SendableDefiniteAssignment, + SendableGenericTypes, + SendableAsExpr, + SendableClassDecorator, // this should always be last enum LAST_ID } diff --git a/ets2panda/linter/lib/TypeScriptLinter.ts b/ets2panda/linter/lib/TypeScriptLinter.ts index db7678c1..9910670c 100644 --- a/ets2panda/linter/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/lib/TypeScriptLinter.ts @@ -565,6 +565,9 @@ export class TypeScriptLinter { private handleParameter(node: ts.Node): void { const tsParam = node as ts.ParameterDeclaration; + if (TsUtils.isInSendableClassAndHasDecorators(tsParam)) { + this.incrementCounters(node, FaultID.SendableClassDecorator); + } this.handleDeclarationDestructuring(tsParam); this.handleDeclarationInferredType(tsParam); } @@ -756,6 +759,26 @@ export class TypeScriptLinter { ); this.handleDeclarationInferredType(node); this.handleDefiniteAssignmentAssertion(node); + this.handleSendableClassProperty(node); + } + + private handleSendableClassProperty(node: ts.PropertyDeclaration): void { + const typeNode = node.type; + if (!typeNode) { + return; + } + const classNode = node.parent; + if (!ts.isClassDeclaration(classNode) || !TsUtils.hasSendableDecorator(classNode)) { + return; + } + if (TsUtils.isInSendableClassAndHasDecorators(node)) { + this.incrementCounters(node, FaultID.SendableClassDecorator); + } + const type = this.tsTypeChecker.getTypeFromTypeNode(typeNode); + const isSendablePropType = TsUtils.isSendableType(type); + if (!isSendablePropType) { + this.incrementCounters(node, FaultID.SendablePropType); + } } private handlePropertyAssignment(node: ts.PropertyAssignment): void { @@ -1319,6 +1342,9 @@ export class TypeScriptLinter { this.countClassMembersWithDuplicateName(tsClassDecl); const isSendableClass = TsUtils.hasSendableDecorator(tsClassDecl); + if (isSendableClass && TsUtils.hasNonSendableDecorator(tsClassDecl)) { + this.incrementCounters(tsClassDecl, FaultID.SendableClassDecorator); + } const visitHClause = (hClause: ts.HeritageClause): void => { for (const tsTypeExpr of hClause.types) { const tsExprType = TsUtils.reduceReference(this.tsTypeChecker.getTypeAtLocation(tsTypeExpr)); @@ -1327,7 +1353,7 @@ export class TypeScriptLinter { this.incrementCounters(tsTypeExpr, FaultID.ImplementsClass); } - const isSendableBaseType = TsUtils.isSendableType(tsExprType); + const isSendableBaseType = TsUtils.isSendableClass(tsExprType); if (isSendableClass !== isSendableBaseType) { this.incrementCounters(tsTypeExpr, FaultID.SendableClassInheritance); } @@ -1442,6 +1468,9 @@ export class TypeScriptLinter { private handleMethodDeclaration(node: ts.Node): void { const tsMethodDecl = node as ts.MethodDeclaration; + if (TsUtils.isInSendableClassAndHasDecorators(tsMethodDecl)) { + this.incrementCounters(node, FaultID.SendableClassDecorator); + } let isStatic = false; if (tsMethodDecl.modifiers) { for (const mod of tsMethodDecl.modifiers) { @@ -1905,6 +1934,26 @@ export class TypeScriptLinter { this.handleStructIdentAndUndefinedInArgs(tsNewExpr, callSignature); this.handleGenericCallWithNoTypeArgs(tsNewExpr, callSignature); } + this.handleSendableGenericTypes(tsNewExpr); + } + + private handleSendableGenericTypes(node: ts.NewExpression): void { + const type = this.tsTypeChecker.getTypeAtLocation(node); + if (!TsUtils.isSendableType(type)) { + return; + } + + const typeArgs = node.typeArguments; + if (!typeArgs || typeArgs.length === 0) { + return; + } + + for (const arg of typeArgs) { + const argType = this.tsTypeChecker.getTypeFromTypeNode(arg); + if (!TsUtils.isSendableType(argType)) { + this.incrementCounters(node, FaultID.SendableGenericTypes); + } + } } private handleAsExpression(node: ts.Node): void { @@ -1921,6 +1970,9 @@ export class TypeScriptLinter { ) { this.incrementCounters(node, FaultID.TypeAssertion); } + if (!TsUtils.isSendableClass(exprType) && TsUtils.isSendableClass(targetType)) { + this.incrementCounters(tsAsExpr, FaultID.SendableAsExpr); + } } private handleTypeReference(node: ts.Node): void { @@ -1998,7 +2050,10 @@ export class TypeScriptLinter { } } - private handleGetAccessor(node: ts.Node): void { + private handleGetAccessor(node: ts.GetAccessorDeclaration): void { + if (TsUtils.isInSendableClassAndHasDecorators(node)) { + this.incrementCounters(node, FaultID.SendableClassDecorator); + } /** * Reserved if needed @@ -2007,7 +2062,10 @@ export class TypeScriptLinter { void this; } - private handleSetAccessor(node: ts.Node): void { + private handleSetAccessor(node: ts.SetAccessorDeclaration): void { + if (TsUtils.isInSendableClassAndHasDecorators(node)) { + this.incrementCounters(node, FaultID.SendableClassDecorator); + } /** * Reserved if needed @@ -2211,7 +2269,6 @@ export class TypeScriptLinter { private handleConstructorDeclaration(node: ts.Node): void { const ctorDecl = node as ts.ConstructorDeclaration; - if (ctorDecl.parameters.some((x) => { return TsUtils.hasAccessModifier(x); })) { diff --git a/ets2panda/linter/lib/utils/TsUtils.ts b/ets2panda/linter/lib/utils/TsUtils.ts index 05d9d200..ca349f78 100644 --- a/ets2panda/linter/lib/utils/TsUtils.ts +++ b/ets2panda/linter/lib/utils/TsUtils.ts @@ -1695,13 +1695,30 @@ export class TsUtils { } static isSendableType(type: ts.Type): boolean { + if ((type.flags & (ts.TypeFlags.Boolean | ts.TypeFlags.Number | ts.TypeFlags.String | + ts.TypeFlags.BigInt | ts.TypeFlags.Null | ts.TypeFlags.Undefined | + ts.TypeFlags.TypeParameter)) !== 0) { + return true; + } + + // Only the sendable nullish union type is supported + if ((type.flags & ts.TypeFlags.Union) !== 0 && TsUtils.isNullishSendableType(type as ts.UnionType)) { + return true; + } + + return this.isSendableClass(type); + } + + static isSendableClass(type: ts.Type): boolean { const sym = type.getSymbol(); if (!sym) { return false; } + const targetType = TsUtils.reduceReference(type); + // class with @Sendable decorator - if (type.isClass()) { + if (targetType.isClass()) { if (sym.declarations?.length) { const decl = sym.declarations[0]; if (ts.isClassDeclaration(decl) && TsUtils.hasSendableDecorator(decl)) { @@ -1713,10 +1730,55 @@ export class TsUtils { return false; } + static isNullishSendableType(type: ts.UnionType): boolean { + const types = type?.types; + if (!types || types.length > 3) { + return false; + } + + let nullCount = 0; + let undefinedCount = 0; + let sendableCount = 0; + + for (const type of types) { + if ((type.flags & ts.TypeFlags.Null) !== 0) { + nullCount++; + } else if ((type.flags & ts.TypeFlags.Undefined) !== 0) { + undefinedCount++; + } else { + if (!TsUtils.isSendableType(type)) { + return false; + } + sendableCount++; + } + } + return nullCount <= 1 && undefinedCount <= 1 && sendableCount === 1; + } + static hasSendableDecorator(decl: ts.ClassDeclaration): boolean { const decorators = ts.getDecorators(decl); return decorators !== undefined && decorators.some((x) => { return TsUtils.getDecoratorName(x) === 'Sendable'; }); } + + static hasNonSendableDecorator(decl: ts.ClassDeclaration): boolean { + const decorators = ts.getDecorators(decl); + return decorators !== undefined && decorators.some((x) => { + return TsUtils.getDecoratorName(x) !== 'Sendable'; + }); + } + + static isInSendableClassAndHasDecorators(declaration: ts.HasDecorators): boolean { + const classNode = TsUtils.getClassNodeFromDeclaration(declaration); + return !!classNode && TsUtils.hasSendableDecorator(classNode) && ts.getDecorators(declaration) !== undefined; + } + + private static getClassNodeFromDeclaration(declaration: ts.HasDecorators): ts.ClassDeclaration | undefined { + if (declaration.kind === ts.SyntaxKind.Parameter) { + return ts.isClassDeclaration(declaration.parent?.parent) ? declaration.parent?.parent : undefined; + } else { + return ts.isClassDeclaration(declaration.parent) ? declaration.parent : undefined; + } + } } diff --git a/ets2panda/linter/test/sendable_as_expr.ts b/ets2panda/linter/test/sendable_as_expr.ts new file mode 100644 index 00000000..9435112d --- /dev/null +++ b/ets2panda/linter/test/sendable_as_expr.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class NonSendableClass4 {} + +@Sendable +class SendableClass6 {} + +let v0 = new SendableClass6() as NonSendableClass4; // OK + +let v1 = new NonSendableClass4() as SendableClass6; // ERROR, non-sendable data can not be cast to "Sendable" data + +let tmp1 = new NonSendableClass4(); + +let v2 = tmp1 as SendableClass6; // ERROR, non-sendable data can not be cast to "Sendable" data \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_as_expr.ts.autofix.json b/ets2panda/linter/test/sendable_as_expr.ts.autofix.json new file mode 100644 index 00000000..925a81b9 --- /dev/null +++ b/ets2panda/linter/test/sendable_as_expr.ts.autofix.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 23, + "column": 10, + "problem": "SendableAsExpr", + "autofixable": false, + "rule": "Non-sendable data can not be cast to \"Sendable\" data (arkts-sendable-as-expr)" + }, + { + "line": 27, + "column": 10, + "problem": "SendableAsExpr", + "autofixable": false, + "rule": "Non-sendable data can not be cast to \"Sendable\" data (arkts-sendable-as-expr)" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_as_expr.ts.json b/ets2panda/linter/test/sendable_as_expr.ts.json new file mode 100644 index 00000000..ef1ec16d --- /dev/null +++ b/ets2panda/linter/test/sendable_as_expr.ts.json @@ -0,0 +1,30 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 23, + "column": 10, + "problem": "SendableAsExpr", + "rule": "Non-sendable data can not be cast to \"Sendable\" data (arkts-sendable-as-expr)" + }, + { + "line": 27, + "column": 10, + "problem": "SendableAsExpr", + "rule": "Non-sendable data can not be cast to \"Sendable\" data (arkts-sendable-as-expr)" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_decorator.ts b/ets2panda/linter/test/sendable_class_decorator.ts new file mode 100644 index 00000000..85da2a56 --- /dev/null +++ b/ets2panda/linter/test/sendable_class_decorator.ts @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +@Sendable // OK +class SendableClass7 { + prop: string; // OK + + constructor() {} // OK + + myMethod1() {} // OK + + myMethod2(param: string) {} // OK + + get myProperty(): string { // OK + return this.prop; + } + set myProperty(value: string) { // OK + this.prop = value; + } +} + +@NonSendable // ERROR, only `@Sendable` can be used on a sendable class declaration +@Sendable +class SendableClass8 { + @SomeDecorator // ERROR, no decorators can be used in a sendable class + prop: string; + + constructor() {} + + @SomeDecorator // ERROR, no decorators can be used in a sendable class + myMethod1() {} + + myMethod2(@SomeDecorator param: string) {} // ERROR, no decorators can be used in a sendable class + + @SomeDecorator // ERROR, no decorators can be used in a sendable class + get myProperty(): string { + return this.prop; + } + @SomeDecorator // ERROR, no decorators can be used in a sendable class + set myProperty(value: string) { + this.prop = value; + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_decorator.ts.autofix.json b/ets2panda/linter/test/sendable_class_decorator.ts.autofix.json new file mode 100644 index 00000000..7fb0a1c6 --- /dev/null +++ b/ets2panda/linter/test/sendable_class_decorator.ts.autofix.json @@ -0,0 +1,76 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 35, + "column": 1, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 38, + "column": 5, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 43, + "column": 5, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 46, + "column": 15, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 48, + "column": 5, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 52, + "column": 5, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 19, + "column": 5, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 39, + "column": 5, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop' has no initializer and is not definitely assigned in the constructor." + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_decorator.ts.json b/ets2panda/linter/test/sendable_class_decorator.ts.json new file mode 100644 index 00000000..b2b5daa7 --- /dev/null +++ b/ets2panda/linter/test/sendable_class_decorator.ts.json @@ -0,0 +1,68 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 35, + "column": 1, + "problem": "SendableClassDecorator", + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 38, + "column": 5, + "problem": "SendableClassDecorator", + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 43, + "column": 5, + "problem": "SendableClassDecorator", + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 46, + "column": 15, + "problem": "SendableClassDecorator", + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 48, + "column": 5, + "problem": "SendableClassDecorator", + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 52, + "column": 5, + "problem": "SendableClassDecorator", + "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + }, + { + "line": 19, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 39, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop' has no initializer and is not definitely assigned in the constructor." + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_property.ts b/ets2panda/linter/test/sendable_class_property.ts new file mode 100644 index 00000000..7cd09dbb --- /dev/null +++ b/ets2panda/linter/test/sendable_class_property.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class NonSendableClass2 {} + +@Sendable +class SendableClass4 { + prop1: number; // OK + prop2: string; // OK + prop3: boolean; // OK + prop4: bigint; // OK + prop5: SendableClass3; // OK + prop6: null; // OK + prop7: undefined; // OK + prop8: U; // OK + prop9: T | null | undefined; // OK +} + +@Sendable +class SendableClass3 { + prop1: string[]; // ERROR, sendable class property cannot be array + prop2: NonSendableClass2; // ERROR, sendable class property cannot be non-sendable-class + prop3: NonSendableClass2 | null; // ERROR, sendable class property cannot be non-sendable-class union type + prop4: NonSendableClass2 | undefined; // ERROR, sendable class property cannot be non-sendable-class union type + prop5: NonSendableClass2 | null | undefined; // ERROR, sendable class property cannot be non-sendable-class union type +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_property.ts.autofix.json b/ets2panda/linter/test/sendable_class_property.ts.autofix.json new file mode 100644 index 00000000..f1d566a0 --- /dev/null +++ b/ets2panda/linter/test/sendable_class_property.ts.autofix.json @@ -0,0 +1,133 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 33, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 34, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 35, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 36, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 37, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 20, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 21, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop2' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 22, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop3' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop3' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 23, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop4' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop4' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 24, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop5' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop5' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 25, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop6' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop6' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 27, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop8' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop8' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 33, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 34, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop2' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 35, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop3' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop3' has no initializer and is not definitely assigned in the constructor." + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_property.ts.json b/ets2panda/linter/test/sendable_class_property.ts.json new file mode 100644 index 00000000..029ff924 --- /dev/null +++ b/ets2panda/linter/test/sendable_class_property.ts.json @@ -0,0 +1,118 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 33, + "column": 3, + "problem": "SendablePropType", + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 34, + "column": 3, + "problem": "SendablePropType", + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 35, + "column": 3, + "problem": "SendablePropType", + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 36, + "column": 3, + "problem": "SendablePropType", + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 37, + "column": 3, + "problem": "SendablePropType", + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 20, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 21, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop2' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 22, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop3' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop3' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 23, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop4' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop4' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 24, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop5' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop5' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 25, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop6' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop6' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 27, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop8' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop8' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 33, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 34, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop2' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 35, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop3' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop3' has no initializer and is not definitely assigned in the constructor." + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_generic_types.ts b/ets2panda/linter/test/sendable_generic_types.ts new file mode 100644 index 00000000..4d7fab52 --- /dev/null +++ b/ets2panda/linter/test/sendable_generic_types.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class NonSendableClass3 {} + +@Sendable +class SendableClass5 { + prop1: T; + prop2: U; +} + +let ins1 = new SendableClass5; // OK +let ins2 = new SendableClass5; // ERROR, sendable class generic type cannot be non-sendable-class +let ins3 = new SendableClass5; // ERROR, sendable class generic type can only be sendable data type + +let e = SendableClass5; +let b = e; + +let c = Math.random()>0.5 ? SendableClass5 : NonSendableClass3; + +let ins4 = new b; // ERROR, sendable class generic type cannot be non-sendable-class +let ins5 = new c; // OK, skip checker \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_generic_types.ts.autofix.json b/ets2panda/linter/test/sendable_generic_types.ts.autofix.json new file mode 100644 index 00000000..ed885845 --- /dev/null +++ b/ets2panda/linter/test/sendable_generic_types.ts.autofix.json @@ -0,0 +1,86 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 25, + "column": 12, + "problem": "SendableGenericTypes", + "autofixable": false, + "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 12, + "problem": "SendableGenericTypes", + "autofixable": false, + "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 12, + "problem": "SendableGenericTypes", + "autofixable": false, + "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + }, + { + "line": 28, + "column": 9, + "problem": "ClassAsObject", + "autofixable": false, + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 31, + "column": 29, + "problem": "ClassAsObject", + "autofixable": false, + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 31, + "column": 46, + "problem": "ClassAsObject", + "autofixable": false, + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 33, + "column": 12, + "problem": "SendableGenericTypes", + "autofixable": false, + "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + }, + { + "line": 20, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 21, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop2' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_generic_types.ts.json b/ets2panda/linter/test/sendable_generic_types.ts.json new file mode 100644 index 00000000..48b0b93c --- /dev/null +++ b/ets2panda/linter/test/sendable_generic_types.ts.json @@ -0,0 +1,77 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 25, + "column": 12, + "problem": "SendableGenericTypes", + "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 12, + "problem": "SendableGenericTypes", + "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 12, + "problem": "SendableGenericTypes", + "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + }, + { + "line": 28, + "column": 9, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 31, + "column": 29, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 31, + "column": 46, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + }, + { + "line": 33, + "column": 12, + "problem": "SendableGenericTypes", + "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + }, + { + "line": 20, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 21, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop2' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." + } + ] +} \ No newline at end of file -- Gitee From d59187873b205372be19e6e76c80fb8127002cd5 Mon Sep 17 00:00:00 2001 From: chenyiyuan Date: Tue, 26 Mar 2024 15:09:45 +0000 Subject: [PATCH 3/5] [ArkTS Linter] Implement `arkts-sendable-initialization` rules and forbid computed property name in sendable class Signed-off-by: chenyiyuan Change-Id: Icf419cae81701e7a02e8889261006ce229cb698b --- ets2panda/linter/lib/CookBookMsg.ts | 1 + ets2panda/linter/lib/FaultAttrs.ts | 1 + ets2panda/linter/lib/FaultDesc.ts | 2 + ets2panda/linter/lib/Problems.ts | 1 + ets2panda/linter/lib/TypeScriptLinter.ts | 17 +++- .../test/sendable_class_initialization.ts | 23 ++++++ ...dable_class_initialization.ts.autofix.json | 62 ++++++++++++++ .../sendable_class_initialization.ts.json | 56 +++++++++++++ .../linter/test/sendable_class_property.ts | 15 +++- .../sendable_class_property.ts.autofix.json | 82 +++++++++++++++---- .../test/sendable_class_property.ts.json | 75 +++++++++++++---- 11 files changed, 305 insertions(+), 30 deletions(-) create mode 100644 ets2panda/linter/test/sendable_class_initialization.ts create mode 100644 ets2panda/linter/test/sendable_class_initialization.ts.autofix.json create mode 100644 ets2panda/linter/test/sendable_class_initialization.ts.json diff --git a/ets2panda/linter/lib/CookBookMsg.ts b/ets2panda/linter/lib/CookBookMsg.ts index c087019d..dfb5706c 100644 --- a/ets2panda/linter/lib/CookBookMsg.ts +++ b/ets2panda/linter/lib/CookBookMsg.ts @@ -183,3 +183,4 @@ cookBookTag[155] = 'Definite assignment assertion in not allowed in "Sendable" c cookBookTag[156] = 'Only "Sendable" data types are allowed as type arguments of generic "Sendable" type (arkts-sendable-generic-types)'; cookBookTag[157] = 'Non-sendable data can not be cast to "Sendable" data (arkts-sendable-as-expr)'; cookBookTag[158] = 'No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)'; +cookBookTag[159] = 'The initialization for "Sendable" objects is limited (arkts-sendable-initialization)'; diff --git a/ets2panda/linter/lib/FaultAttrs.ts b/ets2panda/linter/lib/FaultAttrs.ts index 86b220bc..5d108114 100644 --- a/ets2panda/linter/lib/FaultAttrs.ts +++ b/ets2panda/linter/lib/FaultAttrs.ts @@ -111,3 +111,4 @@ faultsAttrs[FaultID.SendableDefiniteAssignment] = new FaultAttributes(155); faultsAttrs[FaultID.SendableGenericTypes] = new FaultAttributes(156); faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(157); faultsAttrs[FaultID.SendableClassDecorator] = new FaultAttributes(158); +faultsAttrs[FaultID.SendableNoObjectorArrayLiteralInitialization] = new FaultAttributes(159); diff --git a/ets2panda/linter/lib/FaultDesc.ts b/ets2panda/linter/lib/FaultDesc.ts index 098ab319..fa37c1f7 100644 --- a/ets2panda/linter/lib/FaultDesc.ts +++ b/ets2panda/linter/lib/FaultDesc.ts @@ -103,3 +103,5 @@ faultDesc[FaultID.SendableDefiniteAssignment] = 'Use of definite assignment asse faultDesc[FaultID.SendableGenericTypes] = 'Sendable generic types'; faultDesc[FaultID.SendableAsExpr] = 'Sendable as expr'; faultDesc[FaultID.SendableClassDecorator] = 'Sendable class decorator'; +faultDesc[FaultID.SendableNoObjectorArrayLiteralInitialization] = 'Object literal or array literal is not allowed to \ + initialize a "Sendable" object' diff --git a/ets2panda/linter/lib/Problems.ts b/ets2panda/linter/lib/Problems.ts index 0595319e..2799ae70 100644 --- a/ets2panda/linter/lib/Problems.ts +++ b/ets2panda/linter/lib/Problems.ts @@ -100,6 +100,7 @@ export enum FaultID { SendableGenericTypes, SendableAsExpr, SendableClassDecorator, + SendableNoObjectorArrayLiteralInitialization, // this should always be last enum LAST_ID } diff --git a/ets2panda/linter/lib/TypeScriptLinter.ts b/ets2panda/linter/lib/TypeScriptLinter.ts index 9910670c..bfd2d7ab 100644 --- a/ets2panda/linter/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/lib/TypeScriptLinter.ts @@ -527,6 +527,10 @@ export class TypeScriptLinter { ) { this.incrementCounters(node, FaultID.ObjectLiteralNoContextType); } + const classNode = objectLiteralExpr.parent?.parent; + if (classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) { + this.incrementCounters(node, FaultID.SendableNoObjectorArrayLiteralInitialization); + } } private handleArrayLiteralExpression(node: ts.Node): void { @@ -541,6 +545,10 @@ export class TypeScriptLinter { const arrayLitNode = node as ts.ArrayLiteralExpression; let noContextTypeForArrayLiteral = false; + const classNode = arrayLitNode.parent?.parent; + if (classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) { + this.incrementCounters(node, FaultID.SendableNoObjectorArrayLiteralInitialization); + } /* * check that array literal consists of inferrable types * e.g. there is no element which is untyped object literals @@ -1241,6 +1249,11 @@ export class TypeScriptLinter { if (this.tsUtils.needToDeduceStructuralIdentity(tsVarType, tsInitType, tsVarInit)) { this.incrementCounters(tsVarDecl, FaultID.StructuralIdentity); } + + if (TsUtils.isSendableClass(tsVarType) && (ts.isArrayLiteralExpression(tsVarInit) || + ts.isObjectLiteralExpression(tsVarInit))) { + this.incrementCounters(tsVarDecl, FaultID.SendableNoObjectorArrayLiteralInitialization); + } } this.handleEsObjectDelaration(tsVarDecl); this.handleDeclarationInferredType(tsVarDecl); @@ -2045,7 +2058,9 @@ export class TypeScriptLinter { private handleComputedPropertyName(node: ts.Node): void { const computedProperty = node as ts.ComputedPropertyName; - if (!this.tsUtils.isValidComputedPropertyName(computedProperty, false)) { + const classNode = computedProperty.parent?.parent; + if ((classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) || + !this.tsUtils.isValidComputedPropertyName(computedProperty, false)) { this.incrementCounters(node, FaultID.ComputedPropertyName); } } diff --git a/ets2panda/linter/test/sendable_class_initialization.ts b/ets2panda/linter/test/sendable_class_initialization.ts new file mode 100644 index 00000000..8ec14231 --- /dev/null +++ b/ets2panda/linter/test/sendable_class_initialization.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Sendable +class SendableClass9 { + prop1: SendableClass9 = {a: 1}; // ERROR, the initialization for "Sendable" objects is limited + prop2: SendableClass9 = [1, 2]; // ERROR, the initialization for "Sendable" objects is limited +} + +let v0: SendableClass9 = {b: 1}; // ERROR, the initialization for "Sendable" objects is limited +let v1: SendableClass9 = [1, 2]; // ERROR, the initialization for "Sendable" objects is limited \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json b/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json new file mode 100644 index 00000000..dded55a2 --- /dev/null +++ b/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json @@ -0,0 +1,62 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 18, + "column": 27, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 18, + "column": 27, + "problem": "SendableNoObjectorArrayLiteralInitialization", + "autofixable": false, + "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + }, + { + "line": 19, + "column": 27, + "problem": "SendableNoObjectorArrayLiteralInitialization", + "autofixable": false, + "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + }, + { + "line": 22, + "column": 5, + "problem": "SendableNoObjectorArrayLiteralInitialization", + "autofixable": false, + "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + }, + { + "line": 22, + "column": 26, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 23, + "column": 5, + "problem": "SendableNoObjectorArrayLiteralInitialization", + "autofixable": false, + "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_initialization.ts.json b/ets2panda/linter/test/sendable_class_initialization.ts.json new file mode 100644 index 00000000..1f7fcb0c --- /dev/null +++ b/ets2panda/linter/test/sendable_class_initialization.ts.json @@ -0,0 +1,56 @@ +{ + "copyright": [ + "Copyright (c) 2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 18, + "column": 27, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 18, + "column": 27, + "problem": "SendableNoObjectorArrayLiteralInitialization", + "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + }, + { + "line": 19, + "column": 27, + "problem": "SendableNoObjectorArrayLiteralInitialization", + "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + }, + { + "line": 22, + "column": 5, + "problem": "SendableNoObjectorArrayLiteralInitialization", + "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + }, + { + "line": 22, + "column": 26, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 23, + "column": 5, + "problem": "SendableNoObjectorArrayLiteralInitialization", + "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_property.ts b/ets2panda/linter/test/sendable_class_property.ts index 7cd09dbb..dd848ce1 100644 --- a/ets2panda/linter/test/sendable_class_property.ts +++ b/ets2panda/linter/test/sendable_class_property.ts @@ -15,6 +15,9 @@ class NonSendableClass2 {} +@Sendable +class SendableClass10 {} + @Sendable class SendableClass4 { prop1: number; // OK @@ -26,6 +29,8 @@ class SendableClass4 { prop7: undefined; // OK prop8: U; // OK prop9: T | null | undefined; // OK + prop10: alias0; // OK + prop11: alias1; // OK } @Sendable @@ -35,4 +40,12 @@ class SendableClass3 { prop3: NonSendableClass2 | null; // ERROR, sendable class property cannot be non-sendable-class union type prop4: NonSendableClass2 | undefined; // ERROR, sendable class property cannot be non-sendable-class union type prop5: NonSendableClass2 | null | undefined; // ERROR, sendable class property cannot be non-sendable-class union type -} \ No newline at end of file + prop6: alias2; // ERROR, sendable class property cannot be non-sendable-type + prop7: alias3; // ERROR, sendable class property cannot be non-sendable-type + ["aaa"]: number; // ERROR, sendable class property name cannot be computed property +} + +type alias0 = number | null; +type alias1 = SendableClass10; +type alias2 = NonSendableClass2; +type alias3 = NonSendableClass2 | undefined; \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_property.ts.autofix.json b/ets2panda/linter/test/sendable_class_property.ts.autofix.json index f1d566a0..6b400d21 100644 --- a/ets2panda/linter/test/sendable_class_property.ts.autofix.json +++ b/ets2panda/linter/test/sendable_class_property.ts.autofix.json @@ -15,42 +15,64 @@ ], "nodes": [ { - "line": 33, + "line": 38, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 39, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 40, "column": 3, "problem": "SendablePropType", "autofixable": false, "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 34, + "line": 41, "column": 3, "problem": "SendablePropType", "autofixable": false, "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 35, + "line": 42, "column": 3, "problem": "SendablePropType", "autofixable": false, "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 36, + "line": 43, "column": 3, "problem": "SendablePropType", "autofixable": false, "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 37, + "line": 44, "column": 3, "problem": "SendablePropType", "autofixable": false, "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 20, + "line": 45, + "column": 3, + "problem": "ComputedPropertyName", + "autofixable": false, + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 23, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, @@ -58,7 +80,7 @@ "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." }, { - "line": 21, + "line": 24, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, @@ -66,7 +88,7 @@ "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." }, { - "line": 22, + "line": 25, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, @@ -74,7 +96,7 @@ "rule": "Property 'prop3' has no initializer and is not definitely assigned in the constructor." }, { - "line": 23, + "line": 26, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, @@ -82,7 +104,7 @@ "rule": "Property 'prop4' has no initializer and is not definitely assigned in the constructor." }, { - "line": 24, + "line": 27, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, @@ -90,7 +112,7 @@ "rule": "Property 'prop5' has no initializer and is not definitely assigned in the constructor." }, { - "line": 25, + "line": 28, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, @@ -98,23 +120,39 @@ "rule": "Property 'prop6' has no initializer and is not definitely assigned in the constructor." }, { - "line": 27, + "line": 30, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, "suggest": "Property 'prop8' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop8' has no initializer and is not definitely assigned in the constructor." }, + { + "line": 32, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop10' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop10' has no initializer and is not definitely assigned in the constructor." + }, { "line": 33, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, + "suggest": "Property 'prop11' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop11' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 38, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." }, { - "line": 34, + "line": 39, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, @@ -122,12 +160,28 @@ "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." }, { - "line": 35, + "line": 40, "column": 3, "problem": "StrictDiagnostic", "autofixable": false, "suggest": "Property 'prop3' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop3' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 43, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'prop6' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop6' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 45, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property '[\"aaa\"]' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property '[\"aaa\"]' has no initializer and is not definitely assigned in the constructor." } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_property.ts.json b/ets2panda/linter/test/sendable_class_property.ts.json index 029ff924..002715c5 100644 --- a/ets2panda/linter/test/sendable_class_property.ts.json +++ b/ets2panda/linter/test/sendable_class_property.ts.json @@ -15,104 +15,151 @@ ], "nodes": [ { - "line": 33, + "line": 38, + "column": 3, + "problem": "SendablePropType", + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 39, + "column": 3, + "problem": "SendablePropType", + "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 40, "column": 3, "problem": "SendablePropType", "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 34, + "line": 41, "column": 3, "problem": "SendablePropType", "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 35, + "line": 42, "column": 3, "problem": "SendablePropType", "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 36, + "line": 43, "column": 3, "problem": "SendablePropType", "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 37, + "line": 44, "column": 3, "problem": "SendablePropType", "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" }, { - "line": 20, + "line": 45, + "column": 3, + "problem": "ComputedPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 23, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." }, { - "line": 21, + "line": 24, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop2' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." }, { - "line": 22, + "line": 25, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop3' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop3' has no initializer and is not definitely assigned in the constructor." }, { - "line": 23, + "line": 26, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop4' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop4' has no initializer and is not definitely assigned in the constructor." }, { - "line": 24, + "line": 27, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop5' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop5' has no initializer and is not definitely assigned in the constructor." }, { - "line": 25, + "line": 28, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop6' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop6' has no initializer and is not definitely assigned in the constructor." }, { - "line": 27, + "line": 30, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop8' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop8' has no initializer and is not definitely assigned in the constructor." }, + { + "line": 32, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop10' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop10' has no initializer and is not definitely assigned in the constructor." + }, { "line": 33, "column": 3, "problem": "StrictDiagnostic", + "suggest": "Property 'prop11' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop11' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 38, + "column": 3, + "problem": "StrictDiagnostic", "suggest": "Property 'prop1' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop1' has no initializer and is not definitely assigned in the constructor." }, { - "line": 34, + "line": 39, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop2' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop2' has no initializer and is not definitely assigned in the constructor." }, { - "line": 35, + "line": 40, "column": 3, "problem": "StrictDiagnostic", "suggest": "Property 'prop3' has no initializer and is not definitely assigned in the constructor.", "rule": "Property 'prop3' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 43, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property 'prop6' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'prop6' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 45, + "column": 3, + "problem": "StrictDiagnostic", + "suggest": "Property '[\"aaa\"]' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property '[\"aaa\"]' has no initializer and is not definitely assigned in the constructor." } ] } \ No newline at end of file -- Gitee From f5f64c0bdf1c5eb017c6c4981756d9b45fc1f2f4 Mon Sep 17 00:00:00 2001 From: chenyiyuan Date: Wed, 27 Mar 2024 11:14:28 +0000 Subject: [PATCH 4/5] fix typo error / add separated computed name error / sendable union type support Signed-off-by: chenyiyuan Change-Id: Ie9ae9719bbdd729d92e4d7a566d1d0ff1459c972 --- ets2panda/linter/lib/CookBookMsg.ts | 3 ++- ets2panda/linter/lib/FaultAttrs.ts | 3 ++- ets2panda/linter/lib/FaultDesc.ts | 5 ++-- ets2panda/linter/lib/Problems.ts | 3 ++- ets2panda/linter/lib/TypeScriptLinter.ts | 11 ++++---- ets2panda/linter/lib/utils/TsUtils.ts | 26 +++++-------------- ...dable_class_initialization.ts.autofix.json | 8 +++--- .../sendable_class_initialization.ts.json | 8 +++--- .../linter/test/sendable_class_property.ts | 2 +- .../sendable_class_property.ts.autofix.json | 19 +++++++------- .../test/sendable_class_property.ts.json | 19 +++++++------- 11 files changed, 48 insertions(+), 59 deletions(-) diff --git a/ets2panda/linter/lib/CookBookMsg.ts b/ets2panda/linter/lib/CookBookMsg.ts index dfb5706c..94747b61 100644 --- a/ets2panda/linter/lib/CookBookMsg.ts +++ b/ets2panda/linter/lib/CookBookMsg.ts @@ -178,9 +178,10 @@ cookBookTag[150] = '"import" statements after other statements are not allowed ( cookBookTag[151] = 'Usage of "ESObject" type is restricted (arkts-limited-esobj)'; cookBookTag[152] = '"Function.apply", "Function.call" are not supported (arkts-no-func-apply-call)'; cookBookTag[153] = 'The inheritance for "Sendable" classes is limited (arkts-sendable-class-inheritance)'; -cookBookTag[154] = 'Properties in "Sendable" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)'; +cookBookTag[154] = 'Properties in "Sendable" classes must have a Sendable data type (arkts-sendable-prop-types)'; cookBookTag[155] = 'Definite assignment assertion in not allowed in "Sendable" classes (arkts-sendable-definite-assignment)'; cookBookTag[156] = 'Only "Sendable" data types are allowed as type arguments of generic "Sendable" type (arkts-sendable-generic-types)'; cookBookTag[157] = 'Non-sendable data can not be cast to "Sendable" data (arkts-sendable-as-expr)'; cookBookTag[158] = 'No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)'; cookBookTag[159] = 'The initialization for "Sendable" objects is limited (arkts-sendable-initialization)'; +cookBookTag[160] = 'Computed property names are not allowed in "Sendable" classes (arkts-sendable-computed-prop-name)'; diff --git a/ets2panda/linter/lib/FaultAttrs.ts b/ets2panda/linter/lib/FaultAttrs.ts index 5d108114..22043643 100644 --- a/ets2panda/linter/lib/FaultAttrs.ts +++ b/ets2panda/linter/lib/FaultAttrs.ts @@ -111,4 +111,5 @@ faultsAttrs[FaultID.SendableDefiniteAssignment] = new FaultAttributes(155); faultsAttrs[FaultID.SendableGenericTypes] = new FaultAttributes(156); faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(157); faultsAttrs[FaultID.SendableClassDecorator] = new FaultAttributes(158); -faultsAttrs[FaultID.SendableNoObjectorArrayLiteralInitialization] = new FaultAttributes(159); +faultsAttrs[FaultID.SendableNoObjectOrArrayLiteralInitialization] = new FaultAttributes(159); +faultsAttrs[FaultID.SendableComputedPropName] = new FaultAttributes(160); diff --git a/ets2panda/linter/lib/FaultDesc.ts b/ets2panda/linter/lib/FaultDesc.ts index fa37c1f7..23770056 100644 --- a/ets2panda/linter/lib/FaultDesc.ts +++ b/ets2panda/linter/lib/FaultDesc.ts @@ -103,5 +103,6 @@ faultDesc[FaultID.SendableDefiniteAssignment] = 'Use of definite assignment asse faultDesc[FaultID.SendableGenericTypes] = 'Sendable generic types'; faultDesc[FaultID.SendableAsExpr] = 'Sendable as expr'; faultDesc[FaultID.SendableClassDecorator] = 'Sendable class decorator'; -faultDesc[FaultID.SendableNoObjectorArrayLiteralInitialization] = 'Object literal or array literal is not allowed to \ - initialize a "Sendable" object' +faultDesc[FaultID.SendableNoObjectOrArrayLiteralInitialization] = 'Object literal or array literal is not allowed to \ + initialize a "Sendable" object'; +faultDesc[FaultID.SendableComputedPropName] = 'Sendable computed property name'; diff --git a/ets2panda/linter/lib/Problems.ts b/ets2panda/linter/lib/Problems.ts index 2799ae70..80f7b1d2 100644 --- a/ets2panda/linter/lib/Problems.ts +++ b/ets2panda/linter/lib/Problems.ts @@ -100,7 +100,8 @@ export enum FaultID { SendableGenericTypes, SendableAsExpr, SendableClassDecorator, - SendableNoObjectorArrayLiteralInitialization, + SendableNoObjectOrArrayLiteralInitialization, + SendableComputedPropName, // this should always be last enum LAST_ID } diff --git a/ets2panda/linter/lib/TypeScriptLinter.ts b/ets2panda/linter/lib/TypeScriptLinter.ts index bfd2d7ab..99771f13 100644 --- a/ets2panda/linter/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/lib/TypeScriptLinter.ts @@ -529,7 +529,7 @@ export class TypeScriptLinter { } const classNode = objectLiteralExpr.parent?.parent; if (classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) { - this.incrementCounters(node, FaultID.SendableNoObjectorArrayLiteralInitialization); + this.incrementCounters(node, FaultID.SendableNoObjectOrArrayLiteralInitialization); } } @@ -547,7 +547,7 @@ export class TypeScriptLinter { const classNode = arrayLitNode.parent?.parent; if (classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) { - this.incrementCounters(node, FaultID.SendableNoObjectorArrayLiteralInitialization); + this.incrementCounters(node, FaultID.SendableNoObjectOrArrayLiteralInitialization); } /* * check that array literal consists of inferrable types @@ -1252,7 +1252,7 @@ export class TypeScriptLinter { if (TsUtils.isSendableClass(tsVarType) && (ts.isArrayLiteralExpression(tsVarInit) || ts.isObjectLiteralExpression(tsVarInit))) { - this.incrementCounters(tsVarDecl, FaultID.SendableNoObjectorArrayLiteralInitialization); + this.incrementCounters(tsVarDecl, FaultID.SendableNoObjectOrArrayLiteralInitialization); } } this.handleEsObjectDelaration(tsVarDecl); @@ -2059,8 +2059,9 @@ export class TypeScriptLinter { private handleComputedPropertyName(node: ts.Node): void { const computedProperty = node as ts.ComputedPropertyName; const classNode = computedProperty.parent?.parent; - if ((classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) || - !this.tsUtils.isValidComputedPropertyName(computedProperty, false)) { + if (classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) { + this.incrementCounters(node, FaultID.SendableComputedPropName); + } else if (!this.tsUtils.isValidComputedPropertyName(computedProperty, false)) { this.incrementCounters(node, FaultID.ComputedPropertyName); } } diff --git a/ets2panda/linter/lib/utils/TsUtils.ts b/ets2panda/linter/lib/utils/TsUtils.ts index ca349f78..e8f2c023 100644 --- a/ets2panda/linter/lib/utils/TsUtils.ts +++ b/ets2panda/linter/lib/utils/TsUtils.ts @@ -1702,7 +1702,7 @@ export class TsUtils { } // Only the sendable nullish union type is supported - if ((type.flags & ts.TypeFlags.Union) !== 0 && TsUtils.isNullishSendableType(type as ts.UnionType)) { + if ((type.flags & ts.TypeFlags.Union) !== 0 && TsUtils.isSendableUnionType(type as ts.UnionType)) { return true; } @@ -1730,29 +1730,15 @@ export class TsUtils { return false; } - static isNullishSendableType(type: ts.UnionType): boolean { + static isSendableUnionType(type: ts.UnionType): boolean { const types = type?.types; - if (!types || types.length > 3) { + if (!types) { return false; } - let nullCount = 0; - let undefinedCount = 0; - let sendableCount = 0; - - for (const type of types) { - if ((type.flags & ts.TypeFlags.Null) !== 0) { - nullCount++; - } else if ((type.flags & ts.TypeFlags.Undefined) !== 0) { - undefinedCount++; - } else { - if (!TsUtils.isSendableType(type)) { - return false; - } - sendableCount++; - } - } - return nullCount <= 1 && undefinedCount <= 1 && sendableCount === 1; + return types.every((type) => { + return TsUtils.isSendableType(type) + }) } static hasSendableDecorator(decl: ts.ClassDeclaration): boolean { diff --git a/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json b/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json index dded55a2..9b2c4723 100644 --- a/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json +++ b/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json @@ -25,21 +25,21 @@ { "line": 18, "column": 27, - "problem": "SendableNoObjectorArrayLiteralInitialization", + "problem": "SendableNoObjectOrArrayLiteralInitialization", "autofixable": false, "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" }, { "line": 19, "column": 27, - "problem": "SendableNoObjectorArrayLiteralInitialization", + "problem": "SendableNoObjectOrArrayLiteralInitialization", "autofixable": false, "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" }, { "line": 22, "column": 5, - "problem": "SendableNoObjectorArrayLiteralInitialization", + "problem": "SendableNoObjectOrArrayLiteralInitialization", "autofixable": false, "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" }, @@ -54,7 +54,7 @@ { "line": 23, "column": 5, - "problem": "SendableNoObjectorArrayLiteralInitialization", + "problem": "SendableNoObjectOrArrayLiteralInitialization", "autofixable": false, "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" } diff --git a/ets2panda/linter/test/sendable_class_initialization.ts.json b/ets2panda/linter/test/sendable_class_initialization.ts.json index 1f7fcb0c..b1bbebb6 100644 --- a/ets2panda/linter/test/sendable_class_initialization.ts.json +++ b/ets2panda/linter/test/sendable_class_initialization.ts.json @@ -24,19 +24,19 @@ { "line": 18, "column": 27, - "problem": "SendableNoObjectorArrayLiteralInitialization", + "problem": "SendableNoObjectOrArrayLiteralInitialization", "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" }, { "line": 19, "column": 27, - "problem": "SendableNoObjectorArrayLiteralInitialization", + "problem": "SendableNoObjectOrArrayLiteralInitialization", "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" }, { "line": 22, "column": 5, - "problem": "SendableNoObjectorArrayLiteralInitialization", + "problem": "SendableNoObjectOrArrayLiteralInitialization", "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" }, { @@ -49,7 +49,7 @@ { "line": 23, "column": 5, - "problem": "SendableNoObjectorArrayLiteralInitialization", + "problem": "SendableNoObjectOrArrayLiteralInitialization", "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" } ] diff --git a/ets2panda/linter/test/sendable_class_property.ts b/ets2panda/linter/test/sendable_class_property.ts index dd848ce1..f1d59d2d 100644 --- a/ets2panda/linter/test/sendable_class_property.ts +++ b/ets2panda/linter/test/sendable_class_property.ts @@ -28,7 +28,7 @@ class SendableClass4 { prop6: null; // OK prop7: undefined; // OK prop8: U; // OK - prop9: T | null | undefined; // OK + prop9: T | number | undefined; // OK prop10: alias0; // OK prop11: alias1; // OK } diff --git a/ets2panda/linter/test/sendable_class_property.ts.autofix.json b/ets2panda/linter/test/sendable_class_property.ts.autofix.json index 6b400d21..1970d7cc 100644 --- a/ets2panda/linter/test/sendable_class_property.ts.autofix.json +++ b/ets2panda/linter/test/sendable_class_property.ts.autofix.json @@ -19,57 +19,56 @@ "column": 3, "problem": "SendablePropType", "autofixable": false, - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 39, "column": 3, "problem": "SendablePropType", "autofixable": false, - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 40, "column": 3, "problem": "SendablePropType", "autofixable": false, - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 41, "column": 3, "problem": "SendablePropType", "autofixable": false, - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 42, "column": 3, "problem": "SendablePropType", "autofixable": false, - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 43, "column": 3, "problem": "SendablePropType", "autofixable": false, - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 44, "column": 3, "problem": "SendablePropType", "autofixable": false, - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 45, "column": 3, - "problem": "ComputedPropertyName", + "problem": "SendableComputedPropName", "autofixable": false, - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + "rule": "Computed property names are not allowed in \"Sendable\" classes (arkts-sendable-computed-prop-name)" }, { "line": 23, diff --git a/ets2panda/linter/test/sendable_class_property.ts.json b/ets2panda/linter/test/sendable_class_property.ts.json index 002715c5..05a5a356 100644 --- a/ets2panda/linter/test/sendable_class_property.ts.json +++ b/ets2panda/linter/test/sendable_class_property.ts.json @@ -18,50 +18,49 @@ "line": 38, "column": 3, "problem": "SendablePropType", - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 39, "column": 3, "problem": "SendablePropType", - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 40, "column": 3, "problem": "SendablePropType", - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 41, "column": 3, "problem": "SendablePropType", - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 42, "column": 3, "problem": "SendablePropType", - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 43, "column": 3, "problem": "SendablePropType", - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 44, "column": 3, "problem": "SendablePropType", - "rule": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)" + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" }, { "line": 45, "column": 3, - "problem": "ComputedPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + "problem": "SendableComputedPropName", + "rule": "Computed property names are not allowed in \"Sendable\" classes (arkts-sendable-computed-prop-name)" }, { "line": 23, -- Gitee From 3fb42a7599282d44590abb30cfba9eadcdee6442 Mon Sep 17 00:00:00 2001 From: chenyiyuan Date: Thu, 28 Mar 2024 02:29:01 +0000 Subject: [PATCH 5/5] fix problems in comments Signed-off-by: chenyiyuan Change-Id: I0e6a6baf5d06e9bd57744f70811a1d5132cc8ca1 --- ets2panda/linter/lib/CookBookMsg.ts | 8 ++--- ets2panda/linter/lib/FaultAttrs.ts | 2 +- ets2panda/linter/lib/FaultDesc.ts | 2 +- ets2panda/linter/lib/Problems.ts | 2 +- ets2panda/linter/lib/TypeScriptLinter.ts | 28 +++++---------- ets2panda/linter/lib/utils/TsUtils.ts | 2 +- .../test/sendable_as_expr.ts.autofix.json | 4 +-- .../linter/test/sendable_as_expr.ts.json | 4 +-- .../sendable_class_decorator.ts.autofix.json | 12 +++---- .../test/sendable_class_decorator.ts.json | 12 +++---- ...dable_class_initialization.ts.autofix.json | 34 +++++-------------- .../sendable_class_initialization.ts.json | 32 +++++------------ .../sendable_generic_types.ts.autofix.json | 16 ++++----- .../test/sendable_generic_types.ts.json | 16 ++++----- 14 files changed, 67 insertions(+), 107 deletions(-) diff --git a/ets2panda/linter/lib/CookBookMsg.ts b/ets2panda/linter/lib/CookBookMsg.ts index 94747b61..6cc7cc13 100644 --- a/ets2panda/linter/lib/CookBookMsg.ts +++ b/ets2panda/linter/lib/CookBookMsg.ts @@ -180,8 +180,8 @@ cookBookTag[152] = '"Function.apply", "Function.call" are not supported (arkts-n cookBookTag[153] = 'The inheritance for "Sendable" classes is limited (arkts-sendable-class-inheritance)'; cookBookTag[154] = 'Properties in "Sendable" classes must have a Sendable data type (arkts-sendable-prop-types)'; cookBookTag[155] = 'Definite assignment assertion in not allowed in "Sendable" classes (arkts-sendable-definite-assignment)'; -cookBookTag[156] = 'Only "Sendable" data types are allowed as type arguments of generic "Sendable" type (arkts-sendable-generic-types)'; -cookBookTag[157] = 'Non-sendable data can not be cast to "Sendable" data (arkts-sendable-as-expr)'; -cookBookTag[158] = 'No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)'; -cookBookTag[159] = 'The initialization for "Sendable" objects is limited (arkts-sendable-initialization)'; +cookBookTag[156] = 'Type arguments of generic "Sendable" type must be a "Sendable" data type (arkts-sendable-generic-types)'; +cookBookTag[157] = 'Casting "Non-sendable" data to "Sendable" type is not allowed (arkts-sendable-as-expr)'; +cookBookTag[158] = 'Only "@Sendable" decorator can be used on "Sendable" class (arkts-sendable-class-decorator)'; +cookBookTag[159] = 'Objects of "Sendable" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)'; cookBookTag[160] = 'Computed property names are not allowed in "Sendable" classes (arkts-sendable-computed-prop-name)'; diff --git a/ets2panda/linter/lib/FaultAttrs.ts b/ets2panda/linter/lib/FaultAttrs.ts index 22043643..a61a6f02 100644 --- a/ets2panda/linter/lib/FaultAttrs.ts +++ b/ets2panda/linter/lib/FaultAttrs.ts @@ -111,5 +111,5 @@ faultsAttrs[FaultID.SendableDefiniteAssignment] = new FaultAttributes(155); faultsAttrs[FaultID.SendableGenericTypes] = new FaultAttributes(156); faultsAttrs[FaultID.SendableAsExpr] = new FaultAttributes(157); faultsAttrs[FaultID.SendableClassDecorator] = new FaultAttributes(158); -faultsAttrs[FaultID.SendableNoObjectOrArrayLiteralInitialization] = new FaultAttributes(159); +faultsAttrs[FaultID.SendableObjectInitialization] = new FaultAttributes(159); faultsAttrs[FaultID.SendableComputedPropName] = new FaultAttributes(160); diff --git a/ets2panda/linter/lib/FaultDesc.ts b/ets2panda/linter/lib/FaultDesc.ts index 23770056..20d02adc 100644 --- a/ets2panda/linter/lib/FaultDesc.ts +++ b/ets2panda/linter/lib/FaultDesc.ts @@ -103,6 +103,6 @@ faultDesc[FaultID.SendableDefiniteAssignment] = 'Use of definite assignment asse faultDesc[FaultID.SendableGenericTypes] = 'Sendable generic types'; faultDesc[FaultID.SendableAsExpr] = 'Sendable as expr'; faultDesc[FaultID.SendableClassDecorator] = 'Sendable class decorator'; -faultDesc[FaultID.SendableNoObjectOrArrayLiteralInitialization] = 'Object literal or array literal is not allowed to \ +faultDesc[FaultID.SendableObjectInitialization] = 'Object literal or array literal is not allowed to \ initialize a "Sendable" object'; faultDesc[FaultID.SendableComputedPropName] = 'Sendable computed property name'; diff --git a/ets2panda/linter/lib/Problems.ts b/ets2panda/linter/lib/Problems.ts index 80f7b1d2..bc7910e3 100644 --- a/ets2panda/linter/lib/Problems.ts +++ b/ets2panda/linter/lib/Problems.ts @@ -100,7 +100,7 @@ export enum FaultID { SendableGenericTypes, SendableAsExpr, SendableClassDecorator, - SendableNoObjectOrArrayLiteralInitialization, + SendableObjectInitialization, SendableComputedPropName, // this should always be last enum LAST_ID diff --git a/ets2panda/linter/lib/TypeScriptLinter.ts b/ets2panda/linter/lib/TypeScriptLinter.ts index b0acd946..e6d29aee 100644 --- a/ets2panda/linter/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/lib/TypeScriptLinter.ts @@ -518,19 +518,17 @@ export class TypeScriptLinter { if (TsUtils.isDestructuringAssignmentLHS(objectLiteralExpr)) { return; } - // issue 13082: Allow initializing struct instances with object literal. + const objectLiteralType = this.tsTypeChecker.getContextualType(objectLiteralExpr); - if ( + if (objectLiteralType && TsUtils.isSendableClass(objectLiteralType as ts.Type)) { + this.incrementCounters(node, FaultID.SendableObjectInitialization); + } else if ( // issue 13082: Allow initializing struct instances with object literal. !this.tsUtils.isStructObjectInitializer(objectLiteralExpr) && !this.tsUtils.isDynamicLiteralInitializer(objectLiteralExpr) && !this.tsUtils.isObjectLiteralAssignable(objectLiteralType, objectLiteralExpr) ) { this.incrementCounters(node, FaultID.ObjectLiteralNoContextType); } - const classNode = objectLiteralExpr.parent?.parent; - if (classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) { - this.incrementCounters(node, FaultID.SendableNoObjectOrArrayLiteralInitialization); - } } private handleArrayLiteralExpression(node: ts.Node): void { @@ -545,9 +543,10 @@ export class TypeScriptLinter { const arrayLitNode = node as ts.ArrayLiteralExpression; let noContextTypeForArrayLiteral = false; - const classNode = arrayLitNode.parent?.parent; - if (classNode && ts.isClassDeclaration(classNode) && TsUtils.hasSendableDecorator(classNode)) { - this.incrementCounters(node, FaultID.SendableNoObjectOrArrayLiteralInitialization); + const arrayLitType = this.tsTypeChecker.getContextualType(arrayLitNode); + if (arrayLitType && TsUtils.isSendableClass(arrayLitType as ts.Type)) { + this.incrementCounters(node, FaultID.SendableObjectInitialization); + return; } /* * check that array literal consists of inferrable types @@ -1249,11 +1248,6 @@ export class TypeScriptLinter { if (this.tsUtils.needToDeduceStructuralIdentity(tsVarType, tsInitType, tsVarInit)) { this.incrementCounters(tsVarDecl, FaultID.StructuralIdentity); } - - if (TsUtils.isSendableClass(tsVarType) && (ts.isArrayLiteralExpression(tsVarInit) || - ts.isObjectLiteralExpression(tsVarInit))) { - this.incrementCounters(tsVarDecl, FaultID.SendableNoObjectOrArrayLiteralInitialization); - } } this.handleEsObjectDelaration(tsVarDecl); this.handleDeclarationInferredType(tsVarDecl); @@ -1372,12 +1366,8 @@ export class TypeScriptLinter { if (hClause.token === ts.SyntaxKind.ImplementsKeyword) { this.incrementCounters(tsTypeExpr, FaultID.ImplementsClass); } -<<<<<<< HEAD const isSendableBaseType = TsUtils.isSendableClass(tsExprType); -======= - const isSendableBaseType = TsUtils.isSendableType(tsExprType); ->>>>>>> eveg/arkts-linter-sendable if (isSendableClass !== isSendableBaseType) { this.incrementCounters(tsTypeExpr, FaultID.SendableClassInheritance); } @@ -1979,7 +1969,7 @@ export class TypeScriptLinter { for (const arg of typeArgs) { const argType = this.tsTypeChecker.getTypeFromTypeNode(arg); if (!TsUtils.isSendableType(argType)) { - this.incrementCounters(node, FaultID.SendableGenericTypes); + this.incrementCounters(arg, FaultID.SendableGenericTypes); } } } diff --git a/ets2panda/linter/lib/utils/TsUtils.ts b/ets2panda/linter/lib/utils/TsUtils.ts index a98dd9d4..51f055dc 100644 --- a/ets2panda/linter/lib/utils/TsUtils.ts +++ b/ets2panda/linter/lib/utils/TsUtils.ts @@ -1702,7 +1702,7 @@ export class TsUtils { return true; } - // Only the sendable nullish union type is supported + // Only the sendable union type is supported if ((type.flags & ts.TypeFlags.Union) !== 0 && TsUtils.isSendableUnionType(type as ts.UnionType)) { return true; } diff --git a/ets2panda/linter/test/sendable_as_expr.ts.autofix.json b/ets2panda/linter/test/sendable_as_expr.ts.autofix.json index 925a81b9..e4ade086 100644 --- a/ets2panda/linter/test/sendable_as_expr.ts.autofix.json +++ b/ets2panda/linter/test/sendable_as_expr.ts.autofix.json @@ -19,14 +19,14 @@ "column": 10, "problem": "SendableAsExpr", "autofixable": false, - "rule": "Non-sendable data can not be cast to \"Sendable\" data (arkts-sendable-as-expr)" + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" }, { "line": 27, "column": 10, "problem": "SendableAsExpr", "autofixable": false, - "rule": "Non-sendable data can not be cast to \"Sendable\" data (arkts-sendable-as-expr)" + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_as_expr.ts.json b/ets2panda/linter/test/sendable_as_expr.ts.json index ef1ec16d..ebb68d91 100644 --- a/ets2panda/linter/test/sendable_as_expr.ts.json +++ b/ets2panda/linter/test/sendable_as_expr.ts.json @@ -18,13 +18,13 @@ "line": 23, "column": 10, "problem": "SendableAsExpr", - "rule": "Non-sendable data can not be cast to \"Sendable\" data (arkts-sendable-as-expr)" + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" }, { "line": 27, "column": 10, "problem": "SendableAsExpr", - "rule": "Non-sendable data can not be cast to \"Sendable\" data (arkts-sendable-as-expr)" + "rule": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_decorator.ts.autofix.json b/ets2panda/linter/test/sendable_class_decorator.ts.autofix.json index 7fb0a1c6..0cfb8155 100644 --- a/ets2panda/linter/test/sendable_class_decorator.ts.autofix.json +++ b/ets2panda/linter/test/sendable_class_decorator.ts.autofix.json @@ -19,42 +19,42 @@ "column": 1, "problem": "SendableClassDecorator", "autofixable": false, - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 38, "column": 5, "problem": "SendableClassDecorator", "autofixable": false, - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 43, "column": 5, "problem": "SendableClassDecorator", "autofixable": false, - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 46, "column": 15, "problem": "SendableClassDecorator", "autofixable": false, - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 48, "column": 5, "problem": "SendableClassDecorator", "autofixable": false, - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 52, "column": 5, "problem": "SendableClassDecorator", "autofixable": false, - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 19, diff --git a/ets2panda/linter/test/sendable_class_decorator.ts.json b/ets2panda/linter/test/sendable_class_decorator.ts.json index b2b5daa7..5260bf46 100644 --- a/ets2panda/linter/test/sendable_class_decorator.ts.json +++ b/ets2panda/linter/test/sendable_class_decorator.ts.json @@ -18,37 +18,37 @@ "line": 35, "column": 1, "problem": "SendableClassDecorator", - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 38, "column": 5, "problem": "SendableClassDecorator", - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 43, "column": 5, "problem": "SendableClassDecorator", - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 46, "column": 15, "problem": "SendableClassDecorator", - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 48, "column": 5, "problem": "SendableClassDecorator", - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 52, "column": 5, "problem": "SendableClassDecorator", - "rule": "No decorators can be used in a sendable class and only `@Sendable` can be used on a sendable class declaration (arkts-sendable-class-decorator)" + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" }, { "line": 19, diff --git a/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json b/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json index 9b2c4723..93897de7 100644 --- a/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json +++ b/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json @@ -17,46 +17,30 @@ { "line": 18, "column": 27, - "problem": "ObjectLiteralNoContextType", + "problem": "SendableObjectInitialization", "autofixable": false, - "suggest": "", - "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" - }, - { - "line": 18, - "column": 27, - "problem": "SendableNoObjectOrArrayLiteralInitialization", - "autofixable": false, - "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" }, { "line": 19, "column": 27, - "problem": "SendableNoObjectOrArrayLiteralInitialization", + "problem": "SendableObjectInitialization", "autofixable": false, - "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" - }, - { - "line": 22, - "column": 5, - "problem": "SendableNoObjectOrArrayLiteralInitialization", - "autofixable": false, - "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" }, { "line": 22, "column": 26, - "problem": "ObjectLiteralNoContextType", + "problem": "SendableObjectInitialization", "autofixable": false, - "suggest": "", - "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" }, { "line": 23, - "column": 5, - "problem": "SendableNoObjectOrArrayLiteralInitialization", + "column": 26, + "problem": "SendableObjectInitialization", "autofixable": false, - "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_class_initialization.ts.json b/ets2panda/linter/test/sendable_class_initialization.ts.json index b1bbebb6..48fe2dec 100644 --- a/ets2panda/linter/test/sendable_class_initialization.ts.json +++ b/ets2panda/linter/test/sendable_class_initialization.ts.json @@ -17,40 +17,26 @@ { "line": 18, "column": 27, - "problem": "ObjectLiteralNoContextType", - "suggest": "", - "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" - }, - { - "line": 18, - "column": 27, - "problem": "SendableNoObjectOrArrayLiteralInitialization", - "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + "problem": "SendableObjectInitialization", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" }, { "line": 19, "column": 27, - "problem": "SendableNoObjectOrArrayLiteralInitialization", - "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" - }, - { - "line": 22, - "column": 5, - "problem": "SendableNoObjectOrArrayLiteralInitialization", - "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + "problem": "SendableObjectInitialization", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" }, { "line": 22, "column": 26, - "problem": "ObjectLiteralNoContextType", - "suggest": "", - "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + "problem": "SendableObjectInitialization", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" }, { "line": 23, - "column": 5, - "problem": "SendableNoObjectOrArrayLiteralInitialization", - "rule": "The initialization for \"Sendable\" objects is limited (arkts-sendable-initialization)" + "column": 26, + "problem": "SendableObjectInitialization", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/sendable_generic_types.ts.autofix.json b/ets2panda/linter/test/sendable_generic_types.ts.autofix.json index ed885845..f3a191b3 100644 --- a/ets2panda/linter/test/sendable_generic_types.ts.autofix.json +++ b/ets2panda/linter/test/sendable_generic_types.ts.autofix.json @@ -16,24 +16,24 @@ "nodes": [ { "line": 25, - "column": 12, + "column": 39, "problem": "SendableGenericTypes", "autofixable": false, - "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" }, { "line": 26, - "column": 12, + "column": 31, "problem": "SendableGenericTypes", "autofixable": false, - "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" }, { "line": 26, - "column": 12, + "column": 41, "problem": "SendableGenericTypes", "autofixable": false, - "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" }, { "line": 28, @@ -61,10 +61,10 @@ }, { "line": 33, - "column": 12, + "column": 26, "problem": "SendableGenericTypes", "autofixable": false, - "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" }, { "line": 20, diff --git a/ets2panda/linter/test/sendable_generic_types.ts.json b/ets2panda/linter/test/sendable_generic_types.ts.json index 48b0b93c..ef26fcd3 100644 --- a/ets2panda/linter/test/sendable_generic_types.ts.json +++ b/ets2panda/linter/test/sendable_generic_types.ts.json @@ -16,21 +16,21 @@ "nodes": [ { "line": 25, - "column": 12, + "column": 39, "problem": "SendableGenericTypes", - "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" }, { "line": 26, - "column": 12, + "column": 31, "problem": "SendableGenericTypes", - "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" }, { "line": 26, - "column": 12, + "column": 41, "problem": "SendableGenericTypes", - "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" }, { "line": 28, @@ -55,9 +55,9 @@ }, { "line": 33, - "column": 12, + "column": 26, "problem": "SendableGenericTypes", - "rule": "Only \"Sendable\" data types are allowed as type arguments of generic \"Sendable\" type (arkts-sendable-generic-types)" + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" }, { "line": 20, -- Gitee