diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 9d3a0c173263c77c4b9b4d2f709c5b90b174b933..b2d74401d324731293f3c21f3dd465162f179a69 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -1033,8 +1033,10 @@ export class Autofixer { if (this.renameSymbolAsIdentifierCache.has(symbol)) { return this.renameSymbolAsIdentifierCache.get(symbol); } - - if (!TsUtils.isPropertyOfInternalClassOrInterface(symbol)) { + if ( + !TsUtils.isPropertyOfInternalClassOrInterface(symbol) && + !(enumMember?.parent && ts.isEnumDeclaration(enumMember.parent)) + ) { this.renameSymbolAsIdentifierCache.set(symbol, undefined); return undefined; } diff --git a/ets2panda/linter/src/lib/utils/TsUtils.ts b/ets2panda/linter/src/lib/utils/TsUtils.ts index 738928269d0a778b945d0e0c0b9c49f2cf55b3c8..318d5b22a7097788e978bfe43893d14a154d4bbe 100644 --- a/ets2panda/linter/src/lib/utils/TsUtils.ts +++ b/ets2panda/linter/src/lib/utils/TsUtils.ts @@ -2914,13 +2914,6 @@ export class TsUtils { if (TsUtils.hasModifier(ts.getModifiers(propDecl.parent), ts.SyntaxKind.ExportKeyword)) { return false; } - - if ( - ts.isStringLiteral(propDecl.name) && - (ts.isClassDeclaration(propDecl.parent) || ts.isInterfaceDeclaration(propDecl.parent)) - ) { - return false; - } } return true; diff --git a/ets2panda/linter/test/main/literals_as_prop_names.ets b/ets2panda/linter/test/main/literals_as_prop_names.ets index 0f2781e90b8c704334aef16842824a9d1ebd75ac..e0fd0882c2f421890539561d80d79c004339252f 100755 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets @@ -162,4 +162,14 @@ enum TEST2 { let de3 = TEST2[TEST.A] //error let de4 = TEST2[TEST.A| TEST.B] //error -let de5 = TEST[TEST.C] //ok \ No newline at end of file +let de5 = TEST[TEST.C] //ok + +export enum DeviceTypes12 { + PHONE = 'phone', + TABLET = 'tablet', + "2IN1" = '2in1', +} + +export class A{ + public static a= DeviceTypes12["2IN1"] +} \ No newline at end of file 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 25a3ca26f62f9baab6dbf8cc743387bf9b008a95..d7d3490723b86fd6da0f681c38dd5b5e78067cbc 100644 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets.arkts2.json +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets.arkts2.json @@ -754,6 +754,26 @@ "rule": "Enum cannot get member name by member value (arkts-enum-no-props-by-index)", "severity": "ERROR" }, + { + "line": 170, + "column": 3, + "endLine": 170, + "endColumn": 18, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 174, + "column": 20, + "endLine": 174, + "endColumn": 41, + "problem": "UnsupportPropNameFromValue", + "suggest": "", + "rule": "Enum cannot get member name by member value (arkts-enum-no-props-by-index)", + "severity": "ERROR" + }, { "line": 115, "column": 2, 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 127be23a53799c26b92a3aa385e0036f4dc58ded..bbe794fdbdaa4cf93adf2693d55ea1ffeba8a42c 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 @@ -89,6 +89,35 @@ "endLine": 27, "endColumn": 8, "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "Two", + "start": 849, + "end": 854, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + }, + { + "replacementText": "Two", + "start": 940, + "end": 945, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + }, + { + "replacementText": "litAsPropName.Two", + "start": 1032, + "end": 1052, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + } + ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -138,6 +167,35 @@ "endLine": 33, "endColumn": 8, "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "Two", + "start": 849, + "end": 854, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + }, + { + "replacementText": "Two", + "start": 940, + "end": 945, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + }, + { + "replacementText": "litAsPropName.Two", + "start": 1032, + "end": 1052, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + } + ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -229,6 +287,35 @@ "endLine": 38, "endColumn": 33, "problem": "PropertyAccessByIndex", + "autofix": [ + { + "replacementText": "Two", + "start": 849, + "end": 854, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + }, + { + "replacementText": "Two", + "start": 940, + "end": 945, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + }, + { + "replacementText": "litAsPropName.Two", + "start": 1032, + "end": 1052, + "line": 38, + "column": 13, + "endLine": 38, + "endColumn": 33 + } + ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", "severity": "ERROR" @@ -454,6 +541,26 @@ "endLine": 76, "endColumn": 8, "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "__2", + "start": 1739, + "end": 1744, + "line": 81, + "column": 3, + "endLine": 81, + "endColumn": 8 + }, + { + "replacementText": "__2", + "start": 1824, + "end": 1829, + "line": 81, + "column": 3, + "endLine": 81, + "endColumn": 8 + } + ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -504,6 +611,26 @@ "endLine": 81, "endColumn": 8, "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "__2", + "start": 1739, + "end": 1744, + "line": 81, + "column": 3, + "endLine": 81, + "endColumn": 8 + }, + { + "replacementText": "__2", + "start": 1824, + "end": 1829, + "line": 81, + "column": 3, + "endLine": 81, + "endColumn": 8 + } + ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -965,6 +1092,17 @@ "endLine": 132, "endColumn": 15, "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "age", + "start": 2466, + "end": 2471, + "line": 132, + "column": 10, + "endLine": 132, + "endColumn": 15 + } + ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -1278,6 +1416,46 @@ "rule": "Enum cannot get member name by member value (arkts-enum-no-props-by-index)", "severity": "ERROR" }, + { + "line": 170, + "column": 3, + "endLine": 170, + "endColumn": 18, + "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "__2IN1", + "start": 3173, + "end": 3179, + "line": 170, + "column": 3, + "endLine": 170, + "endColumn": 18 + }, + { + "replacementText": "DeviceTypes12.__2IN1", + "start": 3228, + "end": 3249, + "line": 170, + "column": 3, + "endLine": 170, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", + "severity": "ERROR" + }, + { + "line": 174, + "column": 20, + "endLine": 174, + "endColumn": 41, + "problem": "UnsupportPropNameFromValue", + "suggest": "", + "rule": "Enum cannot get member name by member value (arkts-enum-no-props-by-index)", + "severity": "ERROR" + }, { "line": 115, "column": 2, 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 0cbab448d613ab68550f99805762eeb01ddcea13..09312e6f0fa20beb9e4c0fb9935a6ab8f352a88f 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 @@ -29,18 +29,18 @@ enum LiteralAsPropertyNameEnum { class LiteralAsPropertyName { public one: string = "1111111111"; private __2: string; - 'Two': number; + Two: number; } const litAsPropName: LiteralAsPropertyName = { one: "1", __2: 'two', - 'Two': 2.0, + Two: 2.0, }; console.log(litAsPropName.one); console.log(litAsPropName.__2); -console.log(litAsPropName["Two"]); +console.log(litAsPropName.Two); class LiteralAsPropertyName_fix { public one: string = "1111111111"; @@ -82,12 +82,12 @@ console.log(x_fix._2); interface litAsPropNameIface { one: string; ___2: string; - '__2': number; + __2: number; } const int: litAsPropNameIface = { one: '12321', ___2: 'weqwewq', - '__2': 123.0 + __2: 123.0 }; const imp: ExportLitAsPropName = { 1: 234.0 }; @@ -138,7 +138,7 @@ let a:A = { age: 30.0} class B { - public 'age': number = 1.0 // error in arkts2 + public age: number = 1.0 // error in arkts2 } let obj11: Record = { @@ -171,4 +171,14 @@ enum TEST2 { let de3 = TEST2[TEST.A] //error let de4 = TEST2[TEST.A| TEST.B] //error -let de5 = TEST[TEST.C] //ok \ No newline at end of file +let de5 = TEST[TEST.C] //ok + +export enum DeviceTypes12 { + PHONE = 'phone', + TABLET = 'tablet', + __2IN1 = '2in1', +} + +export class A{ + public static a= DeviceTypes12.__2IN1 +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.json b/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.json index 3b5d627860fa5ce150f836bb8f54f8e8cd5e0c38..4f163766c468b80deca1333ffc31443247e46607 100644 --- a/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.json +++ b/ets2panda/linter/test/main/literals_as_prop_names.ets.migrate.json @@ -14,36 +14,6 @@ "limitations under the License." ], "result": [ - { - "line": 32, - "column": 3, - "endLine": 32, - "endColumn": 8, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 38, - "column": 3, - "endLine": 38, - "endColumn": 8, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 43, - "column": 13, - "endLine": 43, - "endColumn": 33, - "problem": "PropertyAccessByIndex", - "suggest": "", - "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", - "severity": "ERROR" - }, { "line": 62, "column": 9, @@ -94,16 +64,6 @@ "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)", "severity": "ERROR" }, - { - "line": 85, - "column": 3, - "endLine": 85, - "endColumn": 8, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, { "line": 87, "column": 7, @@ -114,16 +74,6 @@ "rule": "This keyword cannot be used as identifiers (arkts-invalid-identifier)", "severity": "ERROR" }, - { - "line": 90, - "column": 3, - "endLine": 90, - "endColumn": 8, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, { "line": 93, "column": 36, @@ -214,16 +164,6 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, - { - "line": 141, - "column": 10, - "endLine": 141, - "endColumn": 15, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, { "line": 145, "column": 3, @@ -354,6 +294,16 @@ "rule": "Property '__2' has no initializer and is not definitely assigned in the constructor.", "severity": "ERROR" }, + { + "line": 32, + "column": 3, + "endLine": 32, + "endColumn": 6, + "problem": "StrictDiagnostic", + "suggest": "Property 'Two' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'Two' has no initializer and is not definitely assigned in the constructor.", + "severity": "ERROR" + }, { "line": 47, "column": 11, diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json index f4e1b08a2126a8a998f337a662aa36b8cd859662..6b343da07c8cb9e1cbc00921defdef4529d93e6e 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.autofix.json @@ -207,6 +207,26 @@ "endLine": 35, "endColumn": 26, "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "name", + "start": 1117, + "end": 1123, + "line": 37, + "column": 18, + "endLine": 37, + "endColumn": 24 + }, + { + "replacementText": "name", + "start": 1210, + "end": 1216, + "line": 37, + "column": 18, + "endLine": 37, + "endColumn": 24 + } + ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -256,6 +276,17 @@ "endLine": 36, "endColumn": 26, "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "name", + "start": 1164, + "end": 1170, + "line": 36, + "column": 20, + "endLine": 36, + "endColumn": 26 + } + ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" @@ -266,6 +297,26 @@ "endLine": 37, "endColumn": 24, "problem": "LiteralAsPropertyName", + "autofix": [ + { + "replacementText": "name", + "start": 1117, + "end": 1123, + "line": 37, + "column": 18, + "endLine": 37, + "endColumn": 24 + }, + { + "replacementText": "name", + "start": 1210, + "end": 1216, + "line": 37, + "column": 18, + "endLine": 37, + "endColumn": 24 + } + ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", "severity": "ERROR" diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets index 81211a821a8d1a9666b154b73322f20c0c5a7ffd..a687cd7007513949ded25c8f0a3c23b3c6cab2f5 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.ets @@ -32,9 +32,9 @@ namespace NumericSemanticsDone { } namespace NoNumericSemantics { - interface X1 { "name": number, __2: number} - interface X2 { "name": number, _2: number} - let x: X1 = {"name": 20.0, __2: 30.0} // OK + interface X1 { name: number, __2: number} + interface X2 { name: number, _2: number} + let x: X1 = {name: 20.0, __2: 30.0} // OK console.log(x.__2); // OK let x_fix: X2 = {name: 20.0, _2: 20.0}; diff --git a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json index 3f86f1a88b08a4e9f8c826153a26827a9083cf8b..d7fd5e18c98f902efe9b7e1887594ef201a7abd9 100644 --- a/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json +++ b/ets2panda/linter/test/main/numeric_semantics2.ets.migrate.json @@ -54,36 +54,6 @@ "rule": "Non-declaration statements in namespaces are not supported (single semicolons are considered as empty non-declaration statements) (arkts-no-ns-statements)", "severity": "ERROR" }, - { - "line": 35, - "column": 20, - "endLine": 35, - "endColumn": 26, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 36, - "column": 20, - "endLine": 36, - "endColumn": 26, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, - { - "line": 37, - "column": 18, - "endLine": 37, - "endColumn": 24, - "problem": "LiteralAsPropertyName", - "suggest": "", - "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)", - "severity": "ERROR" - }, { "line": 42, "column": 17,