Skip to content

Commit 1fcaaa6

Browse files
committed
feat: add duplication detection
1 parent fb47496 commit 1fcaaa6

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/NativeCodeGen.Cli/Program.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NativeCodeGen.Core.Models;
55
using NativeCodeGen.Core.Parsing;
66
using NativeCodeGen.Core.Registry;
7+
using NativeCodeGen.Core.Utilities;
78
using NativeCodeGen.Lua;
89
using NativeCodeGen.TypeScript;
910

@@ -263,6 +264,44 @@ static async Task Validate(string input, bool strict)
263264
}
264265
});
265266

267+
// Check for duplicate native names (globally, after normalization)
268+
var duplicateNames = allNatives
269+
.GroupBy(n => NameConverter.NormalizeNativeName(n.Name), StringComparer.OrdinalIgnoreCase)
270+
.Where(g => g.Count() > 1)
271+
.ToList();
272+
273+
foreach (var dup in duplicateNames)
274+
{
275+
var natives = dup.ToList();
276+
var names = natives.Select(n => n.Name).Distinct().ToList();
277+
var nameDisplay = names.Count > 1 ? $"'{string.Join("', '", names)}'" : $"'{names[0]}'";
278+
allErrors.Add(new ParseError
279+
{
280+
FilePath = natives[0].SourceFile ?? "unknown",
281+
Line = 1,
282+
Column = 1,
283+
Message = $"Duplicate native name {nameDisplay} (normalized: '{dup.Key}'). Also defined in: {string.Join(", ", natives.Skip(1).Select(n => Path.GetFileName(n.SourceFile ?? "unknown")))}"
284+
});
285+
}
286+
287+
// Check for duplicate hashes
288+
var duplicateHashes = allNatives
289+
.GroupBy(n => n.Hash, StringComparer.OrdinalIgnoreCase)
290+
.Where(g => g.Count() > 1)
291+
.ToList();
292+
293+
foreach (var dup in duplicateHashes)
294+
{
295+
var natives = dup.ToList();
296+
allErrors.Add(new ParseError
297+
{
298+
FilePath = natives[0].SourceFile ?? "unknown",
299+
Line = 1,
300+
Column = 1,
301+
Message = $"Duplicate hash '{dup.Key}'. Also defined in: {string.Join(", ", natives.Skip(1).Select(n => Path.GetFileName(n.SourceFile ?? "unknown")))}"
302+
});
303+
}
304+
266305
// Group natives by namespace
267306
var namespaceDict = allNatives
268307
.GroupBy(n => n.Namespace, StringComparer.OrdinalIgnoreCase)

0 commit comments

Comments
 (0)