Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SA1113/CA1200/SA1805/SA1629/SA1407/SA1127 warnings #1938

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Polly/Bulkhead/BulkheadRejectedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
/// <summary>
/// Initializes a new instance of the <see cref="BulkheadRejectedException" /> class.
/// </summary>
public BulkheadRejectedException() : this("The bulkhead semaphore and queue are full and execution was rejected.")
public BulkheadRejectedException()
: this("The bulkhead semaphore and queue are full and execution was rejected.")
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BulkheadRejectedException"/> class.
/// </summary>
/// <param name="message">The message.</param>
public BulkheadRejectedException(string message) : base(message)
public BulkheadRejectedException(string message)
: base(message)
{
}

Expand All @@ -33,7 +35,8 @@
/// </summary>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
public BulkheadRejectedException(string message, Exception innerException) : base(message, innerException)
public BulkheadRejectedException(string message, Exception innerException)
: base(message, innerException)

Check warning on line 39 in src/Polly/Bulkhead/BulkheadRejectedException.cs

View check run for this annotation

Codecov / codecov/patch

src/Polly/Bulkhead/BulkheadRejectedException.cs#L39

Added line #L39 was not covered by tests
{
}

Expand All @@ -44,7 +47,8 @@
/// </summary>
/// <param name="info">The information.</param>
/// <param name="context">The context.</param>
protected BulkheadRejectedException(SerializationInfo info, StreamingContext context) : base(info, context)
protected BulkheadRejectedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/Polly/Caching/AbsoluteTtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class AbsoluteTtl : NonSlidingTtl
/// Initializes a new instance of the <see cref="AbsoluteTtl"/> class.
/// </summary>
/// <param name="absoluteExpirationTime">The UTC point in time until which to consider the cache item valid.</param>
public AbsoluteTtl(DateTimeOffset absoluteExpirationTime) : base(absoluteExpirationTime)
public AbsoluteTtl(DateTimeOffset absoluteExpirationTime)
: base(absoluteExpirationTime)
{
}
}
3 changes: 2 additions & 1 deletion src/Polly/Caching/Ttl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public struct Ttl
/// </summary>
/// <param name="timeSpan">The timespan for which this cache-item remains valid.
/// <remarks>Will be considered as not denoting sliding expiration.</remarks></param>
public Ttl(TimeSpan timeSpan) : this(timeSpan, false)
public Ttl(TimeSpan timeSpan)
: this(timeSpan, false)
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/Polly/CircuitBreaker/AdvancedCircuitController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public AdvancedCircuitController(
Action<DelegateResult<TResult>, CircuitState, TimeSpan, Context> onBreak,
Action<Context> onReset,
Action onHalfOpen
) : base(durationOfBreak, onBreak, onReset, onHalfOpen)
)
: base(durationOfBreak, onBreak, onReset, onHalfOpen)
{
_metrics = samplingDuration.Ticks < ResolutionOfCircuitTimer * NumberOfWindows
? new SingleHealthMetrics(samplingDuration)
Expand Down
6 changes: 4 additions & 2 deletions src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class AsyncCircuitBreakerPolicy : AsyncPolicy, ICircuitBreakerPolicy
internal AsyncCircuitBreakerPolicy(
PolicyBuilder policyBuilder,
ICircuitController<EmptyStruct> breakerController
) : base(policyBuilder) =>
)
: base(policyBuilder) =>
_breakerController = breakerController;

/// <summary>
Expand Down Expand Up @@ -64,7 +65,8 @@ public class AsyncCircuitBreakerPolicy<TResult> : AsyncPolicy<TResult>, ICircuit
internal AsyncCircuitBreakerPolicy(
PolicyBuilder<TResult> policyBuilder,
ICircuitController<TResult> breakerController
) : base(policyBuilder) =>
)
: base(policyBuilder) =>
_breakerController = breakerController;

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class CircuitBreakerPolicy : Policy, ICircuitBreakerPolicy
internal CircuitBreakerPolicy(
PolicyBuilder policyBuilder,
ICircuitController<EmptyStruct> breakerController
) : base(policyBuilder) =>
)
: base(policyBuilder) =>
_breakerController = breakerController;

