From 415567e3300757aad8c84fd4cc0b4009b33c8067 Mon Sep 17 00:00:00 2001 From: e-day Date: Fri, 25 Jul 2025 09:31:49 +0300 Subject: [PATCH] no-local-class impl Description: no-local-class rule implemented. Issue: #ICOE0H Signed-off-by: e-day --- ets2panda/linter/rule-config.json | 1 + ets2panda/linter/src/lib/CookBookMsg.ts | 2 +- ets2panda/linter/src/lib/FaultAttrs.ts | 1 + ets2panda/linter/src/lib/FaultDesc.ts | 1 + ets2panda/linter/src/lib/Problems.ts | 1 + ets2panda/linter/src/lib/TypeScriptLinter.ts | 28 ++ .../test/interop/unique_types.ets.arkts2.json | 22 +- .../interop/unique_types.ets.autofix.json | 22 +- .../interop/unique_types.ets.migrate.json | 22 +- .../main/extends_expression.ets.arkts2.json | 22 +- ets2panda/linter/test/main/no_local_class.ets | 135 +++++++ .../test/main/no_local_class.ets.args.json | 19 + .../test/main/no_local_class.ets.arkts2.json | 338 ++++++++++++++++++ .../linter/test/main/no_local_class.ets.json | 48 +++ ...object_literals_properties.ets.arkts2.json | 12 +- ...bject_literals_properties.ets.autofix.json | 12 +- ...bject_literals_properties.ets.migrate.json | 22 +- 17 files changed, 700 insertions(+), 8 deletions(-) create mode 100644 ets2panda/linter/test/main/no_local_class.ets create mode 100644 ets2panda/linter/test/main/no_local_class.ets.args.json create mode 100644 ets2panda/linter/test/main/no_local_class.ets.arkts2.json create mode 100644 ets2panda/linter/test/main/no_local_class.ets.json diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 5ffcc05976..e13f5fab41 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -22,6 +22,7 @@ "arkts-incompatible-function-types", "arkts-limited-void-type", "arkts-no-void-operator", + "arkts-no-local-class", "arkts-no-ts-overload", "arkts-limited-literal-types", "arkts-no-exponent-op", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 48ef059d65..b759c865ca 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -298,7 +298,7 @@ cookBookTag[274] = cookBookTag[275] = 'The Custom component with custom layout capability needs to add the "@CustomLayout" decorator (arkui-custom-layout-need-add-decorator)'; cookBookTag[276] = - 'ArkTS 1.2 should implement all fields in the interface in the class (arkts-no-class-omit-interface-optional-prop)'; +cookBookTag[277] = 'Creating local classes is not supported (arkts-no-local-class)'; cookBookTag[281] = '"@Prop" decorator is not supported (arkui-no-prop-decorator)'; cookBookTag[282] = '"@StorageProp" decorator is not supported (arkui-no-storageprop-decorator)'; cookBookTag[283] = '"@LocalStorageProp" decorator is not supported (arkui-no-localstorageprop-decorator)'; diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index 3b94b8be41..a34add5d8e 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -203,6 +203,7 @@ faultsAttrs[FaultID.InteropJSFunctionInvoke] = new FaultAttributes(270); faultsAttrs[FaultID.MissingSuperCall] = new FaultAttributes(274); faultsAttrs[FaultID.CustomLayoutNeedAddDecorator] = new FaultAttributes(275); faultsAttrs[FaultID.InterfaceFieldNotImplemented] = new FaultAttributes(276); +faultsAttrs[FaultID.NoLocalClass] = new FaultAttributes(277); faultsAttrs[FaultID.PropDecoratorNotSupported] = new FaultAttributes(281); faultsAttrs[FaultID.StoragePropDecoratorNotSupported] = new FaultAttributes(282); faultsAttrs[FaultID.LocalStoragePropDecoratorNotSupported] = new FaultAttributes(283); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index fa4599cdbe..149656720d 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -256,6 +256,7 @@ faultDesc[FaultID.NondecimalBigint] = 'No non decimal'; faultDesc[FaultID.UnsupportOperator] = 'Unsupport operator'; faultDesc[FaultID.CustomLayoutNeedAddDecorator] = 'Custom layout need add decorator'; faultDesc[FaultID.InterfaceFieldNotImplemented] = 'All fields must be implemented'; +faultDesc[FaultID.NoLocalClass] = 'No local classes'; faultDesc[FaultID.PropDecoratorNotSupported] = '"@Prop" decorator is not supported'; faultDesc[FaultID.StoragePropDecoratorNotSupported] = '"@StorageProp" decorator is not supported'; faultDesc[FaultID.LocalStoragePropDecoratorNotSupported] = '"@LocalStorageProp" decorator is not supported'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index 9cab1b911e..f26891240c 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -256,6 +256,7 @@ export enum FaultID { UnsupportOperator, CustomLayoutNeedAddDecorator, InterfaceFieldNotImplemented, + NoLocalClass, PropDecoratorNotSupported, StoragePropDecoratorNotSupported, LocalStoragePropDecoratorNotSupported, diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index e535b3251a..90b5b06709 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -941,6 +941,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.interfaceInheritanceLint(node, interfaceNode.heritageClauses); } this.countDeclarationsWithDuplicateName(interfaceNode.name, interfaceNode); + this.handleLocalDeclarationOfClassAndIface(interfaceNode); } private handleTryStatement(node: ts.TryStatement): void { @@ -3283,6 +3284,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleInvalidIdentifier(tsClassDecl); this.handleSdkMethod(tsClassDecl); this.handleNotsLikeSmartType(tsClassDecl); + this.handleLocalDeclarationOfClassAndIface(tsClassDecl); } private static findFinalExpression(typeNode: ts.TypeNode): ts.Node { @@ -9308,6 +9310,32 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return undefined; } + private handleLocalDeclarationOfClassAndIface(node: ts.ClassDeclaration | ts.InterfaceDeclaration): void { + if (!this.options.arkts2) { + return; + } + this.isLocalClass(node); + } + + private isLocalClass(node: ts.Node): void { + if ( + ts.findAncestor(node, (node) => { + return ( + ts.isArrowFunction(node) || + ts.isFunctionDeclaration(node) || + ts.isMethodDeclaration(node) || + ts.isFunctionExpression(node) || + ts.isConstructorDeclaration(node) || + ts.isGetAccessor(node) || + ts.isSetAccessor(node) || + ts.isBlock(node) + ); + }) + ) { + this.incrementCounters(node, FaultID.NoLocalClass); + } + } + private processPropertyAccessExpression(expression: ts.PropertyAccessExpression): ts.Symbol | undefined { const heritageSymbol = this.tsTypeChecker.getSymbolAtLocation(expression.expression); if (heritageSymbol && expression.name.text === this.getLocalApiListItemByKey(SdkNameInfo.ParentApiName)) { diff --git a/ets2panda/linter/test/interop/unique_types.ets.arkts2.json b/ets2panda/linter/test/interop/unique_types.ets.arkts2.json index ad93ff0af7..afc18ac2cf 100644 --- a/ets2panda/linter/test/interop/unique_types.ets.arkts2.json +++ b/ets2panda/linter/test/interop/unique_types.ets.arkts2.json @@ -494,6 +494,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 323, + "column": 5, + "endLine": 325, + "endColumn": 6, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 326, "column": 23, @@ -524,6 +534,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 372, + "column": 5, + "endLine": 374, + "endColumn": 6, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 375, "column": 23, @@ -575,4 +595,4 @@ "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/interop/unique_types.ets.autofix.json b/ets2panda/linter/test/interop/unique_types.ets.autofix.json index 203ab57067..bddd995dab 100644 --- a/ets2panda/linter/test/interop/unique_types.ets.autofix.json +++ b/ets2panda/linter/test/interop/unique_types.ets.autofix.json @@ -549,6 +549,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 323, + "column": 5, + "endLine": 325, + "endColumn": 6, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 326, "column": 23, @@ -590,6 +600,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 372, + "column": 5, + "endLine": 374, + "endColumn": 6, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 375, "column": 23, @@ -652,4 +672,4 @@ "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/interop/unique_types.ets.migrate.json b/ets2panda/linter/test/interop/unique_types.ets.migrate.json index 3eb75a8fe4..28d850fbfb 100644 --- a/ets2panda/linter/test/interop/unique_types.ets.migrate.json +++ b/ets2panda/linter/test/interop/unique_types.ets.migrate.json @@ -444,6 +444,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 323, + "column": 5, + "endLine": 325, + "endColumn": 6, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 357, "column": 7, @@ -464,6 +474,16 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 372, + "column": 5, + "endLine": 374, + "endColumn": 6, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 184, "column": 3, @@ -505,4 +525,4 @@ "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/extends_expression.ets.arkts2.json b/ets2panda/linter/test/main/extends_expression.ets.arkts2.json index 789b06a0ff..7dc351bfde 100755 --- a/ets2panda/linter/test/main/extends_expression.ets.arkts2.json +++ b/ets2panda/linter/test/main/extends_expression.ets.arkts2.json @@ -114,6 +114,26 @@ "rule": "Function return type inference is limited (arkts-no-implicit-return-types)", "severity": "ERROR" }, + { + "line": 62, + "column": 3, + "endLine": 66, + "endColumn": 4, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 67, + "column": 3, + "endLine": 71, + "endColumn": 4, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 73, "column": 12, @@ -155,4 +175,4 @@ "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/no_local_class.ets b/ets2panda/linter/test/main/no_local_class.ets new file mode 100644 index 0000000000..473c36c98a --- /dev/null +++ b/ets2panda/linter/test/main/no_local_class.ets @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// VALID: Class/interface can be declared outside of functions +class GlobalClass { } +interface GlobalInterface { } + +// INVALID: Class declared inside a function +function foo() { + class Boo { } +} + +// INVALID: Interface declared inside a function +function a() { + interface B { } +} + +// INVALID: Both class and interface declared inside a function +function b() { + interface C { } + class D { } +} + +// INVALID: Interface declared inside an arrow function +const poo = () => { + interface T { } +} + +// INVALID: Both interface and class declared inside an arrow function +const yoo = () => { + interface L { } + class Zoo { } +} + +// INVALID: Class declared inside an arrow function +const qoo = () => { + class Moo { } +} + +// INVALID: Class declared inside a function expression +const dest = function () { + class Doo { } +} + +// INVALID: Both class and interface declared inside a function expression +const test = function () { + class Koo { } + interface Goo { } +} + +// INVALID: Interface declared inside a function expression +const cast = function () { + interface Pop { } +} + +// INVALID: Class declared inside a top-level block statement +{ + class BlockLocal { } +} + +// INVALID: Interface declared inside a top-level block statement +{ + interface BlockIface { } +} + +// INVALID: Class declared inside an if block +if (true) { + class IfBlockClass { } +} + +// INVALID: Interface declared inside an if block +if (false) { + interface IfBlockIface { } +} + +// INVALID: Class declared inside a for loop block +for (let i = 0; i < 1; i++) { + class ForBlockClass { } +} + +// INVALID: Interface declared inside a for loop block +for (let i = 0; i < 1; i++) { + interface ForBlockIface { } +} + +// INVALID: Class declared inside a while loop block +while (false) { + class WhileBlockClass { } +} + +// INVALID: Interface declared inside a while loop block +while (false) { + interface WhileBlockIface { } +} + +// INVALID: Class declared inside a nested block (block inside block) +{ + { + class NestedBlockClass { } + } +} + +// INVALID: Interface declared inside a nested block (block inside block) +{ + { + interface NestedBlockIface { } + } +} + +// VALID: Type alias at top-level (should NOT warn) +type FooType = number; + +// NESTED CASE: Deeply nested class inside arrow functions +function xyc(): void { + const a1 = () => { + const b2 = () => { + class Abc { + + } + } + } +} + diff --git a/ets2panda/linter/test/main/no_local_class.ets.args.json b/ets2panda/linter/test/main/no_local_class.ets.args.json new file mode 100644 index 0000000000..d2ef7038fc --- /dev/null +++ b/ets2panda/linter/test/main/no_local_class.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2023-2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/no_local_class.ets.arkts2.json b/ets2panda/linter/test/main/no_local_class.ets.arkts2.json new file mode 100644 index 0000000000..8e76a64ab1 --- /dev/null +++ b/ets2panda/linter/test/main/no_local_class.ets.arkts2.json @@ -0,0 +1,338 @@ +{ + "copyright": [ + "Copyright (c) 2023-2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 22, + "column": 5, + "endLine": 22, + "endColumn": 18, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 5, + "endLine": 27, + "endColumn": 20, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 32, + "column": 5, + "endLine": 32, + "endColumn": 20, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 33, + "column": 5, + "endLine": 33, + "endColumn": 16, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 38, + "column": 5, + "endLine": 38, + "endColumn": 20, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 43, + "column": 5, + "endLine": 43, + "endColumn": 20, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 44, + "column": 5, + "endLine": 44, + "endColumn": 18, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 49, + "column": 5, + "endLine": 49, + "endColumn": 18, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 53, + "column": 14, + "endLine": 55, + "endColumn": 2, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "severity": "ERROR" + }, + { + "line": 54, + "column": 5, + "endLine": 54, + "endColumn": 18, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 14, + "endLine": 61, + "endColumn": 2, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "severity": "ERROR" + }, + { + "line": 59, + "column": 5, + "endLine": 59, + "endColumn": 18, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 60, + "column": 5, + "endLine": 60, + "endColumn": 22, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 14, + "endLine": 66, + "endColumn": 2, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "severity": "ERROR" + }, + { + "line": 65, + "column": 5, + "endLine": 65, + "endColumn": 22, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 70, + "column": 5, + "endLine": 70, + "endColumn": 25, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 75, + "column": 5, + "endLine": 75, + "endColumn": 29, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 80, + "column": 5, + "endLine": 80, + "endColumn": 27, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 85, + "column": 5, + "endLine": 85, + "endColumn": 31, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 89, + "column": 10, + "endLine": 89, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 89, + "column": 14, + "endLine": 89, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 89, + "column": 21, + "endLine": 89, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 90, + "column": 5, + "endLine": 90, + "endColumn": 28, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 94, + "column": 10, + "endLine": 94, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 94, + "column": 14, + "endLine": 94, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 94, + "column": 21, + "endLine": 94, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 95, + "column": 5, + "endLine": 95, + "endColumn": 32, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 100, + "column": 5, + "endLine": 100, + "endColumn": 30, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 105, + "column": 5, + "endLine": 105, + "endColumn": 34, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 111, + "column": 9, + "endLine": 111, + "endColumn": 35, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 118, + "column": 9, + "endLine": 118, + "endColumn": 39, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, + { + "line": 129, + "column": 13, + "endLine": 131, + "endColumn": 14, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + } + ] +} diff --git a/ets2panda/linter/test/main/no_local_class.ets.json b/ets2panda/linter/test/main/no_local_class.ets.json new file mode 100644 index 0000000000..8d562d8ee2 --- /dev/null +++ b/ets2panda/linter/test/main/no_local_class.ets.json @@ -0,0 +1,48 @@ +{ + "copyright": [ + "Copyright (c) 2023-2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 53, + "column": 14, + "endLine": 55, + "endColumn": 2, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "severity": "ERROR" + }, + { + "line": 58, + "column": 14, + "endLine": 61, + "endColumn": 2, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 14, + "endLine": 66, + "endColumn": 2, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", + "severity": "ERROR" + } + ] +} diff --git a/ets2panda/linter/test/main/object_literals_properties.ets.arkts2.json b/ets2panda/linter/test/main/object_literals_properties.ets.arkts2.json index a63a7a849d..57534ac619 100644 --- a/ets2panda/linter/test/main/object_literals_properties.ets.arkts2.json +++ b/ets2panda/linter/test/main/object_literals_properties.ets.arkts2.json @@ -934,6 +934,16 @@ "rule": "Object literal properties can only contain name-value pairs (arkts-obj-literal-props)", "severity": "ERROR" }, + { + "line": 167, + "column": 3, + "endLine": 167, + "endColumn": 37, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 167, "column": 34, @@ -1255,4 +1265,4 @@ "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/object_literals_properties.ets.autofix.json b/ets2panda/linter/test/main/object_literals_properties.ets.autofix.json index 432b311d06..f650bad3c8 100644 --- a/ets2panda/linter/test/main/object_literals_properties.ets.autofix.json +++ b/ets2panda/linter/test/main/object_literals_properties.ets.autofix.json @@ -1646,6 +1646,16 @@ "rule": "Object literal properties can only contain name-value pairs (arkts-obj-literal-props)", "severity": "ERROR" }, + { + "line": 167, + "column": 3, + "endLine": 167, + "endColumn": 37, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 167, "column": 34, @@ -2181,4 +2191,4 @@ "severity": "ERROR" } ] -} \ No newline at end of file +} diff --git a/ets2panda/linter/test/main/object_literals_properties.ets.migrate.json b/ets2panda/linter/test/main/object_literals_properties.ets.migrate.json index 35c8ec6cd0..056d7631eb 100644 --- a/ets2panda/linter/test/main/object_literals_properties.ets.migrate.json +++ b/ets2panda/linter/test/main/object_literals_properties.ets.migrate.json @@ -194,6 +194,16 @@ "rule": "Object literal properties can only contain name-value pairs (arkts-obj-literal-props)", "severity": "ERROR" }, + { + "line": 207, + "column": 3, + "endLine": 210, + "endColumn": 2, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 212, "column": 26, @@ -234,6 +244,16 @@ "rule": "Object literal properties can only contain name-value pairs (arkts-obj-literal-props)", "severity": "ERROR" }, + { + "line": 223, + "column": 3, + "endLine": 223, + "endColumn": 39, + "problem": "NoLocalClass", + "suggest": "", + "rule": "Creating local classes is not supported (arkts-no-local-class)", + "severity": "ERROR" + }, { "line": 224, "column": 27, @@ -365,4 +385,4 @@ "severity": "ERROR" } ] -} \ No newline at end of file +} -- Gitee