Skip to content

Commit

Permalink
* rename nested class ModelBuilderHelper to ModelBuilderExtension
Browse files Browse the repository at this point in the history
… to fix `AV1708` @ RevisionWithSplitting.cs

* suppress other violations of Roslyn analyzer rules
* replace some `$pragma warning (disable|restore)` with `[SuppressMessage]` attribute and vice versa for better limiting about its scope
@ c#

* always cache regardless of other file changes, this will prevent updating ReSharper tool as long as still using cache @ .github/workflows/c#.yml
  • Loading branch information
n0099 committed Mar 26, 2024
1 parent 5100379 commit 2028d24
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/c#.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
path: |
${{ github.workspace }}/.resharper
~/.dotnet/tools
key: ${{ runner.os }}-resharper-${{ hashFiles('c#/**/*') }}
restore-keys: ${{ runner.os }}-nuget-
key: ${{ runner.os }}-resharper
restore-keys: ${{ runner.os }}-resharper-

- uses: muno92/resharper_inspectcode@v1
with:
Expand Down
10 changes: 10 additions & 0 deletions c#/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
[assembly: SuppressMessage("Maintainability", "AV1537:If-else-if construct should end with an unconditional else clause")]
[assembly: SuppressMessage("Maintainability", "AV1554:Method contains optional parameter in type hierarchy")]
[assembly: SuppressMessage("Maintainability", "AV1564:Parameter in public or internal member is of type bool or bool?")]
[assembly: SuppressMessage("Class Design", "AV1010:Member hides inherited member")]
[assembly: SuppressMessage("Maintainability", "AV1562:Do not declare a parameter as ref or out")]
[assembly: SuppressMessage("Maintainability", "AV1532:Loop statement contains nested loop")]
[assembly: SuppressMessage("Design", "CC0091:Use static method", Justification = "https://github.com/code-cracker/code-cracker/issues/1087")]
[assembly: SuppressMessage("Usage", "MA0015:Specify the parameter name in ArgumentException")]
[assembly: SuppressMessage("Class Design", "AV1008:Class should not be static")]
[assembly: SuppressMessage("Framework", "AV2220:Simple query should be replaced by extension method call")]
[assembly: SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.")]
[assembly: SuppressMessage("Style", "CC0037:Remove commented code.")]
[assembly: SuppressMessage("Documentation", "AV2305:Missing XML comment for internally visible type, member or parameter")]

[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented")]
Expand Down
8 changes: 4 additions & 4 deletions c#/crawler/src/Db/CrawlerDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,22 @@ protected override void OnModelCreating(ModelBuilder b)
b.Entity<SubReplyPost>().ToTable($"tbmc_f{Fid}_subReply");
b.Entity<SubReplyContent>().ToTable($"tbmc_f{Fid}_subReply_content");

var thread = new RevisionWithSplitting<BaseThreadRevision>.ModelBuilderHelper(b, "tbmcr_thread");
var thread = new RevisionWithSplitting<BaseThreadRevision>.ModelBuilderExtension(b, "tbmcr_thread");
thread.HasKey<ThreadRevision>(e => new {e.Tid, e.TakenAt});
thread.SplittingHasKeyAndName<SplitViewCount>("viewCount", e => new {e.Tid, e.TakenAt});

var reply = new RevisionWithSplitting<BaseReplyRevision>.ModelBuilderHelper(b, "tbmcr_reply");
var reply = new RevisionWithSplitting<BaseReplyRevision>.ModelBuilderExtension(b, "tbmcr_reply");
reply.HasKey<ReplyRevision>(e => new {e.Pid, e.TakenAt});
reply.SplittingHasKeyAndName<ReplyRevision.SplitAgreeCount>("agreeCount", e => new {e.Pid, e.TakenAt});
reply.SplittingHasKeyAndName<SplitSubReplyCount>("subReplyCount", e => new {e.Pid, e.TakenAt});
reply.SplittingHasKeyAndName<SplitFloor>("floor", e => new {e.Pid, e.TakenAt});

var subReply = new RevisionWithSplitting<BaseSubReplyRevision>.ModelBuilderHelper(b, "tbmcr_subReply");
var subReply = new RevisionWithSplitting<BaseSubReplyRevision>.ModelBuilderExtension(b, "tbmcr_subReply");
subReply.HasKey<SubReplyRevision>(e => new {e.Spid, e.TakenAt});
subReply.SplittingHasKeyAndName<SubReplyRevision.SplitAgreeCount>("agreeCount", e => new {e.Spid, e.TakenAt});
subReply.SplittingHasKeyAndName<SplitDisagreeCount>("disagreeCount", e => new {e.Spid, e.TakenAt});

var user = new RevisionWithSplitting<BaseUserRevision>.ModelBuilderHelper(b, "tbmcr_user");
var user = new RevisionWithSplitting<BaseUserRevision>.ModelBuilderExtension(b, "tbmcr_user");
user.HasKey<UserRevision>(e => new {e.Uid, e.TakenAt});
user.SplittingHasKeyAndName<SplitIpGeolocation>("ipGeolocation", e => new {e.Uid, e.TakenAt});
user.SplittingHasKeyAndName<SplitPortraitUpdatedAt>("portraitUpdatedAt", e => new {e.Uid, e.TakenAt});
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Db/Revision/RevisionWithSplitting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected void SetSplitEntityValue<TSplitEntity, TValue>
SplitEntities[typeof(TSplitEntity)] = entityFactory();
}

public class ModelBuilderHelper(ModelBuilder builder, string baseTableName)
public class ModelBuilderExtension(ModelBuilder builder, string baseTableName)
{
public void HasKey<TRevision>(Expression<Func<TRevision, object?>> keySelector)

Check notice on line 31 in c#/crawler/src/Db/Revision/RevisionWithSplitting.cs

View workflow job for this annotation

GitHub Actions / ReSharper

"[MA0038] Make method static (deprecated, use CA1822 instead)" on /home/runner/work/open-tbm/open-tbm/c#/crawler/src/Db/Revision/RevisionWithSplitting.cs(31,1270)
where TRevision : class, TBaseRevision =>
Expand Down
2 changes: 2 additions & 0 deletions c#/crawler/src/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace tbm.Crawler;

#pragma warning disable AV1708 // Type name contains term that should be avoided
public abstract partial class Helper
#pragma warning restore AV1708 // Type name contains term that should be avoided
{
public static byte[]? SerializedProtoBufOrNullIfEmpty(IMessage? protoBuf) =>

Check warning on line 10 in c#/crawler/src/Helper.cs

View workflow job for this annotation

GitHub Actions / ReSharper

"[AV1130] Return type in signature for 'Helper.SerializedProtoBufOrNullIfEmpty(IMessage?)' should be an interface to an unchangeable collection" on /home/runner/work/open-tbm/open-tbm/c#/crawler/src/Helper.cs(10,312)
protoBuf == null || protoBuf.CalculateSize() == 0 ? null : protoBuf.ToByteArray();
Expand Down
4 changes: 4 additions & 0 deletions c#/crawler/src/Tieba/ClientRequester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ private async Task<HttpResponseMessage> Post(
await requesterTcs.Wait(stoppingToken);
if (_config.GetValue("LogTrace", false)) logTraceAction();
var ret = responseTaskFactory(http);
#pragma warning disable AV2235 // Call to Task.ContinueWith should be replaced with an await expression
_ = ret.ContinueWith(task =>
#pragma warning restore AV2235 // Call to Task.ContinueWith should be replaced with an await expression
{
// ReSharper disable once MergeIntoPattern
#pragma warning disable SS034 // Use await to get the result of an asynchronous operation
if (task.IsCompletedSuccessfully && task.Result.IsSuccessStatusCode) requesterTcs.Increase();
#pragma warning restore SS034 // Use await to get the result of an asynchronous operation
else requesterTcs.Decrease();
}, stoppingToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
return await ret;
Expand Down
3 changes: 2 additions & 1 deletion c#/crawler/src/Tieba/Crawl/Facade/BaseCrawlFacade.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace tbm.Crawler.Tieba.Crawl.Facade;

[SuppressMessage("Major Code Smell", "S3881:\"IDisposable\" should be implemented correctly")]
#pragma warning disable S3881 // "IDisposable" should be implemented correctly
public abstract class BaseCrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>(
#pragma warning restore S3881 // "IDisposable" should be implemented correctly
BaseCrawler<TResponse, TPostProtoBuf> crawler,
BaseParser<TPost, TPostProtoBuf> parser,
Func<ConcurrentDictionary<PostId, TPost>, BaseSaver<TPost, TBaseRevision>> saverFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ public class ResumeSuspendPostContentsPushingWorker(
public static string GetFilePath(string postType) =>
Path.Combine(AppContext.BaseDirectory, $"suspendPostContentsPushIntoSonic.{postType}.csv");

[SuppressMessage("Reliability", "CA2021:Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types", Justification = "https://github.com/dotnet/roslyn-analyzers/issues/7031")]
protected override Task DoWork(CancellationToken stoppingToken)
{
foreach (var postType in new[] {"replies", "subReplies"})
{
var path = GetFilePath(postType);
if (!File.Exists(path)) continue;
#pragma warning disable CA2021 // Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types
var postTuples = File.ReadLines(path).Select(ParseLine)
.OfType<(Fid Fid, PostId Id, string Content)>().ToList();
#pragma warning restore CA2021 // https://github.com/dotnet/roslyn-analyzers/issues/7031
postTuples.GroupBy(t => t.Fid).ForEach(g =>
pusher.PushPostWithCancellationToken(g.ToList(), g.Key, postType, t => t.Id,
t => Helper.ParseThenUnwrapPostContent(Convert.FromBase64String(t.Content)),
Expand Down
1 change: 1 addition & 0 deletions c#/imagePipeline/src/Db/ImageMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ByteSize : IImageMetadata

public class Exif : IEmbedded
{
[SuppressMessage("ApiDesign", "SS039:An enum should specify a default value")]
public enum ExifOrientation
{ // https://magnushoff.com/articles/jpeg-orientation/
Horizontal = 1,
Expand Down
3 changes: 1 addition & 2 deletions c#/imagePipeline/src/Db/ImagePipelineDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ImagePipelineDbContext() : this(fid: 0, script: "") { }

protected override void OnConfiguringMysql(MySqlDbContextOptionsBuilder builder) => builder.UseNetTopologySuite();

#pragma warning disable IDE0058 // Expression value is never used
[SuppressMessage("Style", "IDE0058:Expression value is never used")]
protected override void OnModelCreating(ModelBuilder b)
{
base.OnModelCreating(b);
Expand Down Expand Up @@ -56,7 +56,6 @@ void SplitImageMetadata<TRelatedEntity>
SplitImageMetadata(e => e.GifMetadata, "gif");
SplitImageMetadata(e => e.BmpMetadata, "bmp");
}
#pragma warning restore IDE0058 // Expression value is never used

public class ModelCacheKeyFactory : IModelCacheKeyFactory
{ // https://stackoverflow.com/questions/51864015/entity-framework-map-model-class-to-table-at-run-time/51899590#51899590
Expand Down

0 comments on commit 2028d24

Please sign in to comment.