Skip to content

Commit

Permalink
Create a shared Common .projitems (#235)
Browse files Browse the repository at this point in the history
This is another preparatory refactoring change. The intention is to make
it easier to share both files and settings across the analyzers and code
fixes by using a shared `Common.projitems` file.

To make editing the common files easier, there's also a `Common.csproj`
project, however that's marked as not packable / publishable. Visual
Studio has its own `.shproj` format for these types of projects, but
they have several disadvantages:

1. They aren't SDK-style
2. They don't work with modern refactoring motions (as experienced when
using in them in SquiggleCop)
3. I haven't tried them in Rider?

A simple project sidesteps all these issues at the expense of compiling
an extra .dll that's unused.
  • Loading branch information
MattKotsenas authored Oct 22, 2024
1 parent 7053d96 commit bbb213d
Show file tree
Hide file tree
Showing 43 changed files with 82 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,8 @@
*.verified.xml text eol=lf working-tree-encoding=UTF-8
*.verified.json text eol=lf working-tree-encoding=UTF-8

# See https://github.com/MattKotsenas/SquiggleCop?tab=readme-ov-file#encodings--line-endings
SquiggleCop.Baseline.yaml text eol=lf

# Fix syntax highlighting on GitHub to allow comments
.vscode/*.json linguist-language=JSON-with-Comments
15 changes: 13 additions & 2 deletions Moq.Analyzers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers", "src\Moq.Analyzers\Moq.Analyzers.csproj", "{41ECC571-F586-460A-9BED-23528C8210C4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers", "src\Analyzers\Moq.Analyzers.csproj", "{41ECC571-F586-460A-9BED-23528C8210C4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers.Test", "tests\Moq.Analyzers.Test\Moq.Analyzers.Test.csproj", "{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers.Benchmarks", "tests\Moq.Analyzers.Benchmarks\Moq.Analyzers.Benchmarks.csproj", "{11B3412F-456C-452E-94D2-B42D5C52F61C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.CodeFixes", "src\Moq.CodeFixes\Moq.CodeFixes.csproj", "{8E99C15C-E80A-49E5-988C-1B5071CE775F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.CodeFixes", "src\CodeFixes\Moq.CodeFixes.csproj", "{8E99C15C-E80A-49E5-988C-1B5071CE775F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{013D4F80-9978-45DA-9BB8-6638239355E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers.Test.Analyzers", "tests\Moq.Analyzers.Test.Analyzers\Moq.Analyzers.Test.Analyzers.csproj", "{C68B6F38-838B-4BD9-963D-95779B6F418B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "src\Common\Common.csproj", "{622DB72F-5609-4C08-838D-6937A680094A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,6 +43,10 @@ Global
{C68B6F38-838B-4BD9-963D-95779B6F418B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C68B6F38-838B-4BD9-963D-95779B6F418B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C68B6F38-838B-4BD9-963D-95779B6F418B}.Release|Any CPU.Build.0 = Release|Any CPU
{622DB72F-5609-4C08-838D-6937A680094A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{622DB72F-5609-4C08-838D-6937A680094A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{622DB72F-5609-4C08-838D-6937A680094A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{622DB72F-5609-4C08-838D-6937A680094A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -53,4 +59,9 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8C917BC1-C0DE-4A46-BEE8-32FD66B447B1}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Common\Common.projitems*{41ecc571-f586-460a-9bed-23528c8210c4}*SharedItemsImports = 5
src\Common\Common.projitems*{622db72f-5609-4c08-838d-6937a680094a}*SharedItemsImports = 5
src\Common\Common.projitems*{8e99c15c-e80a-49e5-988c-1b5071ce775f}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion build/targets/codeanalysis/CodeAnalysis.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<PedanticMode Condition=" '$(PedanticMode)' == '' ">$([MSBuild]::ValueOrDefault('$(ContinuousIntegrationBuild)', 'false'))</PedanticMode>
<TreatWarningsAsErrors>$(PedanticMode)</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>$(PedanticMode)</MSBuildTreatWarningsAsErrors>
<SquiggleCop_Enabled>$(PedanticMode)</SquiggleCop_Enabled>
<SquiggleCop_Enabled Condition=" '$(SquiggleCop_Enabled)' == '' ">$(PedanticMode)</SquiggleCop_Enabled>
</PropertyGroup>
</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
</ItemGroup>

<Import Project="$(RepoRoot)/src/Common/Common.projitems" Label="Shared" />

<ItemGroup>
<Compile Update="Resources.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Resources.resx" />
<EmbeddedResource Update="Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
</ItemGroup>

Expand All @@ -40,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\Moq.CodeFixes\Moq.CodeFixes.csproj" />
<ProjectReference Include="$(RepoRoot)/src/CodeFixes/Moq.CodeFixes.csproj" />
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions src/CodeFixes/Moq.CodeFixes.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Moq.CodeFixes</RootNamespace>
<AssemblyName>Moq.CodeFixes</AssemblyName>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" />
</ItemGroup>

<Import Project="$(RepoRoot)/src/Common/Common.projitems" Label="Shared" />

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@
- {Id: S2479, Title: Whitespace and control characters in string literals should be explicit, Category: Critical Code Smell, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: S2486, Title: Generic exceptions should not be ignored, Category: Minor Code Smell, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: S2551, Title: Shared resources should not be used for locking, Category: Critical Bug, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: S2583, Title: Conditionally executed code should be reachable, Category: Major Bug, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: S2583, Title: Conditionally executed code should be reachable, Category: Major Bug, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: true}
- {Id: S2589, Title: Boolean expressions should not be gratuitous, Category: Major Code Smell, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: true}
- {Id: S2612, Title: Setting loose file permissions is security-sensitive, Category: Major Security Hotspot, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
- {Id: S2629, Title: Logging templates should be constant, Category: Major Code Smell, DefaultSeverity: Warning, IsEnabledByDefault: true, EffectiveSeverities: [Error], IsEverSuppressed: false}
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions src/Common/Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<!--
NOTE: This project is not intended to be referenced directly. The common components should instead be compiled
directly into the consuming project to reduce the dependencies and assembly load costs. Instead, Import
`Common.projitems` in your project file.
This project _could_ be a NoTargets project, but then Navigate-To-Definition and other editor features don't work
when viewing files in the context of the Common project (presumably because it sees them as loose files with no
associated compilation).
This is effectively a .shproj, however they tend to break refactoring tools (namely "Move to file") which don't
understand which "context" they're operating in.
-->

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Moq.Analyzers.Common</RootNamespace>
<AssemblyName>$(RootNamespace)</AssemblyName>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
<SquiggleCop_Enabled>false</SquiggleCop_Enabled>
</PropertyGroup>

<PropertyGroup Label="Shared project settings">
<!-- Disable default behavior so we rely on the included props -->
<EnableDefaultItems>false</EnableDefaultItems>
<ShowCommonFiles>true</ShowCommonFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
</ItemGroup>

<Import Project="$(RepoRoot)/src/Common/Common.projitems" Label="Shared" />
</Project>
5 changes: 5 additions & 0 deletions src/Common/Common.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)/**/*.cs" Visible=" '$(ShowCommonFiles)' == 'true' " />
</ItemGroup>
</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Moq.Analyzers;
namespace Moq.Analyzers.Common;

