Created
September 15, 2018 06:59
-
-
Save kzu/5ebac843a089bf14ba03f3f2db3949a9 to your computer and use it in GitHub Desktop.
Automatically applying Roslyn code fixes during build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: AutoFix | |
Applies code fixes during build | |
Scenario: Can apply StyleCop code fix automatically | |
Given Foo.csproj = | |
""" | |
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<LangVersion>Latest</LangVersion> | |
<TargetFramework>netstandard2.0</TargetFramework> | |
<RestoreSources>$(TEMP)\packages;https://api.nuget.org/v3/index.json</RestoreSources> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="AutoCodeFix" Version="*" /> | |
<PackageReference Include="xunit" Version="2.4.0" /> | |
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta*" /> | |
</ItemGroup> | |
<ItemGroup> | |
<!-- System usings should go first --> | |
<AutoFix Include="SA1208" /> | |
<!-- Blank line required before single-line comment --> | |
<AutoFix Include="SA1515" /> | |
</ItemGroup> | |
</Project> | |
""" | |
And Class1.cs = | |
""" | |
using Xunit; | |
using System; | |
public static class Program | |
{ | |
public static async void Main() | |
{ | |
Console.WriteLine("Hello"); | |
// This comment is too tight | |
Console.ReadLine(); | |
} | |
} | |
""" | |
When restoring packages | |
And building project | |
Then build succeeds | |
And Class1.cs = | |
""" | |
using System; | |
using Xunit; | |
public static class Program | |
{ | |
public static async void Main() | |
{ | |
Console.WriteLine("Hello"); | |
// This comment is too tight | |
Console.ReadLine(); | |
} | |
} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment