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

Update SA1121 and SA1404 to detect global using aliases [on hold] #3671

Conversation

bjornhellander
Copy link
Contributor

Fixes #3594. SA1404 also suffered from the same problem.

@codecov
Copy link

codecov bot commented Jun 19, 2023

Codecov Report

Merging #3671 (16222ee) into master (b80f0c2) will decrease coverage by 0.01%.
The diff coverage is 93.61%.

❗ Current head 16222ee differs from pull request most recent head f2a69ed. Consider uploading reports for the commit f2a69ed to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3671      +/-   ##
==========================================
- Coverage   93.26%   93.26%   -0.01%     
==========================================
  Files        1080     1082       +2     
  Lines      113982   114065      +83     
  Branches     4045     4047       +2     
==========================================
+ Hits       106303   106380      +77     
- Misses       6641     6646       +5     
- Partials     1038     1039       +1     

…ntax tree, by filling the dictionary directly when it is created. In the previous commit, it was checked for global using aliases once and then again for normal using aliases.

DotNetAnalyzers#3594
@bjornhellander bjornhellander force-pushed the feature/global-using-alias branch from cc8ce74 to f2a69ed Compare June 19, 2023 21:10

return nodes.OfType<UsingDirectiveSyntax>().Any(x => x.Alias != null);
foreach (var tree in compilation.SyntaxTrees)
Copy link
Member

@sharwell sharwell Jun 21, 2023

Choose a reason for hiding this comment

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

❗ I have concerns about the performance impact of this change. We've seen many cases where analyzer initialization overhead is the dominant contributor to a negative performance trace. I believe it would be better to use SemanticModel.GetImportScopes for this purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. GetImportScopes seems to be supported from Roslyn 4.3 and global usings from 4.0, so I guess that there will be some versions where the bug will still exist if that approach is taken, but some false negatives might be ok since it will only happen for a few versions?

Would this method be supported automatically with newer (than c# 8) light-up support or would it require manually implementing that support?

Is this method quick? I have gotten the impression that the semantic model should be used with care, but maybe this is not a problematic method.

@bjornhellander bjornhellander changed the title Update SA1121 and SA1404 to detect global using aliases Update SA1121 and SA1404 to detect global using aliases [on hold] Jul 13, 2023
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.

SA1121: Inconsistent behaviour with respect to global using aliases
2 participants