/// <summary>
Expand Down Expand Up @@ -62,7 +63,8 @@ public class CircuitBreakerPolicy<TResult> : Policy<TResult>, ICircuitBreakerPol
internal CircuitBreakerPolicy(
PolicyBuilder<TResult> policyBuilder,
ICircuitController<TResult> breakerController
) : base(policyBuilder) =>
)
: base(policyBuilder) =>
_breakerController = breakerController;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public ConsecutiveCountCircuitController(
Action<DelegateResult<TResult>, CircuitState, TimeSpan, Context> onBreak,
Action<Context> onReset,
Action onHalfOpen
) : base(durationOfBreak, onBreak, onReset, onHalfOpen) =>
)
: base(durationOfBreak, onBreak, onReset, onHalfOpen) =>
_exceptionsAllowedBeforeBreaking = exceptionsAllowedBeforeBreaking;

public override void OnCircuitReset(Context context)
Expand Down
6 changes: 4 additions & 2 deletions src/Polly/Context.Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public partial class Context : IDictionary<string, object>, IDictionary, IReadOn
/// </summary>
/// <param name="operationKey">The operation key.</param>
/// <param name="contextData">The context data.</param>
public Context(string operationKey, IDictionary<string, object> contextData) : this(contextData) =>
public Context(string operationKey, IDictionary<string, object> contextData)
: this(contextData) =>
OperationKey = operationKey;

