Skip to content

Commit cf2cd83

Browse files
authored
Merge pull request #3187 from NextTurn/target-typed-new
Update SA1000 for target-typed new expressions
2 parents 0a4e5b7 + 3874af7 commit cf2cd83

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/SpacingRules/SA1000CSharp9UnitTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules
55
{
6+
using System.Threading.Tasks;
7+
using Microsoft.CodeAnalysis.CSharp;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
10+
using Xunit;
711

812
public class SA1000CSharp9UnitTests : SA1000CSharp8UnitTests
913
{
14+
[Fact]
15+
public async Task TestTargetTypedNewAsync()
16+
{
17+
string statementWithoutSpace = "int a = new();";
18+
19+
await this.TestKeywordStatementAsync(statementWithoutSpace, DiagnosticResult.EmptyDiagnosticResults, statementWithoutSpace, languageVersion: LanguageVersion.Preview).ConfigureAwait(false);
20+
}
1021
}
1122
}

StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ internal static class SyntaxKindEx
1818
public const SyntaxKind ConflictMarkerTrivia = (SyntaxKind)8564;
1919
public const SyntaxKind IsPatternExpression = (SyntaxKind)8657;
2020
public const SyntaxKind RangeExpression = (SyntaxKind)8658;
21+
public const SyntaxKind ImplicitObjectCreationExpression = (SyntaxKind)8659;
2122
public const SyntaxKind CoalesceAssignmentExpression = (SyntaxKind)8725;
2223
public const SyntaxKind IndexExpression = (SyntaxKind)8741;
2324
public const SyntaxKind DefaultLiteralExpression = (SyntaxKind)8755;

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1000KeywordsMustBeSpacedCorrectly.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ private static void HandleNewOrStackAllocKeywordToken(ref SyntaxTreeAnalysisCont
293293

294294
case SyntaxKind.OpenParenToken:
295295
// Disallowed for new() constraint, but otherwise allowed for tuple types
296-
needSpace = !token.Parent.IsKind(SyntaxKind.ConstructorConstraint);
296+
needSpace = !token.Parent.IsKind(SyntaxKind.ConstructorConstraint)
297+
&& !token.Parent.IsKind(SyntaxKindEx.ImplicitObjectCreationExpression);
297298
break;
298299

299300
default:

0 commit comments

Comments
 (0)