Skip to content

Move the file-system and generator-registry checks out of Schema to fix CA1506 [patch] - #353

Open
matt-edmondson wants to merge 2 commits into
mainfrom
fix/336-schema-class-coupling
Open

matt-edmondson wants to merge 2 commits into
mainfrom
fix/336-schema-class-coupling

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #336

What changed

main hasn't built since #332 merged. Schema was coupled to 97 types against a CA1506 limit of 96, and .editorconfig makes CA1506 an error, so every target framework failed to compile. Every PR based on main is red for the same reason.

As the issue recommends, this moves logic out of the type rather than suppressing the warning. Two validation checks move from Schema.Validation.cs into a new internal static SchemaEnvironmentValidator:

  • ReportMissingDataSourceFile (was ValidateDataSourceFileExists): checks that a data source's file exists on disk.
  • ReportReservedNames: checks that no element is named after a file the configured generator writes for itself.

These are the only two checks that consult something outside the schema, the file system and the generator registry. With them gone, Schema no longer references File, IOException, UnauthorizedAccessException, SchemaGenerator or ISchemaCodeGenerator. That also removes a dependency of the model on the generators, which already depend on the model. GeneratedFileNames() becomes internal so Schema can pass the names in, and the CanResolvePaths guard stays in Schema. Behaviour is unchanged.

Verification

  • Before: dotnet build Schema fails with CA1506: 'Schema' is coupled with '97' different types on net8.0, net9.0 and net10.0.
  • After: dotnet build of the whole solution, with analyzers on, gives 0 errors and 0 warnings.
  • Tests on net10.0: Schema.Test 718/718, Schema.Editor.Test 33/33, Schema.Cpp.Test 130/130. Both moved checks were already covered: GeneratedFileNameCollisionTests covers reserved names, and SchemaDataSourceTests covers a missing file and an unanchored schema.

Once this merges, #352 and the Dependabot PRs can go green after a rebase.


Generated by Claude Code

…ix CA1506 [patch]

#332 tipped Schema's class coupling to 97 against a limit of 96, and CA1506 is
an error here, so main stopped building on every target framework. Move the
data-source file-existence check and the reserved-generator-name check into an
internal SchemaEnvironmentValidator. They are the two checks that consult
something outside the schema, and with them gone Schema no longer reaches
File, the IO exceptions, SchemaGenerator or ISchemaCodeGenerator. Behaviour
is unchanged.

Fixes #336

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW67k6oxx5vQPHu3V4Q
File.Exists returns false instead of throwing for a path it can't read,
so the IOException/UnauthorizedAccessException branch never ran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW67k6oxx5vQPHu3V4Q
@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

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.

main does not build since #332 merged: CA1506 on Schema (class coupling 97, limit 96)

2 participants