Skip to content

Commit c737e92

Browse files
committed
Update messages for element ordering diagnostics
The previous messages were confusing with respect to the ability to reconfigure the ordering used by the analyzers.
1 parent 90653ef commit c737e92

7 files changed

Lines changed: 90 additions & 113 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public async Task TestClassOrderingAsync()
112112
public class TestClass2 { }
113113
";
114114

115-
var expected = this.CSharpDiagnostic().WithLocation(2, 14).WithArguments("public", "classes", "internal");
115+
var expected = this.CSharpDiagnostic().WithLocation(2, 14).WithArguments("public", "internal");
116116

117117
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
118118

@@ -157,10 +157,10 @@ public async Task TestPropertiesAsync()
157157

158158
DiagnosticResult[] expected =
159159
{
160-
this.CSharpDiagnostic().WithLocation(4, 22).WithArguments("protected", "properties", "private"),
161-
this.CSharpDiagnostic().WithLocation(5, 31).WithArguments("protected internal", "properties", "protected"),
162-
this.CSharpDiagnostic().WithLocation(6, 21).WithArguments("internal", "properties", "protected internal"),
163-
this.CSharpDiagnostic().WithLocation(7, 19).WithArguments("public", "properties", "internal")
160+
this.CSharpDiagnostic().WithLocation(4, 22).WithArguments("protected", "private"),
161+
this.CSharpDiagnostic().WithLocation(5, 31).WithArguments("protected internal", "protected"),
162+
this.CSharpDiagnostic().WithLocation(6, 21).WithArguments("internal", "protected internal"),
163+
this.CSharpDiagnostic().WithLocation(7, 19).WithArguments("public", "internal")
164164
};
165165

166166
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -198,10 +198,10 @@ public void TestMethod5() { }
198198

199199
DiagnosticResult[] expected =
200200
{
201-
this.CSharpDiagnostic().WithLocation(4, 20).WithArguments("protected", "methods", "private"),
202-
this.CSharpDiagnostic().WithLocation(5, 29).WithArguments("protected internal", "methods", "protected"),
203-
this.CSharpDiagnostic().WithLocation(6, 19).WithArguments("internal", "methods", "protected internal"),
204-
this.CSharpDiagnostic().WithLocation(7, 17).WithArguments("public", "methods", "internal")
201+
this.CSharpDiagnostic().WithLocation(4, 20).WithArguments("protected", "private"),
202+
this.CSharpDiagnostic().WithLocation(5, 29).WithArguments("protected internal", "protected"),
203+
this.CSharpDiagnostic().WithLocation(6, 19).WithArguments("internal", "protected internal"),
204+
this.CSharpDiagnostic().WithLocation(7, 17).WithArguments("public", "internal")
205205
};
206206

207207
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -234,7 +234,7 @@ public async Task TestProtectedInternalBeforePublicAsync()
234234
}
235235
";
236236

237-
var expected = this.CSharpDiagnostic().WithLocation(4, 5).WithArguments("public", "events", "protected internal");
237+
var expected = this.CSharpDiagnostic().WithLocation(4, 5).WithArguments("public", "protected internal");
238238

239239
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
240240

@@ -263,7 +263,7 @@ public async Task TestProtectedBeforePublicAsync()
263263
}
264264
";
265265

266-
var expected = this.CSharpDiagnostic().WithLocation(4, 19).WithArguments("public", "fields", "protected");
266+
var expected = this.CSharpDiagnostic().WithLocation(4, 19).WithArguments("public", "protected");
267267

268268
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
269269

@@ -291,7 +291,7 @@ public event System.Action TestEvent2 { add { } remove { } }
291291
}
292292
";
293293

294-
var expected = this.CSharpDiagnostic().WithLocation(4, 32).WithArguments("public", "events", "private");
294+
var expected = this.CSharpDiagnostic().WithLocation(4, 32).WithArguments("public", "private");
295295

296296
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
297297

@@ -320,7 +320,7 @@ internal event System.Action TestEvent2 { add { } remove { } }
320320
}
321321
";
322322

323-
var expected = this.CSharpDiagnostic().WithLocation(4, 34).WithArguments("internal", "events", "protected");
323+
var expected = this.CSharpDiagnostic().WithLocation(4, 34).WithArguments("internal", "protected");
324324

