Skip to content

Commit a5fbaca

Browse files
Got rid of SA1129; SA1204; S3928; CA1508; CA1822; CA2201; SA1642 warnings in Polly project
1 parent 60288c8 commit a5fbaca

14 files changed

+151
-148
lines changed

src/Polly/AsyncPolicy.ContextAndKeys.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public abstract partial class AsyncPolicy
99
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="AsyncPolicy"/> instance.</param>
1010
public AsyncPolicy WithPolicyKey(string policyKey)
1111
{
12-
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException;
12+
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
1313

1414
policyKeyInternal = policyKey;
1515
return this;
@@ -22,7 +22,7 @@ public AsyncPolicy WithPolicyKey(string policyKey)
2222
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="IAsyncPolicy"/> instance.</param>
2323
IAsyncPolicy IAsyncPolicy.WithPolicyKey(string policyKey)
2424
{
25-
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException;
25+
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
2626

2727
policyKeyInternal = policyKey;
2828
return this;
@@ -38,7 +38,7 @@ public abstract partial class AsyncPolicy<TResult>
3838
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="AsyncPolicy{TResult}"/> instance.</param>
3939
public AsyncPolicy<TResult> WithPolicyKey(string policyKey)
4040
{
41-
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException;
41+
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
4242

4343
policyKeyInternal = policyKey;
4444
return this;
@@ -51,7 +51,7 @@ public AsyncPolicy<TResult> WithPolicyKey(string policyKey)
5151
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="IAsyncPolicy{TResult}"/> instance.</param>
5252
IAsyncPolicy<TResult> IAsyncPolicy<TResult>.WithPolicyKey(string policyKey)
5353
{
54-
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException;
54+
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
5555

5656
policyKeyInternal = policyKey;
5757
return this;

src/Polly/AsyncPolicy.ExecuteOverloads.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public async Task ExecuteAsync(Func<Context, CancellationToken, Task> action, Co
103103
}
104104
finally
105105
{
106-
RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
106+
PolicyBase.RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ public async Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken
223223
}
224224
finally
225225
{
226-
RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
226+
PolicyBase.RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
227227
}
228228
}
229229

src/Polly/AsyncPolicy.TResult.ExecuteOverloads.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public async Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TR
112112
}
113113
finally
114114
{
115-
RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
115+
PolicyBase.RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
116116
}
117117
}
118118

src/Polly/CircuitBreaker/CircuitStateController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public CircuitState CircuitState
3838

3939
using var _ = TimedLock.Lock(_lock);
4040

41-
if (_circuitState == CircuitState.Open && !IsInAutomatedBreak_NeedsLock)
41+
if (!IsInAutomatedBreak_NeedsLock)
4242
{
4343
_circuitState = CircuitState.HalfOpen;
4444
_onHalfOpen();

src/Polly/Policy.ContextAndKeys.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public abstract partial class Policy
99
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="Policy"/> instance.</param>
1010
public Policy WithPolicyKey(string policyKey)
1111
{
12-
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException;
12+
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
1313

1414
policyKeyInternal = policyKey;
1515
return this;
@@ -22,7 +22,7 @@ public Policy WithPolicyKey(string policyKey)
2222
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="Policy"/> instance.</param>
2323
ISyncPolicy ISyncPolicy.WithPolicyKey(string policyKey)
2424
{
25-
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException;
25+
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
2626

2727
policyKeyInternal = policyKey;
2828
return this;
@@ -38,7 +38,7 @@ public abstract partial class Policy<TResult>
3838
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="Policy{TResult}"/> instance.</param>
3939
public Policy<TResult> WithPolicyKey(string policyKey)
4040
{
41-
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException;
41+
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
4242

4343
policyKeyInternal = policyKey;
4444
return this;
@@ -51,7 +51,7 @@ public Policy<TResult> WithPolicyKey(string policyKey)
5151
/// <param name="policyKey">The unique, used-definable key to assign to this <see cref="Policy{TResult}"/> instance.</param>
5252
ISyncPolicy<TResult> ISyncPolicy<TResult>.WithPolicyKey(string policyKey)
5353
{
54-
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException;
54+
if (policyKeyInternal != null) throw PolicyKeyMustBeImmutableException(nameof(policyKey));
5555

5656
policyKeyInternal = policyKey;
5757
return this;

src/Polly/Policy.ExecuteOverloads.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void Execute(Action<Context, CancellationToken> action, Context context,
6969
}
7070
finally
7171
{
72-
RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
72+
PolicyBase.RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
7373
}
7474
}
7575

@@ -160,7 +160,7 @@ public TResult Execute<TResult>(Func<Context, CancellationToken, TResult> action
160160
}
161161
finally
162162
{
163-
RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
163+
PolicyBase.RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
164164
}
165165
}
166166

src/Polly/Policy.TResult.ExecuteOverloads.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public TResult Execute(Func<Context, CancellationToken, TResult> action, Context
8383
}
8484
finally
8585
{
86-
RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
86+
PolicyBase.RestorePolicyContext(context, priorPolicyWrapKey, priorPolicyKey);
8787
}
8888
}
8989

src/Polly/PolicyBase.ContextAndKeys.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@ public abstract partial class PolicyBase
1212
/// </summary>
1313
public string PolicyKey => policyKeyInternal ?? (policyKeyInternal = GetType().Name + "-" + KeyHelper.GuidPart());
1414

15-
internal static ArgumentException PolicyKeyMustBeImmutableException => new("PolicyKey cannot be changed once set; or (when using the default value after the PolicyKey property has been accessed.", "policyKey");
15+
internal static ArgumentException PolicyKeyMustBeImmutableException(string policyKeyParamName) => new ("PolicyKey cannot be changed once set; or (when using the default value after the PolicyKey property has been accessed.", policyKeyParamName);
16+
17+
/// <summary>
18+
/// Restores the supplied keys to the execution <see cref="Context"/>.
19+
/// </summary>
20+
/// <param name="executionContext">The execution <see cref="Context"/>.</param>
21+
/// <param name="priorPolicyWrapKey">The <see cref="M:Context.PolicyWrapKey"/> prior to execution through this policy.</param>
22+
/// <param name="priorPolicyKey">The <see cref="M:Context.PolicyKey"/> prior to execution through this policy.</param>
23+
internal static void RestorePolicyContext(Context executionContext, string priorPolicyWrapKey, string priorPolicyKey)
24+
{
25+
executionContext.PolicyWrapKey = priorPolicyWrapKey;
26+
executionContext.PolicyKey = priorPolicyKey;
27+
}
1628

1729
/// <summary>
1830
/// Updates the execution <see cref="Context"/> with context from the executing policy.
@@ -27,16 +39,4 @@ public abstract partial class PolicyBase
2739

2840
executionContext.PolicyKey = PolicyKey;
2941
}
30-
31-
/// <summary>
32-
/// Restores the supplied keys to the execution <see cref="Context"/>.
33-
/// </summary>
34-
/// <param name="executionContext">The execution <see cref="Context"/>.</param>
35-
/// <param name="priorPolicyWrapKey">The <see cref="M:Context.PolicyWrapKey"/> prior to execution through this policy.</param>
36-
/// <param name="priorPolicyKey">The <see cref="M:Context.PolicyKey"/> prior to execution through this policy.</param>
37-
internal void RestorePolicyContext(Context executionContext, string priorPolicyWrapKey, string priorPolicyKey)
38-
{
39-
executionContext.PolicyWrapKey = priorPolicyWrapKey;
40-
executionContext.PolicyKey = priorPolicyKey;
41-
}
4242
}

src/Polly/Polly.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<NoWarn>$(NoWarn);IDE0044;IDE1006;CA1062;S107;CA1068;S4039;SA1121;CA1000;CA1063;SA1113;CA1031;CA1051;CA1200</NoWarn>
1212
<NoWarn>$(NoWarn);SA1629;SA1612;CA2211;S2223;CA1032;CA1815;CA1816;S4457;SA1615;IDE0250;S109;SA1618;SA1407;CA1033</NoWarn>
1313
<NoWarn>$(NoWarn);SA1515;S4023;CA1010;IDE0063;S2681;S3442;S3880;CA1064;SA1110;SA1203;SA1649;SA1625;SA1623;SA1118</NoWarn>
14-
<NoWarn>$(NoWarn);S3253;S3971;S6605;CA1724;CA1716;SA1108;CA1710;S4049;S3246;SA1204;S3928;CA1508;CA1822;CA2201;SA1642</NoWarn>
15-
<NoWarn>$(NoWarn);SA1805;SA1129;SA1805;CA1805;CA1821</NoWarn>
14+
<NoWarn>$(NoWarn);S3253;S3971;S6605;CA1724;CA1716;SA1108;CA1710;S4049;S3246</NoWarn>
15+
<NoWarn>$(NoWarn);SA1805;SA1805;CA1805;CA1821</NoWarn>
1616

1717
<!--Pulic API Analyzers: We do not need to fix these as it would break compatibility with released Polly versions-->
1818
<NoWarn>$(NoWarn);RS0037;</NoWarn>

src/Polly/RateLimit/LockFreeTokenBucketRateLimiter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal sealed class LockFreeTokenBucketRateLimiter : IRateLimiter
1515
private long addNextTokenAtTicks;
1616

1717
#if !NETSTANDARD2_0
18-
private SpinWait spinner = new();
18+
private SpinWait spinner = default;
1919
#endif
2020

2121
/// <summary>

0 commit comments

Comments
 (0)