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

Fixer for CA1826 #2173

Merged
merged 9 commits into from
Mar 12, 2019
Merged

Conversation

TKharaishvili
Copy link
Contributor

Addresses the issue - #1932

The changes in this PR are obviously not ideal, some of the issues being:

  1. lack of tests
  2. not being implemented for VB
  3. the fixer window showing up for other linq methods too even though it's only implemented for Enumerable.First

but hey it does work for C# and hopefully you guys can help me deal with the rough edges.

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Overall, you need to be much more defensive in code fixers about what nodes/operations are present in the tree. Additionally, it is hard to review the correctness of a PR without unit tests. I would request adding unit tests prior to requesting second round of review. Thanks!

@TKharaishvili
Copy link
Contributor Author

TKharaishvili commented Mar 7, 2019

@mavasani just pushed a new commit with requested fixes as well as unit tests.

The bottom two unit tests named CA1826FixEnumerableFirstMethodChainCallWrongFormattingCSharp and CA1826FixEnumerableFirstProblematicSyntaxCallCSharp document problematic cases I have a little trouble figuring out and will probably need some help with.

As for:

Yes, fixers should not assume anything about the analyzer and/or the diagnostic location or properties.

I added a properties dictionary to the analyzer part. This serves two purposes:

  1. It makes sure that the fixer window only shows up for Enumerable.First and not for the other methods.
  2. The fixer now has more guarantees as to which analyzer invoked it, therefore doesn't require as much defensive code.

If you still think that the fixer should contain those guards regardless, let me know and I'll add them in.

Thanks for your help once again.

@TKharaishvili
Copy link
Contributor Author

@mavasani just pushed the changes addressing the 2nd code review. I'll resolve those conversations now.

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

LGTM. Primary pending request is for adding a VisualBasic unit test.

Thanks for the contribution!

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Marking as request changes as we have a layering violation in the code fixer implementation, that must be fixed prior to merging this in.

mavasani and others added 2 commits March 12, 2019 21:15
…eMethodsOnIndexableCollectionsInsteadUseTheCollectionDirectly.Fixer.cs

Co-Authored-By: TKharaishvili <tor.kharaishvili@gmail.com>
@TKharaishvili
Copy link
Contributor Author

@mavasani I tried to make it work for VB too but wasn't able to. I also opened up a review, please have a look at that as well. Thanks.

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Thanks!

@TKharaishvili
Copy link
Contributor Author

@mavasani thanks to you too! Couldn't have done this without your guidance.

@mavasani
Copy link
Contributor

mavasani commented Mar 12, 2019

@TKharaishvili Can you resolve the merge conflicts? I'd start by just resolving the conflict in src/Microsoft.NetCore.Analyzers/Core/Runtime/SystemRuntimeAnalyzersResources.resx and then doing a rebuild to regenerate the xlf files.

@TKharaishvili
Copy link
Contributor Author

@mavasani I resolved that file in the github ui. But I'm not sure how to trigger rebuild from here...

@mavasani
Copy link
Contributor

I resolved that file in the github ui. But I'm not sure how to trigger rebuild from here...

Not sure if that is supported. You'll probably have to do it locally by deleting the xlf folder on your machine and rebuilding and pushing it.

@TKharaishvili
Copy link
Contributor Author

@mavasani I think it's all finished

@mavasani mavasani merged commit 8652fbc into dotnet:master Mar 12, 2019
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.

2 participants