SPLA-4322 - Sharing the constant analyzer between regular and test analyzers#981
Conversation
-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"; |
There was a problem hiding this comment.
I think this is meaningless? D2L.Core doesn't exist in these tests
There was a problem hiding this comment.
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)
| <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" /> |
There was a problem hiding this comment.
| <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" /> |
| <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" /> |
There was a problem hiding this comment.
| <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" /> |
| <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> |
There was a problem hiding this comment.
| <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> |
| // 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; | ||
| } |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Could do it via AnalyzerOptions, but, follow-up-able
omsmith
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
| <Version>0.224.0</Version> |
|
Compile is clear, FWIW |
-Adding logic to support constant usages in test-only contexts (rhino mocks, for example)