Skip to content

Commit df96cd7

Browse files
authored
Merge pull request #2673 from sharwell/make-readonly
Make fields readonly
2 parents 64016d7 + f70a2de commit df96cd7

File tree

18 files changed

+63
-67
lines changed

18 files changed

+63
-67
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.TreeTextSpan.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ internal TreeTextSpan GetContainingSpan(TextSpan textSpan)
157157
/// </summary>
158158
internal class Builder
159159
{
160+
private readonly List<Builder> children = new List<Builder>();
160161
private int start;
161162
private int end = int.MaxValue;
162-
private List<Builder> children = new List<Builder>();
163163

164164
/// <summary>
165165
/// Initializes a new instance of the <see cref="Builder"/> class.

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.UsingsSorter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ private class UsingsSorter
3030
private readonly bool separateSystemDirectives;
3131
private readonly bool insertBlankLinesBetweenGroups;
3232

33-
private SourceMap sourceMap;
33+
private readonly SourceMap sourceMap;
3434

35-
private Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>> systemUsings = new Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>>();
36-
private Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>> namespaceUsings = new Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>>();
37-
private Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>> aliases = new Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>>();
38-
private Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>> staticImports = new Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>>();
35+
private readonly Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>> systemUsings = new Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>>();
36+
private readonly Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>> namespaceUsings = new Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>>();
37+
private readonly Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>> aliases = new Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>>();
38+
private readonly Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>> staticImports = new Dictionary<TreeTextSpan, List<UsingDirectiveSyntax>>();
3939

4040
public UsingsSorter(StyleCopSettings settings, SemanticModel semanticModel, CompilationUnitSyntax compilationUnit, ImmutableArray<SyntaxTrivia> fileHeader)
4141
{

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/UsingCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private class UsingSyntaxRewriter : CSharpSyntaxRewriter
422422
private readonly List<UsingDirectiveSyntax> stripList;
423423
private readonly Dictionary<UsingDirectiveSyntax, UsingDirectiveSyntax> replaceMap;
424424
private readonly ImmutableArray<SyntaxTrivia> fileHeader;
425-
private LinkedList<SyntaxToken> tokensToStrip = new LinkedList<SyntaxToken>();
425+
private readonly LinkedList<SyntaxToken> tokensToStrip = new LinkedList<SyntaxToken>();
426426

427427
public UsingSyntaxRewriter(List<UsingDirectiveSyntax> stripList, Dictionary<UsingDirectiveSyntax, UsingDirectiveSyntax> replaceMap, ImmutableArray<SyntaxTrivia> fileHeader)
428428
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1101UnitTests.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ namespace StyleCop.Analyzers.Test.ReadabilityRules
1414

1515
public class SA1101UnitTests : CodeFixVerifier
1616
{
17-
private const string ReferenceCode = @"
17+
[Fact]
18+
public async Task TestPrefixLocalCallsWithThisAsync()
19+
{
20+
string testCode = @"
1821
using System;
1922
public class BaseTypeName
2023
{
@@ -130,7 +133,7 @@ public void InstanceMethodName(int ParameterName)
130133
}
131134
";
132135

133-
private static string fixedCode = @"
136+
string fixedCode = @"
134137
using System;
135138
public class BaseTypeName
136139
{
@@ -246,9 +249,6 @@ public void InstanceMethodName(int ParameterName)
246249
}
247250
";
248251

249-
[Fact]
250-
public async Task TestPrefixLocalCallsWithThisDiagnosticsAsync()
251-
{
252252
var expected = new[]
253253
{
254254
this.CSharpDiagnostic().WithLocation(91, 36),
@@ -260,7 +260,9 @@ public async Task TestPrefixLocalCallsWithThisDiagnosticsAsync()
260260
this.CSharpDiagnostic().WithLocation(107, 48),
261261
};
262262

263-
await this.VerifyCSharpDiagnosticAsync(ReferenceCode, expected, CancellationToken.None).ConfigureAwait(false);
263+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
264+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
265+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
264266
}
265267

266268
[Fact]
@@ -300,12 +302,6 @@ public void ConvertAll<T>(T value) { }
300302
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
301303
}
302304

303-
[Fact]
304-
public async Task TestPrefixLocalCallsWithThisCodeFixAsync()
305-
{
306-
await this.VerifyCSharpFixAsync(ReferenceCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
307-
}
308-
309305
/// <summary>
310306
/// Verifies that a collision between a member and a static member is handled properly.
311307
/// This is a regression test for #2093

StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ private static async Task<SyntaxTreeAnalysisContext> CreateAnalysisContextAsync(
375375

376376
private class AdditionalTextHelper : AdditionalText
377377
{
378-
private SourceText sourceText;
378+
private readonly SourceText sourceText;
379379

380380
public AdditionalTextHelper(string path, string text)
381381
{

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonArray.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace LightJson
1515
[DebuggerTypeProxy(typeof(JsonArrayDebugView))]
1616
internal sealed class JsonArray : IEnumerable<JsonValue>
1717
{
18-
private IList<JsonValue> items;
18+
private readonly IList<JsonValue> items;
1919

2020
/// <summary>
2121
/// Initializes a new instance of the <see cref="JsonArray"/> class.
@@ -167,7 +167,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
167167
[ExcludeFromCodeCoverage]
168168
private class JsonArrayDebugView
169169
{
170-
private JsonArray jsonArray;
170+
private readonly JsonArray jsonArray;
171171

172172
public JsonArrayDebugView(JsonArray jsonArray)
173173
{

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonObject.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace LightJson
1414
[DebuggerTypeProxy(typeof(JsonObjectDebugView))]
1515
internal sealed class JsonObject : IEnumerable<KeyValuePair<string, JsonValue>>, IEnumerable<JsonValue>
1616
{
17-
private IDictionary<string, JsonValue> properties;
17+
private readonly IDictionary<string, JsonValue> properties;
1818

1919
/// <summary>
2020
/// Initializes a new instance of the <see cref="JsonObject"/> class.
@@ -189,7 +189,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
189189
[ExcludeFromCodeCoverage]
190190
private class JsonObjectDebugView
191191
{
192-
private JsonObject jsonObject;
192+
private readonly JsonObject jsonObject;
193193

194194
public JsonObjectDebugView(JsonObject jsonObject)
195195
{
@@ -218,10 +218,10 @@ public KeyValuePair[] Keys
218218
public class KeyValuePair
219219
{
220220
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
221-
private string key;
221+
private readonly string key;
222222

223223
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
224-
private JsonValue value;
224+
private readonly JsonValue value;
225225

226226
public KeyValuePair(string key, JsonValue value)
227227
{

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ public override int GetHashCode()
839839
[ExcludeFromCodeCoverage]
840840
private class JsonValueDebugView
841841
{
842-
private JsonValue jsonValue;
842+
private readonly JsonValue jsonValue;
843843

844844
public JsonValueDebugView(JsonValue jsonValue)
845845
{

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/Serialization/JsonReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace LightJson.Serialization
1414
/// </summary>
1515
internal sealed class JsonReader
1616
{
17-
private TextScanner scanner;
17+
private readonly TextScanner scanner;
1818

1919
private JsonReader(TextReader reader)
2020
{

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/Serialization/TextScanner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace LightJson.Serialization
1111
/// </summary>
1212
internal sealed class TextScanner
1313
{
14-
private TextReader reader;
14+
private readonly TextReader reader;
1515
private TextPosition position;
1616

1717
/// <summary>

0 commit comments

Comments
 (0)