From ecd8c077ebf5ce29c96df288b3113a710295ab57 Mon Sep 17 00:00:00 2001 From: ZhongNing Date: Fri, 13 Jun 2025 15:39:09 +0800 Subject: [PATCH] fix issue for arkts-numeric-semantic Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICEWVQ Test scenarios:new tests update to the linter Signed-off-by: ZhongNing --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 8 +- .../linter/src/lib/autofixes/Autofixer.ts | 18 +- .../array_index_expr_type.ets.arkts2.json | 10 + .../array_index_expr_type.ets.autofix.json | 21 ++ .../array_index_expr_type.ets.migrate.ets | 2 +- .../enum_not_support_float.ets.arkts2.json | 10 + .../explicit_function_type.ets.arkts2.json | 10 + .../explicit_function_type.ets.autofix.json | 21 ++ .../explicit_function_type.ets.migrate.ets | 2 +- .../test/main/exponent.ets.autofix.json | 4 +- .../main/invalid_identifier.ets.arkts2.json | 20 ++ .../literals_as_prop_names.ets.arkts2.json | 70 ++++ .../literals_as_prop_names.ets.autofix.json | 147 +++++++++ .../literals_as_prop_names.ets.migrate.ets | 14 +- .../linter/test/main/numeric_semantics.ets | 24 +- .../main/numeric_semantics.ets.arkts2.json | 140 ++++++++ .../main/numeric_semantics.ets.autofix.json | 306 +++++++++++++++++- .../main/numeric_semantics.ets.migrate.ets | 28 +- .../main/numeric_semantics2.ets.arkts2.json | 20 ++ .../main/numeric_semantics2.ets.autofix.json | 42 +++ .../main/numeric_semantics2.ets.migrate.ets | 4 +- .../main/prop_name_from_value.ets.arkts2.json | 60 ++++ .../test/main/swicth_expr.ets.arkts2.json | 20 ++ 23 files changed, 975 insertions(+), 26 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index a15641503f..b07a1ebe02 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -9519,10 +9519,14 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } return false; }; + const isStandardFloatFormat = (): boolean => { + const text = node.getText(); + return /\.\d*0+$/.test(text); + }; const isNoNeedFix = isInElementAccessExpression(node) || - ts.isEnumMember(node.parent) || - 'name' in node.parent && node.parent.name === node; + 'name' in node.parent && node.parent.name === node || + isStandardFloatFormat(); if (isNoNeedFix) { return; } diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 4ae5c87982..47fc286dab 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -4851,7 +4851,23 @@ export class Autofixer { fixNumericLiteralIntToNumber(node: ts.NumericLiteral): Autofix[] | undefined { void this; - return [{ start: node.getStart(), end: node.getEnd(), replacementText: `${node.getText()}.0` }]; + let replacementText = node.getText(); + let parent = node.parent; + + if (ts.isPrefixUnaryExpression(parent) && parent.operator === ts.SyntaxKind.MinusToken) { + replacementText = `-${replacementText}.0`; + return [{ + start: parent.getStart(), + end: node.getEnd(), + replacementText + }]; + } + + return [{ + start: node.getStart(), + end: node.getEnd(), + replacementText: `${replacementText}.0` + }]; } fixPropDecorator(node: ts.Decorator, decoratorName: string): Autofix[] { diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets.arkts2.json b/ets2panda/linter/test/main/array_index_expr_type.ets.arkts2.json index 3643204633..773b1bcf49 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/array_index_expr_type.ets.arkts2.json @@ -754,6 +754,16 @@ "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", "severity": "ERROR" }, + { + "line": 65, + "column": 8, + "endLine": 65, + "endColumn": 9, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 67, "column": 6, diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets.autofix.json b/ets2panda/linter/test/main/array_index_expr_type.ets.autofix.json index f3c4133394..395b7396d1 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets.autofix.json +++ b/ets2panda/linter/test/main/array_index_expr_type.ets.autofix.json @@ -1304,6 +1304,27 @@ "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)", "severity": "ERROR" }, + { + "line": 65, + "column": 8, + "endLine": 65, + "endColumn": 9, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1669, + "end": 1670, + "replacementText": "0.0", + "line": 65, + "column": 8, + "endLine": 65, + "endColumn": 9 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 67, "column": 6, diff --git a/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets b/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets index 5ba7613e1b..767d9a477f 100644 --- a/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/array_index_expr_type.ets.migrate.ets @@ -62,7 +62,7 @@ for (let i: int = 0.0; i < array2.length; i++) { let arr1:number[] = [1.0, 2.0, 3.0] enum TE{ AA = 1.12 - BB = 0 + BB = 0.0 } arr1[TE.AA as int]; arr1[TE.BB]; diff --git a/ets2panda/linter/test/main/enum_not_support_float.ets.arkts2.json b/ets2panda/linter/test/main/enum_not_support_float.ets.arkts2.json index ff258d6c12..95b3bdaefb 100644 --- a/ets2panda/linter/test/main/enum_not_support_float.ets.arkts2.json +++ b/ets2panda/linter/test/main/enum_not_support_float.ets.arkts2.json @@ -14,6 +14,16 @@ "limitations under the License." ], "result": [ + { + "line": 23, + "column": 7, + "endLine": 23, + "endColumn": 9, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 24, "column": 3, diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json b/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json index d79abde569..54fab7a23c 100755 --- a/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.arkts2.json @@ -224,6 +224,16 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, + { + "line": 133, + "column": 10, + "endLine": 133, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 139, "column": 3, diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json b/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json index d3870c4c8f..e56dd8d548 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json +++ b/ets2panda/linter/test/main/explicit_function_type.ets.autofix.json @@ -345,6 +345,27 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, + { + "line": 133, + "column": 10, + "endLine": 133, + "endColumn": 11, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2849, + "end": 2850, + "replacementText": "1.0", + "line": 133, + "column": 10, + "endLine": 133, + "endColumn": 11 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 139, "column": 3, diff --git a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets index 0a5b1a221f..b5a17d538d 100644 --- a/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets +++ b/ets2panda/linter/test/main/explicit_function_type.ets.migrate.ets @@ -130,7 +130,7 @@ let tup38:[['arkts'|Function, 1.0|true, false], string[], Function] = [['arkts', //枚举 enum E39 { Function, - BLUE = 1, + BLUE = 1.0, YELLOW } diff --git a/ets2panda/linter/test/main/exponent.ets.autofix.json b/ets2panda/linter/test/main/exponent.ets.autofix.json index ee4e3b4662..cc6218a973 100644 --- a/ets2panda/linter/test/main/exponent.ets.autofix.json +++ b/ets2panda/linter/test/main/exponent.ets.autofix.json @@ -231,9 +231,9 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 721, + "start": 720, "end": 722, - "replacementText": "1.0", + "replacementText": "-1.0", "line": 25, "column": 15, "endLine": 25, diff --git a/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json b/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json index df7367f9de..b1f3898c92 100644 --- a/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json +++ b/ets2panda/linter/test/main/invalid_identifier.ets.arkts2.json @@ -794,6 +794,16 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, + { + "line": 205, + "column": 12, + "endLine": 205, + "endColumn": 13, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 206, "column": 3, @@ -804,6 +814,16 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, + { + "line": 206, + "column": 9, + "endLine": 206, + "endColumn": 10, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 209, "column": 11, diff --git a/ets2panda/linter/test/main/literals_as_prop_names.ets.arkts2.json b/ets2panda/linter/test/main/literals_as_prop_names.ets.arkts2.json index f6df27e1d6..73e1aec039 100755 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets.arkts2.json +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets.arkts2.json @@ -334,6 +334,16 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 92, + "column": 9, + "endLine": 92, + "endColumn": 10, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 97, "column": 3, @@ -344,6 +354,16 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 97, + "column": 10, + "endLine": 97, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 98, "column": 3, @@ -354,6 +374,16 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 98, + "column": 13, + "endLine": 98, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 102, "column": 3, @@ -364,6 +394,16 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 102, + "column": 10, + "endLine": 102, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 103, "column": 3, @@ -374,6 +414,16 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 103, + "column": 13, + "endLine": 103, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 105, "column": 5, @@ -424,6 +474,16 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 109, + "column": 8, + "endLine": 109, + "endColumn": 9, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 112, "column": 1, @@ -434,6 +494,16 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 112, + "column": 9, + "endLine": 112, + "endColumn": 10, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 118, "column": 18, diff --git a/ets2panda/linter/test/main/literals_as_prop_names.ets.autofix.json b/ets2panda/linter/test/main/literals_as_prop_names.ets.autofix.json index d66cfd8c7c..7cdbaf9895 100644 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets.autofix.json +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets.autofix.json @@ -738,6 +738,27 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 92, + "column": 9, + "endLine": 92, + "endColumn": 10, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1996, + "end": 1997, + "replacementText": "1.0", + "line": 92, + "column": 9, + "endLine": 92, + "endColumn": 10 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 97, "column": 3, @@ -759,6 +780,27 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 97, + "column": 10, + "endLine": 97, + "endColumn": 11, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2040, + "end": 2041, + "replacementText": "1.0", + "line": 97, + "column": 10, + "endLine": 97, + "endColumn": 11 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 98, "column": 3, @@ -780,6 +822,27 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 98, + "column": 13, + "endLine": 98, + "endColumn": 14, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2055, + "end": 2056, + "replacementText": "1.0", + "line": 98, + "column": 13, + "endLine": 98, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 102, "column": 3, @@ -810,6 +873,27 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 102, + "column": 10, + "endLine": 102, + "endColumn": 11, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2095, + "end": 2096, + "replacementText": "1.0", + "line": 102, + "column": 10, + "endLine": 102, + "endColumn": 11 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 103, "column": 3, @@ -840,6 +924,27 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 103, + "column": 13, + "endLine": 103, + "endColumn": 14, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2110, + "end": 2111, + "replacementText": "1.0", + "line": 103, + "column": 13, + "endLine": 103, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 105, "column": 5, @@ -932,6 +1037,27 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 109, + "column": 8, + "endLine": 109, + "endColumn": 9, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2214, + "end": 2215, + "replacementText": "1.0", + "line": 109, + "column": 8, + "endLine": 109, + "endColumn": 9 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 112, "column": 1, @@ -953,6 +1079,27 @@ "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" }, + { + "line": 112, + "column": 9, + "endLine": 112, + "endColumn": 10, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2252, + "end": 2253, + "replacementText": "1.0", + "line": 112, + "column": 9, + "endLine": 112, + "endColumn": 10 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 118, "column": 18, diff --git a/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.ets b/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.ets index 5211df075e..5c91b9deba 100644 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.ets +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.ets @@ -95,27 +95,27 @@ LiteralAsPropertyNameEnum.PrivateTwo; { const enum Direction { - __empty = 1, + __empty = 1.0, } } const enum Direction16 { - ___x5c = 1, - __x5c = 1, + ___x5c = 1.0, + __x5c = 1.0, } const enum Direction17 { - ___x5c = 1, - __x5c = 1, + ___x5c = 1.0, + __x5c = 1.0, } let case17: number = Direction17.___x5c let case172: number = Direction17.__x5c const enum Direction11 { -__x21x21 = 1, +__x21x21 = 1.0, } const enum Direction23 { -aaa = 1, +aaa = 1.0, } // ArkUI @Component diff --git a/ets2panda/linter/test/main/numeric_semantics.ets b/ets2panda/linter/test/main/numeric_semantics.ets index e09d8b47cf..ff1a6aece7 100755 --- a/ets2panda/linter/test/main/numeric_semantics.ets +++ b/ets2panda/linter/test/main/numeric_semantics.ets @@ -202,4 +202,26 @@ for (let i:number = 0; i < 100; i++) { } let cancelIds:ArrayList = arr.subArrayList(6, 86) let a: Array = Array.from(cancelIds) -let arr1: Array = Array.from(new ArrayList()) \ No newline at end of file +let arr1: Array = Array.from(new ArrayList()) + +let a:number = 0.000; + +const b:number = 0.000; + +export enum WalletStageValue { + DEFAULT = 0, + SWIPE_INIT = -1, + SELECT_CARD = 1, + SWIPE_DOING = 2, + SWIPE_SUCCEED = 3, + SWIPE_FAILED = 4, + SWIPE_FINISHED = 5, +} + +export enum AnimationStage { + INIT = 0, + ENTER = 1, + ROTATING = 2, + EXIT_START = 3, + EXIT_END = 4, +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json b/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json index d7c46831b1..38ce8825f5 100755 --- a/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.arkts2.json @@ -514,6 +514,26 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, + { + "line": 112, + "column": 7, + "endLine": 112, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 113, + "column": 7, + "endLine": 113, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 115, "column": 7, @@ -1094,6 +1114,126 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 212, + "column": 13, + "endLine": 212, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 213, + "column": 17, + "endLine": 213, + "endColumn": 18, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 214, + "column": 17, + "endLine": 214, + "endColumn": 18, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 215, + "column": 17, + "endLine": 215, + "endColumn": 18, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 216, + "column": 19, + "endLine": 216, + "endColumn": 20, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 217, + "column": 18, + "endLine": 217, + "endColumn": 19, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 218, + "column": 20, + "endLine": 218, + "endColumn": 21, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 222, + "column": 10, + "endLine": 222, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 223, + "column": 11, + "endLine": 223, + "endColumn": 12, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 224, + "column": 14, + "endLine": 224, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 225, + "column": 16, + "endLine": 225, + "endColumn": 17, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 226, + "column": 14, + "endLine": 226, + "endColumn": 15, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 117, "column": 2, diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json index 5045e3f3cb..f32b87bf78 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics.ets.autofix.json @@ -704,9 +704,9 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 2067, + "start": 2066, "end": 2070, - "replacementText": "234.0", + "replacementText": "-234.0", "line": 85, "column": 11, "endLine": 85, @@ -1073,6 +1073,48 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, + { + "line": 112, + "column": 7, + "endLine": 112, + "endColumn": 8, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2446, + "end": 2447, + "replacementText": "1.0", + "line": 112, + "column": 7, + "endLine": 112, + "endColumn": 8 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 113, + "column": 7, + "endLine": 113, + "endColumn": 8, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 2468, + "end": 2469, + "replacementText": "2.0", + "line": 113, + "column": 7, + "endLine": 113, + "endColumn": 8 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 115, "column": 7, @@ -1636,9 +1678,9 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 3357, + "start": 3356, "end": 3358, - "replacementText": "1.0", + "replacementText": "-1.0", "line": 149, "column": 17, "endLine": 149, @@ -1657,9 +1699,9 @@ "problem": "NumericSemantics", "autofix": [ { - "start": 3361, + "start": 3360, "end": 3362, - "replacementText": "1.0", + "replacementText": "-1.0", "line": 149, "column": 21, "endLine": 149, @@ -2170,6 +2212,258 @@ "rule": "\"new\" expression with dynamic constructor type is not supported (arkts-no-dynamic-ctor-call)", "severity": "ERROR" }, + { + "line": 212, + "column": 13, + "endLine": 212, + "endColumn": 14, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5206, + "end": 5207, + "replacementText": "0.0", + "line": 212, + "column": 13, + "endLine": 212, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 213, + "column": 17, + "endLine": 213, + "endColumn": 18, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5225, + "end": 5227, + "replacementText": "-1.0", + "line": 213, + "column": 17, + "endLine": 213, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 214, + "column": 17, + "endLine": 214, + "endColumn": 18, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5246, + "end": 5247, + "replacementText": "1.0", + "line": 214, + "column": 17, + "endLine": 214, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 215, + "column": 17, + "endLine": 215, + "endColumn": 18, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5266, + "end": 5267, + "replacementText": "2.0", + "line": 215, + "column": 17, + "endLine": 215, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 216, + "column": 19, + "endLine": 216, + "endColumn": 20, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5288, + "end": 5289, + "replacementText": "3.0", + "line": 216, + "column": 19, + "endLine": 216, + "endColumn": 20 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 217, + "column": 18, + "endLine": 217, + "endColumn": 19, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5309, + "end": 5310, + "replacementText": "4.0", + "line": 217, + "column": 18, + "endLine": 217, + "endColumn": 19 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 218, + "column": 20, + "endLine": 218, + "endColumn": 21, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5332, + "end": 5333, + "replacementText": "5.0", + "line": 218, + "column": 20, + "endLine": 218, + "endColumn": 21 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 222, + "column": 10, + "endLine": 222, + "endColumn": 11, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5380, + "end": 5381, + "replacementText": "0.0", + "line": 222, + "column": 10, + "endLine": 222, + "endColumn": 11 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 223, + "column": 11, + "endLine": 223, + "endColumn": 12, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5394, + "end": 5395, + "replacementText": "1.0", + "line": 223, + "column": 11, + "endLine": 223, + "endColumn": 12 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 224, + "column": 14, + "endLine": 224, + "endColumn": 15, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5411, + "end": 5412, + "replacementText": "2.0", + "line": 224, + "column": 14, + "endLine": 224, + "endColumn": 15 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 225, + "column": 16, + "endLine": 225, + "endColumn": 17, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5430, + "end": 5431, + "replacementText": "3.0", + "line": 225, + "column": 16, + "endLine": 225, + "endColumn": 17 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 226, + "column": 14, + "endLine": 226, + "endColumn": 15, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 5447, + "end": 5448, + "replacementText": "4.0", + "line": 226, + "column": 14, + "endLine": 226, + "endColumn": 15 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 117, "column": 2, diff --git a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.ets b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.ets index cecf097403..ba4df96e9d 100644 --- a/ets2panda/linter/test/main/numeric_semantics.ets.migrate.ets +++ b/ets2panda/linter/test/main/numeric_semantics.ets.migrate.ets @@ -112,8 +112,8 @@ let g: number = an_array[] const a: number = 1.0 enum Test { - A = 1, // 显式赋值为 1 - B = 2 // 显式赋值为 2 + A = 1.0, // 显式赋值为 1 + B = 2.0 // 显式赋值为 2 } const test: number = Test.A; @@ -208,4 +208,26 @@ for (let i:number = 0.0; i < 100.0; i++) { } let cancelIds:ArrayList = arr.subArrayList(6.0, 86.0) let a: Array = Array.from(cancelIds) -let arr1: Array = Array.from(new ArrayList()) \ No newline at end of file +let arr1: Array = Array.from(new ArrayList()) + +let a:number = 0.000; + +const b:number = 0.000; + +export enum WalletStageValue { + DEFAULT = 0.0, + SWIPE_INIT = -1.0, + SELECT_CARD = 1.0, + SWIPE_DOING = 2.0, + SWIPE_SUCCEED = 3.0, + SWIPE_FAILED = 4.0, + SWIPE_FINISHED = 5.0, +} + +export enum AnimationStage { + INIT = 0.0, + ENTER = 1.0, + ROTATING = 2.0, + EXIT_START = 3.0, + EXIT_END = 4.0, +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.arkts2.json b/ets2panda/linter/test/main/numeric_semantics2.ets.arkts2.json index 6348e6c1b1..8c2a778ec9 100755 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.arkts2.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.arkts2.json @@ -224,6 +224,26 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 62, + "column": 13, + "endLine": 62, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 13, + "endLine": 63, + "endColumn": 14, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 68, "column": 28, diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json index 56b02d1556..890005064b 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json @@ -439,6 +439,48 @@ "rule": "Array bound not checked. (arkts-runtime-array-check)", "severity": "ERROR" }, + { + "line": 62, + "column": 13, + "endLine": 62, + "endColumn": 14, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1792, + "end": 1793, + "replacementText": "1.0", + "line": 62, + "column": 13, + "endLine": 62, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 63, + "column": 13, + "endLine": 63, + "endColumn": 14, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1808, + "end": 1809, + "replacementText": "2.0", + "line": 63, + "column": 13, + "endLine": 63, + "endColumn": 14 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 68, "column": 28, diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets index db5e2adfbe..3b6d90963d 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets @@ -61,8 +61,8 @@ namespace NoNumericSemantics { let h: number = arr[12. as int] enum E { - A = 1, - B = 2 + A = 1.0, + B = 2.0 } } diff --git a/ets2panda/linter/test/main/prop_name_from_value.ets.arkts2.json b/ets2panda/linter/test/main/prop_name_from_value.ets.arkts2.json index 8cd1ddc908..adf8e2459e 100644 --- a/ets2panda/linter/test/main/prop_name_from_value.ets.arkts2.json +++ b/ets2panda/linter/test/main/prop_name_from_value.ets.arkts2.json @@ -103,6 +103,66 @@ "suggest": "", "rule": "Enum cannot get member name by member value (arkts-unsupport-prop-name-from-value)", "severity": "ERROR" + }, + { + "line": 40, + "column": 27, + "endLine": 40, + "endColumn": 29, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 17, + "endLine": 41, + "endColumn": 18, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 26, + "endLine": 41, + "endColumn": 27, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 35, + "endLine": 41, + "endColumn": 36, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 47, + "column": 7, + "endLine": 47, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 7, + "endLine": 48, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/swicth_expr.ets.arkts2.json b/ets2panda/linter/test/main/swicth_expr.ets.arkts2.json index 5ce55a54ac..207e0d7ebf 100755 --- a/ets2panda/linter/test/main/swicth_expr.ets.arkts2.json +++ b/ets2panda/linter/test/main/swicth_expr.ets.arkts2.json @@ -174,6 +174,26 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, + { + "line": 67, + "column": 7, + "endLine": 67, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 68, + "column": 7, + "endLine": 68, + "endColumn": 8, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, { "line": 70, "column": 7, -- Gitee