Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SA1000: Spacing around new() expression inconsistent with formatter support #3311

Closed
tillig opened this issue Mar 3, 2021 · 3 comments
Closed

Comments

@tillig
Copy link

tillig commented Mar 3, 2021

In C# 9.0, you can omit the type name when using new in some cases:

// With the type name
List<int> ws = new List<int>();

// Without the type name
List<int> xs = new();
List<int> ys = new(capacity: 10_000);
List<int> zs = new() { Capacity = 20_000 };

The SA1000 rule catches new() and wants a space like new () because it assumes the next thing should be a type name. It should treat new() like a function instead of like new TypeHere() with respect to spacing. That would also allow C# formatters, which treat new() like a function, to be consistent with StyleCop rules. (Right now they fight a bit.)

@tillig
Copy link
Author

tillig commented Mar 3, 2021

It looks like there's already a unit test around this so perhaps this just hasn't been released yet?

@tillig
Copy link
Author

tillig commented Mar 3, 2021

I'm dumb and need to RTFM. Updated to 1.2.0-beta.321 and all is well. Sorry for any confusion.

@tillig tillig closed this as completed Mar 3, 2021
@sharwell
Copy link
Member

sharwell commented Mar 3, 2021

Duplicate of #3214

@sharwell sharwell marked this as a duplicate of #3214 Mar 3, 2021
@sharwell sharwell closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants