From bb1acb8a147f17b951f208d3f70ced428b48acff Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Thu, 22 Aug 2024 04:22:48 -0300
Subject: [PATCH] refactor(bazel-module): Reorganize parser into the own
 directory (#30945)

---
 .../{parser.spec.ts => parser/index.spec.ts}  |  6 ++---
 .../manager/bazel-module/parser/index.ts      | 19 ++++++++++++++
 .../{parser.ts => parser/module.ts}           | 26 ++++---------------
 3 files changed, 27 insertions(+), 24 deletions(-)
 rename lib/modules/manager/bazel-module/{parser.spec.ts => parser/index.spec.ts} (97%)
 create mode 100644 lib/modules/manager/bazel-module/parser/index.ts
 rename lib/modules/manager/bazel-module/{parser.ts => parser/module.ts} (58%)

diff --git a/lib/modules/manager/bazel-module/parser.spec.ts b/lib/modules/manager/bazel-module/parser/index.spec.ts
similarity index 97%
rename from lib/modules/manager/bazel-module/parser.spec.ts
rename to lib/modules/manager/bazel-module/parser/index.spec.ts
index 4f6faef34e..2424fa8018 100644
--- a/lib/modules/manager/bazel-module/parser.spec.ts
+++ b/lib/modules/manager/bazel-module/parser/index.spec.ts
@@ -1,8 +1,8 @@
 import { codeBlock } from 'common-tags';
-import * as fragments from './fragments';
-import { parse } from './parser';
+import * as fragments from '../fragments';
+import { parse } from '.';
 
-describe('modules/manager/bazel-module/parser', () => {
+describe('modules/manager/bazel-module/parser/index', () => {
   describe('parse', () => {
     it('returns empty string if invalid content', () => {
       const input = codeBlock`
diff --git a/lib/modules/manager/bazel-module/parser/index.ts b/lib/modules/manager/bazel-module/parser/index.ts
new file mode 100644
index 0000000000..e98d997e87
--- /dev/null
+++ b/lib/modules/manager/bazel-module/parser/index.ts
@@ -0,0 +1,19 @@
+import { lang, query as q } from 'good-enough-parser';
+import { Ctx } from '../context';
+import type { RecordFragment } from '../fragments';
+import { moduleRules } from './module';
+
+const rule = q.alt<Ctx>(moduleRules);
+
+const query = q.tree<Ctx>({
+  type: 'root-tree',
+  maxDepth: 16,
+  search: rule,
+});
+
+const starlarkLang = lang.createLang('starlark');
+
+export function parse(input: string): RecordFragment[] {
+  const parsedResult = starlarkLang.query(input, query, new Ctx());
+  return parsedResult?.results ?? [];
+}
diff --git a/lib/modules/manager/bazel-module/parser.ts b/lib/modules/manager/bazel-module/parser/module.ts
similarity index 58%
rename from lib/modules/manager/bazel-module/parser.ts
rename to lib/modules/manager/bazel-module/parser/module.ts
index 9439164859..0c75234b62 100644
--- a/lib/modules/manager/bazel-module/parser.ts
+++ b/lib/modules/manager/bazel-module/parser/module.ts
@@ -1,8 +1,7 @@
-import { lang, query as q } from 'good-enough-parser';
-import { regEx } from '../../../util/regex';
-import { Ctx } from './context';
-import type { RecordFragment } from './fragments';
-import * as starlark from './starlark';
+import { query as q } from 'good-enough-parser';
+import { regEx } from '../../../../util/regex';
+import type { Ctx } from '../context';
+import * as starlark from '../starlark';
 
 const booleanValuesRegex = regEx(`^${starlark.booleanStringValues.join('|')}$`);
 const supportedRules = [
@@ -26,7 +25,7 @@ const kvParams = q
     q.sym<Ctx>(booleanValuesRegex, (ctx, token) => ctx.addBoolean(token.value)),
   );
 
-const moduleRules = q
+export const moduleRules = q
   .sym<Ctx>(supportedRulesRegex, (ctx, token) => ctx.startRule(token.value))
   .join(
     q.tree({
@@ -36,18 +35,3 @@ const moduleRules = q
       postHandler: (ctx, tree) => ctx.endRule(),
     }),
   );
-
-const rule = q.alt<Ctx>(moduleRules);
-
-const query = q.tree<Ctx>({
-  type: 'root-tree',
-  maxDepth: 16,
-  search: rule,
-});
-
-const starlarkLang = lang.createLang('starlark');
-
-export function parse(input: string): RecordFragment[] {
-  const parsedResult = starlarkLang.query(input, query, new Ctx());
-  return parsedResult?.results ?? [];
-}
-- 
GitLab