From b4302dcc5ec7933e7f2c0d69fb06c93191925a78 Mon Sep 17 00:00:00 2001 From: sefayilmazunal Date: Wed, 6 Aug 2025 15:16:24 +0300 Subject: [PATCH 1/4] abstract override check rule impl Description: arkts-distinct-abstract-method-default-return-type rule implemented Issue: ICRHUI Signed-off-by: sefayilmazunal --- 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 | 105 ++++++++++++++++++ ...ct_abstract_method_default_return_type.ets | 96 ++++++++++++++++ ...t_method_default_return_type.ets.args.json | 19 ++++ ...method_default_return_type.ets.arkts2.json | 88 +++++++++++++++ ...stract_method_default_return_type.ets.json | 17 +++ .../main/method_inheritance.ets.arkts2.json | 72 +++++++++++- 11 files changed, 402 insertions(+), 1 deletion(-) create mode 100644 ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets create mode 100644 ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.args.json create mode 100644 ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.arkts2.json create mode 100644 ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.json diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index dc1ab4b18f..9a7e730ff3 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -61,6 +61,7 @@ "arkts-limited-stdlib-no-setTransferList", "arkts-builtin-object-getOwnPropertyNames", "arkts-no-class-omit-interface-optional-prop", + "arkts-distinct-abstract-method-default-return-type", "arkts-class-no-signature-distinct-with-object-public-api", "arkts-no-sparse-array", "arkts-no-enum-prop-as-type", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 4d5245cdc2..0ce0319d40 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -240,6 +240,8 @@ cookBookTag[185] = 'syntax for import type is disabled (arkts-import-types)'; cookBookTag[186] = '"new" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)'; cookBookTag[187] = 'function "Math.pow()" behavior for ArkTS differs from Typescript version (arkts-math-pow-standard-diff)'; +cookBookTag[188] = + 'In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)'; cookBookTag[189] = 'Numeric semantics is different for integer values (arkts-numeric-semantic)'; cookBookTag[190] = 'Stricter assignments into variables of function type (arkts-incompatible-function-types)'; cookBookTag[191] = 'ASON is not supported. (arkts-no-need-stdlib-ason)'; diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index d52e47f475..b6ea49c9b1 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -153,6 +153,7 @@ faultsAttrs[FaultID.OptionalMethod] = new FaultAttributes(184); faultsAttrs[FaultID.ImportType] = new FaultAttributes(185); faultsAttrs[FaultID.DynamicCtorCall] = new FaultAttributes(186); faultsAttrs[FaultID.MathPow] = new FaultAttributes(187); +faultsAttrs[FaultID.InvalidAbstractOverrideReturnType] = new FaultAttributes(188); faultsAttrs[FaultID.NumericSemantics] = new FaultAttributes(189); faultsAttrs[FaultID.IncompationbleFunctionType] = new FaultAttributes(190); faultsAttrs[FaultID.LimitedStdLibNoASON] = new FaultAttributes(191); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index d2753c7fb5..6b2ba8b943 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -147,6 +147,7 @@ faultDesc[FaultID.OptionalMethod] = 'Optional method'; faultDesc[FaultID.ImportType] = 'Import type syntax'; faultDesc[FaultID.DynamicCtorCall] = 'Dynamic constructor call'; faultDesc[FaultID.MathPow] = 'Exponent call'; +faultDesc[FaultID.InvalidAbstractOverrideReturnType] = 'Missing return type on abstract method'; faultDesc[FaultID.IncompationbleFunctionType] = 'Incompationble function type'; faultDesc[FaultID.VoidOperator] = 'Void operator'; faultDesc[FaultID.ExponentOp] = 'Exponent operation'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index d607d731b1..d6d899c0fe 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -145,6 +145,7 @@ export enum FaultID { ImportType, DynamicCtorCall, MathPow, + InvalidAbstractOverrideReturnType, VoidOperator, ExponentOp, RegularExpressionLiteral, diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 2658cb6a0d..f5732a37f4 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -3924,6 +3924,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleLimitedVoidFunction(tsMethodDecl); this.checkVoidLifecycleReturn(tsMethodDecl); this.handleNoDeprecatedApi(tsMethodDecl); + this.checkAbstractOverrideReturnType(tsMethodDecl); } private checkObjectPublicApiMethods(node: ts.ClassDeclaration | ts.InterfaceDeclaration): void { @@ -10607,6 +10608,110 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return undefined; } + /** + * If a class method overrides a base-class abstract method that had no explicit return type, + * then any explicit return type other than `void` is an error. + * Also flags async overrides with no explicit annotation. + */ + private checkAbstractOverrideReturnType(method: ts.MethodDeclaration): void { + if (!this.options.arkts2) { + return; + } + + const baseClass = this.getDirectBaseClassOfGivenMethodDecl(method); + if (!baseClass) { + return; + } + + // Locate the abstract method in the inheritance chain + const methodName = method.name.getText(); + const baseMethod = this.findAbstractMethodInBaseChain(baseClass, methodName); + if (!baseMethod) { + return; + } + + // Only if base had no explicit return type + if (baseMethod.type) { + return; + } + + // If override declares a return type, and it isn't void → error + if (method.type && method.type.kind !== ts.SyntaxKind.VoidKeyword) { + const target = ts.isIdentifier(method.name) ? method.name : method; + this.incrementCounters(target, FaultID.InvalidAbstractOverrideReturnType); + + // Also catch async overrides with no explicit annotation (defaulting to Promise) + } else if (TsUtils.hasModifier(method.modifiers, ts.SyntaxKind.AsyncKeyword)) { + const target = ts.isIdentifier(method.name) ? method.name : method; + this.incrementCounters(target, FaultID.InvalidAbstractOverrideReturnType); + } + } + + /** + * Finds the direct superclass declaration for the given method's containing class. + * Returns undefined if the class has no extends clause or cannot resolve the base class. + */ + private getDirectBaseClassOfGivenMethodDecl(method: ts.MethodDeclaration): ts.ClassDeclaration | undefined { + // Must live in a class with an extends clause + const classDecl = method.parent; + if (!ts.isClassDeclaration(classDecl) || !classDecl.heritageClauses) { + return undefined; + } + + return this.getBaseClassDeclFromHeritageClause(classDecl.heritageClauses); + } + + /** + * Walks up the inheritance chain starting from `startClass` to find an abstract method + * named `methodName`. Returns the MethodDeclaration if found, otherwise `undefined`. + */ + private findAbstractMethodInBaseChain( + startClass: ts.ClassDeclaration, + methodName: string + ): ts.MethodDeclaration | undefined { + // Prevent infinite loops from circular extends + const visited = new Set(); + let current: ts.ClassDeclaration | undefined = startClass; + while (current && !visited.has(current)) { + visited.add(current); + const found = current.members.find((m) => { + return ( + ts.isMethodDeclaration(m) && + ts.isIdentifier(m.name) && + m.name.text === methodName && + TsUtils.hasModifier(m.modifiers, ts.SyntaxKind.AbstractKeyword) + ); + }) as ts.MethodDeclaration | undefined; + if (found) { + return found; + } + current = this.getBaseClassDeclFromHeritageClause(current.heritageClauses); + } + return undefined; + } + + getBaseClassDeclFromHeritageClause(clauses?: ts.NodeArray): ts.ClassDeclaration | undefined { + if (!clauses) { + return undefined; + } + + const ext = clauses.find((h) => { + return h.token === ts.SyntaxKind.ExtendsKeyword; + }); + if (!ext || ext.types.length === 0) { + return undefined; + } + + // Resolve the base-class declaration + const expr = ext.types[0].expression; + if (!ts.isIdentifier(expr)) { + return undefined; + } + + const sym = this.tsUtils.trueSymbolAtLocation(expr); + return sym?.declarations?.find(ts.isClassDeclaration); + } + /** * Checks for missing super() call in child classes that extend a parent class * with parameterized constructors. If parent class only has parameterized constructors diff --git a/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets new file mode 100644 index 0000000000..95dd7d9c28 --- /dev/null +++ b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 1: Simple override, no explicit type, non-async → OK +// Base has abstract foo() (no annotation), override without annotation defaults to void +abstract class A1 { + abstract foo(); +} +class B1 extends A1 { + foo() { // ✅ no error + // … + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 2: Explicit void override → OK +abstract class A2 { + abstract foo(); +} +class B2 extends A2 { + foo(): void { // ✅ no error + // … + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 3: Non-void override → ERROR +abstract class A3 { + abstract foo(); +} +class B3 extends A3 { + foo(): number { // ❌ should flag AbstractOverrideReturnTypeNotVoid + return 42; + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 4: Async override without annotation → ERROR +// async methods default to Promise, and base foo() had no type +abstract class A4 { + abstract foo(); +} +class B4 extends A4 { + async foo() { // ❌ should flag AbstractOverrideReturnTypeNotVoid + await Promise.resolve(); + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 5: Indirect inheritance through an intermediate class +abstract class A5 { + abstract foo(); +} +class B5 extends A5 { /* no override here */ } +class C5 extends B5 { + foo(): number { // ❌ should flag — walks up to A5 + return 1; + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 6: Base declares a return type +abstract class A6 { + abstract bar(): string; // explicit annotation +} +class B6 extends A6 { + bar() { // ✅ no error (base had annotation) + return "ok"; + } +} +class C6 extends A6 { + bar(): number { // ✅ no InvalidAbstractOverrideReturnType error (this rule only applies when base had no type and derived method's type is different from void) + return 123; + } +} + +// ─────────────────────────────────────────────────────────────────────────── +// CASE 7: Class with its own non-override method — no error +class OwnClass { + fooOwn() { // ✅ no error + return 'own'; + } +} diff --git a/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.args.json b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.args.json new file mode 100644 index 0000000000..bc4d2071da --- /dev/null +++ b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.arkts2.json b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.arkts2.json new file mode 100644 index 0000000000..82d3a8851c --- /dev/null +++ b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.arkts2.json @@ -0,0 +1,88 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 23, + "column": 3, + "endLine": 23, + "endColumn": 6, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 34, + "column": 10, + "endLine": 34, + "endColumn": 14, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 45, + "column": 3, + "endLine": 45, + "endColumn": 6, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 9, + "endLine": 57, + "endColumn": 12, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 57, + "column": 9, + "endLine": 57, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 3, + "endLine": 69, + "endColumn": 6, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, + { + "line": 85, + "column": 10, + "endLine": 85, + "endColumn": 16, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + } + ] +} diff --git a/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.json b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.json new file mode 100644 index 0000000000..ca88f857e9 --- /dev/null +++ b/ets2panda/linter/test/main/distinct_abstract_method_default_return_type.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json b/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json index 54216cf950..820ca0305b 100644 --- a/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json +++ b/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json @@ -244,6 +244,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 266, + "column": 9, + "endLine": 266, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 271, "column": 9, @@ -254,6 +264,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 271, + "column": 9, + "endLine": 271, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 277, "column": 15, @@ -264,6 +284,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 277, + "column": 9, + "endLine": 277, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 282, "column": 15, @@ -274,6 +304,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 282, + "column": 9, + "endLine": 282, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 287, "column": 15, @@ -284,6 +324,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 287, + "column": 9, + "endLine": 287, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 292, "column": 15, @@ -294,6 +344,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 292, + "column": 9, + "endLine": 292, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 298, "column": 10, @@ -304,6 +364,16 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 303, + "column": 3, + "endLine": 303, + "endColumn": 6, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 309, "column": 3, @@ -445,4 +515,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file -- Gitee From 019a183b023d33e2b1fc9fcffc91734369fea980 Mon Sep 17 00:00:00 2001 From: Raif Mirza Erten Date: Tue, 5 Aug 2025 16:46:15 +0300 Subject: [PATCH 2/4] arkts-limited-tuple-index-type rule Issue: #ICRD6M Description: arkts-limited-tuple-index-type rule rule implementation Signed-off-by: Raif Mirza Erten --- 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 | 97 +++++++++++++++++-- .../main/arkts-limited-tuple-index-type.ets | 31 ++++++ ...kts-limited-tuple-index-type.ets.args.json | 19 ++++ ...s-limited-tuple-index-type.ets.arkts2.json | 88 +++++++++++++++++ .../arkts-limited-tuple-index-type.ets.json | 17 ++++ 10 files changed, 249 insertions(+), 9 deletions(-) create mode 100644 ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets create mode 100644 ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.args.json create mode 100644 ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.arkts2.json create mode 100644 ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.json diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 9a7e730ff3..d8a5af3153 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -23,6 +23,7 @@ "arkts-optional-methods", "arkts-use-long-for-large-numeric-literal", "arkts-numeric-semantic", + "arkts-limited-tuple-index-type", "arkts-incompatible-function-types", "arkts-limited-void-type", "arkts-distinct-infinity-bitwise-inversion", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 0ce0319d40..42b12748da 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -90,7 +90,7 @@ cookBookTag[59] = '"delete" operator is not supported (arkts-no-delete)'; cookBookTag[60] = '"typeof" operator is allowed only in expression contexts (arkts-no-type-query)'; cookBookTag[61] = 'The bitwise inversion gives different result for "Infinity" (arkts-distinct-infinity-bitwise-inversion)'; -cookBookTag[62] = ''; +cookBookTag[62] = 'Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)'; cookBookTag[63] = ''; cookBookTag[64] = ''; cookBookTag[65] = '"instanceof" operator is partially supported (arkts-instanceof-ref-types)'; diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index b6ea49c9b1..bbd8785d7d 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -60,6 +60,7 @@ faultsAttrs[FaultID.UnaryArithmNotNumber] = new FaultAttributes(55); faultsAttrs[FaultID.DeleteOperator] = new FaultAttributes(59); faultsAttrs[FaultID.TypeQuery] = new FaultAttributes(60); faultsAttrs[FaultID.PrefixUnaryInfinity] = new FaultAttributes(61); +faultsAttrs[FaultID.TupleIndex] = new FaultAttributes(62); faultsAttrs[FaultID.InstanceofUnsupported] = new FaultAttributes(65); faultsAttrs[FaultID.InOperator] = new FaultAttributes(66); faultsAttrs[FaultID.DestructuringAssignment] = new FaultAttributes(69); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index 6b2ba8b943..9447e186cb 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -91,6 +91,7 @@ faultDesc[FaultID.TemplateStringType] = 'Template string type'; faultDesc[FaultID.ShorthandAmbientModuleDecl] = 'Shorthand ambient module declaration'; faultDesc[FaultID.LongNumeric] = 'Use long for big numbers'; faultDesc[FaultID.WildcardsInModuleName] = 'Wildcards in module name'; +faultDesc[FaultID.TupleIndex] = 'Non-negative integer index for tuples'; faultDesc[FaultID.UMDModuleDefinition] = 'UMD module definition'; faultDesc[FaultID.NewTarget] = '"new.target" meta-property'; faultDesc[FaultID.DefiniteAssignment] = faultDesc[FaultID.DefiniteAssignmentError] = 'Definite assignment assertion'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index d6d899c0fe..f88b74f18e 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -164,6 +164,7 @@ export enum FaultID { ArrayIndexExprType, AvoidUnionTypes, NoTuplesArrays, + TupleIndex, DoubleExclaBindingNotSupported, DoubleDollarBindingNotSupported, DollarBindingNotSupported, diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index f5732a37f4..8cd614e9bf 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -4998,6 +4998,10 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { ); const tsElemAccessArgType = this.tsTypeChecker.getTypeAtLocation(tsElementAccessExpr.argumentExpression); + if (this.options.arkts2 && this.tsUtils.isOrDerivedFrom(tsElemAccessBaseExprType, TsUtils.isTuple)) { + this.handleTupleIndex(tsElementAccessExpr); + } + if (this.tsUtils.hasEsObjectType(tsElementAccessExpr.expression)) { const faultId = this.options.arkts2 ? FaultID.EsValueTypeError : FaultID.EsValueType; this.incrementCounters(node, faultId); @@ -5014,6 +5018,80 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleNoDeprecatedApi(tsElementAccessExpr); } + private handleTupleIndex(expr: ts.ElementAccessExpression): void { + const value = expr.argumentExpression; + + if (this.isArgumentConstDotZero(value)) { + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + return; + } + + if (ts.isNumericLiteral(value)) { + const indexText = value.getText(); + const indexValue = Number(indexText); + const isValid = Number.isInteger(indexValue) && indexValue >= 0; + + if (!isValid) { + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + } + return; + } + + if (ts.isPrefixUnaryExpression(value)) { + const { operator, operand } = value; + const resolved = this.evaluateValueFromDeclaration(operand); + + if (typeof resolved === 'number') { + const final = operator === ts.SyntaxKind.MinusToken ? -resolved : resolved; + const isValid = Number.isInteger(final) && final >= 0; + if (!isValid) { + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + } + return; + } + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + return; + } + + const resolved = this.evaluateValueFromDeclaration(value); + if (typeof resolved === 'number') { + const isValid = Number.isInteger(resolved) && resolved >= 0; + if (!isValid) { + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + } + return; + } + + this.incrementCounters(expr as ts.Node, FaultID.TupleIndex); + } + + private isArgumentConstDotZero(expr: ts.Expression): boolean { + if (ts.isNumericLiteral(expr)) { + return expr.getText().endsWith('.0'); + } + + if (ts.isPrefixUnaryExpression(expr) && ts.isNumericLiteral(expr.operand)) { + return expr.operand.getText().endsWith('.0'); + } + + if (ts.isIdentifier(expr)) { + const declaration = this.tsUtils.getDeclarationNode(expr); + if (declaration && ts.isVariableDeclaration(declaration) && declaration.initializer) { + const init = declaration.initializer; + + if (ts.isNumericLiteral(init)) { + return init.getText().endsWith('.0'); + } + + if (ts.isPrefixUnaryExpression(init) && ts.isNumericLiteral(init.operand)) { + return init.operand.getText().endsWith('.0'); + } + } + } + + return false; + } + private checkPropertyAccessByIndex( tsElementAccessExpr: ts.ElementAccessExpression, tsElemAccessBaseExprType: ts.Type, @@ -5200,14 +5278,17 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!initializer) { return null; } - - if (!ts.isNumericLiteral(initializer)) { - return null; - } - - const numericValue = Number(initializer.text); - if (!Number.isInteger(numericValue)) { - return null; + let numericValue: number | null = null; + if (ts.isNumericLiteral(initializer)) { + numericValue = Number(initializer.text); + } else if (ts.isPrefixUnaryExpression(initializer) && ts.isNumericLiteral(initializer.operand)) { + const rawValue = Number(initializer.operand.text); + numericValue = + initializer.operator === ts.SyntaxKind.MinusToken ? + -rawValue : + initializer.operator === ts.SyntaxKind.PlusToken ? + rawValue : + null; } return numericValue; diff --git a/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets new file mode 100644 index 0000000000..2b73f47073 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let tuple: [number, number] = [1.0,2.0]; +tuple[-1]; +tuple[1]; +tuple[1.0]; +tuple[0.0]; +tuple[0]; +const a = 1; +tuple[a]; +tuple[-a]; +const b = -1; +tuple[b]; +tuple[-b]; +const c = 1.0; +tuple[c]; +tuple[-c]; + diff --git a/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.args.json b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.args.json new file mode 100644 index 0000000000..66fb88f859 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.arkts2.json b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.arkts2.json new file mode 100644 index 0000000000..4c0e206201 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.arkts2.json @@ -0,0 +1,88 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 17, + "column": 1, + "endLine": 17, + "endColumn": 10, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 1, + "endLine": 19, + "endColumn": 11, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 1, + "endLine": 20, + "endColumn": 11, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 24, + "column": 1, + "endLine": 24, + "endColumn": 10, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 1, + "endLine": 26, + "endColumn": 9, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 1, + "endLine": 29, + "endColumn": 9, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + }, + { + "line": 30, + "column": 1, + "endLine": 30, + "endColumn": 10, + "problem": "TupleIndex", + "suggest": "", + "rule": "Index of tuple must be non-negative integer (arkts-limited-tuple-index-type)", + "severity": "ERROR" + } + ] +} diff --git a/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.json b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.json new file mode 100644 index 0000000000..9f305c86d7 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-limited-tuple-index-type.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} -- Gitee From b8580bc1bc179126ff1de9e0b6a91d1f62b90bc5 Mon Sep 17 00:00:00 2001 From: sefayilmazunal Date: Thu, 7 Aug 2025 15:19:40 +0300 Subject: [PATCH 3/4] arkts-var-assignment-before-use remove Description: arkts-var-assignment-before-use rule has been removed Issue: ICP89G Signed-off-by: sefayilmazunal --- 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 | 36 ----- ..._sharedarraybuffer1_arkts2.ets.arkts2.json | 35 +---- ...sharedarraybuffer1_arkts2.ets.autofix.json | 35 +---- ...sharedarraybuffer1_arkts2.ets.migrate.json | 65 ++------ ...t_sharedarraybuffer_arkts2.ets.arkts2.json | 20 --- ..._sharedarraybuffer_arkts2.ets.autofix.json | 20 --- ..._sharedarraybuffer_arkts2.ets.migrate.json | 53 ++----- ...object_literal_constructor.ets.arkts2.json | 12 +- .../interop/unique_types3.ets.arkts2.json | 22 +-- ...arkts-array-type-immutable.ets.arkts2.json | 10 -- ...ts-no-template-string-type.ets.arkts2.json | 10 -- .../test/main/class_as_object.ets.arkts2.json | 12 +- .../main/collections_module.ets.arkts2.json | 20 --- .../main/collections_module.ets.autofix.json | 20 --- .../main/collections_module.ets.migrate.json | 20 --- .../main/definite_assignment.ets.arkts2.json | 20 --- .../test/main/es_object.ets.arkts2.json | 40 ----- .../func_inferred_type_args.ets.arkts2.json | 22 +-- .../main/invalid_identifier.ets.arkts2.json | 10 -- .../test/main/limit_void_type.ets.arkts2.json | 32 +--- .../main/limit_void_type.ets.autofix.json | 32 +--- .../main/limit_void_type.ets.migrate.json | 32 +--- .../main/limited_literal_type.ets.arkts2.json | 50 ------ .../main/method_inheritance.ets.arkts2.json | 30 ---- ...port_namespace_star_as_var.ets.arkts2.json | 10 -- .../main/numeric_semantics.ets.arkts2.json | 12 +- .../main/numeric_semantics.ets.autofix.json | 12 +- .../main/numeric_semantics.ets.migrate.json | 12 +- .../main/structural_identity.ets.arkts2.json | 12 +- ...ntity_extended_inheritance.ets.arkts2.json | 22 +-- .../test/main/var_assignment_before_use.ets | 58 ------- .../var_assignment_before_use.ets.args.json | 19 --- .../var_assignment_before_use.ets.arkts2.json | 148 ------------------ .../main/var_assignment_before_use.ets.json | 68 -------- .../test/main/worker_module.ets.arkts2.json | 22 +-- .../test/sdkcommonapi/sdk_xml.ets.arkts2.json | 10 -- ...cl_with_duplicate_name_sdk.ets.arkts2.json | 10 -- 42 files changed, 50 insertions(+), 1029 deletions(-) delete mode 100644 ets2panda/linter/test/main/var_assignment_before_use.ets delete mode 100644 ets2panda/linter/test/main/var_assignment_before_use.ets.args.json delete mode 100644 ets2panda/linter/test/main/var_assignment_before_use.ets.arkts2.json delete mode 100644 ets2panda/linter/test/main/var_assignment_before_use.ets.json diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index d8a5af3153..e2bf187f76 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -14,7 +14,6 @@ "arkts-no-function-return-this", "arkts-limited-stdlib", "arkts-no-class-add-super-prop-with-readonly", - "arkts-var-assignment-before-use", "arkts-concurrent-deprecated-apis", "arkts-no-classes-as-obj", "arkts-obj-literal-props", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 42b12748da..eaeedd2ab2 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -300,8 +300,6 @@ cookBookTag[268] = 'Direct usage of interop JS objects is not supported (arkts-i cookBookTag[269] = 'Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-expand-static-instance)'; cookBookTag[270] = 'ArkTS1.2 cannot catch a non Error instance thrown from JS code (arkts-interop-js2s-js-exception)'; -cookBookTag[271] = - 'After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)'; cookBookTag[272] = 'This API of process is obsolete in ArkTS 1.1. It\'s no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)'; cookBookTag[273] = diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index bbd8785d7d..8a6fe17151 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -206,7 +206,6 @@ faultsAttrs[FaultID.InteropJsObjectCallStaticFunc] = new FaultAttributes(267, Pr faultsAttrs[FaultID.InteropJsObjectConditionJudgment] = new FaultAttributes(268); faultsAttrs[FaultID.InteropJsObjectExpandStaticInstance] = new FaultAttributes(269); faultsAttrs[FaultID.InteropJSFunctionInvoke] = new FaultAttributes(270); -faultsAttrs[FaultID.VariableMissingInitializer] = new FaultAttributes(271); faultsAttrs[FaultID.DeprecatedProcessApi] = new FaultAttributes(272); faultsAttrs[FaultID.NumericUnsignedShiftBehaviorChange] = new FaultAttributes(273); faultsAttrs[FaultID.MissingSuperCall] = new FaultAttributes(274); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index 9447e186cb..66ca12b4ba 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -175,7 +175,6 @@ faultDesc[FaultID.MethodOverridingField] = '"Method overriding field" to keep st faultDesc[FaultID.InteropJsObjectConditionJudgment] = 'Interop JS Object usage in a condition'; faultDesc[FaultID.InteropJsObjectExpandStaticInstance] = 'Interop JS function usage'; faultDesc[FaultID.InteropJSFunctionInvoke] = 'Interop JS function invoke'; -faultDesc[FaultID.VariableMissingInitializer] = 'Value must be assigned to variable'; faultDesc[FaultID.NotSupportTupleGenericValidation] = 'No Tuple type in Generic'; faultDesc[FaultID.DeprecatedProcessApi] = 'This process Api no longer supported in ArkTS 1.2'; faultDesc[FaultID.ExplicitFunctionType] = 'Not explicit function type'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index f88b74f18e..0c2e333805 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -195,7 +195,6 @@ export enum FaultID { InteropDirectAccessToTSTypes, InteropTSFunctionInvoke, InteropJSFunctionInvoke, - VariableMissingInitializer, DeprecatedProcessApi, LimitedVoidTypeFromSdk, EntryAnnotation, diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 8cd614e9bf..3b7a5a6a4e 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -2754,45 +2754,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handlePropertyDescriptorInScenarios(tsVarDecl); this.handleSdkGlobalApi(tsVarDecl); this.handleNoDeprecatedApi(tsVarDecl); - this.handleMissingInitializer(tsVarDecl); this.checkNumericSemanticsForVariable(tsVarDecl); } - /** - * Reports an error if a `let`/`const` declaration lacks an initializer. - */ - private handleMissingInitializer(decl: ts.VariableDeclaration): void { - if (!this.options.arkts2) { - return; - } - - const list = decl.parent as ts.VariableDeclarationList; - if (!(list.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const))) { - return; - } - - // Skip for‐of/for‐in loop bindings - const parentStmt = list.parent; - if (ts.isForOfStatement(parentStmt) || ts.isForInStatement(parentStmt)) { - return; - } - - // Skip explicit function‐type declarations (they are more like methods) - if (decl.type && ts.isFunctionTypeNode(decl.type)) { - return; - } - - // Skip variables declared as void—voids are handled by a different rule - if (decl.type && decl.type.kind === ts.SyntaxKind.VoidKeyword) { - return; - } - - // If no initializer, report - if (!decl.initializer) { - this.incrementCounters(decl.name, FaultID.VariableMissingInitializer); - } - } - private checkNumericSemanticsForBinaryExpression(node: ts.BinaryExpression): void { if (!this.options.arkts2) { return; diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json index 1f7540062c..ca88f857e9 100755 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json @@ -13,36 +13,5 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [ - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 7, - "endLine": 24, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 28, - "column": 7, - "endLine": 28, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - } - ] -} + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json index 1f7540062c..ca88f857e9 100755 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json @@ -13,36 +13,5 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [ - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 7, - "endLine": 24, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 28, - "column": 7, - "endLine": 28, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - } - ] -} + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json index d0fa8937d5..ca88f857e9 100755 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json @@ -1,48 +1,17 @@ -{ - "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "result": [ - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 7, - "endLine": 24, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 28, - "column": 7, - "endLine": 28, - "endColumn": 9, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - } - ] -} +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.arkts2.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.arkts2.json index e702358e51..afa0bcaf5d 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.arkts2.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.arkts2.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 16, - "column": 5, - "endLine": 16, - "endColumn": 13, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 16, "column": 15, @@ -64,16 +54,6 @@ "rule": "SharedArrayBuffer is not supported (arkts-no-need-stdlib-sharedArrayBuffer)", "severity": "ERROR" }, - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 22, "column": 28, diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.autofix.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.autofix.json index 07ba20c5cc..5665081830 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.autofix.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.autofix.json @@ -14,16 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 16, - "column": 5, - "endLine": 16, - "endColumn": 13, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 16, "column": 15, @@ -108,16 +98,6 @@ "rule": "SharedArrayBuffer is not supported (arkts-no-need-stdlib-sharedArrayBuffer)", "severity": "ERROR" }, - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 22, "column": 28, diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.migrate.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.migrate.json index 1b71547ad7..ca88f857e9 100644 --- a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.migrate.json +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer_arkts2.ets.migrate.json @@ -1,38 +1,17 @@ { - "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "result": [ - { - "line": 16, - "column": 5, - "endLine": 16, - "endColumn": 13, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - } - ] -} + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/object_literal_constructor.ets.arkts2.json b/ets2panda/linter/test/interop/object_literal_constructor.ets.arkts2.json index b9f57ab5c0..a9680f6f23 100644 --- a/ets2panda/linter/test/interop/object_literal_constructor.ets.arkts2.json +++ b/ets2panda/linter/test/interop/object_literal_constructor.ets.arkts2.json @@ -124,16 +124,6 @@ "rule": "Object literal cannot be directly assigned to class with a constructor. (arkts-interop-d2s-object-literal-no-args-constructor)", "severity": "ERROR" }, - { - "line": 67, - "column": 5, - "endLine": 67, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 69, "column": 5, @@ -165,4 +155,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json b/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json index 92f20acbdf..88d820858d 100644 --- a/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json +++ b/ets2panda/linter/test/interop/unique_types3.ets.arkts2.json @@ -594,16 +594,6 @@ "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", "severity": "ERROR" }, - { - "line": 195, - "column": 9, - "endLine": 195, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 195, "column": 13, @@ -644,16 +634,6 @@ "rule": "Cannot access typescript types directly (arkts-interop-ts2s-static-access-ts-type)", "severity": "ERROR" }, - { - "line": 201, - "column": 9, - "endLine": 201, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 201, "column": 12, @@ -715,4 +695,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-array-type-immutable.ets.arkts2.json b/ets2panda/linter/test/main/arkts-array-type-immutable.ets.arkts2.json index fa2a742d07..b8110abb5b 100644 --- a/ets2panda/linter/test/main/arkts-array-type-immutable.ets.arkts2.json +++ b/ets2panda/linter/test/main/arkts-array-type-immutable.ets.arkts2.json @@ -24,16 +24,6 @@ "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", "severity": "ERROR" }, - { - "line": 22, - "column": 5, - "endLine": 22, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 23, "column": 1, diff --git a/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json b/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json index 761207d787..a09f343947 100644 --- a/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json +++ b/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json @@ -44,16 +44,6 @@ "rule": "Template string type is not supported (arkts-no-template-string-type)", "severity": "ERROR" }, - { - "line": 25, - "column": 5, - "endLine": 25, - "endColumn": 13, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 25, "column": 15, diff --git a/ets2panda/linter/test/main/class_as_object.ets.arkts2.json b/ets2panda/linter/test/main/class_as_object.ets.arkts2.json index ae6c793e86..46d9c9c834 100644 --- a/ets2panda/linter/test/main/class_as_object.ets.arkts2.json +++ b/ets2panda/linter/test/main/class_as_object.ets.arkts2.json @@ -214,16 +214,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 98, - "column": 5, - "endLine": 98, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 98, "column": 8, @@ -735,4 +725,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/collections_module.ets.arkts2.json b/ets2panda/linter/test/main/collections_module.ets.arkts2.json index 2c8d9f8365..e3169afb99 100644 --- a/ets2panda/linter/test/main/collections_module.ets.arkts2.json +++ b/ets2panda/linter/test/main/collections_module.ets.arkts2.json @@ -94,16 +94,6 @@ "rule": "Sendable containers are not supported (arkts-no-need-stdlib-sendable-containers)", "severity": "ERROR" }, - { - "line": 32, - "column": 7, - "endLine": 32, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 32, "column": 21, @@ -134,16 +124,6 @@ "rule": "Sendable containers are not supported (arkts-no-need-stdlib-sendable-containers)", "severity": "ERROR" }, - { - "line": 36, - "column": 7, - "endLine": 36, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 40, "column": 22, diff --git a/ets2panda/linter/test/main/collections_module.ets.autofix.json b/ets2panda/linter/test/main/collections_module.ets.autofix.json index 9afdf943ba..717aaa4ab4 100644 --- a/ets2panda/linter/test/main/collections_module.ets.autofix.json +++ b/ets2panda/linter/test/main/collections_module.ets.autofix.json @@ -227,16 +227,6 @@ "rule": "Sendable containers are not supported (arkts-no-need-stdlib-sendable-containers)", "severity": "ERROR" }, - { - "line": 32, - "column": 7, - "endLine": 32, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 32, "column": 21, @@ -300,16 +290,6 @@ "rule": "Sendable containers are not supported (arkts-no-need-stdlib-sendable-containers)", "severity": "ERROR" }, - { - "line": 36, - "column": 7, - "endLine": 36, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 40, "column": 22, diff --git a/ets2panda/linter/test/main/collections_module.ets.migrate.json b/ets2panda/linter/test/main/collections_module.ets.migrate.json index 5a14ab57e1..9b9298a1b6 100644 --- a/ets2panda/linter/test/main/collections_module.ets.migrate.json +++ b/ets2panda/linter/test/main/collections_module.ets.migrate.json @@ -14,26 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 32, - "column": 7, - "endLine": 32, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 36, - "column": 7, - "endLine": 36, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 41, "column": 11, diff --git a/ets2panda/linter/test/main/definite_assignment.ets.arkts2.json b/ets2panda/linter/test/main/definite_assignment.ets.arkts2.json index 5a0520e0f2..cd7c54679e 100644 --- a/ets2panda/linter/test/main/definite_assignment.ets.arkts2.json +++ b/ets2panda/linter/test/main/definite_assignment.ets.arkts2.json @@ -24,26 +24,6 @@ "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", "severity": "ERROR" }, - { - "line": 16, - "column": 5, - "endLine": 16, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 5, - "endLine": 24, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 33, "column": 3, diff --git a/ets2panda/linter/test/main/es_object.ets.arkts2.json b/ets2panda/linter/test/main/es_object.ets.arkts2.json index 0fc6f0e05a..7463fcb51f 100644 --- a/ets2panda/linter/test/main/es_object.ets.arkts2.json +++ b/ets2panda/linter/test/main/es_object.ets.arkts2.json @@ -34,26 +34,6 @@ "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, - { - "line": 20, - "column": 5, - "endLine": 20, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 21, - "column": 5, - "endLine": 21, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 21, "column": 9, @@ -64,16 +44,6 @@ "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, - { - "line": 22, - "column": 5, - "endLine": 22, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 22, "column": 11, @@ -784,16 +754,6 @@ "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", "severity": "ERROR" }, - { - "line": 148, - "column": 5, - "endLine": 148, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 149, "column": 1, diff --git a/ets2panda/linter/test/main/func_inferred_type_args.ets.arkts2.json b/ets2panda/linter/test/main/func_inferred_type_args.ets.arkts2.json index 7b672d3e61..125bd65b78 100755 --- a/ets2panda/linter/test/main/func_inferred_type_args.ets.arkts2.json +++ b/ets2panda/linter/test/main/func_inferred_type_args.ets.arkts2.json @@ -74,16 +74,6 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, - { - "line": 56, - "column": 5, - "endLine": 56, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 56, "column": 8, @@ -224,16 +214,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 72, - "column": 7, - "endLine": 72, - "endColumn": 8, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 72, "column": 10, @@ -725,4 +705,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json b/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json index 9a3582fd08..1041e601a3 100644 --- a/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json +++ b/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json @@ -714,16 +714,6 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, - { - "line": 210, - "column": 9, - "endLine": 210, - "endColumn": 15, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 214, "column": 13, diff --git a/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json b/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json index 8466667c74..b388ce8814 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.arkts2.json @@ -994,16 +994,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 169, - "column": 5, - "endLine": 169, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 169, "column": 12, @@ -1014,16 +1004,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 172, - "column": 5, - "endLine": 172, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 174, "column": 22, @@ -1064,16 +1044,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 200, - "column": 5, - "endLine": 200, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 201, "column": 19, @@ -1655,4 +1625,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json index b558bfd5f1..eed9dfb9db 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.autofix.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.autofix.json @@ -1087,16 +1087,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 169, - "column": 5, - "endLine": 169, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 169, "column": 12, @@ -1107,16 +1097,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 172, - "column": 5, - "endLine": 172, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 174, "column": 22, @@ -1157,16 +1137,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 200, - "column": 5, - "endLine": 200, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 201, "column": 19, @@ -2142,4 +2112,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json index 996008ade7..4af5f71eae 100644 --- a/ets2panda/linter/test/main/limit_void_type.ets.migrate.json +++ b/ets2panda/linter/test/main/limit_void_type.ets.migrate.json @@ -914,16 +914,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 177, - "column": 5, - "endLine": 177, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 177, "column": 12, @@ -934,16 +924,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 180, - "column": 5, - "endLine": 180, - "endColumn": 10, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 182, "column": 22, @@ -984,16 +964,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 208, - "column": 5, - "endLine": 208, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 209, "column": 19, @@ -1235,4 +1205,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/limited_literal_type.ets.arkts2.json b/ets2panda/linter/test/main/limited_literal_type.ets.arkts2.json index 4137773b30..3570308268 100644 --- a/ets2panda/linter/test/main/limited_literal_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/limited_literal_type.ets.arkts2.json @@ -44,26 +44,6 @@ "rule": "Literal types are restricted(arkts-limited-literal-types)", "severity": "ERROR" }, - { - "line": 19, - "column": 5, - "endLine": 19, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 22, - "column": 5, - "endLine": 22, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 30, "column": 7, @@ -74,26 +54,6 @@ "rule": "Literal types are restricted(arkts-limited-literal-types)", "severity": "ERROR" }, - { - "line": 35, - "column": 5, - "endLine": 35, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 36, - "column": 5, - "endLine": 36, - "endColumn": 12, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 39, "column": 22, @@ -124,16 +84,6 @@ "rule": "Literal types are restricted(arkts-limited-literal-types)", "severity": "ERROR" }, - { - "line": 44, - "column": 5, - "endLine": 44, - "endColumn": 8, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 44, "column": 10, diff --git a/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json b/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json index 820ca0305b..0e4ea28d2f 100644 --- a/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json +++ b/ets2panda/linter/test/main/method_inheritance.ets.arkts2.json @@ -404,16 +404,6 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, - { - "line": 319, - "column": 9, - "endLine": 319, - "endColumn": 11, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 324, "column": 3, @@ -424,16 +414,6 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, - { - "line": 325, - "column": 9, - "endLine": 325, - "endColumn": 11, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 330, "column": 3, @@ -444,16 +424,6 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, - { - "line": 331, - "column": 9, - "endLine": 331, - "endColumn": 11, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 336, "column": 16, diff --git a/ets2panda/linter/test/main/no_import_namespace_star_as_var.ets.arkts2.json b/ets2panda/linter/test/main/no_import_namespace_star_as_var.ets.arkts2.json index 6e0b7d9828..1266c69bfc 100644 --- a/ets2panda/linter/test/main/no_import_namespace_star_as_var.ets.arkts2.json +++ b/ets2panda/linter/test/main/no_import_namespace_star_as_var.ets.arkts2.json @@ -124,16 +124,6 @@ "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", "severity": "ERROR" }, - { - "line": 34, - "column": 5, - "endLine": 34, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 35, "column": 5, diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json b/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json index f7d3a8c29c..a41ae5fb22 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json @@ -24,16 +24,6 @@ "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", "severity": "ERROR" }, - { - "line": 57, - "column": 5, - "endLine": 57, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 92, "column": 19, @@ -505,4 +495,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json index da7ce528c0..ea95d2fc5c 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json @@ -24,16 +24,6 @@ "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", "severity": "ERROR" }, - { - "line": 57, - "column": 5, - "endLine": 57, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 92, "column": 19, @@ -868,4 +858,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json index 713d6b80a9..dc507ae5a9 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.json @@ -24,16 +24,6 @@ "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)", "severity": "ERROR" }, - { - "line": 67, - "column": 5, - "endLine": 67, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 102, "column": 19, @@ -255,4 +245,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/structural_identity.ets.arkts2.json b/ets2panda/linter/test/main/structural_identity.ets.arkts2.json index 5bbd4876a8..bdec107230 100644 --- a/ets2panda/linter/test/main/structural_identity.ets.arkts2.json +++ b/ets2panda/linter/test/main/structural_identity.ets.arkts2.json @@ -674,16 +674,6 @@ "rule": "Structural typing is not supported (arkts-no-structural-typing)", "severity": "ERROR" }, - { - "line": 507, - "column": 5, - "endLine": 507, - "endColumn": 7, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 511, "column": 1, @@ -1285,4 +1275,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/structural_identity_extended_inheritance.ets.arkts2.json b/ets2panda/linter/test/main/structural_identity_extended_inheritance.ets.arkts2.json index 4d493d1fed..39ff7c832c 100644 --- a/ets2panda/linter/test/main/structural_identity_extended_inheritance.ets.arkts2.json +++ b/ets2panda/linter/test/main/structural_identity_extended_inheritance.ets.arkts2.json @@ -24,26 +24,6 @@ "rule": "Array type is immutable in ArkTS1.2 (arkts-array-type-immutable)", "severity": "ERROR" }, - { - "line": 58, - "column": 5, - "endLine": 58, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 60, - "column": 5, - "endLine": 60, - "endColumn": 16, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 73, "column": 1, @@ -85,4 +65,4 @@ "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/var_assignment_before_use.ets b/ets2panda/linter/test/main/var_assignment_before_use.ets deleted file mode 100644 index 35554385ce..0000000000 --- a/ets2panda/linter/test/main/var_assignment_before_use.ets +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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. - */ - -// Positive (should be flagged) -let a: A; // ❌ VariableMissingInitializer -let b: number[]; // ❌ VariableMissingInitializer -let c: A; // ❌ VariableMissingInitializer -const x: X; // ❌ VariableMissingInitializer - -// Negative (should NOT be flagged) -// 1) Initialized declarations -let d: D = new D(); // ✅ OK -const y1: string = "hello"; // ✅ OK - -// 2) Function‐typed declarations are skipped -let add: (a: number, b: number) => number; // ✅ OK -let handler: (e: Event) => void; // ✅ OK - -// 3) Explicit void‐typed declarations are skipped -let v: void; // ✅ OK -const v2: void; // ✅ OK - -// 4) For…of and For…in loop bindings -for (let item of items) { // ✅ OK - console.log(item); -} - -for (let key in record) { // ✅ OK - console.log(key); -} - -// 5) Function declarations / expressions -function foo() { // ✅ OK - return 42; -} - -let bar = function() { // ✅ OK - return "hi"; -}; - -let baz = () => { // ✅ OK - return true; -}; - -// 6) Destructuring with initializer -let { x, y } = point; // ✅ OK diff --git a/ets2panda/linter/test/main/var_assignment_before_use.ets.args.json b/ets2panda/linter/test/main/var_assignment_before_use.ets.args.json deleted file mode 100644 index bc4d2071da..0000000000 --- a/ets2panda/linter/test/main/var_assignment_before_use.ets.args.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "mode": { - "arkts2": "" - } -} diff --git a/ets2panda/linter/test/main/var_assignment_before_use.ets.arkts2.json b/ets2panda/linter/test/main/var_assignment_before_use.ets.arkts2.json deleted file mode 100644 index f827da9ffb..0000000000 --- a/ets2panda/linter/test/main/var_assignment_before_use.ets.arkts2.json +++ /dev/null @@ -1,148 +0,0 @@ -{ - "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "result": [ - { - "line": 17, - "column": 5, - "endLine": 17, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 18, - "column": 5, - "endLine": 18, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 19, - "column": 5, - "endLine": 19, - "endColumn": 6, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 19, - "column": 10, - "endLine": 19, - "endColumn": 17, - "problem": "EsValueTypeError", - "suggest": "", - "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", - "severity": "ERROR" - }, - { - "line": 20, - "column": 7, - "endLine": 20, - "endColumn": 8, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, - { - "line": 24, - "column": 16, - "endLine": 24, - "endColumn": 17, - "problem": "DynamicCtorCall", - "suggest": "", - "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", - "severity": "ERROR" - }, - { - "line": 32, - "column": 8, - "endLine": 32, - "endColumn": 12, - "problem": "LimitedVoidType", - "suggest": "", - "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", - "severity": "ERROR" - }, - { - "line": 33, - "column": 11, - "endLine": 33, - "endColumn": 15, - "problem": "LimitedVoidType", - "suggest": "", - "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", - "severity": "ERROR" - }, - { - "line": 36, - "column": 10, - "endLine": 36, - "endColumn": 14, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 40, - "column": 14, - "endLine": 40, - "endColumn": 16, - "problem": "ForInStatement", - "suggest": "", - "rule": "\"for .. in\" is not supported (arkts-no-for-in)", - "severity": "ERROR" - }, - { - "line": 49, - "column": 11, - "endLine": 51, - "endColumn": 2, - "problem": "FunctionExpression", - "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", - "severity": "ERROR" - }, - { - "line": 58, - "column": 5, - "endLine": 58, - "endColumn": 21, - "problem": "DestructuringDeclaration", - "suggest": "", - "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", - "severity": "ERROR" - }, - { - "line": 29, - "column": 18, - "endLine": 29, - "endColumn": 23, - "problem": "UIInterfaceImport", - "suggest": "", - "rule": "The ArkUI interface \"Event\" should be imported before it is used (arkui-modular-interface)", - "severity": "ERROR" - } - ] -} \ No newline at end of file diff --git a/ets2panda/linter/test/main/var_assignment_before_use.ets.json b/ets2panda/linter/test/main/var_assignment_before_use.ets.json deleted file mode 100644 index 687dd6fe19..0000000000 --- a/ets2panda/linter/test/main/var_assignment_before_use.ets.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "result": [ - { - "line": 19, - "column": 10, - "endLine": 19, - "endColumn": 17, - "problem": "EsValueType", - "suggest": "", - "rule": "Usage of 'ESValue' type is restricted (arkts-limited-esobj)", - "severity": "WARNING" - }, - { - "line": 36, - "column": 10, - "endLine": 36, - "endColumn": 14, - "problem": "AnyType", - "suggest": "", - "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)", - "severity": "ERROR" - }, - { - "line": 40, - "column": 14, - "endLine": 40, - "endColumn": 16, - "problem": "ForInStatement", - "suggest": "", - "rule": "\"for .. in\" is not supported (arkts-no-for-in)", - "severity": "ERROR" - }, - { - "line": 49, - "column": 11, - "endLine": 51, - "endColumn": 2, - "problem": "FunctionExpression", - "suggest": "", - "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)", - "severity": "ERROR" - }, - { - "line": 58, - "column": 5, - "endLine": 58, - "endColumn": 21, - "problem": "DestructuringDeclaration", - "suggest": "", - "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)", - "severity": "ERROR" - } - ] -} diff --git a/ets2panda/linter/test/main/worker_module.ets.arkts2.json b/ets2panda/linter/test/main/worker_module.ets.arkts2.json index d01b01f98e..535d022afd 100644 --- a/ets2panda/linter/test/main/worker_module.ets.arkts2.json +++ b/ets2panda/linter/test/main/worker_module.ets.arkts2.json @@ -114,16 +114,6 @@ "rule": "Worker are not supported(arkts-no-need-stdlib-worker)", "severity": "ERROR" }, - { - "line": 34, - "column": 7, - "endLine": 34, - "endColumn": 14, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 34, "column": 16, @@ -153,16 +143,6 @@ "suggest": "", "rule": "Worker are not supported(arkts-no-need-stdlib-worker)", "severity": "ERROR" - }, - { - "line": 38, - "column": 7, - "endLine": 38, - "endColumn": 14, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" } ] -} +} \ No newline at end of file diff --git a/ets2panda/linter/test/sdkcommonapi/sdk_xml.ets.arkts2.json b/ets2panda/linter/test/sdkcommonapi/sdk_xml.ets.arkts2.json index f3ac4e12f2..e3df86ce85 100755 --- a/ets2panda/linter/test/sdkcommonapi/sdk_xml.ets.arkts2.json +++ b/ets2panda/linter/test/sdkcommonapi/sdk_xml.ets.arkts2.json @@ -364,16 +364,6 @@ "rule": "The \"ConvertOptions\" in SDK is no longer supported.(sdk-method-not-supported)", "severity": "ERROR" }, - { - "line": 54, - "column": 5, - "endLine": 54, - "endColumn": 8, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 54, "column": 9, diff --git a/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json b/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json index 709ee01e70..ec1d247f94 100644 --- a/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json +++ b/ets2panda/linter/test/sdkwhite/decl_with_duplicate_name_sdk.ets.arkts2.json @@ -154,16 +154,6 @@ "rule": "API path have changed - please update your imports accordingly (sdk-no-decl-with-duplicate-name)", "severity": "ERROR" }, - { - "line": 52, - "column": 5, - "endLine": 52, - "endColumn": 19, - "problem": "VariableMissingInitializer", - "suggest": "", - "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", - "severity": "ERROR" - }, { "line": 53, "column": 18, -- Gitee From 1e07369ff1ebd64bd7b17c8efd30b9f345fee669 Mon Sep 17 00:00:00 2001 From: cihatfurkaneken Date: Fri, 8 Aug 2025 10:58:53 +0300 Subject: [PATCH 4/4] no-inferred-generic-params autofix bugfix Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICR7WT Signed-off-by: cihatfurkaneken --- ets2panda/linter/src/cli/LinterCLI.ts | 6 ++ .../linter/src/lib/autofixes/Autofixer.ts | 6 +- .../test/main/func_inferred_type_args_2.ets | 18 +++- .../func_inferred_type_args_2.ets.arkts2.json | 40 +++++++++ ...func_inferred_type_args_2.ets.autofix.json | 84 +++++++++++++++++++ .../func_inferred_type_args_2.ets.migrate.ets | 18 +++- .../main/method_inheritance2.ets.arkts2.json | 34 ++++++++ 7 files changed, 201 insertions(+), 5 deletions(-) diff --git a/ets2panda/linter/src/cli/LinterCLI.ts b/ets2panda/linter/src/cli/LinterCLI.ts index 447a2358d1..b0851047c3 100644 --- a/ets2panda/linter/src/cli/LinterCLI.ts +++ b/ets2panda/linter/src/cli/LinterCLI.ts @@ -128,6 +128,12 @@ async function executeHomeCheckTask(scanTaskRelatedInfo: ScanTaskRelatedInfo): P migrationTool = null; scanTaskRelatedInfo.homeCheckResult = transferIssues2ProblemInfo(result); for (const [filePath, problems] of scanTaskRelatedInfo.homeCheckResult) { + if ( + !scanTaskRelatedInfo.cmdOptions.scanWholeProjectInHomecheck && + !scanTaskRelatedInfo.cmdOptions.inputFiles.includes(filePath) + ) { + continue; + } if (!scanTaskRelatedInfo.mergedProblems.has(filePath)) { scanTaskRelatedInfo.mergedProblems.set(filePath, []); } diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 3ef2aba012..c321277ede 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -4739,7 +4739,7 @@ export class Autofixer { return undefined; } - const typeArgs = Autofixer.getTypeArgumentsFromType(contextualType); + const typeArgs = this.getTypeArgumentsFromType(contextualType); if (typeArgs.length === 0) { return undefined; } @@ -5044,8 +5044,8 @@ export class Autofixer { return [{ start: identifier.getEnd(), end: identifier.getEnd(), replacementText: typeArgsText }]; } - static getTypeArgumentsFromType(type: ts.Type): ts.Type[] { - const typeReference = type as ts.TypeReference; + private getTypeArgumentsFromType(type: ts.Type): ts.Type[] { + const typeReference = this.utils.getNonNullableType(type) as ts.TypeReference; if (typeReference.typeArguments) { return [...typeReference.typeArguments]; } diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets b/ets2panda/linter/test/main/func_inferred_type_args_2.ets index 43830e5da0..173fc2a7ab 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets @@ -121,4 +121,20 @@ let subWeakSet = new SubWeakSet(); class C {} class D {} -let a: D<[C]> = new D(); \ No newline at end of file +let a: D<[C]> = new D(); + +function fun(a?:Map){ + let c:Map|undefined + if(a === undefined){ + a = new Map() + } + if(a){ + a = new Map() + } + if(c){ + c = new Map() + } + if(c === undefined){ + c = new Map() + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json index 788aaf8aaa..255cfcd961 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json @@ -534,6 +534,46 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 84, "column": 2, diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json index 6d8c8403ac..990925b779 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json @@ -787,6 +787,90 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3430, + "end": 3430, + "replacementText": "", + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3461, + "end": 3461, + "replacementText": "", + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3492, + "end": 3492, + "replacementText": "", + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3537, + "end": 3537, + "replacementText": "", + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 84, "column": 2, diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets index 3cfe89eaab..68520df9e2 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets @@ -128,4 +128,20 @@ let subWeakSet = new SubWeakSet(); class C {} class D {} -let a: D<[C]> = new D<[C]>(); \ No newline at end of file +let a: D<[C]> = new D<[C]>(); + +function fun(a?:Map){ + let c:Map|undefined + if(a === undefined){ + a = new Map() + } + if(a){ + a = new Map() + } + if(c){ + c = new Map() + } + if(c === undefined){ + c = new Map() + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json b/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json index 4e6f89111a..618278e62c 100755 --- a/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json +++ b/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "result": [ { "line": 46, @@ -240,6 +254,26 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 255, + "column": 9, + "endLine": 255, + "endColumn": 12, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, + { + "line": 258, + "column": 3, + "endLine": 258, + "endColumn": 7, + "problem": "InvalidAbstractOverrideReturnType", + "suggest": "", + "rule": "In 1.1, the default type obtained for the abstract method without the annotation type is any. In 1.2, the default type for the abstract method without the annotation type is void. (arkts-distinct-abstract-method-default-return-type)", + "severity": "ERROR" + }, { "line": 268, "column": 10, -- Gitee