Skip to content

Add Moq.Analyzers #6253

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add Moq.Analyzers #6253

wants to merge 6 commits into from

Conversation

Evangelink
Copy link
Member

No description provided.

@@ -34,6 +34,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="$(MicrosoftCodeAnalysisBannedApiAnalyzersVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(MicrosoftCodeAnalysisPublicApiAnalyzersVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.14.15" />
<PackageVersion Include="Moq.Analyzers" Version="0.3.0" />
Copy link
Member

Choose a reason for hiding this comment

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

Note: This package is BSD-3-Clause license. I'm not super familiar with that but thought it's worth noting.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have seen other projects using it so we should be fine. The only question is whether we need to specify that in the third-party licenses given this is only for testing and not shipped.

Copy link
Member

Choose a reason for hiding this comment

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

I think we need it in third-party-notices indeed.

@@ -22,7 +22,7 @@ public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkAssembly()
GetReferencedAssembliesSetter = () => [v1AssemblyName],
};

var mockAssemblyUtility = new Mock<IAssemblyUtility>();
var mockAssemblyUtility = new Mock<IAssemblyUtility>(MockBehavior.Loose);
Copy link
Member

Choose a reason for hiding this comment

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

I feel this analyzer is too annoying. There is nothing very wrong with not specifying the "default" MockBehavior.Loose.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's always about making explicit choice, we have something similar about parallelization in MSTest. Ideally, we should only mock with strict level to ensure no other API is called (another analyzer is set for that).

I am happy to undo changes and reduce severity of this.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we should only mock with strict level

I do agree, but I think we are too far from reaching there.

I'm fine as-is then, even though I personally don't see a point when specifying Loose everywhere. The advantage I can see here is for tests that will be written in future. This might ring a bell for us to not rely on Loose and have the new tests going into the right direction.

Youssef1313
Youssef1313 previously approved these changes Jul 31, 2025
Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

There are few more analyzer warnings, but LGTM.

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

Blocking on license question to avoid accidental merge

Copy link
Contributor

Hello @@Evangelink,
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants