diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index cb6e60231607695fbcf308bb8f8c57ef2febaf09..d2c3c0420da6060c14c4470c9e3b1b21313a8b34 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -16,6 +16,7 @@ "arkts-no-class-add-super-prop-with-readonly", "arkts-no-classes-as-obj", "arkts-obj-literal-props", + "arkts-no-template-string-type", "arkts-obj-literal-key-type", "arkts-optional-methods", "arkts-numeric-semantic", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 3d57443dac78dc01f25c86b8ad02f1ef30322461..6ad0564ae5e9cf2447423e0fece27584e5120408 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -104,7 +104,7 @@ cookBookTag[73] = ''; cookBookTag[74] = 'Destructuring variable declarations are not supported (arkts-no-destruct-decls)'; cookBookTag[75] = 'Use string-literal keys with Record (arkts-obj-literal-key-type)'; cookBookTag[76] = 'Type of parameter must be defined explicitly (arkts-require-func-arg-type)'; -cookBookTag[77] = ''; +cookBookTag[77] = 'Template string type is not supported (arkts-no-template-string-type)'; cookBookTag[78] = ''; cookBookTag[79] = 'Type annotation in catch clause is not supported (arkts-no-types-in-catch)'; cookBookTag[80] = '"for .. in" is not supported (arkts-no-for-in)'; diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index a862704a0c1a67da760d3d9f051eb45eaa45bf5f..3e2879c02d7c402e73731fb3b5f2dc4810c99356 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -66,6 +66,7 @@ faultsAttrs[FaultID.CommaOperator] = new FaultAttributes(71); faultsAttrs[FaultID.DestructuringDeclaration] = new FaultAttributes(74); faultsAttrs[FaultID.ObjectLiteralKeyType] = new FaultAttributes(75); faultsAttrs[FaultID.ParameterType] = new FaultAttributes(76); +faultsAttrs[FaultID.TemplateStringType] = new FaultAttributes(77); faultsAttrs[FaultID.CatchWithUnsupportedType] = new FaultAttributes(79); faultsAttrs[FaultID.ForInStatement] = new FaultAttributes(80); faultsAttrs[FaultID.MappedType] = new FaultAttributes(83); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index 93a31cd080ed89812acd9ae2bcd38e709cb5b654..a0fa2572b5f4ceb07bb7ad34c91e08783a344d6a 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -84,6 +84,7 @@ faultDesc[FaultID.ImportAssignment] = 'Import assignments (import = ..)'; faultDesc[FaultID.GenericCallNoTypeArgs] = 'Generic calls without type arguments'; faultDesc[FaultID.ParameterProperties] = 'Parameter properties in constructor'; faultDesc[FaultID.InstanceofUnsupported] = 'Left-hand side of "instanceof" is wrong'; +faultDesc[FaultID.TemplateStringType] = 'Template string type'; faultDesc[FaultID.ShorthandAmbientModuleDecl] = 'Shorthand ambient module declaration'; faultDesc[FaultID.WildcardsInModuleName] = 'Wildcards in module name'; faultDesc[FaultID.UMDModuleDefinition] = 'UMD module definition'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index 649892bfc7c64b686f49ff1aae5d4c283b0ff335..ea86a9a955ec60841855075caaf5267dfb2846a0 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -173,6 +173,7 @@ export enum FaultID { TaggedTemplates, IncompationbleFunctionType, InvalidIdentifier, + TemplateStringType, NoImportJsonFile, ExtendsExpression, NumericSemantics, diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index e58892c5304b12d882aa65c1a7e5728daf368fb5..8b0ea627247d2f5d23c32c6ce129d1a957f6ab9a 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -402,6 +402,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { [ts.SyntaxKind.TypeAssertionExpression, this.handleTypeAssertionExpression], [ts.SyntaxKind.MethodDeclaration, this.handleMethodDeclaration], [ts.SyntaxKind.TupleType, this.handleTupleType], + [ts.SyntaxKind.TemplateLiteralType, this.handleTemplateType], [ts.SyntaxKind.MethodSignature, this.handleMethodSignature], [ts.SyntaxKind.ClassStaticBlockDeclaration, this.handleClassStaticBlockDeclaration], [ts.SyntaxKind.Identifier, this.handleIdentifier], @@ -3689,6 +3690,13 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } + private handleTemplateType(node: ts.TemplateLiteralTypeNode): void { + if (!this.options.arkts2) { + return; + } + this.incrementCounters(node, FaultID.TemplateStringType); + } + private handleTupleType(node: ts.TupleTypeNode): void { if (!this.options.arkts2) { return; diff --git a/ets2panda/linter/test/main/arkts-no-template-string-type.ets b/ets2panda/linter/test/main/arkts-no-template-string-type.ets new file mode 100644 index 0000000000000000000000000000000000000000..151de4d06d7144f61b1ac0c125d24598b5be77bf --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-template-string-type.ets @@ -0,0 +1,26 @@ +/* + * 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. + */ + +type Action = "verify"; +type ContentMatch = "match"; +type Outcome = `${Action}_${ContentMatch}`; +type Outcome2 = `${Action}_match`; +type Outcome3 = `verify_${ContentMatch}`; + +type Foo = "Foo"; +type Bar = "Bar"; + +let template: `${Foo}_${Bar}`; +function foo(template: `${Foo}_${Bar}`): `${number}` {} diff --git a/ets2panda/linter/test/main/arkts-no-template-string-type.ets.args.json b/ets2panda/linter/test/main/arkts-no-template-string-type.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..66fb88f85945924e8be0e83d90123507033f4c5d --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-template-string-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-no-template-string-type.ets.arkts2.json b/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..859370ed7b218a08e50e92b5017e482dccd87e1c --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-template-string-type.ets.arkts2.json @@ -0,0 +1,64 @@ +{ + "result": [ + { + "line": 18, + "column": 16, + "endLine": 18, + "endColumn": 43, + "problem": "TemplateStringType", + "suggest": "", + "rule": "Template string type is not supported (arkts-no-template-string-type)", + "severity": "ERROR" + }, + { + "line": 19, + "column": 17, + "endLine": 19, + "endColumn": 34, + "problem": "TemplateStringType", + "suggest": "", + "rule": "Template string type is not supported (arkts-no-template-string-type)", + "severity": "ERROR" + }, + { + "line": 20, + "column": 17, + "endLine": 20, + "endColumn": 41, + "problem": "TemplateStringType", + "suggest": "", + "rule": "Template string type is not supported (arkts-no-template-string-type)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 15, + "endLine": 25, + "endColumn": 30, + "problem": "TemplateStringType", + "suggest": "", + "rule": "Template string type is not supported (arkts-no-template-string-type)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 24, + "endLine": 26, + "endColumn": 39, + "problem": "TemplateStringType", + "suggest": "", + "rule": "Template string type is not supported (arkts-no-template-string-type)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 42, + "endLine": 26, + "endColumn": 53, + "problem": "TemplateStringType", + "suggest": "", + "rule": "Template string type is not supported (arkts-no-template-string-type)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-no-template-string-type.ets.json b/ets2panda/linter/test/main/arkts-no-template-string-type.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..dd03fcf5442488620bcd4b3447f0fcdd89e1905b --- /dev/null +++ b/ets2panda/linter/test/main/arkts-no-template-string-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": [] +}