Skip to content

Analyzers to secure [DependsOnClasses] attribute#26

Merged
olstakh merged 2 commits intomainfrom
users/olstakh/new-analyzer
Apr 2, 2026
Merged

Analyzers to secure [DependsOnClasses] attribute#26
olstakh merged 2 commits intomainfrom
users/olstakh/new-analyzer

Conversation

@olstakh
Copy link
Copy Markdown
Owner

@olstakh olstakh commented Apr 1, 2026

This pull request introduces a new analyzer, AttributeUsageDependsOnClassesAnalyzer, to the codebase. The analyzer enforces correct usage of the [DependsOnClasses] attribute by ensuring that dependency types are properly associated with test collections. It reports diagnostics when a dependency already belongs to a collection or when a dependency is not part of any named collection in certain scenarios. The pull request also adds corresponding diagnostic descriptors, updates the analyzer release notes, and provides comprehensive tests for the new analyzer.

Analyzer implementation:

  • Added a new analyzer AttributeUsageDependsOnClassesAnalyzer that reports:
    • When a dependency in [DependsOnClasses] already belongs to a collection (via [Collection] or [CollectionDefinition]), suggesting to use [DependsOnCollections] instead.
    • When a dependency is a plain class not part of a named collection and the assembly uses CollectionBehavior.CollectionPerAssembly, suggesting to add [DependsOnClasses(Name = "...")] to the dependency.

Diagnostic descriptors and documentation:

  • Added new diagnostic descriptors XIT0013 and XIT0014 to AttributeUsageDescriptors for the analyzer's warnings.
  • Documented the new diagnostics in AnalyzerReleases.Unshipped.md.

Testing:

  • Added a comprehensive test suite in AttributeUsageDependsOnClassesAnalyzerTests covering all relevant scenarios for the new analyzer, including both positive and negative cases.

@olstakh olstakh merged commit 95b9896 into main Apr 2, 2026
2 checks passed
@olstakh olstakh deleted the users/olstakh/new-analyzer branch April 2, 2026 03:22
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