diff --git a/ets2panda/linter/lib/CookBookMsg.ts b/ets2panda/linter/lib/CookBookMsg.ts index 69e2bae704023ede57390565475814dbce86072e..6cc7cc13ea85ab9f1601ed4a24ebf37c688befb5 100644 --- a/ets2panda/linter/lib/CookBookMsg.ts +++ b/ets2panda/linter/lib/CookBookMsg.ts @@ -178,4 +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 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] = '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 138856ca03fc9fce2125a122b87b439046ca3a77..a61a6f0266696ddc091f0f0ff88c14f17e19d821 100644 --- a/ets2panda/linter/lib/FaultAttrs.ts +++ b/ets2panda/linter/lib/FaultAttrs.ts @@ -106,4 +106,10 @@ 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); +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 cd2330993b8f1a57c9f2f6755e8c94c66bb04cdc..20d02adc180851cf619c7161817081f53de95e02 100644 --- a/ets2panda/linter/lib/FaultDesc.ts +++ b/ets2panda/linter/lib/FaultDesc.ts @@ -98,4 +98,11 @@ 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'; +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 5e5e15b7a1a833006bce08607720f8d96cdddd30..bc7910e380d2a7831688b58ace95a0eed270a733 100644 --- a/ets2panda/linter/lib/Problems.ts +++ b/ets2panda/linter/lib/Problems.ts @@ -95,7 +95,13 @@ export enum FaultID { ImportAfterStatement, EsObjectType, SendableClassInheritance, + SendablePropType, SendableDefiniteAssignment, + SendableGenericTypes, + SendableAsExpr, + SendableClassDecorator, + 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 6936f3111b46767905a9bfced6458ee409f8bb66..e6d29aee2138f07e062116910cffc3cd1b821acd 100644 --- a/ets2panda/linter/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/lib/TypeScriptLinter.ts @@ -518,9 +518,11 @@ 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) @@ -541,6 +543,11 @@ export class TypeScriptLinter { const arrayLitNode = node as ts.ArrayLiteralExpression; let noContextTypeForArrayLiteral = false; + 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 * e.g. there is no element which is untyped object literals @@ -565,6 +572,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 +766,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 +1349,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) { @@ -1333,7 +1366,8 @@ export class TypeScriptLinter { if (hClause.token === ts.SyntaxKind.ImplementsKeyword) { this.incrementCounters(tsTypeExpr, FaultID.ImplementsClass); } - const isSendableBaseType = TsUtils.isSendableType(tsExprType); + + const isSendableBaseType = TsUtils.isSendableClass(tsExprType); if (isSendableClass !== isSendableBaseType) { this.incrementCounters(tsTypeExpr, FaultID.SendableClassInheritance); } @@ -1452,6 +1486,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) { @@ -1915,6 +1952,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(arg, FaultID.SendableGenericTypes); + } + } } private handleAsExpression(node: ts.Node): void { @@ -1931,6 +1988,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 { @@ -2003,12 +2063,18 @@ 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.incrementCounters(node, FaultID.SendableComputedPropName); + } else if (!this.tsUtils.isValidComputedPropertyName(computedProperty, false)) { this.incrementCounters(node, FaultID.ComputedPropertyName); } } - private handleGetAccessor(node: ts.Node): void { + private handleGetAccessor(node: ts.GetAccessorDeclaration): void { + if (TsUtils.isInSendableClassAndHasDecorators(node)) { + this.incrementCounters(node, FaultID.SendableClassDecorator); + } /** * Reserved if needed @@ -2017,7 +2083,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 @@ -2221,7 +2290,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 1984f9a96c1589aeb6ea9131d4f1ead447330731..51f055dc0ed326ffcfca1a6ad9ac940e96136df4 100644 --- a/ets2panda/linter/lib/utils/TsUtils.ts +++ b/ets2panda/linter/lib/utils/TsUtils.ts @@ -1696,13 +1696,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 union type is supported + if ((type.flags & ts.TypeFlags.Union) !== 0 && TsUtils.isSendableUnionType(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)) { @@ -1714,10 +1731,41 @@ export class TsUtils { return false; } + static isSendableUnionType(type: ts.UnionType): boolean { + const types = type?.types; + if (!types) { + return false; + } + + return types.every((type) => { + return TsUtils.isSendableType(type) + }) + } + static hasSendableDecorator(decl: ts.ClassDeclaration): boolean { const decorators = ts.getDecorators(decl); return decorators !== undefined && decorators.some((x) => { return TsUtils.getDecoratorName(x) === SENDABLE_DECORATOR; }); } + + 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 0000000000000000000000000000000000000000..9435112d4435826ceb258e4166f5601a1b3c4c12 --- /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 0000000000000000000000000000000000000000..e4ade08616dcc9a1df270d8e9a5120708fc49af7 --- /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": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 27, + "column": 10, + "problem": "SendableAsExpr", + "autofixable": false, + "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 new file mode 100644 index 0000000000000000000000000000000000000000..ebb68d91f553e866532fdca927c05c88e45e3a9d --- /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": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)" + }, + { + "line": 27, + "column": 10, + "problem": "SendableAsExpr", + "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 b/ets2panda/linter/test/sendable_class_decorator.ts new file mode 100644 index 0000000000000000000000000000000000000000..85da2a561f704892ff5545d212d381fa58866ad8 --- /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 0000000000000000000000000000000000000000..0cfb8155f4e9f5ed902689a48edec20d5d34e17b --- /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": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 38, + "column": 5, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 43, + "column": 5, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 46, + "column": 15, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 48, + "column": 5, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 52, + "column": 5, + "problem": "SendableClassDecorator", + "autofixable": false, + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (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 0000000000000000000000000000000000000000..5260bf460f46a73050e5362a8a79e38a0d35db11 --- /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": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 38, + "column": 5, + "problem": "SendableClassDecorator", + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 43, + "column": 5, + "problem": "SendableClassDecorator", + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 46, + "column": 15, + "problem": "SendableClassDecorator", + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 48, + "column": 5, + "problem": "SendableClassDecorator", + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)" + }, + { + "line": 52, + "column": 5, + "problem": "SendableClassDecorator", + "rule": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (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_initialization.ts b/ets2panda/linter/test/sendable_class_initialization.ts new file mode 100644 index 0000000000000000000000000000000000000000..8ec142319e59840efedee906b8e95e4bd212aab9 --- /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 0000000000000000000000000000000000000000..93897de7af6f8b5a2a165db8db1d600efb28ce9f --- /dev/null +++ b/ets2panda/linter/test/sendable_class_initialization.ts.autofix.json @@ -0,0 +1,46 @@ +{ + "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": "SendableObjectInitialization", + "autofixable": false, + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 19, + "column": 27, + "problem": "SendableObjectInitialization", + "autofixable": false, + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 22, + "column": 26, + "problem": "SendableObjectInitialization", + "autofixable": false, + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 23, + "column": 26, + "problem": "SendableObjectInitialization", + "autofixable": false, + "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 new file mode 100644 index 0000000000000000000000000000000000000000..48fe2decca5c18981fe962ecffa91fc878ed976f --- /dev/null +++ b/ets2panda/linter/test/sendable_class_initialization.ts.json @@ -0,0 +1,42 @@ +{ + "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": "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": "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": "SendableObjectInitialization", + "rule": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)" + }, + { + "line": 23, + "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_class_property.ts b/ets2panda/linter/test/sendable_class_property.ts new file mode 100644 index 0000000000000000000000000000000000000000..f1d59d2d75e735e717baa1e323e94687533b49ab --- /dev/null +++ b/ets2panda/linter/test/sendable_class_property.ts @@ -0,0 +1,51 @@ +/* + * 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 SendableClass10 {} + +@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 | number | undefined; // OK + prop10: alias0; // OK + prop11: alias1; // 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 + 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 new file mode 100644 index 0000000000000000000000000000000000000000..1970d7cc67e96d283c87d408b954fe65cc54c520 --- /dev/null +++ b/ets2panda/linter/test/sendable_class_property.ts.autofix.json @@ -0,0 +1,186 @@ +{ + "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": 38, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "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 must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 40, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "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 must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 42, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "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 must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 44, + "column": 3, + "problem": "SendablePropType", + "autofixable": false, + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 45, + "column": 3, + "problem": "SendableComputedPropName", + "autofixable": false, + "rule": "Computed property names are not allowed in \"Sendable\" classes (arkts-sendable-computed-prop-name)" + }, + { + "line": 23, + "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": 24, + "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": 25, + "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": 26, + "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": 27, + "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": 28, + "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": 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": 39, + "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": 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 new file mode 100644 index 0000000000000000000000000000000000000000..05a5a3565e675c87d6cc5854b238434e462c648b --- /dev/null +++ b/ets2panda/linter/test/sendable_class_property.ts.json @@ -0,0 +1,164 @@ +{ + "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": 38, + "column": 3, + "problem": "SendablePropType", + "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 must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 40, + "column": 3, + "problem": "SendablePropType", + "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 must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 42, + "column": 3, + "problem": "SendablePropType", + "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 must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 44, + "column": 3, + "problem": "SendablePropType", + "rule": "Properties in \"Sendable\" classes must have a Sendable data type (arkts-sendable-prop-types)" + }, + { + "line": 45, + "column": 3, + "problem": "SendableComputedPropName", + "rule": "Computed property names are not allowed in \"Sendable\" classes (arkts-sendable-computed-prop-name)" + }, + { + "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": 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": 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": 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": 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": 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": 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": 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": 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 diff --git a/ets2panda/linter/test/sendable_generic_types.ts b/ets2panda/linter/test/sendable_generic_types.ts new file mode 100644 index 0000000000000000000000000000000000000000..4d7fab52b05a1dbdd8e1765f15ec2c3a1299e139 --- /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 0000000000000000000000000000000000000000..f3a191b3e525658c7182c9b00b7b5fc2a83300e2 --- /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": 39, + "problem": "SendableGenericTypes", + "autofixable": false, + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 31, + "problem": "SendableGenericTypes", + "autofixable": false, + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 41, + "problem": "SendableGenericTypes", + "autofixable": false, + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data 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": 26, + "problem": "SendableGenericTypes", + "autofixable": false, + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data 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 0000000000000000000000000000000000000000..ef26fcd373712479c0d50c00651c967de01537ea --- /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": 39, + "problem": "SendableGenericTypes", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 31, + "problem": "SendableGenericTypes", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)" + }, + { + "line": 26, + "column": 41, + "problem": "SendableGenericTypes", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data 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": 26, + "problem": "SendableGenericTypes", + "rule": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data 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