Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditorConfig control File-scoped namespace declaration

I'm using C# 10 new feature File-scoped namespace declaration.

I have old code like this

namespace SampleCode
{
    public class MyClass
    {
    }
}

I'm moving this code to

namespace SampleCode;

public class MyClass
{
}

But I have a bunch of warnings : IDE0160: Convert to block scoped namespace

How do I make sure people will have warnings only with old syntax ?

like image 655
JuChom Avatar asked Dec 09 '22 23:12

JuChom


1 Answers

To control the code style in editorconfig use this line :

To enforce this style

namespace SampleCode
{
    public class MyClass
    {
    }
}

Add this line in .editorconfig

# IDE0160: Convert to block-scoped namespace
csharp_style_namespace_declarations = block_scoped:warning

To enforce this style

namespace SampleCode;

public class MyClass
{
}

Add this line in .editorconfig

# IDE0160: Convert to file-scoped namespace
csharp_style_namespace_declarations = file_scoped:warning
like image 164
JuChom Avatar answered Jan 28 '23 00:01

JuChom