Skip to content

Add HandlerStyleAnalyzer to enforce nservicebus_handler_style editorconfig setting#7682

Closed
Copilot wants to merge 2 commits intohandler-style-settingfrom
copilot/sub-pr-7681
Closed

Add HandlerStyleAnalyzer to enforce nservicebus_handler_style editorconfig setting#7682
Copilot wants to merge 2 commits intohandler-style-settingfrom
copilot/sub-pr-7681

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

The nservicebus_handler_style editorconfig setting previously only influenced code fix suggestions for new handlers. This adds an analyzer that enforces the setting on existing handlers too.

Changes

  • DiagnosticIds.cs — Two new IDs:

    • NSB0039 (HandlerStyleConventionRequired)
    • NSB0040 (HandlerStyleIHandleMessagesRequired)
  • Handlers/HandlerStyleAnalyzer.cs (new) — Enforces the editorconfig setting:

    • Returns early if nservicebus_handler_style is not set
    • Skips sagas (convention-based identification not supported)
    • Conventions setting → NSB0039 warning on any class implementing IHandleMessages<T>
    • IHandleMessages setting → NSB0040 warning on any class with [Handler] that does not implement IHandleMessages<T>
    • Setting evaluation is case-insensitive; both diagnostics are Warning severity
// .editorconfig: nservicebus_handler_style = IHandleMessages

[Handler]
public class MyHandler  // ⚠ NSB0040: does not implement IHandleMessages<T>
{
    public async Task Handle(MyMessage message, IMessageHandlerContext context) { }
}

// .editorconfig: nservicebus_handler_style = Conventions

[Handler]
public class MyHandler : IHandleMessages<MyMessage>  // ⚠ NSB0039: should use convention-based Handle method
{
    public async Task Handle(MyMessage message, IMessageHandlerContext context) { }
}

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 1, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet build src/NServiceBus.Core.Analyzer/NServiceBus.Core.Analyzer.csproj --no-incremental (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build src/NServiceBus.Core.Analyzer/NServiceBus.Core.Analyzer.csproj --no-restore (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Add options for handler style settable via .editorconfig Add HandlerStyleAnalyzer to enforce nservicebus_handler_style editorconfig setting Apr 1, 2026
Copilot AI requested a review from DavidBoike April 1, 2026 13:59
@DavidBoike
Copy link
Copy Markdown
Member

Closing, not sold on this implementation

@DavidBoike DavidBoike closed this Apr 6, 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.

3 participants