Skip to content

Commit

Permalink
style: fix or suppress all known warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoona committed Sep 24, 2022
1 parent aa2eb8f commit 1af6ecd
Show file tree
Hide file tree
Showing 10 changed files with 739 additions and 696 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private void DeadlineBackgroundTaskEntryPoint()
"Request {0} to {1} exceed deadline, deadline={2:u}, now1={3:u}, now2={4:u}",
entry.Key,
this.RemoteEndPoint,
entry.Value.Deadline,
now,
DateTime.UtcNow);
requestContext.TaskCompletionSource.TrySetException(new RpcException(new Status(
Expand Down
16 changes: 9 additions & 7 deletions Memoization.Net/Memoization.Tests/TestMemoization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ public void Test2()
m_fib(7);
Assert.Equal(0, counter);
}
}

internal static class YCombinator<T>
{
public static Func<Func<Func<T, T>, Func<T, T>>, Func<T, T>> Fix =
f => ((Recursive)(g =>
f(x => g(g)(x))))((Recursive)(g => f(x => g(g)(x))));
internal static class YCombinator<T>
{
private static Func<Func<Func<T, T>, Func<T, T>>, Func<T, T>> fix =
f => ((Recursive)(g =>
f(x => g(g)(x))))((Recursive)(g => f(x => g(g)(x))));

private delegate Func<T, T> Recursive(Recursive recursive);
private delegate Func<T, T> Recursive(Recursive recursive);

public static Func<Func<Func<T, T>, Func<T, T>>, Func<T, T>> Fix { get => fix; set => fix = value; }
}
}
}
14 changes: 14 additions & 0 deletions Memoization.Net/Memoization/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// <copyright file="GlobalSuppressions.cs" company="Shuai Zhang">
// Copyright Shuai Zhang. All rights reserved.
// Licensed under the GPLv3 license. See LICENSE file in the project root for full license information.
// </copyright>
//
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1119:Statement should not use unnecessary parenthesis", Justification = "<挂起>", Scope = "member", Target = "~M:Memoization.Memoization.Create``2(System.Func{``0,``1},Microsoft.Extensions.Caching.Memory.IMemoryCache,Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions)~System.Func{``0,``1}")]
[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1119:Statement should not use unnecessary parenthesis", Justification = "<挂起>", Scope = "member", Target = "~M:Memoization.Memoization.Create``2(System.Func{``0,``1},Microsoft.Extensions.Caching.Memory.IMemoryCache)~System.Func{``0,``1}")]
1,276 changes: 638 additions & 638 deletions Memoization.Net/Memoization/Memoization.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,43 @@ internal async Task<string> GetFileStatuses()
}
}

private static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds)
{
#if _NET462 || _NETSTANDARD2_0
return DateTimeOffset.FromUnixTimeMilliseconds(milliseconds);
#else
// Number of days in a non-leap year
const int DaysPerYear = 365;

// Number of days in 4 years
const int DaysPer4Years = (DaysPerYear * 4) + 1; // 1461

// Number of days in 100 years
const int DaysPer100Years = (DaysPer4Years * 25) - 1; // 36524

// Number of days in 400 years
const int DaysPer400Years = (DaysPer100Years * 4) + 1; // 146097

const int DaysTo1970 = (DaysPer400Years * 4) + (DaysPer100Years * 3) + (DaysPer4Years * 17) + DaysPerYear; // 719,162

const long UnixEpochTicks = TimeSpan.TicksPerDay * DaysTo1970; // 621,355,968,000,000,000
const long UnixEpochMilliseconds = UnixEpochTicks / TimeSpan.TicksPerMillisecond; // 62,135,596,800,000

long minMilliseconds = (DateTime.MinValue.Ticks / TimeSpan.TicksPerMillisecond) - UnixEpochMilliseconds;
long maxMilliseconds = (DateTime.MaxValue.Ticks / TimeSpan.TicksPerMillisecond) - UnixEpochMilliseconds;

if (milliseconds < minMilliseconds || milliseconds > maxMilliseconds)
{
throw new ArgumentOutOfRangeException(
nameof(milliseconds),
string.Format("Valid value between {0} and {1} (included).", minMilliseconds, maxMilliseconds));
}

long ticks = (milliseconds * TimeSpan.TicksPerMillisecond) + UnixEpochTicks;
return new DateTimeOffset(ticks, TimeSpan.Zero);
#endif
}

private void SetFileStatus(WebHdfsFileStatus fileStatus)
{
if (fileStatus == null || fileStatus == WebHdfsFileStatus.Empty)
Expand Down Expand Up @@ -149,42 +186,5 @@ private async Task<string> GetFileStatus()
}
}
}

