Skip to content

Add NonAwaitableTypeAttribute for MA0042/MA0045#1153

Merged
meziantou merged 10 commits into
mainfrom
meziantou/async-exclusion-attributes
May 12, 2026
Merged

Add NonAwaitableTypeAttribute for MA0042/MA0045#1153
meziantou merged 10 commits into
mainfrom
meziantou/async-exclusion-attributes

Conversation

@meziantou
Copy link
Copy Markdown
Owner

@meziantou meziantou commented May 12, 2026

MA0042/MA0045 needed a clear attribute-based way to opt out of await and await using recommendations for specific types. The existing ExcludeFromBlockingCallAnalysisAttribute only targeted member-level blocking-call diagnostics and did not provide a dedicated type-level await exclusion model.

What changed

  • Added NonAwaitableTypeAttribute in Meziantou.Analyzer.Annotations (assembly-level, Type argument) and bumped the annotations package version.
  • Updated annotation symbol detection for all rules that use AwaitableTypes.
  • This keeps method/property exclusion (ExcludeFromBlockingCallAnalysisAttribute) and type-level await exclusion (NonAwaitableTypeAttribute) as separate concepts.

Fix #1152

meziantou and others added 10 commits May 12, 2026 13:33
Add a dedicated annotations attribute to configure MA0042/MA0045 await exclusions by type, wire it into await and await-using analysis, and update tests and docs accordingly.

Co-authored-by: Copilot <[email protected]>
Limit NonAwaitableTypeAttribute matching to the declared type instead of its hierarchy, add regression tests for derived await/await-using cases, and document exact-type semantics.

Co-authored-by: Copilot <[email protected]>
Centralize NonAwaitableTypeAttribute parsing/matching in AwaitableTypes so rules sharing awaitable detection can reuse it, and update MA0042/MA0045 to consume the shared API.

Add regression coverage for MA0134 and MA0137 behavior with NonAwaitableTypeAttribute.

Co-authored-by: Copilot <[email protected]>
Update MA0100, MA0134, MA0137, and MA0138 documentation to describe NonAwaitableTypeAttribute support and exact-type matching behavior.

Co-authored-by: Copilot <[email protected]>
Add test coverage for NonAwaitableTypeAttribute(typeof(T<>)) so open generic declarations are validated across MA0042, MA0134, and MA0137 behaviors.

Co-authored-by: Copilot <[email protected]>
Ensure each rule doc mentioning NonAwaitableTypeAttribute also references the Meziantou.Analyzer.Annotations README, following the MA0042 pattern.

Co-authored-by: Copilot <[email protected]>
Adjust AwaitableTypes to evaluate only the provided type in IsNonAwaitableType, without unwrapping Task<T>/ValueTask<T>. Update rule tests to reflect task-wrapped types are no longer excluded by inner type annotations.

Co-authored-by: Copilot <[email protected]>
Inline ValueTask and ValueTask generic symbol lookups directly in the constructor branch and remove temporary locals.

Co-authored-by: Copilot <[email protected]>
@meziantou meziantou merged commit 299b684 into main May 12, 2026
13 checks passed
@meziantou meziantou deleted the meziantou/async-exclusion-attributes branch May 12, 2026 20:07
This was referenced May 12, 2026
This was referenced May 16, 2026
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.

ExcludeFromBlockingCallAnalysisAttribute not working as expected

1 participant