Skip to content

SPLA-4322 - Sharing the constant analyzer between regular and test analyzers#981

Merged
omsmith merged 5 commits into
mainfrom
littlefoot/splitting
Jul 16, 2026
Merged

SPLA-4322 - Sharing the constant analyzer between regular and test analyzers#981
omsmith merged 5 commits into
mainfrom
littlefoot/splitting

Conversation

@toddlang

Copy link
Copy Markdown
Contributor

-Adding logic to support constant usages in test-only contexts (rhino mocks, for example)

-Adding logic to support constant usages in test-only contexts (rhino mocks, for example)
#region String tests
string variableStr = "This is a variable message";
const string CONSTANT_STR = "This is a constant message";
ConstantString constantStr = "This is a constant string message";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is meaningless? D2L.Core doesn't exist in these tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sorry, thought I had removed that in another commit, but the merge brought it back. A leftover from when I was exploring making the analyzer "understand" ConstantString. (It was a dumb idea)

Comment thread src/D2L.CodeStyle.Analyzers/D2L.CodeStyle.Analyzers.csproj
Comment on lines +30 to +31
<None Include="$(OutputPath)\$(AssemblyName).Rule.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\$(AssemblyName).Rule.Constant.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<None Include="$(OutputPath)\$(AssemblyName).Rule.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\$(AssemblyName).Rule.Constant.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\$(AssemblyName).Rule.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\$(AssemblyName).Rule.Constant.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />

Comment on lines +29 to +30
<None Include="$(OutputPath)\D2L.CodeStyle.Analyzers.Rule.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\D2L.CodeStyle.Analyzers.Rule.Constant.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<None Include="$(OutputPath)\D2L.CodeStyle.Analyzers.Rule.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\D2L.CodeStyle.Analyzers.Rule.Constant.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\D2L.CodeStyle.Analyzers.Rule.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\D2L.CodeStyle.Analyzers.Rule.Constant.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />

Comment on lines +52 to +59
<ItemGroup>
<ProjectReference Include="..\Rules\D2L.CodeStyle.Analyzers.Rule.Constant\D2L.CodeStyle.Analyzers.Rule.Constant\D2L.CodeStyle.Analyzers.Rule.Constant.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
<ProjectReference Include="..\Rules\D2L.CodeStyle.Analyzers.Rule\D2L.CodeStyle.Analyzers.Rule\D2L.CodeStyle.Analyzers.Rule.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<ItemGroup>
<ProjectReference Include="..\Rules\D2L.CodeStyle.Analyzers.Rule.Constant\D2L.CodeStyle.Analyzers.Rule.Constant\D2L.CodeStyle.Analyzers.Rule.Constant.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
<ProjectReference Include="..\Rules\D2L.CodeStyle.Analyzers.Rule\D2L.CodeStyle.Analyzers.Rule\D2L.CodeStyle.Analyzers.Rule.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Rules\D2L.CodeStyle.Analyzers.Rule.Constant\D2L.CodeStyle.Analyzers.Rule.Constant\D2L.CodeStyle.Analyzers.Rule.Constant.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
<ProjectReference Include="..\Rules\D2L.CodeStyle.Analyzers.Rule\D2L.CodeStyle.Analyzers.Rule\D2L.CodeStyle.Analyzers.Rule.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>

Comment on lines +136 to +144
// Argument is inside an expression tree (e.g. Moq Verify/Setup), so do nothing
if( IsInsideExpressionTree( argument ) ) {
return;
}

// Argument is a mock argument constraint (e.g. Arg<string>.Is.Anything), so do nothing
if( IsMockArgumentConstraint( argument.Value ) ) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was wondering if there was a way we could make this toggleable, like #if D2L_INCLUDE_TEST_CHECKS and pass that via <AdditionalProperties> in the ProjectReference, but I couldn't figure it out quickly (and may not work having two versions of the same DLL loaded into analyzers)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could do it via AnalyzerOptions, but, follow-up-able

@omsmith omsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I maybe didn't catch all of the tabs-in-csproj. But between fixing those up, and the D2L.Core-in-tests, looks good

-Removing D2L.Core addition and ConstantString reference in spec tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<Version>0.224.0</Version>

@toddlang toddlang changed the title Sharing the constant analyzer between regular and test analyzers SPLA-4322 - Sharing the constant analyzer between regular and test analyzers Jul 16, 2026
@toddlang

Copy link
Copy Markdown
Contributor Author

Compile is clear, FWIW

@omsmith
omsmith merged commit 8302699 into main Jul 16, 2026
5 checks passed
@omsmith
omsmith deleted the littlefoot/splitting branch July 16, 2026 20:41
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