dotnet / dotnet/format

Runs multiple formatters instead of one

Open
#1,591 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
1.9k
Forks
173
Avg merge
10d 13h
Merged PRs (30d)
1

Description

I want to format a file to "file-scoped namespaces". I want to make that change only.

My `.editorconfig` contains this only:
````ini
[*.cs]
csharp_style_namespace_declarations = file_scoped:warning # config for IDE0161
````

A test file `Foo.cs`:
````cs
namespace MyNamespace
{

public class Foo
{

public Foo(int someInt, string someString)
{
_someInt = someInt; // aligned
_someString = someString; // aligned
}

private readonly int _someInt;
private readonly string _someString;

}
}
````

I run this:
````sh
dotnet format MyProject.csproj --severity info --diagnostics=IDE0161 --include=Foo.cs
````

The result:
````cs
namespace MyNamespace;

public class Foo
{

public Foo(int someInt, string someString)
{
_someInt = someInt; // not aligned
_someString = someString; // not aligned
}

private readonly int _someInt;
private readonly string _someString;

}
````

The alignment is changed as shown. There are various other places where alignment is changed too.

I only want to run one analyser/fixer - `IDE0161`. I don't want the format command to do anything else.

How do I do that?

(Note if I run the code fix in vscode, it works. It's only via `dotnet format` that it fails. However I can't change 1000s of files via the IDE, that would take forever.)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.