From 2c69f73ee91d1c8744cbf6d8850d8c78c68b3bb9 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 16 Jun 2017 18:31:39 -0500 Subject: [PATCH] Ignore spacing around a default literal expression Full support for C# 7.1 will be added when it is finally released, but this change offers a clean workaround for #2420 in the interim. --- .../StyleCop.Analyzers/Lightup/SyntaxKindEx.cs | 1 + .../SA1000KeywordsMustBeSpacedCorrectly.cs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs index 1c06a4699..e020e4fb3 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs @@ -9,6 +9,7 @@ internal static class SyntaxKindEx { public const SyntaxKind UnderscoreToken = (SyntaxKind)8491; public const SyntaxKind IsPatternExpression = (SyntaxKind)8657; + public const SyntaxKind DefaultLiteralExpression = (SyntaxKind)8755; public const SyntaxKind LocalFunctionStatement = (SyntaxKind)8830; public const SyntaxKind TupleType = (SyntaxKind)8924; public const SyntaxKind TupleElement = (SyntaxKind)8925; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1000KeywordsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1000KeywordsMustBeSpacedCorrectly.cs index 00f42e07a..552bd9f65 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1000KeywordsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1000KeywordsMustBeSpacedCorrectly.cs @@ -9,6 +9,7 @@ namespace StyleCop.Analyzers.SpacingRules using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; + using StyleCop.Analyzers.Lightup; /// /// The spacing around a C# keyword is incorrect. @@ -124,6 +125,15 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context) break; case SyntaxKind.DefaultKeyword: + if (token.Parent.IsKind(SyntaxKindEx.DefaultLiteralExpression)) + { + // Ignore spacing around a default literal expression for now + break; + } + + HandleDisallowedSpaceToken(ref context, token); + break; + case SyntaxKind.NameOfKeyword: case SyntaxKind.SizeOfKeyword: case SyntaxKind.TypeOfKeyword: