Skip to content

Apply ruleset to compilation so tests can enable default-disabled diagnostics#20

Merged
Arthurvdv merged 1 commit into
masterfrom
feat/apply-ruleset-in-tests
Jun 18, 2026
Merged

Apply ruleset to compilation so tests can enable default-disabled diagnostics#20
Arthurvdv merged 1 commit into
masterfrom
feat/apply-ruleset-in-tests

Conversation

@Arthurvdv

Copy link
Copy Markdown
Member

Summary

BaseTestFixture exposed RuleSetPath via the fixture configs, but it was only forwarded to ProjectInfo.RuleSetPath. The in-memory AdhocWorkspace builds the compilation from ProjectState.CompilationOptions and never applies the ruleset, so RuleSetPath was effectively a no-op for diagnostics.

This change loads the ruleset and applies it to the compilation's diagnostic options, so tests can enable/disable diagnostics — in particular, enabling rules declared isEnabledByDefault: false.

Changes

  • BaseTestFixture.CreateDocumentFromCode: after computing CompilationOptions, call new ApplyRuleSet(...) helper.
  • ApplyRuleSet: loads the ruleset via RuleSetResolver.LoadFromFile(...) and merges GeneralDiagnosticOption + SpecificDiagnosticOptions onto the options. Throws RoslynTestKitException.InvalidRuleSet on load errors.
  • RoslynTestKitException.InvalidRuleSet(...): new factory for clear failures on invalid/missing ruleset files.
  • README.md: document that RuleSetPath is now applied, with a JSON ruleset example for enabling default-disabled diagnostics.

Notes

  • Uses public SDK APIs present in netstandard2.1, net8.0 and net10.0 — no #if guards needed.
  • The existing ProjectInfo.RuleSetPath plumbing is left intact (harmless).

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…gnostics

BaseTestFixture exposed RuleSetPath but only passed it to ProjectInfo, which
the in-memory AdhocWorkspace never applies to the compilation's diagnostic
options. Load the ruleset via RuleSetResolver and merge its general and
per-rule options into the CompilationOptions used to build the test project.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Arthurvdv Arthurvdv merged commit 9431d3b into master Jun 18, 2026
1 check passed
@Arthurvdv Arthurvdv deleted the feat/apply-ruleset-in-tests branch June 18, 2026 13:45
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.

1 participant