private static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds)
{
#if _NET462 || _NETSTANDARD2_0
return DateTimeOffset.FromUnixTimeMilliseconds(milliseconds);
#else
// Number of days in a non-leap year
const int DaysPerYear = 365;

// Number of days in 4 years
const int DaysPer4Years = (DaysPerYear * 4) + 1; // 1461

// Number of days in 100 years
const int DaysPer100Years = (DaysPer4Years * 25) - 1; // 36524

// Number of days in 400 years
const int DaysPer400Years = (DaysPer100Years * 4) + 1; // 146097

const int DaysTo1970 = (DaysPer400Years * 4) + (DaysPer100Years * 3) + (DaysPer4Years * 17) + DaysPerYear; // 719,162

const long UnixEpochTicks = TimeSpan.TicksPerDay * DaysTo1970; // 621,355,968,000,000,000
const long UnixEpochMilliseconds = UnixEpochTicks / TimeSpan.TicksPerMillisecond; // 62,135,596,800,000

long minMilliseconds = (DateTime.MinValue.Ticks / TimeSpan.TicksPerMillisecond) - UnixEpochMilliseconds;
long maxMilliseconds = (DateTime.MaxValue.Ticks / TimeSpan.TicksPerMillisecond) - UnixEpochMilliseconds;

if (milliseconds < minMilliseconds || milliseconds > maxMilliseconds)
{
throw new ArgumentOutOfRangeException(
nameof(milliseconds),
string.Format("Valid value between {0} and {1} (included).", minMilliseconds, maxMilliseconds));
}

long ticks = (milliseconds * TimeSpan.TicksPerMillisecond) + UnixEpochTicks;
return new DateTimeOffset(ticks, TimeSpan.Zero);
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public void Test_Baseline()

CollectionAssert.AreEqual(
new long[] { 3, 4, 5, 6, 7 },
queueArray
);
queueArray);

Assert.AreEqual(25, arrivalWindow.Sum);
Assert.AreEqual(5, arrivalWindow.Avg);
Expand Down
16 changes: 16 additions & 0 deletions RateLimiter/RateLimiter/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// <copyright file="GlobalSuppressions.cs" company="Shuai Zhang">
// Copyright Shuai Zhang. All rights reserved.
// Licensed under the GPLv3 license. See LICENSE file in the project root for full license information.
// </copyright>
//
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "<挂起>", Scope = "member", Target = "~F:RateLimiter.RateLimiterBase.StopwatchProvider")]
[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "<挂起>", Scope = "member", Target = "~F:RateLimiter.SmoothRateLimiter.storedPermits")]
[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "<挂起>", Scope = "member", Target = "~F:RateLimiter.SmoothRateLimiter.maxPermits")]
[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "<挂起>", Scope = "member", Target = "~F:RateLimiter.SmoothRateLimiter.stableInterval")]
15 changes: 9 additions & 6 deletions RateLimiter/RateLimiter/RateLimiterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,25 @@ public abstract class RateLimiterBase : IRateLimiter
private readonly IAsyncBlocker asyncBlocker;
#endif

protected RateLimiterBase(IStopwatchProvider<long> stopwatchProvider)
#if !NET20
: this(stopwatchProvider, null)
{
}

internal RateLimiterBase(
IStopwatchProvider<long> stopwatchProvider,
IAsyncBlocker asyncBlocker)
{
this.asyncBlocker = asyncBlocker ?? TaskDelayAsyncBlocker.Instance;
this.StopwatchProvider = stopwatchProvider ?? throw new ArgumentNullException(nameof(stopwatchProvider));
}

protected RateLimiterBase(IStopwatchProvider<long> stopwatchProvider)
: this(stopwatchProvider, null)
{
}
#else
protected RateLimiterBase(IStopwatchProvider<long> stopwatchProvider)
{
#endif
this.StopwatchProvider = stopwatchProvider ?? throw new ArgumentNullException(nameof(stopwatchProvider));
}
#endif

public double PermitsPerSecond
{
Expand Down
13 changes: 8 additions & 5 deletions RateLimiter/RateLimiter/SmoothRateLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ public abstract class SmoothRateLimiter : RateLimiterBase

private long nextFreeTicketTimestamp = 0;

protected SmoothRateLimiter(IStopwatchProvider<long> stopwatchProvider)
#if !NET20
: this(stopwatchProvider, null)
internal SmoothRateLimiter(IStopwatchProvider<long> stopwatchProvider, IAsyncBlocker asyncBlocker)
: base(stopwatchProvider, asyncBlocker)
{
}

internal SmoothRateLimiter(IStopwatchProvider<long> stopwatchProvider, IAsyncBlocker asyncBlocker)
: base(stopwatchProvider, asyncBlocker)
protected SmoothRateLimiter(IStopwatchProvider<long> stopwatchProvider)
: this(stopwatchProvider, null)
{
}
#else
protected SmoothRateLimiter(IStopwatchProvider<long> stopwatchProvider)
: base(stopwatchProvider)
#endif
{
}
#endif

protected abstract TimeSpan CoolDownInterval { get; }

Expand Down
7 changes: 6 additions & 1 deletion third_party/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<!-- Won't run code analysis for third party codes. -->
<RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>

<!-- Won't run code analysis for third party codes. -->
<ItemGroup>
<PackageReference Remove="Microsoft.CodeAnalysis.FxCopAnalyzers" />
<PackageReference Remove="Microsoft.CodeAnalysis.NetAnalyzers" />
<PackageReference Remove="Microsoft.CodeAnalysis.BannedApiAnalyzers" />
<PackageReference Remove="StyleCop.Analyzers" />
</ItemGroup>
Expand Down

0 comments on commit 1af6ecd

Please sign in to comment.