dotnet / format

Home for the dotnet-format command

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong indentation when using primary constructor

aserrabi opened this issue · comments

using Microsoft.AspNetCore.Mvc;

namespace Web.Controllers;

[Route("test")]
public class TestController : ControllerBase
{
  private readonly ILogger<TestController> logger;

  public TestController(ILogger<TestController> logger)
  {
    this.logger = logger;
  }

  [HttpPost("test/{id}")]
  public ActionResult Test(string id)
  {
    this.logger.LogInformation("Hello {Id}", id);
    return this.Ok("Format me");
  }
}
  • When I run dotnet dotnet-format the file is formatted as follows:
image
  • After some time digging into the problem I realized that changing the primary constructor to a regular constructor fixes the issue. And dotnet-format will not format wrongly the file.
image