internal Context(IDictionary<string, object> contextData) : this()
internal Context(IDictionary<string, object> contextData)
: this()
{
if (contextData == null) throw new ArgumentNullException(nameof(contextData));
wrappedDictionary = new Dictionary<string, object>(contextData);
Expand Down
3 changes: 2 additions & 1 deletion src/Polly/Fallback/AsyncFallbackPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ internal AsyncFallbackPolicy(
PolicyBuilder<TResult> policyBuilder,
Func<DelegateResult<TResult>, Context, Task> onFallbackAsync,
Func<DelegateResult<TResult>, Context, CancellationToken, Task<TResult>> fallbackAction
) : base(policyBuilder)
)
: base(policyBuilder)
{
_onFallbackAsync = onFallbackAsync ?? throw new ArgumentNullException(nameof(onFallbackAsync));
_fallbackAction = fallbackAction ?? throw new ArgumentNullException(nameof(fallbackAction));
Expand Down
3 changes: 2 additions & 1 deletion src/Polly/Fallback/FallbackPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ internal FallbackPolicy(
PolicyBuilder<TResult> policyBuilder,
Action<DelegateResult<TResult>, Context> onFallback,
Func<DelegateResult<TResult>, Context, CancellationToken, TResult> fallbackAction
) : base(policyBuilder)
)
: base(policyBuilder)
{
_onFallback = onFallback ?? throw new ArgumentNullException(nameof(onFallback));
_fallbackAction = fallbackAction ?? throw new ArgumentNullException(nameof(fallbackAction));
Expand Down
32 changes: 24 additions & 8 deletions src/Polly/Policy.HandleSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public partial class Policy
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public static PolicyBuilder Handle<TException>() where TException : Exception =>
public static PolicyBuilder Handle<TException>()
where TException : Exception
=>
new(exception => exception is TException ? exception : null);

/// <summary>
Expand All @@ -16,23 +18,29 @@ public static PolicyBuilder Handle<TException>() where TException : Exception =>
/// <typeparam name="TException">The type of the exception.</typeparam>
/// <param name="exceptionPredicate">The exception predicate to filter the type of exception this policy can handle.</param>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public static PolicyBuilder Handle<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception =>
public static PolicyBuilder Handle<TException>(Func<TException, bool> exceptionPredicate)
where TException : Exception
=>
new(exception => exception is TException texception && exceptionPredicate(texception) ? exception : null);

/// <summary>
/// Specifies the type of exception that this policy can handle if found as an InnerException of a regular <see cref="Exception"/>, or at any level of nesting within an <see cref="AggregateException"/>.
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public static PolicyBuilder HandleInner<TException>() where TException : Exception =>
public static PolicyBuilder HandleInner<TException>()
where TException : Exception
=>
new(PolicyBuilder.HandleInner(ex => ex is TException));

/// <summary>
/// Specifies the type of exception that this policy can handle, with additional filters on this exception type, if found as an InnerException of a regular <see cref="Exception"/>, or at any level of nesting within an <see cref="AggregateException"/>.
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public static PolicyBuilder HandleInner<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception =>
public static PolicyBuilder HandleInner<TException>(Func<TException, bool> exceptionPredicate)
where TException : Exception
=>
new(PolicyBuilder.HandleInner(ex => ex is TException texception && exceptionPredicate(texception)));

/// <summary>
Expand Down Expand Up @@ -62,7 +70,9 @@ public partial class Policy<TResult>
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance.</returns>
public static PolicyBuilder<TResult> Handle<TException>() where TException : Exception =>
public static PolicyBuilder<TResult> Handle<TException>()
where TException : Exception
=>
new(exception => exception is TException ? exception : null);

/// <summary>
Expand All @@ -71,23 +81,29 @@ public static PolicyBuilder<TResult> Handle<TException>() where TException : Exc
/// <typeparam name="TException">The type of the exception.</typeparam>
/// <param name="exceptionPredicate">The exception predicate to filter the type of exception this policy can handle.</param>
/// <returns>The PolicyBuilder instance.</returns>
public static PolicyBuilder<TResult> Handle<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception =>
public static PolicyBuilder<TResult> Handle<TException>(Func<TException, bool> exceptionPredicate)
where TException : Exception
=>
new(exception => exception is TException texception && exceptionPredicate(texception) ? exception : null);

/// <summary>
/// Specifies the type of exception that this policy can handle if found as an InnerException of a regular <see cref="Exception"/>, or at any level of nesting within an <see cref="AggregateException"/>.
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public static PolicyBuilder<TResult> HandleInner<TException>() where TException : Exception =>
public static PolicyBuilder<TResult> HandleInner<TException>()
where TException : Exception
=>
new(PolicyBuilder.HandleInner(ex => ex is TException));

/// <summary>
/// Specifies the type of exception that this policy can handle, with additional filters on this exception type, if found as an InnerException of a regular <see cref="Exception"/>, or at any level of nesting within an <see cref="AggregateException"/>.
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public static PolicyBuilder<TResult> HandleInner<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception =>
public static PolicyBuilder<TResult> HandleInner<TException>(Func<TException, bool> exceptionPredicate)
where TException : Exception
=>
new(PolicyBuilder.HandleInner(ex => ex is TException texception && exceptionPredicate(texception)));

/// <summary>
Expand Down
26 changes: 17 additions & 9 deletions src/Polly/PolicyBuilder.OrSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public partial class PolicyBuilder
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance.</returns>
public PolicyBuilder Or<TException>() where TException : Exception
public PolicyBuilder Or<TException>()
where TException : Exception
{
ExceptionPredicates.Add(exception => exception is TException ? exception : null);
return this;
Expand All @@ -21,7 +22,8 @@ public PolicyBuilder Or<TException>() where TException : Exception
/// <typeparam name="TException">The type of the exception.</typeparam>
/// <param name="exceptionPredicate">The exception predicate to filter the type of exception this policy can handle.</param>
/// <returns>The PolicyBuilder instance.</returns>
public PolicyBuilder Or<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception
public PolicyBuilder Or<TException>(Func<TException, bool> exceptionPredicate)
where TException : Exception
{
ExceptionPredicates.Add(exception => exception is TException texception && exceptionPredicate(texception) ? exception : null);
return this;
Expand All @@ -32,7 +34,8 @@ public PolicyBuilder Or<TException>(Func<TException, bool> exceptionPredicate) w
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public PolicyBuilder OrInner<TException>() where TException : Exception
public PolicyBuilder OrInner<TException>()
where TException : Exception
{
ExceptionPredicates.Add(HandleInner(ex => ex is TException));
return this;
Expand All @@ -44,7 +47,8 @@ public PolicyBuilder OrInner<TException>() where TException : Exception
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <param name="exceptionPredicate">The exception predicate to filter the type of exception this policy can handle.</param>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public PolicyBuilder OrInner<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception
public PolicyBuilder OrInner<TException>(Func<TException, bool> exceptionPredicate)
where TException : Exception
{
ExceptionPredicates.Add(HandleInner(exception => exception is TException innerEx && exceptionPredicate(innerEx)));
return this;
Expand Down Expand Up @@ -134,7 +138,8 @@ public PolicyBuilder<TResult> OrResult(TResult result) =>
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance.</returns>
public PolicyBuilder<TResult> Or<TException>() where TException : Exception
public PolicyBuilder<TResult> Or<TException>()
where TException : Exception
{
ExceptionPredicates.Add(exception => exception is TException ? exception : null);
return this;
Expand All @@ -146,9 +151,10 @@ public PolicyBuilder<TResult> Or<TException>() where TException : Exception
/// <typeparam name="TException">The type of the exception.</typeparam>
/// <param name="exceptionPredicate">The exception predicate to filter the type of exception this policy can handle.</param>
/// <returns>The PolicyBuilder instance.</returns>
public PolicyBuilder<TResult> Or<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception
public PolicyBuilder<TResult> Or<TException>(Func<TException, bool> exceptionPredicate)
where TException : Exception
{
ExceptionPredicates.Add(exception => exception is TException texception && exceptionPredicate(texception) ? exception : null);
ExceptionPredicates.Add(exception => exception is TException texception && exceptionPredicate(texception) ? exception : null);
return this;
}

Expand All @@ -157,7 +163,8 @@ public PolicyBuilder<TResult> Or<TException>(Func<TException, bool> exceptionPre
/// </summary>
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public PolicyBuilder<TResult> OrInner<TException>() where TException : Exception
public PolicyBuilder<TResult> OrInner<TException>()
where TException : Exception
{
ExceptionPredicates.Add(PolicyBuilder.HandleInner(ex => ex is TException));
return this;
Expand All @@ -169,7 +176,8 @@ public PolicyBuilder<TResult> OrInner<TException>() where TException : Exception
/// <typeparam name="TException">The type of the exception to handle.</typeparam>
/// <param name="exceptionPredicate">The exception predicate to filter the type of exception this policy can handle.</param>
/// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
public PolicyBuilder<TResult> OrInner<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception
public PolicyBuilder<TResult> OrInner<TException>(Func<TException, bool> exceptionPredicate)
where TException : Exception
{
ExceptionPredicates.Add(PolicyBuilder.HandleInner(ex => ex is TException texception && exceptionPredicate(texception)));
return this;
Expand Down
8 changes: 4 additions & 4 deletions src/Polly/PolicyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ private PolicyBuilder()
ResultPredicates = new ResultPredicates<TResult>();
}

internal PolicyBuilder(Func<TResult, bool> resultPredicate) : this() =>
OrResult(resultPredicate);
internal PolicyBuilder(Func<TResult, bool> resultPredicate)
: this() => OrResult(resultPredicate);

internal PolicyBuilder(ExceptionPredicate predicate) : this() =>
ExceptionPredicates.Add(predicate);
internal PolicyBuilder(ExceptionPredicate predicate)
: this() => ExceptionPredicates.Add(predicate);

internal PolicyBuilder(ExceptionPredicates exceptionPredicates)
: this() =>
Expand Down
8 changes: 4 additions & 4 deletions src/Polly/Polly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<ProjectType>Library</ProjectType>
<MutationScore>70</MutationScore>
<IncludePollyUsings>true</IncludePollyUsings>
<NoWarn>$(NoWarn);IDE0011;SA1501;S103;IDE0055;SA1111;S3872;SA1127;SA1128;SA1402;SA1513;SA1414;S3215;S2955</NoWarn>
<NoWarn>$(NoWarn);IDE1006;CA1062;S107;CA1068;S4039;SA1121;CA1000;CA1063;SA1113;CA1031;CA1051;CA1200</NoWarn>
<NoWarn>$(NoWarn);SA1629;SA1612;CA2211;S2223;CA1032;CA1815;CA1816;S4457;SA1615;S109;SA1618;SA1407;CA1033</NoWarn>
<NoWarn>$(NoWarn);IDE0011;SA1501;S103;IDE0055;SA1111;S3872;SA1402;SA1513;SA1414;S3215;S2955</NoWarn>
<NoWarn>$(NoWarn);IDE1006;CA1062;S107;CA1068;S4039;SA1121;CA1000;CA1063;CA1031;CA1051</NoWarn>
<NoWarn>$(NoWarn);SA1612;CA2211;S2223;CA1032;CA1815;CA1816;S4457;SA1615;S109;SA1618;CA1033</NoWarn>
<NoWarn>$(NoWarn);SA1515;S4023;CA1010;S2681;S3442;S3880;CA1064;SA1110;SA1203;SA1649;SA1625;SA1623;SA1118</NoWarn>
<NoWarn>$(NoWarn);S3253;S3971;S6605;CA1724;CA1716;SA1108;CA1710;S4049;S3246</NoWarn>
<NoWarn>$(NoWarn);SA1805;SA1805;CA1805;CA1821</NoWarn>
<NoWarn>$(NoWarn);CA1805;CA1821</NoWarn>

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