Skip to content

Add Roslyn analyzer for event sink helper consistency (NOE001-NOE003)#473

Merged
jozefizso merged 4 commits intomainfrom
analyzers/event_binders
Apr 14, 2026
Merged

Add Roslyn analyzer for event sink helper consistency (NOE001-NOE003)#473
jozefizso merged 4 commits intomainfrom
analyzers/event_binders

Conversation

@jozefizso
Copy link
Copy Markdown
Member

@jozefizso jozefizso commented Apr 9, 2026

Add Roslyn analyzer for event sink helper consistency (NOE001-NOE003)

Summary

  • Adds a new Roslyn analyzer (EventValidateRaiseConsistencyAnalyzer) that detects common bugs in NetOffice event sink helpers where the event name passed to Validate() doesn't match the event name passed to RaiseCustomEvent()
  • Scoped to classes inheriting from NetOffice.SinkHelper to avoid false positives on unrelated code
  • Introduces three diagnostic rules:
    • NOE001 (Warning): Validate() event name must match RaiseCustomEvent() event name
    • NOE002 (Info): RaiseCustomEvent() event name should match the containing method name
    • NOE003 (Info): Reports when the analyzer cannot reliably verify consistency (non-literal strings, multiple distinct names, etc.)

Motivation

Event sink helpers follow a pattern where Validate("EventName") checks if the event should fire, and RaiseCustomEvent("EventName") actually fires it. A mismatch between these names is a subtle bug that can cause events to never fire or fire incorrectly. This analyzer catches these issues at compile time.

Test plan

  • Build the NetOffice.Analyzers project
  • Reference the analyzer from a NetOffice project
  • Verify NOE001 triggers when Validate("Foo") is paired with RaiseCustomEvent("Bar")
  • Verify NOE002 triggers when method name doesn't match the event name
  • Verify no false positives on non-SinkHelper classes

@jozefizso jozefizso requested a review from m-kovac April 9, 2026 14:55
@jozefizso jozefizso self-assigned this Apr 9, 2026
@jozefizso jozefizso changed the title Create a analyzer for issues with event sink helpers Create an analyzer for issues with event sink helpers Apr 9, 2026
@jozefizso jozefizso changed the title Create an analyzer for issues with event sink helpers Add Roslyn analyzer for event sink helper consistency (NOE001-NOE003) Apr 9, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47a859f19e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Source/Analyzers/NetOffice.Analyzers/NetOffice.Analyzers.csproj
@jozefizso
Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Collaborator

@m-kovac m-kovac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the analyzer in random class that derives from SinkHelper (RecordsetEvents_SinkHelper) but I found out it does not work here because of #pragma warning disable preprocessor directive preventing warnings for whole file.

There are more classes deriving from SinkHelper with the warnings disabled so the analyzer would not be able to catch the event name mismatch there also. Even changing the NOE001 to Error will not help, since those will be also hidden.

I would focus all the preprocessor directives hiding warnings in all the files contaning classes derived from SinkHelper to e.g. #pragma warning disable CS1591 since I assume that warning was a reason why it was used in first place. This way we will get shown valid warnings from new analyzer and can fix them.

We will keep the warning CS1591 (Missing XML comment for publicly visible type or member) disabled as many members are missing documentation comments
@jozefizso jozefizso force-pushed the analyzers/event_binders branch from 878ef99 to 55b26b3 Compare April 14, 2026 13:42
@jozefizso jozefizso requested a review from m-kovac April 14, 2026 13:42
@jozefizso jozefizso merged commit e582054 into main Apr 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants