Skip to content

Commit da22125

Browse files
committed
Disable SA1008 for cases where SA1000 will be reported
Fixes #1774
1 parent 7839dc6 commit da22125

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,50 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
101101
}
102102

103103
var prevToken = token.GetPreviousToken();
104+
105+
// Don't check leading spaces when preceded by a keyword that is already handled by SA1000
106+
bool precededByKeyword;
107+
switch (prevToken.Kind())
108+
{
109+
case SyntaxKind.AwaitKeyword:
110+
case SyntaxKind.CaseKeyword:
111+
case SyntaxKind.CatchKeyword:
112+
case SyntaxKind.CheckedKeyword:
113+
case SyntaxKind.DefaultKeyword:
114+
case SyntaxKind.FixedKeyword:
115+
case SyntaxKind.ForKeyword:
116+
case SyntaxKind.ForEachKeyword:
117+
case SyntaxKind.FromKeyword:
118+
case SyntaxKind.GroupKeyword:
119+
case SyntaxKind.IfKeyword:
120+
case SyntaxKind.InKeyword:
121+
case SyntaxKind.IntoKeyword:
122+
case SyntaxKind.JoinKeyword:
123+
case SyntaxKind.LetKeyword:
124+
case SyntaxKind.LockKeyword:
125+
case SyntaxKind.NameOfKeyword:
126+
case SyntaxKind.NewKeyword:
127+
case SyntaxKind.OrderByKeyword:
128+
case SyntaxKind.ReturnKeyword:
129+
case SyntaxKind.SelectKeyword:
130+
case SyntaxKind.SizeOfKeyword:
131+
case SyntaxKind.StackAllocKeyword:
132+
case SyntaxKind.SwitchKeyword:
133+
case SyntaxKind.ThrowKeyword:
134+
case SyntaxKind.TypeOfKeyword:
135+
case SyntaxKind.UncheckedKeyword:
136+
case SyntaxKind.UsingKeyword:
137+
case SyntaxKind.WhereKeyword:
138+
case SyntaxKind.WhileKeyword:
139+
case SyntaxKind.YieldKeyword:
140+
precededByKeyword = true;
141+
break;
142+
143+
default:
144+
precededByKeyword = false;
145+
break;
146+
}
147+
104148
var leadingTriviaList = TriviaHelper.MergeTriviaLists(prevToken.TrailingTrivia, token.LeadingTrivia);
105149

106150
var isFirstOnLine = false;
@@ -191,7 +235,7 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
191235

192236
// Ignore spacing before if another opening parenthesis is before this.
193237
// That way the first opening parenthesis will report any spacing errors.
194-
if (!prevTokenIsOpenParen)
238+
if (!prevTokenIsOpenParen && !precededByKeyword)
195239
{
196240
var hasLeadingComment = (leadingTriviaList.Count > 0) && leadingTriviaList.Last().IsKind(SyntaxKind.MultiLineCommentTrivia);
197241
var hasLeadingSpace = (leadingTriviaList.Count > 0) && leadingTriviaList.Last().IsKind(SyntaxKind.WhitespaceTrivia);

0 commit comments

Comments
 (0)