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.11k stars 4.04k forks source link

Allow vertical alignment without triggering IDE0055 #51389

Open lonix1 opened 3 years ago

lonix1 commented 3 years ago

Brief description:

The csharp_space_around_declaration_statements allows this:

var a    = foo;
var bc   = 123;
var some = thing;

But all the following have no support:

a    = foo;
bc   = 123;
some = thing;
static int Foo(int x, int y) => (x, y) switch {
  (    0,     0) => 0,
  (int i,     0) => 11,
  (int i, int j) => i + j,
};
if (foo == null)       throw new ArgumentNullException(nameof(foo));
if (foo == wrongValue) throw new ArgumentException(nameof(foo));
if (qux == 42)         throw new ArgumentOutOfRangeException(nameof(qux));
switch (i) {
  case 0:      foo(); break;
  case 1:      bar(); break;
  case 424242: baz(); break;
  case XYZ:    return;
  default:     throw new InvalidOperationException();
}
     if (true)      foo();
else if (false)     bar();
else if (something) baz();
else                qux();
AddJsonFile("appsettings.json",                    optional:false, reloadOnChange:true)
AddJsonFile($"appsettings.{environmentName}.json", optional:true,  reloadOnChange:true)

Please consider adding support for them?

Languages applicable:

C#

Code example that the analyzer should report:

See above

Documentation requirements:

When this analyzer is implemented, it must be documented by following the steps at Documentation for IDE CodeStyle analyzers.

Youssef1313 commented 3 years ago

Related to (but not duplicate of): https://github.com/dotnet/roslyn/issues/38241

levicki commented 3 years ago

Please consider this for C++ as well.

CyrusNajmabadi commented 3 years ago

@levicki Roslyn is unrelated to the c++ vs experience. Please file requests for that experience over at developercommunity. Thanks!

levicki commented 3 years ago

Like anyone is going to read that. It would be just another "closed due to inactivity" thread.

CyrusNajmabadi commented 3 years ago

Like anyone is going to read that. It would be just another "closed due to inactivity" thread.

@levicki This is not the c++ repro. No one on C++ is present here, and no one here works on the C++ components. If you would like teh C++ to investigate and/or triage issues relates to their experience, then issues will need to be filed against them. Thanks!

levicki commented 3 years ago

This is not the c++ repro. No one on C++ is present here, and no one here works on the C++ components. If you would like teh C++ to investigate and/or triage issues relates to their experience, then issues will need to be filed against them. Thanks!

And if I am writing C++/CLI code and have this issue, where do I report that? /sarcasm (if not obvious).

CyrusNajmabadi commented 3 years ago

@levicki I'm not sure why sarcasm is appropriate. C++/cli has nothing to do with Roslyn. You would report it to the c++ team.

jibbers42 commented 2 years ago

It may be obvious to anyone working on this issue, but calling out this alternate switch expression spacing to be considered as well...

static int Foo(int x, int y) => (x, y) switch {
  (0, 0)         => 0,
  (int i, 0)     => 11,
  (int i, int j) => i + j,
};
JDA88 commented 2 weeks ago

No idea why but the last version of Visual Studio 2022 (17.12.0) made it worse, I have hundread of IDE0055 warnings