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

Retarget analysers from .NETStandard 2.1 to 2.0 #692

Open
wants to merge 9 commits into
base: v8.1
Choose a base branch
from

Conversation

Patonymous
Copy link
Contributor

Targeting .NET Standard 2.0 allows us to support msbuild used in Visual Studio.

I've attempted not to modify the analysers source code and instead provided implementations of .NET System Corelib functionalities which were missing. Taking them from official implementation wherever possible and providing my own were it was simpler.

Copy link

github-actions bot commented Sep 2, 2024

Test Results

 35 files  136 suites   1m 1s ⏱️
772 tests 759 ✅ 13 💤 0 ❌
788 runs  768 ✅ 20 💤 0 ❌

Results for commit 58fcd13.

♻️ This comment has been updated with latest results.

Copy link
Member

@jakubfijalkowski jakubfijalkowski left a comment

Choose a reason for hiding this comment

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

Okay, I checked what would be needed if we don't want to import the Index and Range and not include the NotNull attributes, and I conclude that it is not worth it. This will be literally 8 line change, whereas we import almost 500 lines of code to make the 8 work. Not worth it.

Copy link
Member

Choose a reason for hiding this comment

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

This is a heavy dependency and I wonder if it is worth it. What would be needed if we remove this and Range (roughly)?

Copy link
Member

Choose a reason for hiding this comment

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

I suggest we just add a reference to Microsoft.Bcl.Memory and that would be it.

(I also just learned that this package exists because it's fairly new.)

Copy link
Member

Choose a reason for hiding this comment

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

Or do that, that would be okay, provided that the package would not be in preview (although that is still much better than vendoring these).

Copy link
Member

Choose a reason for hiding this comment

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

Thinking about it more - I fear that re-defining the types or importing them from Bcl-polyfills package would be problematic. MSBuild loads the analyzers in-proc, thus it will fail if types are re-imported, or if there is a need to load two versions of the same library. :(

Copy link
Member

Choose a reason for hiding this comment

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

It should leave the preview stage next week (or at worst next month) but I'm not sure if we should even care about it, we are using the part of it that I'd expect be stable by now.

About multiple versions: if other analyzers having their own deps is not a problem already then this one shouldn't be either. But let's give it a try and see if anything breaks 🙂

Copy link
Member

Choose a reason for hiding this comment

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

The main problem with

if other analyzers having their own deps is not a problem already
that I have is - we don't know that. Noone uses VS, we tend not to use too many analyzers. :P

However, let's indeed test that case - i.e. let's test if two analyzers with conflicting libraries work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the Microsoft.Bcl.Memory package reference and will test if it works with msbuild

Copy link
Member

@jakubfijalkowski jakubfijalkowski Sep 3, 2024

Choose a reason for hiding this comment

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

Remember to test the case of two analyzers with conflicting references, e.g. one uses version X and the other version Y and both are used in a single project. I am pretty sure that this particular package won't be a problem now, but it might be when the next version comes up and other analyzers decide to use it.

@Saancreed
Copy link
Member

Okay, I checked what would be needed if we don't want to import the Index and Range and not include the NotNull attributes, and I conclude that it is not worth it. This will be literally 8 line change, whereas we import almost 500 lines of code to make the 8 work. Not worth it.

I'd try to import Index and Range from standalone BCL compatibility packages, and the reconsider if nullables are worth it or not. But for them I have no strong preference so we could just get rid of nullables if you think that would make it less clunky.

Copy link
Member

@Saancreed Saancreed left a comment

Choose a reason for hiding this comment

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

I have one more random idea to consider but current revision looks okay too.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 suggestion.

Files not reviewed (2)
  • Directory.Build.targets: Language not supported
  • src/Tools/LeanCode.CodeAnalysis/LeanCode.CodeAnalysis.csproj: Language not supported
Comments skipped due to low confidence (1)

src/Tools/LeanCode.CodeAnalysis/NetStandard21Compatibility/MissingFileMethods.cs:33

  • The error message 'Path is invalid' is unclear. Consider changing it to 'The provided path is either null, empty, or contains only white-space characters.'
throw new ArgumentException("Path is invalid");

public static class MissingStringMethods
{
public static bool Contains(this string s, string value, StringComparison comparisonType) =>
s.IndexOf(value, comparisonType) >= 0;
Copy link
Preview

Copilot AI Nov 21, 2024

Choose a reason for hiding this comment

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

The method Contains should handle null values for the value parameter to avoid potential ArgumentNullException.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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.

3 participants