/// <summary>
/// A class that, given a <see cref="SemanticModel"/> and a <see cref="MemberAccessExpressionSyntax"/>, determines if
Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions src/Moq.CodeFixes/Moq.CodeFixes.csproj

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)/src/Moq.Analyzers/Moq.Analyzers.csproj" />
<ProjectReference Include="$(RepoRoot)/src/Analyzers/Moq.Analyzers.csproj" />
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Moq.Analyzers\Moq.Analyzers.csproj" />
<ProjectReference Include="$(RepoRoot)/src/Analyzers/Moq.Analyzers.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions tests/Moq.Analyzers.Test/Moq.Analyzers.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<PackageReference Include="Verify.Nupkg" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(RepoRoot)/src/Moq.Analyzers/Moq.Analyzers.csproj" AddPackageAsOutput="true" />
<ProjectReference Include="..\Moq.Analyzers.Test.Analyzers\Moq.Analyzers.Test.Analyzers.csproj" />
<ProjectReference Include="$(RepoRoot)/src/Analyzers/Moq.Analyzers.csproj" AddPackageAsOutput="true" />
<ProjectReference Include="$(RepoRoot)/tests/Moq.Analyzers.Test.Analyzers/Moq.Analyzers.Test.Analyzers.csproj" />
</ItemGroup>

</Project>

0 comments on commit bbb213d

Please sign in to comment.