-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add an analyzer that warns about non-literal sequence numbers #35805
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
src/Framework/Analyzer/src/RenderTreeBuilder/DiagnosticDescriptors.cs
Outdated
Show resolved
Hide resolved
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.
The changes look great. I'd prefer if @SteveSandersonMS to sign off on this to see if there was more / less we should be doing here.
src/Framework/Analyzer/src/RenderTreeBuilder/DiagnosticDescriptors.cs
Outdated
Show resolved
Hide resolved
src/Framework/Analyzer/src/RenderTreeBuilder/DiagnosticDescriptors.cs
Outdated
Show resolved
Hide resolved
src/Framework/Analyzer/src/RenderTreeBuilder/DiagnosticDescriptors.cs
Outdated
Show resolved
Hide resolved
src/Framework/Analyzer/src/RenderTreeBuilder/RenderTreeBuilderAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Framework/Analyzer/test/Components/DisallowNonLiteralSequenceNumbersTest.cs
Show resolved
Hide resolved
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.
Looks brilliant - thanks!
Applying the change in main.
Add an analyzer that warns about non-literal sequence numbers
The analyzer warns when using anything other than integer literals for sequence numbers in
RenderTreeBuilder
methods.Potential improvements to consider
There are definitely situations where it's appropriate for developers to use non-literals as the sequence number (e.g.
RenderTreeBuilder
extension methods that accept asequence
and pass it to aRenderTreeBuilder
method). In such cases, should we expect developers to suppress the warning, or should we attempt something smarter? For example, if the argument passed as the sequence number is itself a parameter of the containing method, should we perform the same analysis on the method containing theRenderTreeBuilder
method invocation? Should we go even further and ensure that the parameter is not reassigned anywhere in the containing method?Fixes #14579