Skip to content

Commit 88c7cfc

Browse files
dmealingclaude
andcommitted
chore(csharp): pre-merge simplifier pass — FR5a polish
Two small, behavior-preserving tidies to the FR5a C# port: 1. JsonPath.cs — dedupe the two identical compiled identifier regex instances (one in JsonPathBuilder, one in JsonPath) into a single internal JsonPathRegex.Ident. Removes a copy and makes intent obvious (one rule, two consumers). 2. ValidationPasses.cs — remove unused default-null defaults from three private helpers (ValidateFromPath label + originSource, ValidateViaPath originSource, CheckFilterClauses layoutSource). Every call site already passes these arguments; the defaults were dead and let a future bug elide a source unnoticed. Now the type system requires them. No public API changes. C# all 4 projects 561/561 still green (Conformance 302, Render 88, Codegen 164, Cli 7). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c6ce7fc commit 88c7cfc

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

server/csharp/MetaObjects/Loader/ValidationPasses.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ private static void ValidateFromPath(
314314
string projectionName,
315315
string fieldName,
316316
List<MetaError> errors,
317-
string label = "origin.passthrough.@from",
318-
ErrorSource? originSource = null)
317+
string label,
318+
ErrorSource originSource)
319319
{
320320
int dotIdx = fromAttr.IndexOf('.', StringComparison.Ordinal);
321321
if (dotIdx < 1 || dotIdx == fromAttr.Length - 1)
@@ -363,7 +363,7 @@ private static void ValidateViaPath(
363363
string projectionName,
364364
string fieldName,
365365
List<MetaError> errors,
366-
ErrorSource? originSource = null)
366+
ErrorSource originSource)
367367
{
368368
var segments = viaAttr.Split('.');
369369
if (segments.Length < 2)
@@ -502,7 +502,7 @@ private static void CheckFilterClauses(
502502
string entityName,
503503
string layoutName,
504504
List<MetaError> errors,
505-
ErrorSource? layoutSource = null)
505+
ErrorSource layoutSource)
506506
{
507507
foreach (var (key, clause) in filter)
508508
{

server/csharp/MetaObjects/Source/JsonPath.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313

1414
namespace MetaObjects.Source;
1515

16+
/// <summary>
17+
/// Shared identifier regex for dot-vs-bracket key dispatch. Used by both
18+
/// <see cref="JsonPathBuilder"/> and the <see cref="JsonPath"/> static helpers.
19+
/// </summary>
20+
internal static class JsonPathRegex
21+
{
22+
public static readonly Regex Ident =
23+
new("^[A-Za-z_][A-Za-z0-9_]*$", RegexOptions.Compiled);
24+
}
25+
1626
/// <summary>
1727
/// Builds the canonical JSONPath string for a node as the parser walks the
1828
/// JSON tree. Push a key or index when descending; pop when returning.
@@ -24,9 +34,6 @@ namespace MetaObjects.Source;
2434
/// </summary>
2535
public sealed class JsonPathBuilder
2636
{
27-
private static readonly Regex IdentRe =
28-
new("^[A-Za-z_][A-Za-z0-9_]*$", RegexOptions.Compiled);
29-
3037
private readonly List<Segment> _segments = new();
3138

3239
/// <summary>Push an object key segment (e.g. <c>.foo</c> or <c>['my-key']</c>).</summary>
@@ -61,7 +68,7 @@ public override string ToString()
6168
else
6269
{
6370
string key = seg.Key!;
64-
if (IdentRe.IsMatch(key))
71+
if (JsonPathRegex.Ident.IsMatch(key))
6572
{
6673
sb.Append('.').Append(key);
6774
}
@@ -84,16 +91,13 @@ private enum SegmentKind { Key, Index }
8491
/// </summary>
8592
public static class JsonPath
8693
{
87-
private static readonly Regex IdentRe =
88-
new("^[A-Za-z_][A-Za-z0-9_]*$", RegexOptions.Compiled);
89-
9094
/// <summary>
9195
/// Render a single object-key segment as it would appear in canonical form,
9296
/// without the leading <c>$</c> — i.e. <c>.foo</c> or <c>['my-key']</c>.
9397
/// </summary>
9498
public static string SegmentForKey(string key)
9599
{
96-
return IdentRe.IsMatch(key)
100+
return JsonPathRegex.Ident.IsMatch(key)
97101
? $".{key}"
98102
: $"['{key.Replace("'", "\\'")}']";
99103
}

0 commit comments

Comments
 (0)