Skip to content

Commit 20dda6d

Browse files
authored
Updated the naming of const and static fields (#8326)
1 parent deb499b commit 20dda6d

File tree

466 files changed

+3133
-3126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

466 files changed

+3133
-3126
lines changed

.editorconfig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,16 @@ resharper_csharp_braces_for_using = required
140140
resharper_csharp_braces_for_lock = required
141141
resharper_csharp_braces_for_fixed = required
142142

143+
# Name all constant fields using PascalCase
144+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning
145+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
146+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
147+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
148+
dotnet_naming_symbols.constant_fields.required_modifiers = const
149+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
150+
143151
# Static fields should have s_ prefix
144-
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
152+
dotnet_naming_rule.static_fields_should_have_prefix.severity = warning
145153
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
146154
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
147155
dotnet_naming_symbols.static_fields.applicable_kinds = field

src/CookieCrumble/src/CookieCrumble.HotChocolate/Formatters/ExecutionResultSnapshotValueFormatter.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ private static async Task FormatStreamAsync(
101101

102102
internal sealed class JsonResultPatcher
103103
{
104-
private const string _data = "data";
105-
private const string _items = "items";
106-
private const string _incremental = "incremental";
107-
private const string _path = "path";
104+
private const string Data = "data";
105+
private const string Items = "items";
106+
private const string Incremental = "incremental";
107+
private const string Path = "path";
108108
private JsonObject? _json;
109109

110110
public void SetResponse(JsonDocument response)
@@ -138,18 +138,18 @@ public void ApplyPatch(JsonDocument patch)
138138
"You must first set the initial response before you can apply patches.");
139139
}
140140

141-
if (!patch.RootElement.TryGetProperty(_incremental, out var incremental))
141+
if (!patch.RootElement.TryGetProperty(Incremental, out var incremental))
142142
{
143143
throw new ArgumentException("A patch result must contain a property `incremental`.");
144144
}
145145

146146
foreach (var element in incremental.EnumerateArray())
147147
{
148-
if (element.TryGetProperty(_data, out var data))
148+
if (element.TryGetProperty(Data, out var data))
149149
{
150150
PatchIncrementalData(element, JsonObject.Create(data)!);
151151
}
152-
else if (element.TryGetProperty(_items, out var items))
152+
else if (element.TryGetProperty(Items, out var items))
153153
{
154154
PatchIncrementalItems(element, JsonArray.Create(items)!);
155155
}
@@ -158,18 +158,18 @@ public void ApplyPatch(JsonDocument patch)
158158

159159
private void PatchIncrementalData(JsonElement incremental, JsonObject data)
160160
{
161-
if (incremental.TryGetProperty(_path, out var pathProp))
161+
if (incremental.TryGetProperty(Path, out var pathProp))
162162
{
163-
var (current, last) = SelectNodeToPatch(_json![_data]!, pathProp);
163+
var (current, last) = SelectNodeToPatch(_json![Data]!, pathProp);
164164
ApplyPatch(current, last, data);
165165
}
166166
}
167167

168168
private void PatchIncrementalItems(JsonElement incremental, JsonArray items)
169169
{
170-
if (incremental.TryGetProperty(_path, out var pathProp))
170+
if (incremental.TryGetProperty(Path, out var pathProp))
171171
{
172-
var (current, last) = SelectNodeToPatch(_json![_data]!, pathProp);
172+
var (current, last) = SelectNodeToPatch(_json![Data]!, pathProp);
173173
var i = last.GetInt32();
174174
var target = current.AsArray();
175175

src/CookieCrumble/src/CookieCrumble/Extensions/WriterExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ namespace CookieCrumble;
55

66
public static class WriterExtensions
77
{
8-
private static readonly Encoding _utf8 = Encoding.UTF8;
8+
private static readonly Encoding s_utf8 = Encoding.UTF8;
99

1010
public static void Append(this IBufferWriter<byte> snapshot, string value)
1111
=> Append(snapshot, value.AsSpan());
1212

1313
public static void Append(this IBufferWriter<byte> snapshot, ReadOnlySpan<char> value)
1414
{
15-
_utf8.GetBytes(value, snapshot);
15+
s_utf8.GetBytes(value, snapshot);
1616
}
1717

1818
public static void AppendLine(this IBufferWriter<byte> snapshot)

src/CookieCrumble/src/CookieCrumble/Formatters/JsonSnapshotValueFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace CookieCrumble.Formatters;
88

99
internal sealed class JsonSnapshotValueFormatter : ISnapshotValueFormatter, IMarkdownSnapshotValueFormatter
1010
{
11-
private static readonly JsonSerializerSettings _settings =
11+
private static readonly JsonSerializerSettings s_settings =
1212
new()
1313
{
1414
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
@@ -24,7 +24,7 @@ public bool CanHandle(object? value)
2424
=> true;
2525

2626
public void Format(IBufferWriter<byte> snapshot, object? value)
27-
=> snapshot.Append(JsonConvert.SerializeObject(value, _settings));
27+
=> snapshot.Append(JsonConvert.SerializeObject(value, s_settings));
2828

2929
public void FormatMarkdown(IBufferWriter<byte> snapshot, object? value)
3030
{

src/CookieCrumble/src/CookieCrumble/Snapshot.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ namespace CookieCrumble;
1515

1616
public class Snapshot
1717
{
18-
private static readonly object _sync = new();
19-
private static readonly UTF8Encoding _encoding = new();
20-
private static ImmutableStack<ISnapshotValueFormatter> _formatters =
18+
private static readonly object s_sync = new();
19+
private static readonly UTF8Encoding s_encoding = new();
20+
private static ImmutableStack<ISnapshotValueFormatter> s_formatters =
2121
CreateRange(new ISnapshotValueFormatter[]
2222
{
2323
new PlainTextSnapshotValueFormatter(),
2424
new ExceptionSnapshotValueFormatter(),
2525
new HttpResponseSnapshotValueFormatter(),
2626
new JsonElementSnapshotValueFormatter()
2727
});
28-
private static readonly JsonSnapshotValueFormatter _defaultFormatter = new();
28+
private static readonly JsonSnapshotValueFormatter s_defaultFormatter = new();
2929

30-
private static ITestFramework _testFramework = null!;
30+
private static ITestFramework s_testFramework = null!;
3131
private readonly List<ISnapshotSegment> _segments = [];
3232
private readonly string _title;
3333
private readonly string _fileName;
@@ -36,7 +36,7 @@ public class Snapshot
3636

3737
public Snapshot(string? postFix = null, string? extension = null)
3838
{
39-
if (_testFramework is null)
39+
if (s_testFramework is null)
4040
{
4141
throw new Exception("Please initialize a test framework before using Snapshot");
4242
}
@@ -98,9 +98,9 @@ public static void RegisterTestFramework(
9898
{
9999
ArgumentNullException.ThrowIfNull(testFramework);
100100

101-
lock (_sync)
101+
lock (s_sync)
102102
{
103-
_testFramework = testFramework;
103+
s_testFramework = testFramework;
104104
}
105105
}
106106

@@ -109,9 +109,9 @@ public static void RegisterFormatter(
109109
{
110110
ArgumentNullException.ThrowIfNull(formatter);
111111

112-
lock (_sync)
112+
lock (s_sync)
113113
{
114-
_formatters = _formatters.Push(formatter);
114+
s_formatters = s_formatters.Push(formatter);
115115
}
116116
}
117117

@@ -121,25 +121,25 @@ public static void TryRegisterFormatter(
121121
{
122122
ArgumentNullException.ThrowIfNull(formatter);
123123

124-
lock (_sync)
124+
lock (s_sync)
125125
{
126126
if (typeCheck)
127127
{
128128
var type = formatter.GetType();
129-
if (_formatters.Any(t => t.GetType() == type))
129+
if (s_formatters.Any(t => t.GetType() == type))
130130
{
131131
return;
132132
}
133133
}
134134
else
135135
{
136-
if (_formatters.Contains(formatter))
136+
if (s_formatters.Contains(formatter))
137137
{
138138
return;
139139
}
140140
}
141141

142-
_formatters = _formatters.Push(formatter);
142+
s_formatters = s_formatters.Push(formatter);
143143
}
144144
}
145145

@@ -200,7 +200,7 @@ public Snapshot SetPostFix(string postFix)
200200
private static ISnapshotValueFormatter FindSerializer(object? value)
201201
{
202202
// we capture the current immutable serializer list
203-
var serializers = _formatters;
203+
var serializers = s_formatters;
204204

205205
// we iterate over the captured stack.
206206
foreach (var serializer in serializers)
@@ -211,7 +211,7 @@ private static ISnapshotValueFormatter FindSerializer(object? value)
211211
}
212212
}
213213

214-
return _defaultFormatter;
214+
return s_defaultFormatter;
215215
}
216216

217217
public async ValueTask MatchAsync(CancellationToken cancellationToken = default)
@@ -235,14 +235,14 @@ public async ValueTask MatchAsync(CancellationToken cancellationToken = default)
235235
EnsureFileDoesNotExist(mismatchFile);
236236

237237
var before = await File.ReadAllTextAsync(snapshotFile, cancellationToken);
238-
var after = _encoding.GetString(writer.WrittenSpan);
238+
var after = s_encoding.GetString(writer.WrittenSpan);
239239

240240
if (!MatchSnapshot(before, after, false, out var diff))
241241
{
242242
EnsureDirectoryExists(mismatchFile);
243243
await using var stream = File.Create(mismatchFile);
244244
await stream.WriteAsync(writer.WrittenMemory, cancellationToken);
245-
_testFramework.ThrowTestException(diff);
245+
s_testFramework.ThrowTestException(diff);
246246
}
247247
}
248248
}
@@ -267,14 +267,14 @@ public void Match()
267267
var mismatchFile = Combine(CreateMismatchDirectoryName(), CreateSnapshotFileName());
268268
EnsureFileDoesNotExist(mismatchFile);
269269
var before = File.ReadAllText(snapshotFile);
270-
var after = _encoding.GetString(writer.WrittenSpan);
270+
var after = s_encoding.GetString(writer.WrittenSpan);
271271

272272
if (!MatchSnapshot(before, after, false, out var diff))
273273
{
274274
EnsureDirectoryExists(mismatchFile);
275275
using var stream = File.Create(mismatchFile);
276276
stream.Write(writer.WrittenSpan);
277-
_testFramework.ThrowTestException(diff);
277+
s_testFramework.ThrowTestException(diff);
278278
}
279279
}
280280
}
@@ -303,7 +303,7 @@ public async ValueTask MatchMarkdownAsync(CancellationToken cancellationToken =
303303
var mismatchFile = Combine(CreateMismatchDirectoryName(), CreateMarkdownSnapshotFileName());
304304
EnsureFileDoesNotExist(mismatchFile);
305305
var before = await File.ReadAllTextAsync(snapshotFile, cancellationToken);
306-
var after = _encoding.GetString(writer.WrittenSpan);
306+
var after = s_encoding.GetString(writer.WrittenSpan);
307307

308308
if (MatchSnapshot(before, after, false, out var diff))
309309
{
@@ -313,7 +313,7 @@ public async ValueTask MatchMarkdownAsync(CancellationToken cancellationToken =
313313
EnsureDirectoryExists(mismatchFile);
314314
await using var stream = File.Create(mismatchFile);
315315
await stream.WriteAsync(writer.WrittenMemory, cancellationToken);
316-
_testFramework.ThrowTestException(diff);
316+
s_testFramework.ThrowTestException(diff);
317317
}
318318
}
319319

@@ -341,7 +341,7 @@ public void MatchMarkdown()
341341
var mismatchFile = Combine(CreateMismatchDirectoryName(), CreateMarkdownSnapshotFileName());
342342
EnsureFileDoesNotExist(mismatchFile);
343343
var before = File.ReadAllText(snapshotFile);
344-
var after = _encoding.GetString(writer.WrittenSpan);
344+
var after = s_encoding.GetString(writer.WrittenSpan);
345345

346346
if (MatchSnapshot(before, after, false, out var diff))
347347
{
@@ -351,7 +351,7 @@ public void MatchMarkdown()
351351
EnsureDirectoryExists(mismatchFile);
352352
using var stream = File.Create(mismatchFile);
353353
stream.Write(writer.WrittenSpan);
354-
_testFramework.ThrowTestException(diff);
354+
s_testFramework.ThrowTestException(diff);
355355
}
356356
}
357357

@@ -360,11 +360,11 @@ public void MatchInline(string expected)
360360
var writer = new ArrayBufferWriter<byte>();
361361
WriteSegments(writer);
362362

363-
var after = _encoding.GetString(writer.WrittenSpan);
363+
var after = s_encoding.GetString(writer.WrittenSpan);
364364

365365
if (!MatchSnapshot(expected, after, true, out var diff))
366366
{
367-
_testFramework.ThrowTestException(diff);
367+
s_testFramework.ThrowTestException(diff);
368368
}
369369
}
370370

@@ -626,7 +626,7 @@ private static string CreateFileName(StackFrame[] frames)
626626

627627
if (method is not null &&
628628
!string.IsNullOrEmpty(fileName) &&
629-
_testFramework.IsValidTestMethod(method))
629+
s_testFramework.IsValidTestMethod(method))
630630
{
631631
return Combine(GetDirectoryName(fileName)!, method.ToName());
632632
}
@@ -635,7 +635,7 @@ private static string CreateFileName(StackFrame[] frames)
635635

636636
if (method is not null &&
637637
!string.IsNullOrEmpty(fileName) &&
638-
_testFramework.IsValidTestMethod(method))
638+
s_testFramework.IsValidTestMethod(method))
639639
{
640640
return Combine(GetDirectoryName(fileName)!, method.ToName());
641641
}
@@ -659,7 +659,7 @@ private static string CreateMarkdownTitle(StackFrame[] frames)
659659

660660
if (method is not null &&
661661
!string.IsNullOrEmpty(fileName) &&
662-
_testFramework.IsValidTestMethod(method))
662+
s_testFramework.IsValidTestMethod(method))
663663
{
664664
return method.Name;
665665
}
@@ -668,7 +668,7 @@ private static string CreateMarkdownTitle(StackFrame[] frames)
668668

669669
if (method is not null &&
670670
!string.IsNullOrEmpty(fileName) &&
671-
_testFramework.IsValidTestMethod(method))
671+
s_testFramework.IsValidTestMethod(method))
672672
{
673673
return method.Name;
674674
}
@@ -713,7 +713,7 @@ private static void CheckStrictMode()
713713
if (string.Equals(value, "on", StringComparison.Ordinal)
714714
|| (bool.TryParse(value, out var b) && b))
715715
{
716-
_testFramework.ThrowTestException(
716+
s_testFramework.ThrowTestException(
717717
"Strict mode is enabled and no snapshot has been found " +
718718
"for the current test. Create a new snapshot locally and " +
719719
"rerun your tests.");

src/CookieCrumble/test/CookieCrumble.Tests/SnapshotTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace CookieCrumble;
99

1010
public class SnapshotTests
1111
{
12-
private const string _strictModeExceptionMessage =
12+
private const string StrictModeExceptionMessage =
1313
"Strict mode is enabled and no snapshot has been found " +
1414
"for the current test. Create a new snapshot locally and " +
1515
"rerun your tests.";
@@ -134,16 +134,16 @@ public async Task Match_StrictMode_On(string strictMode)
134134
try
135135
{
136136
Assert.Equal(
137-
_strictModeExceptionMessage,
137+
StrictModeExceptionMessage,
138138
(await Assert.ThrowsAsync<XunitException>(Act1)).Message);
139139

140-
Assert.Equal(_strictModeExceptionMessage, Assert.Throws<XunitException>(Act2).Message);
140+
Assert.Equal(StrictModeExceptionMessage, Assert.Throws<XunitException>(Act2).Message);
141141

142142
Assert.Equal(
143-
_strictModeExceptionMessage,
143+
StrictModeExceptionMessage,
144144
(await Assert.ThrowsAsync<XunitException>(Act3)).Message);
145145

146-
Assert.Equal(_strictModeExceptionMessage, Assert.Throws<XunitException>(Act4).Message);
146+
Assert.Equal(StrictModeExceptionMessage, Assert.Throws<XunitException>(Act4).Message);
147147
}
148148
finally
149149
{

0 commit comments

Comments
 (0)