Skip to content

Commit a45080c

Browse files
committed
Use DiagnosticResult.CompilerError where appropriate
1 parent 3c3d7dc commit a45080c

37 files changed

Lines changed: 59 additions & 73 deletions

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/ReadabilityRules/SA1139CSharp7UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void Method()
208208

209209
DiagnosticResult[] expectedDiagnosticResult =
210210
{
211-
CompilerError("CS0221")
211+
DiagnosticResult.CompilerError("CS0221")
212212
.WithMessage($"Constant value '{literalValue}' cannot be converted to a '{type}' (use 'unchecked' syntax to override)")
213213
.WithLocation(6, 17),
214214
};

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task TestRegressionMethodGlobalNamespaceAsync(string code, int colu
3434

3535
DiagnosticResult[] expected =
3636
{
37-
CompilerError("CS0116").WithMessage("A namespace cannot directly contain members such as fields or methods").WithLocation(4, column),
37+
DiagnosticResult.CompilerError("CS0116").WithMessage("A namespace cannot directly contain members such as fields or methods").WithLocation(4, column),
3838
Diagnostic().WithLocation(4, column),
3939
};
4040

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ public string MethodName
778778

779779
DiagnosticResult[] expected =
780780
{
781-
CompilerError("CS1002").WithMessage("; expected").WithLocation(5, 29),
781+
DiagnosticResult.CompilerError("CS1002").WithMessage("; expected").WithLocation(5, 29),
782782
};
783783

784784
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1633UnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,14 @@ public async Task TestIncompleteMultilineCommentAsync()
388388

389389
DiagnosticResult[] expectedDiagnostics =
390390
{
391-
CompilerError("CS1035").WithMessage("End-of-file found, '*/' expected").WithLocation(1, 1),
391+
DiagnosticResult.CompilerError("CS1035").WithMessage("End-of-file found, '*/' expected").WithLocation(1, 1),
392392
Diagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1),
393393
};
394394

395395
// The fixed code will still have the incomplete comment, as there is no certainty that the incomplete comment was intended as file header.
396396
DiagnosticResult[] expectedFixedDiagnostics =
397397
{
398-
CompilerError("CS1035").WithMessage("End-of-file found, '*/' expected").WithLocation(3, 1),
398+
DiagnosticResult.CompilerError("CS1035").WithMessage("End-of-file found, '*/' expected").WithLocation(3, 1),
399399
};
400400

401401
await this.VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedCode, expectedFixedDiagnostics, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1500/SA1500UnitTests.Properties.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,17 @@ int Property
493493
DiagnosticResult accessorError;
494494
if (LightupHelpers.SupportsCSharp7)
495495
{
496-
accessorError = CompilerError("CS8180").WithMessage("{ or ; or => expected");
496+
accessorError = DiagnosticResult.CompilerError("CS8180").WithMessage("{ or ; or => expected");
497497
}
498498
else
499499
{
500-
accessorError = CompilerError("CS1043").WithMessage("{ or ; expected");
500+
accessorError = DiagnosticResult.CompilerError("CS1043").WithMessage("{ or ; expected");
501501
}
502502

503503
DiagnosticResult[] expected =
504504
{
505505
accessorError.WithLocation(6, 12),
506-
CompilerError("CS1022").WithMessage("Type or namespace definition, or end-of-file expected").WithLocation(9, 1),
506+
DiagnosticResult.CompilerError("CS1022").WithMessage("Type or namespace definition, or end-of-file expected").WithLocation(9, 1),
507507
};
508508
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
509509
}
@@ -526,10 +526,10 @@ int Property
526526