325325
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
326326

@@ -349,7 +349,7 @@ public async Task TestPrivateBeforeInternalAsync()
349349
}
350350
";
351351

352-
var expected = this.CSharpDiagnostic().WithLocation(4, 28).WithArguments("internal", "delegates", "private");
352+
var expected = this.CSharpDiagnostic().WithLocation(4, 28).WithArguments("internal", "private");
353353

354354
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
355355

@@ -378,7 +378,7 @@ protected internal void TestMethod2() { }
378378
}
379379
";
380380

381-
var expected = this.CSharpDiagnostic().WithLocation(4, 29).WithArguments("protected internal", "methods", "private");
381+
var expected = this.CSharpDiagnostic().WithLocation(4, 29).WithArguments("protected internal", "private");
382382

383383
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
384384

@@ -407,7 +407,7 @@ internal protected void TestMethod2() { }
407407
}
408408
";
409409

410-
var expected = this.CSharpDiagnostic().WithLocation(4, 29).WithArguments("protected internal", "methods", "private");
410+
var expected = this.CSharpDiagnostic().WithLocation(4, 29).WithArguments("protected internal", "private");
411411

412412
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
413413

@@ -437,7 +437,7 @@ public async Task TestMembersWithoutAccessModifiersAsync()
437437
}
438438
";
439439

440-
var expected = this.CSharpDiagnostic().WithLocation(4, 19).WithArguments("public", "fields", "private");
440+
var expected = this.CSharpDiagnostic().WithLocation(4, 19).WithArguments("public", "private");
441441

442442
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
443443

@@ -464,7 +464,7 @@ public async Task TestClassesWithoutAccessModifiersAsync()
464464
public class TestClass2 { }
465465
";
466466

467-
var expected = this.CSharpDiagnostic().WithLocation(2, 14).WithArguments("public", "classes", "internal");
467+
var expected = this.CSharpDiagnostic().WithLocation(2, 14).WithArguments("public", "internal");
468468

469469
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
470470

@@ -491,7 +491,7 @@ public async Task TestOnlyFirstViolationReportedAsync()
491491
}
492492
";
493493

494-
var expected = this.CSharpDiagnostic().WithLocation(4, 19).WithArguments("public", "fields", "private");
494+
var expected = this.CSharpDiagnostic().WithLocation(4, 19).WithArguments("public", "private");
495495

496496
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
497497

@@ -526,7 +526,7 @@ public void B()
526526
}
527527
";
528528

529-
var expected = this.CSharpDiagnostic().WithLocation(7, 17).WithArguments("public", "methods", "private");
529+
var expected = this.CSharpDiagnostic().WithLocation(7, 17).WithArguments("public", "private");
530530

531531
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
532532

@@ -565,10 +565,10 @@ public static void TestMethod5() { }
565565

566566
DiagnosticResult[] expected =
567567
{
568-
this.CSharpDiagnostic().WithLocation(4, 27).WithArguments("protected", "methods", "private"),
569-
this.CSharpDiagnostic().WithLocation(5, 36).WithArguments("protected internal", "methods", "protected"),
570-
this.CSharpDiagnostic().WithLocation(6, 26).WithArguments("internal", "methods", "protected internal"),
571-
this.CSharpDiagnostic().WithLocation(7, 24).WithArguments("public", "methods", "internal")
568+
this.CSharpDiagnostic().WithLocation(4, 27).WithArguments("protected", "private"),
569+
this.CSharpDiagnostic().WithLocation(5, 36).WithArguments("protected internal", "protected"),
570+
this.CSharpDiagnostic().WithLocation(6, 26).WithArguments("internal", "protected internal"),
571+
this.CSharpDiagnostic().WithLocation(7, 24).WithArguments("public", "internal")
572572
};
573573

574574
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -604,8 +604,8 @@ public async Task TestConstOrderingAsync()
604604

