Skip to content

Wrong indentation when using primary constructor #2165

Open
@aserrabi

Description

@aserrabi
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions