dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.12k stars 4.04k forks source link

Formatting option to insert newline after file scoped namespace declarations #67400

Open vsfeedback opened 1 year ago

vsfeedback commented 1 year ago

This issue has been moved from a ticket on Developer Community.


Currently, the default formatter for C# does not care whether you have a newline after a file scoped namespace or not.

// This:

namespace OL. PharmaPos.Modules.ProductsCatalog.Domain.Products;
using FluentResults;

public readonly record struct ProductId
{
}

// ... as well as this:

namespace OL. PharmaPos.Modules.ProductsCatalog.Domain.Products;

using FluentResults;

public readonly record struct ProductId
{
}

// ... are perfectly accepted by VS 2022, currently.

I would like to have the option to make the first variant illegal or be automatically formatted on document format (Ctrl+K, Ctrl+D) to look like the second variant. Basically this inserts a new line after a file scoped namespace declaration.


Original Comments

Feedback Bot on 3/13/2023, 01:18 AM:

(private comment, text removed)

sharwell commented 9 months ago

I don't think we need an option here, since we could simply update the formatter to always apply the blank line.

sagarok commented 2 months ago

Is it going to be implemented?

CyrusNajmabadi commented 2 months ago

@sagarok We're happy to take community contributions, if this is something that you would find valuable to have :)