Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kzu
Created September 15, 2018 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzu/5ebac843a089bf14ba03f3f2db3949a9 to your computer and use it in GitHub Desktop.
Save kzu/5ebac843a089bf14ba03f3f2db3949a9 to your computer and use it in GitHub Desktop.
Automatically applying Roslyn code fixes during build
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