diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index f92cb256be93530ad9bf0680bd9ab6fde85fa2be..a9954c677b2001aff7f2c9e159af50f4f8a78a55 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -757,12 +757,10 @@ export class TypeScriptLinter { } private handlePropertySignature(node: ts.PropertySignature): void { - - /** - * Handler in case any further restrictions are put on properties of interfaces - */ - void this; - void node; + const propName = node.name; + if (!!propName && ts.isNumericLiteral(propName)) { + this.incrementCounters(node, FaultID.LiteralAsPropertyName, ); + } } private filterOutDecoratorsDiagnostics( @@ -2062,7 +2060,7 @@ export class TypeScriptLinter { } private handleGetAccessor(node: ts.Node) { - + /** * Reserved if needed */ @@ -2071,7 +2069,7 @@ export class TypeScriptLinter { } private handleSetAccessor(node: ts.Node) { - + /** * Reserved if needed */ @@ -2106,7 +2104,7 @@ export class TypeScriptLinter { // option is enabled, compiler attempts to infer type from variable references: // see https://github.com/microsoft/TypeScript/pull/11263. // In this case, we still want to report the error, since ArkTS doesn't allow - // to omit both type annotation and initializer. + // to omit both type annotation and initializer. if (((ts.isVariableDeclaration(decl) && ts.isVariableStatement(decl.parent.parent)) || ts.isPropertyDeclaration(decl)) && !decl.initializer) { this.incrementCounters(decl, FaultID.AnyType); diff --git a/linter-4.2/test/literals_as_prop_names.ts.strict.json b/linter-4.2/test/literals_as_prop_names.ts.strict.json index 40de3a10c25edf794dab5192b156b3ab15720fe1..96feeb09ac3172f8594eee753ee070378634485d 100644 --- a/linter-4.2/test/literals_as_prop_names.ts.strict.json +++ b/linter-4.2/test/literals_as_prop_names.ts.strict.json @@ -84,6 +84,13 @@ "suggest": "", "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" }, + { + "line": 67, + "column": 3, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, { "line": 34, "column": 11, diff --git a/linter-4.2/test/types.ts.strict.json b/linter-4.2/test/types.ts.strict.json index 31431c270701dd29d6a757f203ada3f488a2dd26..0be6ecd0d17495c948b41b84d9838e0d8dcb8d76 100644 --- a/linter-4.2/test/types.ts.strict.json +++ b/linter-4.2/test/types.ts.strict.json @@ -98,6 +98,13 @@ "suggest": "", "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" }, + { + "line": 56, + "column": 3, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, { "line": 57, "column": 3, diff --git a/linter-4.2/test_rules/rule1.ts b/linter-4.2/test_rules/rule1.ts index 0a37d2e6d970b4d1b1214d7d759686fad3268e6f..fea7f2cbec86d5bd2e12311d828ff1b7958a21a9 100644 --- a/linter-4.2/test_rules/rule1.ts +++ b/linter-4.2/test_rules/rule1.ts @@ -39,3 +39,8 @@ const a2: A2 = { S1["s1"]; S2["s2"]; + + +interface I { + 2: number; +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule1.ts.autofix.json b/linter-4.2/test_rules/rule1.ts.autofix.json index d6f3182b519658612887f6d672cfa63b60d64801..170b37dcd7e91d10ea17338efad7eca454968209 100644 --- a/linter-4.2/test_rules/rule1.ts.autofix.json +++ b/linter-4.2/test_rules/rule1.ts.autofix.json @@ -85,6 +85,14 @@ "autofixable": false, "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 45, + "column": 3, + "problem": "LiteralAsPropertyName", + "autofixable": false, + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" } ] } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule1.ts.strict.json b/linter-4.2/test_rules/rule1.ts.strict.json index 2f185ba3ad655e26fbf84729f8cd1b37b6bdd5a7..1fd9a452adf10a9df38c2eae3ce92ca33f1409e1 100644 --- a/linter-4.2/test_rules/rule1.ts.strict.json +++ b/linter-4.2/test_rules/rule1.ts.strict.json @@ -62,6 +62,13 @@ "problem": "ComputedPropertyName", "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 45, + "column": 3, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" } ] } \ No newline at end of file diff --git a/linter/lib/TypeScriptLinter.ts b/linter/lib/TypeScriptLinter.ts index 6b889e4885dc7c559ad1f067730ed0309651e5b3..ee3722f59d3af11b1c33a6406a1ab989c6b5b108 100644 --- a/linter/lib/TypeScriptLinter.ts +++ b/linter/lib/TypeScriptLinter.ts @@ -754,12 +754,10 @@ export class TypeScriptLinter { } private handlePropertySignature(node: ts.PropertySignature): void { - - /** - * Handler in case any further restrictions are put on properties of interfaces - */ - void this; - void node; + const propName = node.name; + if (!!propName && ts.isNumericLiteral(propName)) { + this.incrementCounters(node, FaultID.LiteralAsPropertyName, ); + } } private filterOutDecoratorsDiagnostics( diff --git a/linter/test/literals_as_prop_names.ts.strict.json b/linter/test/literals_as_prop_names.ts.strict.json index 40de3a10c25edf794dab5192b156b3ab15720fe1..96feeb09ac3172f8594eee753ee070378634485d 100644 --- a/linter/test/literals_as_prop_names.ts.strict.json +++ b/linter/test/literals_as_prop_names.ts.strict.json @@ -84,6 +84,13 @@ "suggest": "", "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" }, + { + "line": 67, + "column": 3, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, { "line": 34, "column": 11, diff --git a/linter/test/types.ts.strict.json b/linter/test/types.ts.strict.json index 31431c270701dd29d6a757f203ada3f488a2dd26..0be6ecd0d17495c948b41b84d9838e0d8dcb8d76 100644 --- a/linter/test/types.ts.strict.json +++ b/linter/test/types.ts.strict.json @@ -98,6 +98,13 @@ "suggest": "", "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" }, + { + "line": 56, + "column": 3, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, { "line": 57, "column": 3, diff --git a/linter/test_rules/rule1.ts b/linter/test_rules/rule1.ts index 0a37d2e6d970b4d1b1214d7d759686fad3268e6f..3e6e04ac34cb46cb5d6b1d307769d15b591fb871 100644 --- a/linter/test_rules/rule1.ts +++ b/linter/test_rules/rule1.ts @@ -39,3 +39,7 @@ const a2: A2 = { S1["s1"]; S2["s2"]; + +interface I { + 2: number; +} \ No newline at end of file diff --git a/linter/test_rules/rule1.ts.autofix.json b/linter/test_rules/rule1.ts.autofix.json index d6f3182b519658612887f6d672cfa63b60d64801..ab1eb2fb30945efc682cc3bb2db3d91d26ba6a7f 100644 --- a/linter/test_rules/rule1.ts.autofix.json +++ b/linter/test_rules/rule1.ts.autofix.json @@ -85,6 +85,14 @@ "autofixable": false, "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 44, + "column": 3, + "problem": "LiteralAsPropertyName", + "autofixable": false, + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule1.ts.strict.json b/linter/test_rules/rule1.ts.strict.json index 2f185ba3ad655e26fbf84729f8cd1b37b6bdd5a7..272db883eeb414975afcf2da63d6b55a375d60dd 100644 --- a/linter/test_rules/rule1.ts.strict.json +++ b/linter/test_rules/rule1.ts.strict.json @@ -62,6 +62,13 @@ "problem": "ComputedPropertyName", "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 44, + "column": 3, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" } ] } \ No newline at end of file