Skip to content

Report same-named metadata files whose contents differ [patch] - #64

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/34-duplicate-metadata-names
Nov 4, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/34-duplicate-metadata-names

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

GeneratorBase grouped the AdditionalTexts by file name and kept the first one with content. The code comment assumed every copy held the same metadata, but nothing checked it. With /a/Legacy/things.json and /a/Metadata/things.json holding different entries, the run reported nothing and generated from whichever file was listed first.

Now, when the non-empty files of one declared name differ:

  • MetadataParseFailed is reported for that name. The reason is it was supplied more than once with different contents: <path>, <path>.
  • None of the copies is handed to Generate, the same way a file that fails to parse produces no output. MetadataFileMissing is not reported as well.

Identical copies, and an empty copy next to a full one, stay silent as before.

I reused the existing descriptor rather than adding a new abstract MetadataFileDuplicated, so every existing consumer gets the diagnostic without a breaking change. MetadataFile gains an internal FilePath property, which replaces the private field it already had, so the diagnostic can name the paths. The README's MetadataParseFailed row and the property's XML doc now mention the case.

Tests:

  • GeneratorHarness keys its files by name, so the new tests in GeneratorBaseTests run CSharpGeneratorDriver directly with two paths.
  • SameNamedMetadataFilesWithDifferentContentsAreReportedWithBothPaths fails on main (0 diagnostics) and passes with the change.
  • SameNamedMetadataFilesWithIdenticalContentsAreNotReported and AnEmptyDuplicateOfAMetadataFileIsNotAConflict cover the cases that stay silent.
  • The full suite passes: 69 of 69.

Fixes #34


Generated by Claude Code

GeneratorBase grouped AdditionalTexts by file name and kept the first with
content, so a stale copy in another folder could silently replace the real
metadata. When the copies differ, MetadataParseFailed is now reported with
every path and none of them is used. Identical copies stay silent.

Fixes #34

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4i7FzmxvaxCZgeCwe
…data-names

# Conflicts:
#	SourceGeneratorToolkit/GeneratorBase.cs
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit e5dd2d1 into main Nov 4, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two different metadata files with the same name in different folders: the generator silently uses whichever comes first, with no diagnostic

2 participants