Skip to content

Commit 8346a5c

Browse files
authored
Project: Enable StyleCop and fix existing rules to make PRs easier going forward (#2757)
* Project: Enable StyleCop and fix existing rules to make PRs easier going forward This adopts StyleCop and fixes most issues (and disables things we wouldn't want) to make PRs more consistent in an automated way and prevent formatting problems affecting git history, etc. It also does all the documentation enforcement. Note: since I had to fix up many anyway, I finally did the `<inheritdoc />` minimization on `IDatabase`/`IDatabaseAsync` to remove 10% of duplicate documentation. That should also make PRs and maintenance less monotonous. * Fix stylecop issues
1 parent 4852cca commit 8346a5c

File tree

201 files changed

+2553
-4054
lines changed

Some content is hidden

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

201 files changed

+2553
-4054
lines changed

.editorconfig

+64-14
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,73 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
138138
csharp_preserve_single_line_statements = true
139139
csharp_preserve_single_line_blocks = true
140140

141-
# IDE0090: Use 'new(...)'
142-
dotnet_diagnostic.IDE0090.severity = silent
143141

144-
# RCS1037: Remove trailing white-space.
145-
dotnet_diagnostic.RCS1037.severity = error
142+
# IDE preferences
143+
dotnet_diagnostic.IDE0090.severity = silent # IDE0090: Use 'new(...)'
144+
145+
#Roslynator preferences
146+
dotnet_diagnostic.RCS1037.severity = error # RCS1037: Remove trailing white-space.
147+
dotnet_diagnostic.RCS1098.severity = none # RCS1098: Constant values should be placed on right side of comparisons.
148+
149+
dotnet_diagnostic.RCS1194.severity = none # RCS1194: Implement exception constructors.
150+
dotnet_diagnostic.RCS1229.severity = none # RCS1229: Use async/await when necessary.
151+
dotnet_diagnostic.RCS1233.severity = none # RCS1233: Use short-circuiting operator.
152+
dotnet_diagnostic.RCS1234.severity = none # RCS1234: Duplicate enum value.
153+
154+
# StyleCop preferences
155+
dotnet_diagnostic.SA0001.severity = none # SA0001: XML comment analysis is disabled
156+
157+
dotnet_diagnostic.SA1101.severity = none # SA1101: Prefix local calls with this
158+
dotnet_diagnostic.SA1108.severity = none # SA1108: Block statements should not contain embedded comments
159+
dotnet_diagnostic.SA1122.severity = none # SA1122: Use string.Empty for empty strings
160+
dotnet_diagnostic.SA1127.severity = none # SA1127: Generic type constraints should be on their own line
161+
dotnet_diagnostic.SA1128.severity = none # SA1128: Put constructor initializers on their own line
162+
dotnet_diagnostic.SA1132.severity = none # SA1132: Do not combine fields
163+
dotnet_diagnostic.SA1133.severity = none # SA1133: Do not combine attributes
164+
165+
dotnet_diagnostic.SA1200.severity = none # SA1200: Using directives should be placed correctly
166+
dotnet_diagnostic.SA1201.severity = none # SA1201: Elements should appear in the correct order
167+
dotnet_diagnostic.SA1202.severity = none # SA1202: Elements should be ordered by access
168+
dotnet_diagnostic.SA1203.severity = none # SA1203: Constants should appear before fields
169+
170+
dotnet_diagnostic.SA1306.severity = none # SA1306: Field names should begin with lower-case letter
171+
dotnet_diagnostic.SA1309.severity = none # SA1309: Field names should not begin with underscore
172+
dotnet_diagnostic.SA1310.severity = silent # SA1310: Field names should not contain underscore
173+
dotnet_diagnostic.SA1311.severity = none # SA1311: Static readonly fields should begin with upper-case letter
174+
dotnet_diagnostic.SA1312.severity = none # SA1312: Variable names should begin with lower-case letter
175+
176+
dotnet_diagnostic.SA1401.severity = silent # SA1401: Fields should be private
177+
dotnet_diagnostic.SA1402.severity = suggestion # SA1402: File may only contain a single type
178+
179+
dotnet_diagnostic.SA1503.severity = silent # SA1503: Braces should not be omitted
180+
dotnet_diagnostic.SA1516.severity = silent # SA1516: Elements should be separated by blank line
181+
182+
dotnet_diagnostic.SA1600.severity = none # SA1600: Elements should be documented
183+
dotnet_diagnostic.SA1601.severity = none # SA1601: Partial elements should be documented
184+
dotnet_diagnostic.SA1602.severity = none # SA1602: Enumeration items should be documented
185+
dotnet_diagnostic.SA1615.severity = none # SA1615: Element return value should be documented
186+
dotnet_diagnostic.SA1623.severity = none # SA1623: Property summary documentation should match accessors
187+
dotnet_diagnostic.SA1633.severity = none # SA1633: File should have header
188+
dotnet_diagnostic.SA1642.severity = none # SA1642: Constructor summary documentation should begin with standard text
189+
dotnet_diagnostic.SA1643.severity = none # SA1643: Destructor summary documentation should begin with standard text
190+
191+
192+
# To Fix:
193+
dotnet_diagnostic.SA1204.severity = none # SA1204: Static elements should appear before instance elements
194+
dotnet_diagnostic.SA1214.severity = none # SA1214: Readonly fields should appear before non-readonly fields
195+
dotnet_diagnostic.SA1304.severity = none # SA1304: Non-private readonly fields should begin with upper-case letter
196+
dotnet_diagnostic.SA1307.severity = none # SA1307: Accessible fields should begin with upper-case letter
197+
dotnet_diagnostic.SA1308.severity = suggestion # SA1308: Variable names should not be prefixed
198+
dotnet_diagnostic.SA1131.severity = none # SA1131: Use readable conditions
199+
dotnet_diagnostic.SA1405.severity = none # SA1405: Debug.Assert should provide message text
200+
dotnet_diagnostic.SA1501.severity = none # SA1501: Statement should not be on a single line
201+
dotnet_diagnostic.SA1502.severity = suggestion # SA1502: Element should not be on a single line
202+
dotnet_diagnostic.SA1513.severity = none # SA1513: Closing brace should be followed by blank line
203+
dotnet_diagnostic.SA1515.severity = none # SA1515: Single-line comment should be preceded by blank line
204+
dotnet_diagnostic.SA1611.severity = suggestion # SA1611: Element parameters should be documented
205+
dotnet_diagnostic.SA1649.severity = suggestion # SA1649: File name should match first type name
146206

147-
# RCS1098: Constant values should be placed on right side of comparisons.
148-
dotnet_diagnostic.RCS1098.severity = none
149207

150-
# RCS1194: Implement exception constructors.
151-
dotnet_diagnostic.RCS1194.severity = none
152208

153-
# RCS1229: Use async/await when necessary.
154-
dotnet_diagnostic.RCS1229.severity = none
155209

156-
# RCS1233: Use short-circuiting operator.
157-
dotnet_diagnostic.RCS1233.severity = none
158210

159-
# RCS1234: Duplicate enum value.
160-
dotnet_diagnostic.RCS1234.severity = none

Directory.Build.props

+3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
<Deterministic>true</Deterministic>
3434
<EmbedUntrackedSources>true</EmbedUntrackedSources>
3535
</PropertyGroup>
36+
3637
<ItemGroup Condition="'$(Configuration)' == 'Release' and '$(SourceRoot)'==''">
3738
<SourceRoot Include="$(MSBuildThisFileDirectory)/"/>
3839
</ItemGroup>
40+
3941
<ItemGroup>
4042
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="all" />
43+
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
4144
</ItemGroup>
4245
</Project>

Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
2121
<PackageVersion Include="NSubstitute" Version="5.0.0" />
2222
<PackageVersion Include="StackExchange.Redis" Version="2.6.96" />
23+
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
2324
<!-- For binding redirect testing, main package gets this transitively -->
2425
<PackageVersion Include="System.IO.Pipelines" Version="5.0.1" />
2526
<PackageVersion Include="System.Runtime.Caching" Version="5.0.0" />

src/StackExchange.Redis/APITypes/ClientKillFilter.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public ClientKillFilter WithSkipMe(bool? skipMe)
113113
/// <summary>
114114
/// Set the MaxAgeInSeconds filter.
115115
/// </summary>
116-
/// <param name="maxAgeInSeconds">Age of connection in seconds</param>
116+
/// <param name="maxAgeInSeconds">Age of connection in seconds.</param>
117117
public ClientKillFilter WithMaxAgeInSeconds(long? maxAgeInSeconds)
118118
{
119119
MaxAgeInSeconds = maxAgeInSeconds;
@@ -123,9 +123,9 @@ public ClientKillFilter WithMaxAgeInSeconds(long? maxAgeInSeconds)
123123
internal List<RedisValue> ToList(bool withReplicaCommands)
124124
{
125125
var parts = new List<RedisValue>(15)
126-
{
127-
RedisLiterals.KILL
128-
};
126+
{
127+
RedisLiterals.KILL,
128+
};
129129
if (Id != null)
130130
{
131131
parts.Add(RedisLiterals.ID);

src/StackExchange.Redis/APITypes/GeoRadiusOptions.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,26 @@ public enum GeoRadiusOptions
1313
/// No Options.
1414
/// </summary>
1515
None = 0,
16+
1617
/// <summary>
1718
/// Redis will return the coordinates of any results.
1819
/// </summary>
1920
WithCoordinates = 1,
21+
2022
/// <summary>
2123
/// Redis will return the distance from center for all results.
2224
/// </summary>
2325
WithDistance = 2,
26+
2427
/// <summary>
2528
/// Redis will return the geo hash value as an integer. (This is the score in the sorted set).
2629
/// </summary>
2730
WithGeoHash = 4,
31+
2832
/// <summary>
2933
/// Populates the commonly used values from the entry (the integer hash is not returned as it is not commonly useful).
3034
/// </summary>
31-
Default = WithCoordinates | WithDistance
35+
Default = WithCoordinates | WithDistance,
3236
}
3337

3438
internal static class GeoRadiusOptionsExtensions

src/StackExchange.Redis/APITypes/GeoRadiusResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public readonly struct GeoRadiusResult
2323
/// <summary>
2424
/// The hash value of the matched member as an integer. (The key in the sorted set).
2525
/// </summary>
26-
/// <remarks>Note that this is not the same as the hash returned from GeoHash</remarks>
26+
/// <remarks>Note that this is not the same as the hash returned from GeoHash.</remarks>
2727
public long? Hash { get; }
2828

2929
/// <summary>

src/StackExchange.Redis/APITypes/GeoSearchShape.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace StackExchange.Redis;
44

55
/// <summary>
6-
/// A Shape that you can use for a GeoSearch
6+
/// A Shape that you can use for a GeoSearch.
77
/// </summary>
88
public abstract class GeoSearchShape
99
{
@@ -18,9 +18,9 @@ public abstract class GeoSearchShape
1818
internal abstract int ArgCount { get; }
1919

2020
/// <summary>
21-
/// constructs a <see cref="GeoSearchShape"/>
21+
/// constructs a <see cref="GeoSearchShape"/>.
2222
/// </summary>
23-
/// <param name="unit"></param>
23+
/// <param name="unit">The geography unit to use.</param>
2424
public GeoSearchShape(GeoUnit unit)
2525
{
2626
Unit = unit;
@@ -30,7 +30,7 @@ public GeoSearchShape(GeoUnit unit)
3030
}
3131

3232
/// <summary>
33-
/// A circle drawn on a map bounding
33+
/// A circle drawn on a map bounding.
3434
/// </summary>
3535
public class GeoSearchCircle : GeoSearchShape
3636
{
@@ -41,17 +41,16 @@ public class GeoSearchCircle : GeoSearchShape
4141
/// </summary>
4242
/// <param name="radius">The radius of the circle.</param>
4343
/// <param name="unit">The distance unit the circle will use, defaults to Meters.</param>
44-
public GeoSearchCircle(double radius, GeoUnit unit = GeoUnit.Meters) : base (unit)
44+
public GeoSearchCircle(double radius, GeoUnit unit = GeoUnit.Meters) : base(unit)
4545
{
4646
_radius = radius;
4747
}
4848

4949
internal override int ArgCount => 3;
5050

5151
/// <summary>
52-
/// Gets the <exception cref="RedisValue"/>s for this shape
52+
/// Gets the <see cref="RedisValue"/>s for this shape.
5353
/// </summary>
54-
/// <returns></returns>
5554
internal override void AddArgs(List<RedisValue> args)
5655
{
5756
args.Add(RedisLiterals.BYRADIUS);
@@ -61,7 +60,7 @@ internal override void AddArgs(List<RedisValue> args)
6160
}
6261

6362
/// <summary>
64-
/// A box drawn on a map
63+
/// A box drawn on a map.
6564
/// </summary>
6665
public class GeoSearchBox : GeoSearchShape
6766
{

src/StackExchange.Redis/APITypes/LatencyHistoryEntry.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace StackExchange.Redis;
44

55
/// <summary>
6-
/// A latency entry as reported by the built-in LATENCY HISTORY command
6+
/// A latency entry as reported by the built-in LATENCY HISTORY command.
77
/// </summary>
88
public readonly struct LatencyHistoryEntry
99
{
@@ -30,12 +30,12 @@ protected override bool TryParse(in RawResult raw, out LatencyHistoryEntry parse
3030
}
3131

3232
/// <summary>
33-
/// The time at which this entry was recorded
33+
/// The time at which this entry was recorded.
3434
/// </summary>
3535
public DateTime Timestamp { get; }
3636

3737
/// <summary>
38-
/// The latency recorded for this event
38+
/// The latency recorded for this event.
3939
/// </summary>
4040
public int DurationMilliseconds { get; }
4141

src/StackExchange.Redis/APITypes/LatencyLatestEntry.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace StackExchange.Redis;
44

55
/// <summary>
6-
/// A latency entry as reported by the built-in LATENCY LATEST command
6+
/// A latency entry as reported by the built-in LATENCY LATEST command.
77
/// </summary>
88
public readonly struct LatencyLatestEntry
99
{
@@ -31,22 +31,22 @@ protected override bool TryParse(in RawResult raw, out LatencyLatestEntry parsed
3131
}
3232

3333
/// <summary>
34-
/// The name of this event
34+
/// The name of this event.
3535
/// </summary>
3636
public string EventName { get; }
3737

3838
/// <summary>
39-
/// The time at which this entry was recorded
39+
/// The time at which this entry was recorded.
4040
/// </summary>
4141
public DateTime Timestamp { get; }
4242

4343
/// <summary>
44-
/// The latency recorded for this event
44+
/// The latency recorded for this event.
4545
/// </summary>
4646
public int DurationMilliseconds { get; }
4747

4848
/// <summary>
49-
/// The max latency recorded for all events
49+
/// The max latency recorded for all events.
5050
/// </summary>
5151
public int MaxDurationMilliseconds { get; }
5252

src/StackExchange.Redis/APITypes/StreamPendingMessageInfo.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-

2-
namespace StackExchange.Redis;
1+
namespace StackExchange.Redis;
32

43
/// <summary>
54
/// Describes properties of a pending message.

src/StackExchange.Redis/BufferReader.cs

+16-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ private bool FetchNextSegment()
4141
_current = _iterator.Current.Span;
4242
OffsetThisSpan = 0;
4343
RemainingThisSpan = _current.Length;
44-
} while (IsEmpty); // skip empty segments, they don't help us!
44+
}
45+
while (IsEmpty); // skip empty segments, they don't help us!
4546

4647
return true;
4748
}
@@ -59,7 +60,7 @@ public BufferReader(scoped in ReadOnlySequence<byte> buffer)
5960
}
6061

6162
/// <summary>
62-
/// Note that in results other than success, no guarantees are made about final state; if you care: snapshot
63+
/// Note that in results other than success, no guarantees are made about final state; if you care: snapshot.
6364
/// </summary>
6465
public ConsumeResult TryConsumeCRLF()
6566
{
@@ -82,6 +83,7 @@ public ConsumeResult TryConsumeCRLF()
8283
return result;
8384
}
8485
}
86+
8587
public bool TryConsume(int count)
8688
{
8789
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
@@ -102,7 +104,8 @@ public bool TryConsume(int count)
102104
// consume all of this span
103105
_totalConsumed += available;
104106
count -= available;
105-
} while (FetchNextSegment());
107+
}
108+
while (FetchNextSegment());
106109
return false;
107110
}
108111

@@ -127,13 +130,18 @@ public ReadOnlySequence<byte> ConsumeAsBuffer(int count)
127130
if (!TryConsumeAsBuffer(count, out var buffer)) throw new EndOfStreamException();
128131
return buffer;
129132
}
133+
130134
public ReadOnlySequence<byte> ConsumeToEnd()
131135
{
132136
var from = SnapshotPosition();
133137
var result = _buffer.Slice(from);
134-
while (FetchNextSegment()) { } // consume all
138+
while (FetchNextSegment())
139+
{
140+
// consume all
141+
}
135142
return result;
136143
}
144+
137145
public bool TryConsumeAsBuffer(int count, out ReadOnlySequence<byte> buffer)
138146
{
139147
var from = SnapshotPosition();
@@ -146,6 +154,7 @@ public bool TryConsumeAsBuffer(int count, out ReadOnlySequence<byte> buffer)
146154
buffer = _buffer.Slice(from, to);
147155
return true;
148156
}
157+
149158
public void Consume(int count)
150159
{
151160
if (!TryConsume(count)) throw new EndOfStreamException();
@@ -163,13 +172,14 @@ public void Consume(int count)
163172
if (found >= 0) return totalSkipped + found;
164173

165174
totalSkipped += span.Length;
166-
} while (reader.FetchNextSegment());
175+
}
176+
while (reader.FetchNextSegment());
167177
return -1;
168178
}
179+
169180
internal static int FindNextCrLf(BufferReader reader) // very deliberately not ref; want snapshot
170181
{
171182
// is it in the current span? (we need to handle the offsets differently if so)
172-
173183
int totalSkipped = 0;
174184
bool haveTrailingCR = false;
175185
do

0 commit comments

Comments
 (0)