Skip to content

Commit 0bfd6c5

Browse files
committed
Replaced message parameter of CSharpCompilerError with WithMessage()
1 parent 057eede commit 0bfd6c5

21 files changed

Lines changed: 36 additions & 30 deletions

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

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

3434
DiagnosticResult[] expected =
3535
{
36-
this.CSharpCompilerError("CS0116", "A namespace cannot directly contain members such as fields or methods").WithLocation(4, column),
36+
this.CSharpCompilerError("CS0116").WithMessage("A namespace cannot directly contain members such as fields or methods").WithLocation(4, column),
3737
this.CSharpDiagnostic().WithLocation(4, column),
3838
};
3939

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

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

780780
DiagnosticResult[] expected =
781781
{
782-
this.CSharpCompilerError("CS1002", "; expected").WithLocation(5, 29),
782+
this.CSharpCompilerError("CS1002").WithMessage("; expected").WithLocation(5, 29),
783783
};
784784

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

StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ public DiagnosticResult WithArguments(params object[] arguments)
100100
return result;
101101
}
102102

103+
public DiagnosticResult WithMessage(string message)
104+
{
105+
DiagnosticResult result = this;
106+
result.Message = message;
107+
return result;
108+
}
109+
103110
public DiagnosticResult WithMessageFormat(LocalizableString messageFormat)
104111
{
105112
DiagnosticResult result = this;

StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,12 @@ protected DiagnosticResult CSharpDiagnostic(DiagnosticDescriptor descriptor)
209209
return new DiagnosticResult(descriptor);
210210
}
211211

212-
protected DiagnosticResult CSharpCompilerError(string errorIdentifier, string message)
212+
protected DiagnosticResult CSharpCompilerError(string errorIdentifier)
213213
{
214214
return new DiagnosticResult
215215
{
216216
Id = errorIdentifier,
217217
Severity = DiagnosticSeverity.Error,
218-
Message = message,
219218
};
220219
}
221220

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public int Prop
291291
}";
292292
DiagnosticResult[] expected =
293293
{
294-
this.CSharpCompilerError("CS0501", "'Foo.Prop.get' must declare a body because it is not marked abstract, extern, or partial").WithLocation(6, 9),
294+
this.CSharpCompilerError("CS0501").WithMessage("'Foo.Prop.get' must declare a body because it is not marked abstract, extern, or partial").WithLocation(6, 9),
295295
};
296296

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

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

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

852852
DiagnosticResult[] expected =
853853
{
854-
this.CSharpCompilerError("CS1022", "Type or namespace definition, or end-of-file expected").WithLocation(3, 28),
855-
this.CSharpCompilerError("CS1513", "} expected").WithLocation(3, 28),
856-
this.CSharpCompilerError("CS1514", "{ expected").WithLocation(3, 28),
857-
this.CSharpCompilerError("CS1022", "Type or namespace definition, or end-of-file expected").WithLocation(6, 1),
854+
this.CSharpCompilerError("CS1022").WithMessage("Type or namespace definition, or end-of-file expected").WithLocation(3, 28),
855+
this.CSharpCompilerError("CS1513").WithMessage("} expected").WithLocation(3, 28),
856+
this.CSharpCompilerError("CS1514").WithMessage("{ expected").WithLocation(3, 28),
857+
this.CSharpCompilerError("CS1022").WithMessage("Type or namespace definition, or end-of-file expected").WithLocation(6, 1),
858858
};
859859

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,8 @@ public string
936936
// We don't care about the syntax errors.
937937
var expected = new[]
938938
{
939-
this.CSharpCompilerError("CS1585", "Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
940-
this.CSharpCompilerError("CS1519", "Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
939+
this.CSharpCompilerError("CS1585").WithMessage("Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
940+
this.CSharpCompilerError("CS1519").WithMessage("Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
941941
};
942942

943943
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -961,8 +961,8 @@ public string
961961
// We don't care about the syntax errors.
962962
DiagnosticResult[] expected =
963963
{
964-
this.CSharpCompilerError("CS1585", "Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
965-
this.CSharpCompilerError("CS1519", "Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
964+
this.CSharpCompilerError("CS1585").WithMessage("Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
965+
this.CSharpCompilerError("CS1519").WithMessage("Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
966966
};
967967

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

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1204UnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ public static string
578578
// We don't care about the syntax errors.
579579
DiagnosticResult[] expected =
580580
{
581-
this.CSharpCompilerError("CS1585", "Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
582-
this.CSharpCompilerError("CS1519", "Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
581+
this.CSharpCompilerError("CS1585").WithMessage("Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
582+
this.CSharpCompilerError("CS1519").WithMessage("Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
583583
};
584584

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

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1206UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public async Task TestWithIncompleteMembersAsync()
193193

194194
DiagnosticResult[] expected =
195195
{
196-
this.CSharpCompilerError("CS1519", "Invalid token '}' in class, struct, or interface member declaration").WithLocation(4, 1),
196+
this.CSharpCompilerError("CS1519").WithMessage("Invalid token '}' in class, struct, or interface member declaration").WithLocation(4, 1),
197197
};
198198

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

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1132UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class Foo
126126

127127
DiagnosticResult[] expected =
128128
{
129-
this.CSharpCompilerError(id, message).WithLocation(4, column),
129+
this.CSharpCompilerError(id).WithMessage(message).WithLocation(4, column),
130130
};
131131

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

0 commit comments

Comments
 (0)