I'm trying to get CodeRush for Roslyn configured such that whitespace is normalized / cleaned up after running Code Cleanup.
My desired outcome is that every member in the entire class has exactly one blank line between it and the next member. Also, there should be no whitespace after opening a class / namespace or before closing it.
Unfortunately, I'm unable to figure out the right combination of settings to make that happen.
For example, starting with this code…
C#using System;
using System.Linq;
using Microsoft.AspNet.Mvc;
namespace MyProject.Controllers
{
public class KeysController : Controller
{
[Route("api/keys")]
[HttpGet]
public IActionResult GetKeys()
{
throw new NotImplementedException();
}
[Route("api/keys/{id}")]
[HttpGet]
public IActionResult GetKey(int id)
{
throw new NotImplementedException();
}
}
}
Notice the whitespace above and below the "GetKeys" method.
After running code cleanup, what I want it to look like is this:
C#using System;
using System.Linq;
using Microsoft.AspNet.Mvc;
namespace MyProject.Controllers
{
public class KeysController : Controller
{
[Route("api/keys/{id}")]
[HttpGet]
public IActionResult GetKey(int id)
{
throw new NotImplementedException();
}
[Route("api/keys")]
[HttpGet]
public IActionResult GetKeys()
{
throw new NotImplementedException();
}
}
}
What it actually looks like is this:
C#using System;
using System.Linq;
using Microsoft.AspNet.Mvc;
namespace MyProject.Controllers
{
public class KeysController : Controller
{
[Route("api/keys/{id}")]
[HttpGet]
public IActionResult GetKey(int id)
{
throw new NotImplementedException();
}
[Route("api/keys")]
[HttpGet]
public IActionResult GetKeys()
{
throw new NotImplementedException();
}
}
}
My "organize members" settings are as follows:
* Rules scheme = StyleCop
* Empty line count between groups = 1
* Remove existing line breaks = checked
* Skip initialized fields = unchecked
* All default rules listed have the "Empty line count between members" value set to 1. (That's the only change.)
My "code cleanup" settings have the following items checked:
* Organize members
* Remove all regions
* Remove unused namespace references
* Sort namespace references
* Use 'nameof'
* Remove redundant type cast
* Force braces in statements
* Remove unused variables
* Remove redundant braces in statements
* Apply variable declaration style
* Apply built-in type style
* Apply 'this' qualifier style
* Apply visibility style
Let me know if there's something I'm missing to get the desired result. Thanks!
Hi Travis,
Thank you for providing the code sample and your Organize Members and Code Cleanup settings. I have reproduced this issue with remaining redundant line breaks after applying the Code Cleanup feature. We are working on it and will notify you when we have any results.