605605
DiagnosticResult[] expected =
606606
{
607-
this.CSharpDiagnostic().WithLocation(4, 25).WithArguments("protected", "fields", "private"),
608-
this.CSharpDiagnostic().WithLocation(5, 16).WithArguments("public", "fields", "protected")
607+
this.CSharpDiagnostic().WithLocation(4, 25).WithArguments("protected", "private"),
608+
this.CSharpDiagnostic().WithLocation(5, 16).WithArguments("public", "protected")
609609
};
610610

611611
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -637,7 +637,7 @@ internal class TestClass3 { }
637637
}
638638
";
639639

640-
var expected = this.CSharpDiagnostic().WithLocation(5, 20).WithArguments("internal", "classes", "private");
640+
var expected = this.CSharpDiagnostic().WithLocation(5, 20).WithArguments("internal", "private");
641641

642642
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
643643

@@ -671,8 +671,8 @@ public class TestClass2 { }
671671

672672
DiagnosticResult[] expected =
673673
{
674-
this.CSharpDiagnostic().WithLocation(4, 17).WithArguments("public", "enums", "internal"),
675-
this.CSharpDiagnostic().WithLocation(6, 18).WithArguments("public", "classes", "internal")
674+
this.CSharpDiagnostic().WithLocation(4, 17).WithArguments("public", "internal"),
675+
this.CSharpDiagnostic().WithLocation(6, 18).WithArguments("public", "internal")
676676
};
677677

678678
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -733,7 +733,7 @@ public MyClass(int a)
733733
}
734734
";
735735

736-
var expected = this.CSharpDiagnostic().WithLocation(8, 12).WithArguments("public", "constructors", "private");
736+
var expected = this.CSharpDiagnostic().WithLocation(8, 12).WithArguments("public", "private");
737737

738738
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
739739

@@ -812,9 +812,9 @@ void IA.TestMethod1() { }
812812
DiagnosticResult[] expected =
813813
{
814814
// explicit interface events are considered private by StyleCop
815-
this.CSharpDiagnostic().WithLocation(34, 12).WithArguments("public", "properties", "protected"),
816-
this.CSharpDiagnostic().WithLocation(41, 15).WithArguments("public", "indexers", "protected"),
817-
this.CSharpDiagnostic().WithLocation(45, 13).WithArguments("public", "methods", "protected")
815+
this.CSharpDiagnostic().WithLocation(34, 12).WithArguments("public", "protected"),
816+
this.CSharpDiagnostic().WithLocation(41, 15).WithArguments("public", "protected"),
817+
this.CSharpDiagnostic().WithLocation(45, 13).WithArguments("public", "protected")
818818
};
819819

820820
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -892,7 +892,7 @@ void TestInterface.SomeMethod()
892892
}
893893
";
894894

895-
var expected = this.CSharpDiagnostic().WithLocation(13, 24).WithArguments("public", "methods", "private");
895+
var expected = this.CSharpDiagnostic().WithLocation(13, 24).WithArguments("public", "private");
896896

897897
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
898898

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1203UnitTests.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class Foo
101101
private int Baz = 1;
102102
private const int Bar = 2;
103103
}";
104-
var firstDiagnostic = this.CSharpDiagnostic().WithLocation(5, 23).WithArguments("private");
104+
var firstDiagnostic = this.CSharpDiagnostic().WithLocation(5, 23);
105105
await this.VerifyCSharpDiagnosticAsync(testCode, firstDiagnostic, CancellationToken.None).ConfigureAwait(false);
106106

107107
var fixedTestCode = @"
@@ -123,7 +123,7 @@ public struct Foo
123123
private int baz;
124124
private const int Bar = 2;
125125
}";
126-
var firstDiagnostic = this.CSharpDiagnostic().WithLocation(5, 23).WithArguments("private");
126+
var firstDiagnostic = this.CSharpDiagnostic().WithLocation(5, 23);
127127
await this.VerifyCSharpDiagnosticAsync(testCode, firstDiagnostic, CancellationToken.None).ConfigureAwait(false);
128128

129129
var fixedTestCode = @"
@@ -146,7 +146,7 @@ public class Foo
146146
private int Baz = 1;
147147
private const int FooBar = 2;
148148
}";
149-
var firstDiagnostic = this.CSharpDiagnostic().WithLocation(6, 23).WithArguments("private");
149+
var firstDiagnostic = this.CSharpDiagnostic().WithLocation(6, 23);
150150
await this.VerifyCSharpDiagnosticAsync(testCode, firstDiagnostic, CancellationToken.None).ConfigureAwait(false);
151151

