-
Notifications
You must be signed in to change notification settings - Fork 649
Analyzer: Error when Feature Defaults are used to enable other features #7468
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
Conversation
DavidBoike
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review done on an iPad on an airplane, no compiler support. 😉
src/NServiceBus.Core.Analyzer/FeatureDefaultsEnableFeatureAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NServiceBus.Core.Analyzer/FeatureDefaultsEnableFeatureAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NServiceBus.Core.Analyzer/FeatureDefaultsEnableFeatureAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NServiceBus.Core.Analyzer.Tests.Common/FeatureDefaultsEnableFeatureAnalyzerTests.cs
Show resolved
Hide resolved
src/NServiceBus.Core.Analyzer.Tests.Common/FeatureDefaultsEnableFeatureFixerTests.cs
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
* Initial plan * Optimize analyzer performance and modernize test code blocks Co-authored-by: danielmarbach <174258+danielmarbach@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danielmarbach <174258+danielmarbach@users.noreply.github.com>
src/NServiceBus.Core.Analyzer/FeatureDefaultsEnableFeatureAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NServiceBus.Core.Analyzer/FeatureDefaultsEnableFeatureAnalyzer.cs
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
|
@danielmarbach I've opened a new pull request, #7476, to work on those changes. Once the pull request is ready, I'll request review from you. |
andreasohlund
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (based on very limited analyzer knowledge so I would wait for Davids approval)
DavidBoike
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I can't think of any other tests to add, let's go with it but be sure to smoke test it with the next alpha.
This pull request introduces a new Roslyn analyzer and code fix to enforce best practices around enabling features. It detects and corrects the use of
EnableFeature<TFeature>()within theDefaultsmethod of a feature, prompting developers to use the protectedEnable<TFeature>()method in the constructor instead.Analyzer and code fix for feature enablement:
FeatureDefaultsEnableFeatureAnalyzerto report diagnostics whenEnableFeature<TFeature>()is called inside aDefaultslambda, enforcing that dependent features should be enabled usingEnable<TFeature>()in the constructor instead.FeatureDefaultsEnableFeatureFixerto automatically moveEnableFeature<TFeature>()calls from withinDefaultslambdas to the feature constructor, optionally removing or updating theDefaultsblock as needed.NSB0019for this rule inDiagnosticIds.Scoped out: