Skip to content

Commit

Permalink
* fix all violations of Roslyn analyzer rules and ReSharper inspection
Browse files Browse the repository at this point in the history
* rename lambda param with type `ImageInReply` from `reply` to `image` @ `ReplyContentImageSaver.Save()`
@ c#
  • Loading branch information
n0099 committed Jun 10, 2024
1 parent cddbec5 commit a811dba
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// ReSharper disable PropertyCanBeMadeInitOnly.Global

Check warning on line 1 in c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs

View workflow job for this annotation

GitHub Actions / ReSharper

"[AD0001] Analyzer 'Microsoft.CodeAnalysis.CodeStyle.CSharpFormattingAnalyzer' threw an exception of type 'System.TypeLoadException' with message 'Could not load type 'Microsoft.CodeAnalysis.SyntaxList' from assembly 'Microsoft.CodeAnalysis, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.'. Exception occurred with following context: Compilation: tbm.Crawler SyntaxTree: /home/runner/work/open-tbm/open-tbm/c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.SyntaxList' from assembly 'Microsoft.CodeAnalysis, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. at Microsoft.CodeAnalysis.CSharp.Extensions.MemberDeclarationSyntaxExtensions.GetAttributes(MemberDeclarationSyntax member) at Microsoft.CodeAnalysis.CSharp.Formatting.FormattingHelpers.GetFirstAndLastMemberDeclarationTokensAfterAttributes(MemberDeclarationSyntax node) at Microsoft.CodeAnalysis.CSharp.Formatting.SuppressFormattingRule.AddSpecificNodesSuppressOperations(List`1 list, SyntaxNode node) at Microsoft.CodeAnalysis.Formatting.Rules.NextSuppressOperationAction.Invoke() at Microsoft.CodeAnalysis.CSharp.Formatting.ElasticTriviaFormattingRule.AddSuppressOperations(List`1 list, SyntaxNode node, NextSuppressOperationAction& nextOperation) at Microsoft.CodeAnalysis.Formatting.Rules.NextSuppressOperationAction.Invoke() at Microsoft.CodeAnalysis.CSharp.Formatting.SpacingFormattingRule.AddSuppressOperations(List`1 list, SyntaxNode node, NextSuppressOperationAction& nextOperation) at Microsoft.CodeAnalysis.Formatting.Rules.NextSuppressOperationAction.Invoke() at Microsoft.CodeAnalysis.CSharp.Formatting.WrappingFormattingRule.AddSuppressOperations(List`1 list, SyntaxNode node, NextSuppressOperationAction& nextOperation) at Microsoft.CodeAnalysis.Formatting.ChainedFormattingRules.AddSuppressOperations(List`1 list, SyntaxNode currentNode) at Microsoft.CodeAnalysis.Formatting.AbstractFormatEngine.AddOperations[T](SegmentedList`1 operations, List`1 scratch, SyntaxNode node, Action`2 addOperations) at Microsoft.CodeAnalysis.Formatting.AbstractFormatEngine.CreateNodeOperations(CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Formatting.AbstractFormatEngine.Format(CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Formatting.AbstractSyntaxFormatting.GetFormattingResult(SyntaxNode node, IEnumerable`1 spans, SyntaxFormattingOptions options, IEnumerable`1 rules, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.CodeStyle.FormattingAnalyzerHelper.AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context, ISyntaxFormatting formattingProvider, DiagnosticDescriptor descriptor, SyntaxFormattingOptions options) at Microsoft.CodeAnalysis.CodeStyle.AbstractFormattingAnalyzer.<>c__DisplayClass4_0.<InitializeWorker>b__1(SyntaxTreeAnalysisContext treeContext) at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSyntaxTreeActions>b__50_1(ValueTuple`2 data) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 590 at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1185 ----- Suppress the following diagnostics to disable this analyzer: IDE0055" on /home/runner/work/open-tbm/open-tbm/c#/crawler/src/Db/Post/PostWithContentAndAuthorExpGrade.cs
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace tbm.Crawler.Db.Post;

#pragma warning disable AV1000 // Type name contains the word 'and', which suggests it has multiple purposes
public abstract class PostWithContentAndAuthorExpGrade : PostWithAuthorExpGrade
#pragma warning restore AV1000 // Type name contains the word 'and', which suggests it has multiple purposes
{
[NotMapped] public byte[]? Content { get; set; }

Expand Down
4 changes: 3 additions & 1 deletion c#/crawler/src/Tieba/Crawl/Parser/Post/ReplyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ protected override ReplyPost Convert(Reply inPost)
throw new InvalidDataException("Reply parse error.", e);
}
}

}
public partial class ReplyParser
{
public static void SimplifyImagesInReplyContent<TLoggerCategory>
(ILogger<TLoggerCategory> logger, ref Reply inPost)
{
Expand Down
4 changes: 2 additions & 2 deletions c#/crawler/src/Tieba/Crawl/Saver/ReplyContentImageSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where images.Keys.Contains(e.UrlFilename)
.Where(pair => GlobalLockedImagesInReplyKeyByUrlFilename.TryAdd(pair.Key, pair.Value))
.ToDictionary();
newlyLockedImages.Values()
.Where(reply => !Monitor.TryEnter(reply, TimeSpan.FromSeconds(10)))
.Where(image => !Monitor.TryEnter(image, TimeSpan.FromSeconds(10)))
.ForEach(image => logger.LogWarning(
"Wait for locking newly locked image {} timed out after 10s", image.UrlFilename));

Expand All @@ -45,7 +45,7 @@ where images.Keys.Contains(e.UrlFilename)
.Keys().Except(newlyLockedImages.Keys()))
.ToDictionary();
alreadyLockedImages.Values()
.Where(reply => !Monitor.TryEnter(reply, TimeSpan.FromSeconds(10)))
.Where(image => !Monitor.TryEnter(image, TimeSpan.FromSeconds(10)))
.ForEach(image => logger.LogWarning(
"Wait for locking already locked image {} timed out after 10s", image.UrlFilename));
if (alreadyLockedImages.Count != 0)
Expand Down
1 change: 1 addition & 0 deletions c#/shared/src/Db/TbmDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private static void ManipulateCommand(DbCommand command) =>
"RETURNING pg_current_xact_id()::xid");
}
}

public class TbmDbContext<TModelCacheKeyFactory>(ILogger<TbmDbContext<TModelCacheKeyFactory>> logger)
: TbmDbContext(logger)
where TModelCacheKeyFactory : class, IModelCacheKeyFactory
Expand Down
2 changes: 1 addition & 1 deletion c#/shared/src/TransformEntityWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async Task SaveThenLog(int processedCount, Process currentProcess)
logger.LogTrace("processedEntityCount:{} updatedEntityCount:{} elapsed:{}ms processMemory:{}MiB exceptions:{}",
processedCount, updatedEntityCount,
stopwatch.ElapsedMilliseconds,
currentProcess.PrivateMemorySize64 / 1024 / 1024,
currentProcess.PrivateMemorySize64 / 1024f / 1024,
JsonSerializer.Serialize(exceptions, JsonSerializerOptions));
stopwatch.Restart();
}
Expand Down

0 comments on commit a811dba

Please sign in to comment.