Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Roslyn analyzer for pubsub #1448

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ngruson
Copy link

@ngruson ngruson commented Jan 16, 2025

Description

Added an analyzer to check if MapSubscribeHandler is called in app startup when Dapr programmatic subscriptions are setup.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #1426

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Introduced a new diagnostic analyzer `WorkflowActivityAnalyzer` to check if workflow activities are registered in the DI container. Updated the solution to include new projects for analyzers and their tests. Added unit tests to verify analyzer functionality and updated documentation to reflect the new release and rules. Included necessary package references and streamlined testing setup.

Signed-off-by: Nils Gruson <[email protected]>
Introduce `WorkflowRegistrationAnalyzer` and `WorkflowActivityAnalyzer` to validate workflow and activity registrations in the DI container. Implement corresponding code fix providers to suggest automatic fixes. Add tests to ensure functionality and robustness of the Dapr workflow framework.

Signed-off-by: Nils Gruson <[email protected]>
Signed-off-by: Nils Gruson <[email protected]>
Added `<IncludeBuildOutput>false</IncludeBuildOutput>` to
`Dapr.Workflow.Analyzers.csproj` to prevent the build output
from being included as a library dependency. This change
includes a comment for clarity and aligns with existing
NuGet package properties.

Signed-off-by: Nils Gruson <[email protected]>
Updated the WorkflowRegistrationCodeFixProvider to include logic for obtaining the semantic model and extracting workflow type names. Added methods for finding and creating the AddDaprWorkflow invocation. Modified the Utilities class to reference WebApplication. Expanded test coverage in WorkflowRegistrationCodeFixProviderTests with new cases for handling AddDaprWorkflow invocations, including standard and top-level statements.

Signed-off-by: Nils Gruson <[email protected]>
- Introduced new projects for `Dapr.Pubsub.Analyzers` and `Dapr.Pubsub.Analyzers.Test` in the solution.
- Updated solution configuration to include new analyzers for Debug and Release builds.
- Added analyzer rule DAPR2001 to enforce calling `MapSubscribeHandler` for Dapr subscriptions.
- Implemented `MapSubscribeHandlerCodeFixProvider` for automatic code fixes.
- Developed `SubscriptionAnalyzer` to validate subscription method usage.
- Added unit tests for the new analyzer and code fix provider.
- Updated test utilities and configurations to support new functionality.

Signed-off-by: Nils Gruson <[email protected]>
@ngruson ngruson requested review from a team as code owners January 16, 2025 15:48
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.

Add analyzers that help prevent developer gotchas
2 participants