Skip to content

Add diagnostic when notifications are passed to Send#283

Open
EvolvingMayur wants to merge 1 commit into
martinothamar:mainfrom
EvolvingMayur:feat/diagnose-send-notification-230
Open

Add diagnostic when notifications are passed to Send#283
EvolvingMayur wants to merge 1 commit into
martinothamar:mainfrom
EvolvingMayur:feat/diagnose-send-notification-230

Conversation

@EvolvingMayur

Copy link
Copy Markdown

Summary

Adds a source-generator warning when an INotification is passed to ISender.Send or IMediator.Send instead of being published.

The new MSG0011 diagnostic:

  • identifies calls to the Mediator Send contract using Roslyn symbols;
  • recommends using Publish instead;
  • reports the warning on the notification argument;
  • handles concrete notification types, variables typed as INotification, generic notification constraints, and reordered named arguments;
  • avoids warnings for normal requests, valid Publish calls, and unrelated methods named Send.

The syntax provider performs narrow filtering for .Send(...) invocations before semantic analysis.

Testing

dotnet test \
  -f net10.0 \
  ./test/Mediator.SourceGenerator.Tests/ \
  --no-restore \
  --filter "FullyQualifiedName!~Mediator.SourceGenerator.Tests.SampleTests"

Result:

198 passed
0 failed
0 skipped

git diff --check also passes, and no Verify .received files remain.

The existing SampleTests were excluded locally because their MSBuild workspace project loading fails on the unchanged upstream baseline in this environment.

Closes #230

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.

Addition of a diagnostic that detects cases where Send is called on a notification instead of Publish

1 participant