From 0b3ba6f0ab0943e08d392631139a8ccd3d39aa41 Mon Sep 17 00:00:00 2001
From: Aleksandr Mezin <aleksandr.mezin@webpros.com>
Date: Tue, 20 Aug 2024 10:45:39 +0300
Subject: [PATCH] refactor(template): remove unused `containsTemplates()`
 (#30907)

---
 lib/util/template/index.spec.ts | 31 -------------------------------
 lib/util/template/index.ts      | 22 ----------------------
 2 files changed, 53 deletions(-)

diff --git a/lib/util/template/index.spec.ts b/lib/util/template/index.spec.ts
index 9bf157e907..eceb5229a8 100644
--- a/lib/util/template/index.spec.ts
+++ b/lib/util/template/index.spec.ts
@@ -253,37 +253,6 @@ describe('util/template/index', () => {
     });
   });
 
-  describe('containsTemplate', () => {
-    it('supports null', () => {
-      expect(template.containsTemplates(null, 'logJSON')).toBeFalse();
-    });
-
-    it('contains template', () => {
-      expect(
-        template.containsTemplates(
-          '{{#if logJSON}}{{logJSON}}{{/if}}',
-          'logJSON',
-        ),
-      ).toBeTrue();
-      expect(
-        template.containsTemplates(
-          '{{#with logJSON.hasReleaseNotes as | hasNotes |}}{{hasNotes}}{{/if}}',
-          'logJSON',
-        ),
-      ).toBeTrue();
-      expect(
-        template.containsTemplates(
-          '{{#if logJSON.hasReleaseNotes}}has notes{{/if}}',
-          'logJSON',
-        ),
-      ).toBeTrue();
-    });
-
-    it('does not contain template', () => {
-      expect(template.containsTemplates('{{body}}', ['logJSON'])).toBeFalse();
-    });
-  });
-
   describe('percent encoding', () => {
     it('encodes values', () => {
       const output = template.compile(
diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts
index 9a347b9132..b170419523 100644
--- a/lib/util/template/index.ts
+++ b/lib/util/template/index.ts
@@ -291,10 +291,6 @@ export function proxyCompileInput(
   );
 }
 
-const templateRegex = regEx(
-  /{{(?:#(?:if|unless|with|each) )?([a-zA-Z.]+)(?: as \| [a-zA-Z.]+ \|)?}}/g,
-);
-
 export function compile(
   template: string,
   input: CompileInput,
@@ -332,21 +328,3 @@ export function safeCompile(
     return '';
   }
 }
-
-export function containsTemplates(
-  value: unknown,
-  templates: string | string[],
-): boolean {
-  if (!is.string(value)) {
-    return false;
-  }
-  for (const m of [...value.matchAll(templateRegex)]) {
-    for (const template of is.string(templates) ? [templates] : templates) {
-      if (m[1] === template || m[1].startsWith(`${template}.`)) {
-        return true;
-      }
-    }
-  }
-
-  return false;
-}
-- 
GitLab