527527
DiagnosticResult[] expected =
528528
{
529-
CompilerError("CS0161").WithMessage("'ClassName.Property.get': not all code paths return a value").WithLocation(6, 9),
530-
CompilerError("CS1513").WithMessage("} expected").WithLocation(7, 10),
531-
CompilerError("CS1513").WithMessage("} expected").WithLocation(7, 10),
532-
CompilerError("CS1513").WithMessage("} expected").WithLocation(7, 10),
529+
DiagnosticResult.CompilerError("CS0161").WithMessage("'ClassName.Property.get': not all code paths return a value").WithLocation(6, 9),
530+
DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(7, 10),
531+
DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(7, 10),
532+
DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(7, 10),
533533
};
534534
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
535535
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1501UnitTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,16 @@ void MethodName()
517517
ExpectedDiagnostics =
518518
{
519519
Diagnostic().WithLocation(7, 12),
520-
CompilerError("CS0103").WithLocation(7, 14).WithMessage("The name 'Bar' does not exist in the current context"),
521-
CompilerError("CS1513").WithLocation(7, 37).WithMessage("} expected"),
522-
CompilerError("CS1513").WithLocation(7, 37).WithMessage("} expected"),
520+
DiagnosticResult.CompilerError("CS0103").WithLocation(7, 14).WithMessage("The name 'Bar' does not exist in the current context"),
521+
DiagnosticResult.CompilerError("CS1513").WithLocation(7, 37).WithMessage("} expected"),
522+
DiagnosticResult.CompilerError("CS1513").WithLocation(7, 37).WithMessage("} expected"),
523523
},
524524
FixedCode = fixedTestCode,
525525
RemainingDiagnostics =
526526
{
527-
CompilerError("CS0103").WithLocation(9, 13).WithMessage("The name 'Bar' does not exist in the current context"),
528-
CompilerError("CS1513").WithLocation(11, 23).WithMessage("} expected"),
529-
CompilerError("CS1513").WithLocation(11, 23).WithMessage("} expected"),
527+
DiagnosticResult.CompilerError("CS0103").WithLocation(9, 13).WithMessage("The name 'Bar' does not exist in the current context"),
528+
DiagnosticResult.CompilerError("CS1513").WithLocation(11, 23).WithMessage("} expected"),
529+
DiagnosticResult.CompilerError("CS1513").WithLocation(11, 23).WithMessage("} expected"),
530530
},
531531
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
532532
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1504UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public int Prop
304304
}";
305305
DiagnosticResult[] expected =
306306
{
307-
CompilerError("CS0501").WithMessage("'Foo.Prop.get' must declare a body because it is not marked abstract, extern, or partial").WithLocation(6, 9),
307+
DiagnosticResult.CompilerError("CS0501").WithMessage("'Foo.Prop.get' must declare a body because it is not marked abstract, extern, or partial").WithLocation(6, 9),
308308
};
309309

310310
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1505UnitTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace StyleCop.Analyzers.Test.LayoutRules
66
using System.Collections.Generic;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using Microsoft.CodeAnalysis.Testing;
910
using StyleCop.Analyzers.LayoutRules;
1011
using Xunit;
1112
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
@@ -834,7 +835,7 @@ public async Task TestOpeningBraceAtEndOfFileAsync()
834835
{
835836
";
836837

837-
var expected = CompilerError("CS1513").WithMessage("} expected").WithLocation(2, 2);
838+
var expected = DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(2, 2);
838839
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
839840
}
840841
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1508UnitTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,10 @@ public class TestClass /
819819

820820
DiagnosticResult[] expected =
821821
{
822-
CompilerError("CS1022").WithMessage("Type or namespace definition, or end-of-file expected").WithLocation(3, 28),
823-
CompilerError("CS1513").WithMessage("} expected").WithLocation(3, 28),
824-
CompilerError("CS1514").WithMessage("{ expected").WithLocation(3, 28),
825-
CompilerError("CS1022").WithMessage("Type or namespace definition, or end-of-file expected").WithLocation(6, 1),
822+
DiagnosticResult.CompilerError("CS1022").WithMessage("Type or namespace definition, or end-of-file expected").WithLocation(3, 28),
823+
DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(3, 28),
824+
DiagnosticResult.CompilerError("CS1514").WithMessage("{ expected").WithLocation(3, 28),
825+
DiagnosticResult.CompilerError("CS1022").WithMessage("Type or namespace definition, or end-of-file expected").WithLocation(6, 1),
826826
};
827827

828828
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1404UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public void Bar()
397397
DiagnosticResult[] expected =
398398
{
399399
Diagnostic().WithLocation(4, 66),
400-
CompilerError("CS0029").WithMessage("Cannot implicitly convert type 'int' to 'string'").WithLocation(4, 82),
400+
DiagnosticResult.CompilerError("CS0029").WithMessage("Cannot implicitly convert type 'int' to 'string'").WithLocation(4, 82),
401401
};
402402
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
403403
}

0 commit comments

Comments
 (0)