elastic / elastic/docs-builder
chore: Simplify verbose C# code with LINQ and idiomatic patterns
- Dominant language
- C#
- Stars
- 24
- Forks
- 44
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 146
Description
## What
Several methods use verbose imperative loops where idiomatic LINQ or shorter patterns apply.
## Changes
### `ChangelogTextUtilities` — collapse parallel helper pairs
`FormatPrLink`/`FormatIssueLink` and their `*Asciidoc` twins, plus `ExtractPrNumber`/`ExtractIssueNumber`, differ only by the URL segment (`"pull"` vs `"issues"`). Collapse each pair into one method with a parameter.
File: `src/Elastic.Documentation/ReleaseNotes/ChangelogTextUtilities.cs:168-229,322-441` (~60→20 lines)
### `ChangelogBundlingService.ApplyGlobalContentBundleFilter` → `.Where()`
Manual `new List<>` + `foreach` + multiple `if...continue` guards. Replace with `.Where()` and a combined predicate.
File: `src/services/Elastic.Changelog/Bundling/ChangelogBundlingService.cs` (~30→6 lines)
### `OpenApiGenerator` classification → `.GroupBy()`
Nested `foreach` + `List.Add()` manual grouping. Replace with `.GroupBy().Select()`.
File: `src/Elastic.ApiExplorer/OpenApiGenerator.cs:~119-163` (~25 lines)
### `Move.cs` dict accumulation → `TryAdd`
`if (!dict.ContainsKey(k)) dict[k] = []` (two sites). Replace with `dict.TryAdd(k, [])`.
File: `src/authoring/Elastic.Documentation.Refactor/Move.cs:78,323`
### `StreamTransformerFactory` + `AskAiGatewayFactory` → direct resolution
Both are service-locator shims with a single call site that dispatch to one of two impls by config string. Collapse to a conditional resolver in the call site or use DI keyed services.
Files: `src/api/Elastic.Documentation.Api/Adapters/AskAi/StreamTransformerFactory.cs` (~47 lines), `AskAiGatewayFactory.cs` (~33 lines)
### `CodexPageViewFactory` → inline into caller
Pure delegation wrapper with one call site; sets two properties then calls `Index.Create()`. Inline into `CodexBuildService`.
File: `src/Elastic.Codex/Page/CodexPageViewFactory.cs` (~23 lines)
### `AddLlmMarkdownExport` extension → inline into caller
One-line duplicate of the `new LlmMarkdownExporter(branded)` logic already in `CreateMarkdownExporters`; single caller at `ReloadableGeneratorState.cs:104`.
File: `src/Elastic.Markdown/Exporters/LlmMarkdownExporter.cs:227` (~3 lines)
~225 lines removed across these changes.
Part of the broader ponytail over-engineering audit tracked in #3574.
Contributor guide
Assessment
This issue has not been assessed yet.