Skip to content

Commit

Permalink
Move analyzers to main repo (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcoltheart authored Dec 15, 2024
1 parent 59414c9 commit f93c224
Show file tree
Hide file tree
Showing 24 changed files with 1,218 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Machine.Specifications.sln
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Machine.Specifications", "src\Machine.Specifications\Machine.Specifications.csproj", "{EC054D80-8858-4A61-9FD9-0185EA3F4643}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{1D85E618-71A9-43F2-B76D-95DC161E2A13}"
ProjectSection(SolutionItems) = preProject
build.ps1 = build.ps1
build.sh = build.sh
.github\workflows\build.yml = .github\workflows\build.yml
CONTRIBUTING.md = CONTRIBUTING.md
.config\dotnet-tools.json = .config\dotnet-tools.json
GitVersion.yml = GitVersion.yml
.github\workflows\publish.yml = .github\workflows\publish.yml
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Machine.Specifications.Runner.Utility", "src\Machine.Specifications.Runner.Utility\Machine.Specifications.Runner.Utility.csproj", "{7E11A6CD-5900-4FFD-AE68-231BDA2436BA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Machine.Specifications.Runner.Utility.Specs", "src\Machine.Specifications.Runner.Utility.Specs\Machine.Specifications.Runner.Utility.Specs.csproj", "{068B7D50-95A9-4510-96DC-59AB697D6C5F}"
Expand All @@ -33,6 +21,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Machine.Specifications.Core
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Machine.Specifications.Fixtures", "src\Machine.Specifications.Fixtures\Machine.Specifications.Fixtures.csproj", "{2934AB5B-7506-4150-B61B-FE16EBB13D50}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Machine.Specifications.Analyzers", "src\Machine.Specifications.Analyzers\Machine.Specifications.Analyzers.csproj", "{0CFB2FE5-BDAF-4B7B-9E05-F05491B05CDA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Machine.Specifications.Analyzers.Tests", "src\Machine.Specifications.Analyzers.Tests\Machine.Specifications.Analyzers.Tests.csproj", "{402EF260-6140-4633-880B-18BEBF7B9DA2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -75,6 +67,14 @@ Global
{2934AB5B-7506-4150-B61B-FE16EBB13D50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2934AB5B-7506-4150-B61B-FE16EBB13D50}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2934AB5B-7506-4150-B61B-FE16EBB13D50}.Release|Any CPU.Build.0 = Release|Any CPU
{0CFB2FE5-BDAF-4B7B-9E05-F05491B05CDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CFB2FE5-BDAF-4B7B-9E05-F05491B05CDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CFB2FE5-BDAF-4B7B-9E05-F05491B05CDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CFB2FE5-BDAF-4B7B-9E05-F05491B05CDA}.Release|Any CPU.Build.0 = Release|Any CPU
{402EF260-6140-4633-880B-18BEBF7B9DA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{402EF260-6140-4633-880B-18BEBF7B9DA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{402EF260-6140-4633-880B-18BEBF7B9DA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{402EF260-6140-4633-880B-18BEBF7B9DA2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
48 changes: 48 additions & 0 deletions src/Machine.Specifications.Analyzers.Tests/AnalyzerVerifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;

namespace Machine.Specifications.Analyzers.Tests;

public static class AnalyzerVerifier<TAnalyzer>
where TAnalyzer : DiagnosticAnalyzer, new()
{
public static DiagnosticResult Diagnostic()
{
return CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic();
}

public static DiagnosticResult Diagnostic(string diagnosticId)
{
return CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic(diagnosticId);
}

public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
{
return CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic(descriptor);
}

public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
{
var test = new Test
{
TestCode = source
};

test.ExpectedDiagnostics.AddRange(expected);

await test.RunAsync(CancellationToken.None);
}

private class Test : CSharpAnalyzerTest<TAnalyzer, DefaultVerifier>
{
public Test()
{
ReferenceAssemblies = VerifierHelper.MspecAssemblies;
SolutionTransforms.Add(VerifierHelper.GetNullableTransform);
}
}
}
74 changes: 74 additions & 0 deletions src/Machine.Specifications.Analyzers.Tests/CodeFixVerifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;

namespace Machine.Specifications.Analyzers.Tests
{
public static class CodeFixVerifier<TAnalyzer, TCodeFix>
where TAnalyzer : DiagnosticAnalyzer, new()
where TCodeFix : CodeFixProvider, new()
{
public static DiagnosticResult Diagnostic()
{
return CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic();
}

public static DiagnosticResult Diagnostic(string diagnosticId)
{
return CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(diagnosticId);
}

public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
{
return CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(descriptor);
}

public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
{
var test = new Test
{
TestCode = source
};

test.ExpectedDiagnostics.AddRange(expected);

await test.RunAsync(CancellationToken.None);
}

public static async Task VerifyCodeFixAsync(string source, string fixedSource)
{
await VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource);
}

public static async Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource)
{
await VerifyCodeFixAsync(source, new[] {expected}, fixedSource);
}

public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource)
{
var test = new Test
{
TestCode = source,
FixedCode = fixedSource
};

test.ExpectedDiagnostics.AddRange(expected);

await test.RunAsync(CancellationToken.None);
}

private class Test : CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier>
{
public Test()
{
ReferenceAssemblies = VerifierHelper.MspecAssemblies;
SolutionTransforms.Add(VerifierHelper.GetNullableTransform);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Machine.Specifications.Analyzers\Machine.Specifications.Analyzers.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit f93c224

Please sign in to comment.