@@ -194,6 +194,114 @@ public void Bar()
194194 await this . VerifyCSharpFixAsync ( testCode , fixedTestCode , numberOfFixAllIterations : 2 , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
195195 }
196196
197+ [ Fact ]
198+ [ WorkItem ( 2471 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2471" ) ]
199+ public async Task TestUnaryMemberAccessAsync ( )
200+ {
201+ var testCode = @"public class ClassName
202+ {
203+ public unsafe void MethodName()
204+ {
205+ int? x = 0;
206+ int* y = null;
207+
208+ x -- .ToString();
209+ x --.ToString();
210+ x-- .ToString();
211+
212+ x ++ .ToString();
213+ x ++.ToString();
214+ x++ .ToString();
215+
216+ x -- ?.ToString();
217+ x --?.ToString();
218+ x-- ?.ToString();
219+
220+ x ++ ?.ToString();
221+ x ++?.ToString();
222+ x++ ?.ToString();
223+
224+ y -- ->ToString();
225+ y --->ToString();
226+ y-- ->ToString();
227+
228+ y ++ ->ToString();
229+ y ++->ToString();
230+ y++ ->ToString();
231+ }
232+ }
233+ " ;
234+ var fixedTestCode = @"public class ClassName
235+ {
236+ public unsafe void MethodName()
237+ {
238+ int? x = 0;
239+ int* y = null;
240+
241+ x--.ToString();
242+ x--.ToString();
243+ x--.ToString();
244+
245+ x++.ToString();
246+ x++.ToString();
247+ x++.ToString();
248+
249+ x--?.ToString();
250+ x--?.ToString();
251+ x--?.ToString();
252+
253+ x++?.ToString();
254+ x++?.ToString();
255+ x++?.ToString();
256+
257+ y--->ToString();
258+ y--->ToString();
259+ y--->ToString();
260+
261+ y++->ToString();
262+ y++->ToString();
263+ y++->ToString();
264+ }
265+ }
266+ " ;
267+ DiagnosticResult [ ] expected =
268+ {
269+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 8 , 11 ) . WithArguments ( "--" ) ,
270+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 8 , 11 ) . WithArguments ( "--" ) ,
271+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 9 , 11 ) . WithArguments ( "--" ) ,
272+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 10 , 10 ) . WithArguments ( "--" ) ,
273+
274+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 12 , 11 ) . WithArguments ( "++" ) ,
275+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 12 , 11 ) . WithArguments ( "++" ) ,
276+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 13 , 11 ) . WithArguments ( "++" ) ,
277+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 14 , 10 ) . WithArguments ( "++" ) ,
278+
279+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 16 , 11 ) . WithArguments ( "--" ) ,
280+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 16 , 11 ) . WithArguments ( "--" ) ,
281+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 17 , 11 ) . WithArguments ( "--" ) ,
282+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 18 , 10 ) . WithArguments ( "--" ) ,
283+
284+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 20 , 11 ) . WithArguments ( "++" ) ,
285+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 20 , 11 ) . WithArguments ( "++" ) ,
286+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 21 , 11 ) . WithArguments ( "++" ) ,
287+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 22 , 10 ) . WithArguments ( "++" ) ,
288+
289+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 24 , 11 ) . WithArguments ( "--" ) ,
290+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 24 , 11 ) . WithArguments ( "--" ) ,
291+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 25 , 11 ) . WithArguments ( "--" ) ,
292+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 26 , 10 ) . WithArguments ( "--" ) ,
293+
294+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 28 , 11 ) . WithArguments ( "++" ) ,
295+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 28 , 11 ) . WithArguments ( "++" ) ,
296+ this . CSharpDiagnostic ( DescriptorNotPrecededByWhitespace ) . WithLocation ( 29 , 11 ) . WithArguments ( "++" ) ,
297+ this . CSharpDiagnostic ( DescriptorNotFollowedByWhitespace ) . WithLocation ( 30 , 10 ) . WithArguments ( "++" ) ,
298+ } ;
299+
300+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
301+ await this . VerifyCSharpDiagnosticAsync ( fixedTestCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
302+ await this . VerifyCSharpFixAsync ( testCode , fixedTestCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
303+ }
304+
197305 /// <summary>
198306 /// Verifies that valid binary expressions do not produce diagnostics.
199307 /// </summary>
0 commit comments