152152
var fixedTestCode = @"
@@ -171,7 +171,7 @@ public class Test
171171
const int Test3 = 3;
172172
}";
173173

174-
var expected = this.CSharpDiagnostic().WithLocation(5, 15).WithArguments("private");
174+
var expected = this.CSharpDiagnostic().WithLocation(5, 15);
175175

176176
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
177177

@@ -182,7 +182,7 @@ public class Test
182182
private int Test1 = 1;
183183
const int Test3 = 3;
184184
}";
185-
expected = this.CSharpDiagnostic().WithLocation(6, 15).WithArguments("private");
185+
expected = this.CSharpDiagnostic().WithLocation(6, 15);
186186
await this.VerifyCSharpDiagnosticAsync(testCodeAfterFix1, expected, CancellationToken.None).ConfigureAwait(false);
187187

188188
var fixCode = @"
@@ -240,8 +240,8 @@ public class Foo
240240

241241
var diagnosticResults = new[]
242242
{
243-
this.CSharpDiagnostic().WithLocation(10, 25).WithArguments("public"),
244-
this.CSharpDiagnostic().WithLocation(14, 25).WithArguments("public")
243+
this.CSharpDiagnostic().WithLocation(10, 25),
244+
this.CSharpDiagnostic().WithLocation(14, 25)
245245
};
246246
await this.VerifyCSharpDiagnosticAsync(testCode, diagnosticResults, CancellationToken.None).ConfigureAwait(false);
247247
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
@@ -289,8 +289,8 @@ public async Task TestCodeFixAsync()
289289

290290
var diagnosticResults = new[]
291291
{
292-
this.CSharpDiagnostic().WithLocation(9, 26).WithArguments("private"),
293-
this.CSharpDiagnostic().WithLocation(13, 25).WithArguments("public")
292+
this.CSharpDiagnostic().WithLocation(9, 26),
293+
this.CSharpDiagnostic().WithLocation(13, 25)
294294
};
295295
await this.VerifyCSharpDiagnosticAsync(testCode, diagnosticResults, CancellationToken.None).ConfigureAwait(false);
296296
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
@@ -340,8 +340,8 @@ public async Task TestCodeFixWithCommentsAsync()
340340

341341
var diagnosticResults = new[]
342342
{
343-
this.CSharpDiagnostic().WithLocation(10, 26).WithArguments("private"),
344-
this.CSharpDiagnostic().WithLocation(14, 25).WithArguments("public")
343+
this.CSharpDiagnostic().WithLocation(10, 26),
344+
this.CSharpDiagnostic().WithLocation(14, 25)
345345
};
346346
await this.VerifyCSharpDiagnosticAsync(testCode, diagnosticResults, CancellationToken.None).ConfigureAwait(false);
347347
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
@@ -367,7 +367,7 @@ public async Task TestOnlyLeadingWhitespaceIsMovedAsync()
367367

368368
var diagnosticResults = new[]
369369
{
370-
this.CSharpDiagnostic().WithLocation(7, 14).WithArguments("private"),
370+
this.CSharpDiagnostic().WithLocation(7, 14),
371371
};
372372
await this.VerifyCSharpDiagnosticAsync(testCode, diagnosticResults, CancellationToken.None).ConfigureAwait(false);
373373

@@ -428,8 +428,8 @@ public async Task TestCodeFixWithoutOrderByAccessAsync()
428428

429429
var diagnosticResults = new[]
430430
{
431-
this.CSharpDiagnostic().WithLocation(9, 26).WithArguments("private"),
432-
this.CSharpDiagnostic().WithLocation(13, 25).WithArguments("public")
431+
this.CSharpDiagnostic().WithLocation(9, 26),
432+
this.CSharpDiagnostic().WithLocation(13, 25)
433433
};
434434
await this.VerifyCSharpDiagnosticAsync(testCode, diagnosticResults, CancellationToken.None).ConfigureAwait(false);
435435
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);

0 commit comments

Comments
 (0)