From 656ed62545d652feef50963c90e2a6bee662e38f Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 09:27:19 +0900 Subject: [PATCH 01/27] chore: suppress CA1512 messages --- src/Docfx.Common/Path/RelativePath.cs | 6 ++---- src/Docfx.Plugins/DocumentExceptionExtensions.cs | 6 +----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Docfx.Common/Path/RelativePath.cs b/src/Docfx.Common/Path/RelativePath.cs index e1961551f48..7e4be9a976c 100644 --- a/src/Docfx.Common/Path/RelativePath.cs +++ b/src/Docfx.Common/Path/RelativePath.cs @@ -447,10 +447,8 @@ private static RelativePath Create(bool isFromWorkingFolder, int parentDirectory private IEnumerable GetSubdirectories(int skip) { - if (_parts.Length <= skip) - { - throw new ArgumentOutOfRangeException(nameof(skip)); - } + ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(skip, _parts.Length); + return _parts.Take(_parts.Length - skip - 1); } diff --git a/src/Docfx.Plugins/DocumentExceptionExtensions.cs b/src/Docfx.Plugins/DocumentExceptionExtensions.cs index 6b2866a3b40..c06164972d3 100644 --- a/src/Docfx.Plugins/DocumentExceptionExtensions.cs +++ b/src/Docfx.Plugins/DocumentExceptionExtensions.cs @@ -72,11 +72,7 @@ public static void RunAll(this IEnumerable elements, Action< { ArgumentNullException.ThrowIfNull(elements); ArgumentNullException.ThrowIfNull(action); - - if (parallelism <= 0) - { - throw new ArgumentOutOfRangeException(nameof(parallelism)); - } + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(parallelism); try { From 437848399393589b7204514b162d0cabbeb6e73b Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:08:47 +0900 Subject: [PATCH 02/27] chore: suppress CA1514 messages --- src/Docfx.MarkdigEngine.Extensions/ExtensionsHelper.cs | 2 +- src/docfx/Models/MetadataCommand.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Docfx.MarkdigEngine.Extensions/ExtensionsHelper.cs b/src/Docfx.MarkdigEngine.Extensions/ExtensionsHelper.cs index 2a47f838972..7a13261884c 100644 --- a/src/Docfx.MarkdigEngine.Extensions/ExtensionsHelper.cs +++ b/src/Docfx.MarkdigEngine.Extensions/ExtensionsHelper.cs @@ -253,7 +253,7 @@ private static bool MatchPath(ref StringSlice slice, ref string path) if (includedFilePath.Length >= 1 && includedFilePath.First() == '<' && slice.CurrentChar == '>') { - includedFilePath = includedFilePath.Substring(1, includedFilePath.Length - 1).Trim(); + includedFilePath = includedFilePath.Substring(1).Trim(); } if (slice.CurrentChar == ')') diff --git a/src/docfx/Models/MetadataCommand.cs b/src/docfx/Models/MetadataCommand.cs index d41552f48e6..520e27e413d 100644 --- a/src/docfx/Models/MetadataCommand.cs +++ b/src/docfx/Models/MetadataCommand.cs @@ -69,7 +69,7 @@ private static Dictionary ResolveMSBuildProperties(MetadataComma if (index > -1) { // Latter one overwrites former one - properties[pair.Substring(0, index)] = pair.Substring(index + 1, pair.Length - index - 1); + properties[pair.Substring(0, index)] = pair.Substring(index + 1); } } } From a7ee9b676746b2ec94d229908367ae00aa2c6aeb Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 09:27:05 +0900 Subject: [PATCH 03/27] chore: suppress CA1816 messages --- src/Docfx.Build.Common/DisposableDocumentProcessor.cs | 9 +++++++++ src/Docfx.Build/DocumentBuilder.cs | 2 +- src/Docfx.Build/XRefMaps/XRefArchiveReader.cs | 2 +- src/Docfx.Common/Loggers/CompositeLogListener.cs | 2 +- .../ExternalReferences/ExternalReferencePackageWriter.cs | 2 +- src/Docfx.Plugins/DefaultFileAbstractLayer.cs | 2 +- test/.editorconfig | 2 ++ 7 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Docfx.Build.Common/DisposableDocumentProcessor.cs b/src/Docfx.Build.Common/DisposableDocumentProcessor.cs index 1b0047efee8..bee6f68db69 100644 --- a/src/Docfx.Build.Common/DisposableDocumentProcessor.cs +++ b/src/Docfx.Build.Common/DisposableDocumentProcessor.cs @@ -22,6 +22,15 @@ public abstract class DisposableDocumentProcessor : IDocumentProcessor, IDisposa public void Dispose() { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!disposing) + return; + if (BuildSteps != null) { foreach (var buildStep in BuildSteps) diff --git a/src/Docfx.Build/DocumentBuilder.cs b/src/Docfx.Build/DocumentBuilder.cs index 33e141fc275..ebb275cdf2d 100644 --- a/src/Docfx.Build/DocumentBuilder.cs +++ b/src/Docfx.Build/DocumentBuilder.cs @@ -12,7 +12,7 @@ namespace Docfx.Build.Engine; -public class DocumentBuilder : IDisposable +public sealed class DocumentBuilder : IDisposable { [ImportMany] internal IEnumerable Processors { get; set; } diff --git a/src/Docfx.Build/XRefMaps/XRefArchiveReader.cs b/src/Docfx.Build/XRefMaps/XRefArchiveReader.cs index bc9411e4779..d13a654b493 100644 --- a/src/Docfx.Build/XRefMaps/XRefArchiveReader.cs +++ b/src/Docfx.Build/XRefMaps/XRefArchiveReader.cs @@ -5,7 +5,7 @@ namespace Docfx.Build.Engine; -public class XRefArchiveReader : XRefRedirectionReader, IDisposable +public sealed class XRefArchiveReader : XRefRedirectionReader, IDisposable { #region Fields private readonly LruList> _lru; diff --git a/src/Docfx.Common/Loggers/CompositeLogListener.cs b/src/Docfx.Common/Loggers/CompositeLogListener.cs index d6ed964219c..afc21e0374e 100644 --- a/src/Docfx.Common/Loggers/CompositeLogListener.cs +++ b/src/Docfx.Common/Loggers/CompositeLogListener.cs @@ -3,7 +3,7 @@ namespace Docfx.Common; -public class CompositeLogListener : ILoggerListener +public sealed class CompositeLogListener : ILoggerListener { private readonly object _sync = new(); private readonly List _listeners = []; diff --git a/src/Docfx.DataContracts.Common/ExternalReferences/ExternalReferencePackageWriter.cs b/src/Docfx.DataContracts.Common/ExternalReferences/ExternalReferencePackageWriter.cs index e74f785437b..d065ea3ba2d 100644 --- a/src/Docfx.DataContracts.Common/ExternalReferences/ExternalReferencePackageWriter.cs +++ b/src/Docfx.DataContracts.Common/ExternalReferences/ExternalReferencePackageWriter.cs @@ -7,7 +7,7 @@ namespace Docfx.DataContracts.Common; -public class ExternalReferencePackageWriter : IDisposable +public sealed class ExternalReferencePackageWriter : IDisposable { private readonly ZipArchive _zip; diff --git a/src/Docfx.Plugins/DefaultFileAbstractLayer.cs b/src/Docfx.Plugins/DefaultFileAbstractLayer.cs index 204f3562b17..37212d65a1c 100644 --- a/src/Docfx.Plugins/DefaultFileAbstractLayer.cs +++ b/src/Docfx.Plugins/DefaultFileAbstractLayer.cs @@ -5,7 +5,7 @@ namespace Docfx.Plugins; -public class DefaultFileAbstractLayer : IFileAbstractLayer +public sealed class DefaultFileAbstractLayer : IFileAbstractLayer { public IEnumerable GetAllInputFiles() { diff --git a/test/.editorconfig b/test/.editorconfig index a04ced14a58..d3ec49a07b9 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -5,4 +5,6 @@ root = false csharp_style_unused_value_expression_statement_preference = discard_variable:silent # IDE0058: Remove unnecessary expression value csharp_style_unused_value_assignment_preference = discard_variable:silent # IDE0059: Remove unnecessary value assignment +dotnet_diagnostic.CA1816.severity = none # CA1816: Call GC.SuppressFinalize correctly + dotnet_diagnostic.SYSLIB1045.severity = silent # SYSLIB1045: Convert to 'GeneratedRegexAttribute'. From 1909ee3c2adbb0b8342d6c4fb08faabbd5fc6cbe Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 14:40:13 +0900 Subject: [PATCH 04/27] chore: suppress CA1822 messages --- src/Docfx.Build/TableOfContents/TocDocumentProcessor.cs | 6 +++--- src/Docfx.Build/XRefMaps/XRefMapDownloader.cs | 2 +- test/docfx.Snapshot.Tests/SamplesTest.cs | 2 +- .../docfx.Tests/SerializationTests/JsonSerializationTest.cs | 2 +- .../docfx.Tests/SerializationTests/YamlSerializationTest.cs | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Docfx.Build/TableOfContents/TocDocumentProcessor.cs b/src/Docfx.Build/TableOfContents/TocDocumentProcessor.cs index cc8d371c1d0..d9424acc1be 100644 --- a/src/Docfx.Build/TableOfContents/TocDocumentProcessor.cs +++ b/src/Docfx.Build/TableOfContents/TocDocumentProcessor.cs @@ -72,7 +72,7 @@ public override void UpdateHref(FileModel model, IDocumentBuildContext context) model.Content = toc; } - private void UpdateTocItemHref(TocItemViewModel toc, FileModel model, IDocumentBuildContext context, string includedFrom = null) + private static void UpdateTocItemHref(TocItemViewModel toc, FileModel model, IDocumentBuildContext context, string includedFrom = null) { if (toc.IsHrefUpdated) return; @@ -170,7 +170,7 @@ private static string ResolveHref(string pathToFile, string originalPathToFile, return fli.Href + segments; } - private void RegisterTocToContext(TocItemViewModel toc, FileModel model, IDocumentBuildContext context) + private static void RegisterTocToContext(TocItemViewModel toc, FileModel model, IDocumentBuildContext context) { var key = model.Key; @@ -180,7 +180,7 @@ private void RegisterTocToContext(TocItemViewModel toc, FileModel model, IDocume context.RegisterTocInfo(new() { TocFileKey = key, Order = toc.Order ?? 0 }); } - private void RegisterTocMapToContext(TocItemViewModel item, FileModel model, IDocumentBuildContext context) + private static void RegisterTocMapToContext(TocItemViewModel item, FileModel model, IDocumentBuildContext context) { var key = model.Key; // If tocHref is set, href is originally RelativeFolder type, and href is set to the homepage of TocHref, diff --git a/src/Docfx.Build/XRefMaps/XRefMapDownloader.cs b/src/Docfx.Build/XRefMaps/XRefMapDownloader.cs index 340df7e7729..a4ebdeb330f 100644 --- a/src/Docfx.Build/XRefMaps/XRefMapDownloader.cs +++ b/src/Docfx.Build/XRefMaps/XRefMapDownloader.cs @@ -80,7 +80,7 @@ private ValueTask ReadLocalFileWithFallback(Uri uri, Cancellatio /// /// Support scheme: http, https, file. /// - private async ValueTask DownloadBySchemeAsync(Uri uri, CancellationToken token = default) + private static async ValueTask DownloadBySchemeAsync(Uri uri, CancellationToken token = default) { IXRefContainer result; if (uri.IsFile) diff --git a/test/docfx.Snapshot.Tests/SamplesTest.cs b/test/docfx.Snapshot.Tests/SamplesTest.cs index da72625b456..2facfe666a7 100644 --- a/test/docfx.Snapshot.Tests/SamplesTest.cs +++ b/test/docfx.Snapshot.Tests/SamplesTest.cs @@ -211,7 +211,7 @@ private void ScrubFile(string path, StringBuilder builder) } } - private string ExtractText(Page page) + private static string ExtractText(Page page) { // Gets PDF text content var text = ContentOrderTextExtractor.GetText(page, new ContentOrderTextExtractor.Options { ReplaceWhitespaceWithSpace = true }); diff --git a/test/docfx.Tests/SerializationTests/JsonSerializationTest.cs b/test/docfx.Tests/SerializationTests/JsonSerializationTest.cs index efc3b471eaa..8acd8b9e54d 100644 --- a/test/docfx.Tests/SerializationTests/JsonSerializationTest.cs +++ b/test/docfx.Tests/SerializationTests/JsonSerializationTest.cs @@ -13,7 +13,7 @@ public partial class JsonSerializationTest /// /// Helper method to validate serialize/deserialize results. /// - protected void ValidateJsonRoundTrip(T model) + private static void ValidateJsonRoundTrip(T model) { // 1. Validate serialized result. var newtonsoftJson = NewtonsoftJsonUtility.Serialize(model); diff --git a/test/docfx.Tests/SerializationTests/YamlSerializationTest.cs b/test/docfx.Tests/SerializationTests/YamlSerializationTest.cs index badbc3ccc32..8ca63495949 100644 --- a/test/docfx.Tests/SerializationTests/YamlSerializationTest.cs +++ b/test/docfx.Tests/SerializationTests/YamlSerializationTest.cs @@ -15,7 +15,7 @@ public partial class YamlSerializationTest /// /// Helper method to validate serialize/deserialize results. /// - protected void ValidateYamlRoundTrip(T model) + private static void ValidateYamlRoundTrip(T model) { // Act using var writer = new StringWriter(); @@ -31,7 +31,7 @@ protected void ValidateYamlRoundTrip(T model) /// /// Helper method to validate serialize/deserialize results. /// - protected void ValidateYamlJsonRoundTrip(T model) + protected static void ValidateYamlJsonRoundTrip(T model) { // 1. Serialize to JSON with YamlDotNet using var writer = new StringWriter(); From b2f1cd38c4f87e15389b6627076a068d65d1ecfc Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 09:29:52 +0900 Subject: [PATCH 05/27] chore: suppress CA1827 messages --- .../MarkdigExtensionSettingConverter.NewtonsoftJson.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Docfx.MarkdigEngine.Extensions/MarkdigExtensionSettingConverter.NewtonsoftJson.cs b/src/Docfx.MarkdigEngine.Extensions/MarkdigExtensionSettingConverter.NewtonsoftJson.cs index 9434a18f1b5..07e9ee6a4f5 100644 --- a/src/Docfx.MarkdigEngine.Extensions/MarkdigExtensionSettingConverter.NewtonsoftJson.cs +++ b/src/Docfx.MarkdigEngine.Extensions/MarkdigExtensionSettingConverter.NewtonsoftJson.cs @@ -41,7 +41,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var name = prop.Name; var options = prop.Value; - if (options.Count() == 0) + if (!options.Any()) { return new MarkdigExtensionSetting(name); } From 347810eed114567518a368dcc1a2047aafd66b6b Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 09:48:14 +0900 Subject: [PATCH 06/27] chore: suppress CA1845 messages --- src/Docfx.Build.RestApi/RestApiDocumentProcessor.cs | 3 ++- .../QuoteSectionNote/QuoteSectionNoteRender.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Docfx.Build.RestApi/RestApiDocumentProcessor.cs b/src/Docfx.Build.RestApi/RestApiDocumentProcessor.cs index fe922ad87a2..72bc22a9968 100644 --- a/src/Docfx.Build.RestApi/RestApiDocumentProcessor.cs +++ b/src/Docfx.Build.RestApi/RestApiDocumentProcessor.cs @@ -248,7 +248,8 @@ private static void CheckOperationId(SwaggerModel swagger, string fileName) private static string ChangeFileExtension(string file) { - return file.Substring(0, file.Length - SupportedFileEndings.First(s => IsSupportedFileEnding(file, s)).Length) + ".json"; + var suffix = SupportedFileEndings.First(s => IsSupportedFileEnding(file, s)); + return $"{file.AsSpan(0, file.Length - suffix.Length)}.json"; } private static Dictionary MergeMetadata(IDictionary item, IDictionary overwriteItems) diff --git a/src/Docfx.MarkdigEngine.Extensions/QuoteSectionNote/QuoteSectionNoteRender.cs b/src/Docfx.MarkdigEngine.Extensions/QuoteSectionNote/QuoteSectionNoteRender.cs index da1ee519202..cde5de55df3 100644 --- a/src/Docfx.MarkdigEngine.Extensions/QuoteSectionNote/QuoteSectionNoteRender.cs +++ b/src/Docfx.MarkdigEngine.Extensions/QuoteSectionNote/QuoteSectionNoteRender.cs @@ -104,7 +104,7 @@ public static string FixUpLink(string link) { if (link.StartsWith("http:")) { - link = "https:" + link.Substring("http:".Length); + link = $"https:{link.AsSpan("http:".Length)}"; } if (Uri.TryCreate(link, UriKind.Absolute, out Uri videoLink)) { From 1adaa14aa4d77399903c17c411938a2d462e3404 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:30:11 +0900 Subject: [PATCH 07/27] chore: suppress CA1860 messages --- src/Docfx.Build/TemplateProcessors/TemplateManager.cs | 2 +- src/Docfx.Build/XRefMaps/XRefCollection.cs | 2 +- src/Docfx.MarkdigEngine.Extensions/CodeSnippet/CodeSnippet.cs | 2 +- src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Docfx.Build/TemplateProcessors/TemplateManager.cs b/src/Docfx.Build/TemplateProcessors/TemplateManager.cs index e1f1c3537c6..c6f8d9557e8 100644 --- a/src/Docfx.Build/TemplateProcessors/TemplateManager.cs +++ b/src/Docfx.Build/TemplateProcessors/TemplateManager.cs @@ -89,7 +89,7 @@ private bool TryExportResourceFiles(List resourceNames, string outputDir { ArgumentException.ThrowIfNullOrEmpty(outputDirectory); - if (!resourceNames.Any()) + if (resourceNames.Count == 0) return false; bool isEmpty = true; diff --git a/src/Docfx.Build/XRefMaps/XRefCollection.cs b/src/Docfx.Build/XRefMaps/XRefCollection.cs index b1c3eabf1df..6a5e10fc9d2 100644 --- a/src/Docfx.Build/XRefMaps/XRefCollection.cs +++ b/src/Docfx.Build/XRefMaps/XRefCollection.cs @@ -44,7 +44,7 @@ public async Task CreateAsync(CancellationToken cancellati AddToDownloadList(_uris, cancellationToken); var dict = new Dictionary(); - while (_processing.Any()) + while (_processing.Count != 0) { Task task = await Task.WhenAny(_processing.Keys) .WaitAsync(cancellationToken); diff --git a/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/CodeSnippet.cs b/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/CodeSnippet.cs index 0c9063a1ed8..d1397fec621 100644 --- a/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/CodeSnippet.cs +++ b/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/CodeSnippet.cs @@ -111,7 +111,7 @@ public string ToAttributeString() public string GetHighlightLinesString() { - if (HighlightRanges != null && HighlightRanges.Any()) + if (HighlightRanges != null && HighlightRanges.Count != 0) { return string.Join(',', HighlightRanges.Select(highlight => { diff --git a/src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs b/src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs index 1fe3f5e6c62..1d775204092 100644 --- a/src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs +++ b/src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs @@ -59,7 +59,7 @@ public static MarkdownPipelineBuilder UseOptionalExtensions( this MarkdownPipelineBuilder pipeline, MarkdigExtensionSetting[] optionalExtensions) { - if (!optionalExtensions.Any()) + if (optionalExtensions.Length == 0) { return pipeline; } From 9f78270916ae83ea96262b950a529cfe8147cf51 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:43:44 +0900 Subject: [PATCH 08/27] chore: suppress CA1861 messages --- test/.editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/test/.editorconfig b/test/.editorconfig index d3ec49a07b9..c6a31b12cc9 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -6,5 +6,6 @@ csharp_style_unused_value_expression_statement_preference = discard_variable:sil csharp_style_unused_value_assignment_preference = discard_variable:silent # IDE0059: Remove unnecessary value assignment dotnet_diagnostic.CA1816.severity = none # CA1816: Call GC.SuppressFinalize correctly +dotnet_diagnostic.CA1861.severity = none # CA1861: Avoid constant arrays as arguments dotnet_diagnostic.SYSLIB1045.severity = silent # SYSLIB1045: Convert to 'GeneratedRegexAttribute'. From d35552a9210277d77b7bbc5b88bee729cc46e426 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:45:21 +0900 Subject: [PATCH 09/27] chore: suppress CA1866 messages --- .../Processors/MarkdownInterpreter.cs | 2 +- src/Docfx.Common/Git/GitUtility.cs | 2 +- .../CodeSnippet/HtmlCodeSnippetRenderer.cs | 4 ++-- test/Docfx.Glob.Tests/GlobFileTest.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Docfx.Build.SchemaDriven/Processors/MarkdownInterpreter.cs b/src/Docfx.Build.SchemaDriven/Processors/MarkdownInterpreter.cs index 8e21df466ac..90213afea8c 100644 --- a/src/Docfx.Build.SchemaDriven/Processors/MarkdownInterpreter.cs +++ b/src/Docfx.Build.SchemaDriven/Processors/MarkdownInterpreter.cs @@ -37,7 +37,7 @@ private static string MarkupCore(string content, IProcessContext context, string context.Dependency.UnionWith(mr.Dependency); if (mr.Html.StartsWith(""), " jsonPath=\"" + path + "\""); + mr.Html = mr.Html.Insert(mr.Html.IndexOf('>'), " jsonPath=\"" + path + "\""); return mr.Html; } } diff --git a/src/Docfx.Common/Git/GitUtility.cs b/src/Docfx.Common/Git/GitUtility.cs index 1901dab8e2e..2a1ec1bc790 100644 --- a/src/Docfx.Common/Git/GitUtility.cs +++ b/src/Docfx.Common/Git/GitUtility.cs @@ -168,7 +168,7 @@ static string GitUrlToHttps(string url) foreach (var text in File.ReadAllLines(configPath)) { var line = text.Trim(); - if (line.StartsWith("[")) + if (line.StartsWith('[')) { var remote = RemoteRegex().Replace(line, "$1"); key = remote != line ? remote : ""; diff --git a/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs b/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs index fa6c849dbf9..b047d008377 100644 --- a/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs +++ b/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs @@ -155,14 +155,14 @@ static void BuildFileExtensionLanguageMap() { foreach (var (language, aliases) in s_languageAlias.Select(i => (i.Key, i.Value))) { - Debug.Assert(!language.StartsWith(".")); + Debug.Assert(!language.StartsWith('.')); s_languageByFileExtension.Add(language, language); s_languageByFileExtension.Add($".{language}", language); foreach (var alias in aliases) { - Debug.Assert(!alias.StartsWith(".")); + Debug.Assert(!alias.StartsWith('.')); s_languageByFileExtension.Add(alias, language); s_languageByFileExtension.Add($".{alias}", language); diff --git a/test/Docfx.Glob.Tests/GlobFileTest.cs b/test/Docfx.Glob.Tests/GlobFileTest.cs index da22b713f17..6ea1062ed69 100644 --- a/test/Docfx.Glob.Tests/GlobFileTest.cs +++ b/test/Docfx.Glob.Tests/GlobFileTest.cs @@ -87,7 +87,7 @@ private static void CreateFilesOrFolders(string cwd, params string[] items) foreach (var i in items) { var item = cwd + "/" + i; - if (item.EndsWith("/")) + if (item.EndsWith('/')) { Directory.CreateDirectory(item); } From df3aa24af693362d3fada7bd435a96f715c0e99b Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:49:08 +0900 Subject: [PATCH 10/27] chore: suppress CA1869 messages --- test/.editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/test/.editorconfig b/test/.editorconfig index c6a31b12cc9..aa113483a11 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -7,5 +7,6 @@ csharp_style_unused_value_assignment_preference = discard_variable:sil dotnet_diagnostic.CA1816.severity = none # CA1816: Call GC.SuppressFinalize correctly dotnet_diagnostic.CA1861.severity = none # CA1861: Avoid constant arrays as arguments +dotnet_diagnostic.CA1869.severity = none # CA1869: Cache and reuse 'JsonSerializerOptions' instances dotnet_diagnostic.SYSLIB1045.severity = silent # SYSLIB1045: Convert to 'GeneratedRegexAttribute'. From 404eea3b381a816e9bb1c44e66d4062eff533ce3 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:49:28 +0900 Subject: [PATCH 11/27] chore: suppress CA2016 messages --- src/Docfx.App/PdfBuilder.cs | 2 +- src/Docfx.Build/DocumentBuilder.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Docfx.App/PdfBuilder.cs b/src/Docfx.App/PdfBuilder.cs index b31e3704854..a88d0bc6ad8 100644 --- a/src/Docfx.App/PdfBuilder.cs +++ b/src/Docfx.App/PdfBuilder.cs @@ -221,7 +221,7 @@ Task PrintHeaderFooter(Outline toc, int pageNumber, int totalPages, Page async Task PrintHeaderFooterCore() { - await pageLimiter.WaitAsync(); + await pageLimiter.WaitAsync(cancellationToken); var page = pagePool.TryTake(out var pooled) ? pooled : await context.NewPageAsync(); try diff --git a/src/Docfx.Build/DocumentBuilder.cs b/src/Docfx.Build/DocumentBuilder.cs index ebb275cdf2d..055ac658b06 100644 --- a/src/Docfx.Build/DocumentBuilder.cs +++ b/src/Docfx.Build/DocumentBuilder.cs @@ -146,7 +146,7 @@ public void Build(IList parameters, string outputDirect .WriteToManifest(generatedManifest, parameters[0].OutputBaseDir) .Create(); - _postProcessorsManager.Process(generatedManifest, outputDirectory); + _postProcessorsManager.Process(generatedManifest, outputDirectory, cancellationToken); generatedManifest.Dereference(parameters[0].OutputBaseDir, parameters[0].MaxParallelism); From 27fcf146099e7274c8d176943977caf7401ec666 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 11:32:29 +0900 Subject: [PATCH 12/27] chore: suppress CA2211 messages --- .../CodeTest.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/CodeTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/CodeTest.cs index 35b563d1c86..b306433a019 100644 --- a/test/Docfx.MarkdigEngine.Extensions.Tests/CodeTest.cs +++ b/test/Docfx.MarkdigEngine.Extensions.Tests/CodeTest.cs @@ -7,7 +7,7 @@ namespace Docfx.MarkdigEngine.Tests; public class CodeTest { - public static string contentCSharp = @"using System; + private static readonly string contentCSharp = @"using System; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -216,7 +216,7 @@ void TableCellConst() } } }"; - public static string contentCSharp2 = @"using System; + private static readonly string contentCSharp2 = @"using System; using System.Collections.Generic; using System.IO; using System.Threading; @@ -376,7 +376,7 @@ private static CosmosClient BuildCosmosClient(IConfiguration configuration) } } }"; - public static string contentCSharpRegion = @"using Microsoft.AspNetCore.Builder; + private static readonly string contentCSharpRegion = @"using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -446,7 +446,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) } } }"; - public static string contentASPNet = @"@{ + private static readonly string contentASPNet = @"@{ ViewData[""Title""] = ""Anchor Tag Helper""; } @@ -650,7 +650,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) "; - public static string contentVB = @"' + private static readonly string contentVB = @"' Class ADSetupInformation Shared Sub Main() @@ -709,7 +709,7 @@ End Sub End Class ' "; - public static string contentCPP = @"// + private static readonly string contentCPP = @"// using namespace System; int main() @@ -771,7 +771,7 @@ int main() AppDomain4::Main(); } // "; - public static string contentCPP2 = @"// + private static readonly string contentCPP2 = @"// using namespace System; using namespace System::Collections::Generic; @@ -947,7 +947,7 @@ int main() Key ""doc"" is not found. */ //"; - public static string contentCrazy = @"// + private static readonly string contentCrazy = @"// using namespace System; int main() @@ -1009,7 +1009,7 @@ int main() AppDomain4::Main(); } // "; - public static string contentSQL = @"-- + private static readonly string contentSQL = @"-- -- SELECT * FROM Students WHERE Grade = 12 @@ -1022,7 +1022,7 @@ int main() AND Class = 'Math' -- --"; - public static string contentPython = @"# + private static readonly string contentPython = @"# # from flask import Flask app = Flask(__name__) @@ -1035,21 +1035,21 @@ def hello(): # # "; - public static string contentBatch = @"REM + private static readonly string contentBatch = @"REM :Label1 :Label2 :: Comment line 3 REM :: Comment line 4 IF EXIST C:\AUTOEXEC.BAT REM AUTOEXEC.BAT exists"; - public static string contentErlang = @"-module(hello_world). + private static readonly string contentErlang = @"-module(hello_world). -compile(export_all). % hello() -> io:format(""hello world~n""). % "; - public static string contentLisp = @"; + private static readonly string contentLisp = @"; USER(64): (member 'b '(perhaps today is a good day to die)) ; test fails NIL ; @@ -1057,7 +1057,7 @@ def hello(): '(a good day to die) ; ;"; - public static string contentRuby = @"source 'https://rubygems.org' + private static readonly string contentRuby = @"source 'https://rubygems.org' git_source(:github) { |repo| ""https://github.com/#{repo}.git"" } ruby '2.6.5' @@ -1119,7 +1119,7 @@ def hello(): gem 'activerecord-session_store', '~> 1.1' # "; - public static string contentCSS = @"body { + private static readonly string contentCSS = @"body { padding-top: 70px; } From 110324905c177659fd5eb8a9eae501af781d428e Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 14:50:43 +0900 Subject: [PATCH 13/27] chore: suppress CA2263 messages --- src/Docfx.YamlSerialization/YamlDeserializer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Docfx.YamlSerialization/YamlDeserializer.cs b/src/Docfx.YamlSerialization/YamlDeserializer.cs index 71d6fe8f571..9080bea8fe5 100644 --- a/src/Docfx.YamlSerialization/YamlDeserializer.cs +++ b/src/Docfx.YamlSerialization/YamlDeserializer.cs @@ -146,7 +146,7 @@ public void RegisterTypeConverter(IYamlTypeConverter typeConverter) public object? Deserialize(TextReader input, IValueDeserializer? deserializer = null) { - return Deserialize(input, typeof(object), deserializer); + return Deserialize(input, deserializer); } public object? Deserialize(TextReader input, Type type, IValueDeserializer? deserializer = null) @@ -161,7 +161,7 @@ public void RegisterTypeConverter(IYamlTypeConverter typeConverter) public object? Deserialize(IParser reader, IValueDeserializer? deserializer = null) { - return Deserialize(reader, typeof(object), deserializer); + return Deserialize(reader, deserializer); } /// From 019ec9c706817266184fea47d9865d6a481b8d88 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 14:16:53 +0900 Subject: [PATCH 14/27] chore: suppress IDE0004 messages --- .../MarkdigExtensionSettingConverter.SystemTextJson.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Docfx.MarkdigEngine.Extensions/MarkdigExtensionSettingConverter.SystemTextJson.cs b/src/Docfx.MarkdigEngine.Extensions/MarkdigExtensionSettingConverter.SystemTextJson.cs index 93f7a1cf69d..7444c6900ff 100644 --- a/src/Docfx.MarkdigEngine.Extensions/MarkdigExtensionSettingConverter.SystemTextJson.cs +++ b/src/Docfx.MarkdigEngine.Extensions/MarkdigExtensionSettingConverter.SystemTextJson.cs @@ -53,7 +53,7 @@ public override void Write(Utf8JsonWriter writer, MarkdigExtensionSetting value, if (value == null) return; - var model = (MarkdigExtensionSetting)value; + var model = value; if (model.Options == null || !model.Options.HasValue) { From 6edf9ad5d85a3da0f37d54386a2668e85525a31f Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 12:10:21 +0900 Subject: [PATCH 15/27] chore: suppress IDE0019 messages --- src/Docfx.Build.SchemaDriven/SchemaDrivenDocumentProcessor.cs | 3 +-- src/Docfx.Build/Conceptual/ConceptualDocumentProcessor.cs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Docfx.Build.SchemaDriven/SchemaDrivenDocumentProcessor.cs b/src/Docfx.Build.SchemaDriven/SchemaDrivenDocumentProcessor.cs index b6fb209ee32..545e0d3e837 100644 --- a/src/Docfx.Build.SchemaDriven/SchemaDrivenDocumentProcessor.cs +++ b/src/Docfx.Build.SchemaDriven/SchemaDrivenDocumentProcessor.cs @@ -185,8 +185,7 @@ public override SaveResult Save(FileModel model) if (((IDictionary)model.Properties).TryGetValue("XrefSpec", out var value)) { - var xrefSpec = value as XRefSpec; - if (xrefSpec != null) + if (value is XRefSpec xrefSpec) { result.XRefSpecs = [xrefSpec]; } diff --git a/src/Docfx.Build/Conceptual/ConceptualDocumentProcessor.cs b/src/Docfx.Build/Conceptual/ConceptualDocumentProcessor.cs index acc43035a68..14cd89c49e8 100644 --- a/src/Docfx.Build/Conceptual/ConceptualDocumentProcessor.cs +++ b/src/Docfx.Build/Conceptual/ConceptualDocumentProcessor.cs @@ -107,8 +107,7 @@ public override SaveResult Save(FileModel model) if (((IDictionary)model.Properties).TryGetValue("XrefSpec", out var value)) { - var xrefSpec = value as XRefSpec; - if (xrefSpec != null) + if (value is XRefSpec xrefSpec) { result.XRefSpecs = [xrefSpec]; } From 9483e742c9d99642fe63b65ea779b4816fd20c25 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 15:05:04 +0900 Subject: [PATCH 16/27] chore: suppress IDE0044 messages --- .../MarkdownFragmentsValidationTest.cs | 2 +- test/Docfx.Tests.Common/TestListenerScope.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Docfx.Build.SchemaDriven.Tests/MarkdownFragmentsValidationTest.cs b/test/Docfx.Build.SchemaDriven.Tests/MarkdownFragmentsValidationTest.cs index 1c1497e016b..814cdd70777 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/MarkdownFragmentsValidationTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/MarkdownFragmentsValidationTest.cs @@ -21,7 +21,7 @@ public class MarkdownFragmentsValidationTest : TestBase private TemplateManager _templateManager; private FileCollection _files; - private TestLoggerListener _listener = new(); + private readonly TestLoggerListener _listener = new(); private string _rawModelFilePath; private const string RawModelFileExtension = ".raw.json"; diff --git a/test/Docfx.Tests.Common/TestListenerScope.cs b/test/Docfx.Tests.Common/TestListenerScope.cs index 13c43b8bc32..e5be72d50e2 100644 --- a/test/Docfx.Tests.Common/TestListenerScope.cs +++ b/test/Docfx.Tests.Common/TestListenerScope.cs @@ -7,7 +7,7 @@ namespace Docfx.Tests.Common; public class TestListenerScope : ILoggerListener, IDisposable { - private static AsyncLocal> s_items = new(); + private readonly static AsyncLocal> s_items = new(); private readonly LogLevel _logLevel; public List Items => s_items.Value; From e97adfee67bf1983d47d48f096a36d32eb8dbe30 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 15:20:49 +0900 Subject: [PATCH 17/27] chore: suppress IDE0051 messages --- .../Processors/MergeTypeInterpreter.cs | 5 ----- .../MonikerRange/MonikerRangeParser.cs | 2 +- .../MergeMarkdownFragmentsTest.cs | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Docfx.Build.SchemaDriven/Processors/MergeTypeInterpreter.cs b/src/Docfx.Build.SchemaDriven/Processors/MergeTypeInterpreter.cs index 8abff012fa9..f9a55570624 100644 --- a/src/Docfx.Build.SchemaDriven/Processors/MergeTypeInterpreter.cs +++ b/src/Docfx.Build.SchemaDriven/Processors/MergeTypeInterpreter.cs @@ -17,9 +17,4 @@ public object Interpret(BaseSchema schema, object value, IProcessContext context // TODO implement return value; } - - private static object MergeCore(object value, IProcessContext context) - { - return value; - } } diff --git a/src/Docfx.MarkdigEngine.Extensions/MonikerRange/MonikerRangeParser.cs b/src/Docfx.MarkdigEngine.Extensions/MonikerRange/MonikerRangeParser.cs index ec73184fe3a..71bbc507a5c 100644 --- a/src/Docfx.MarkdigEngine.Extensions/MonikerRange/MonikerRangeParser.cs +++ b/src/Docfx.MarkdigEngine.Extensions/MonikerRange/MonikerRangeParser.cs @@ -10,7 +10,7 @@ namespace Docfx.MarkdigEngine.Extensions; public class MonikerRangeParser : BlockParser { - private const string StartString = "moniker"; + // private const string StartString = "moniker"; private const string EndString = "moniker-end"; private const char Colon = ':'; diff --git a/test/Docfx.Build.SchemaDriven.Tests/MergeMarkdownFragmentsTest.cs b/test/Docfx.Build.SchemaDriven.Tests/MergeMarkdownFragmentsTest.cs index 97158492044..15909a250f9 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/MergeMarkdownFragmentsTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/MergeMarkdownFragmentsTest.cs @@ -44,7 +44,7 @@ public MergeMarkdownFragmentsTest() } [Fact] - void TestMergeMarkdownFragments() + public void TestMergeMarkdownFragments() { // Arrange CreateFile("Suppressions.yml.md", File.ReadAllText("TestData/inputs/Suppressions.yml.md"), _inputFolder); From e519ccd3bc3da9fd1d7697b25e9c9f469262155e Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Mon, 3 Mar 2025 15:21:29 +0900 Subject: [PATCH 18/27] chore: suppress IDE0052 messages --- src/Docfx.Build/XRefMaps/XRefArchive.cs | 1 - .../PostProcessors/SitemapGeneratorTests.cs | 8 -------- test/docfx.Tests/JsonSchemaTest.cs | 8 -------- 3 files changed, 17 deletions(-) diff --git a/src/Docfx.Build/XRefMaps/XRefArchive.cs b/src/Docfx.Build/XRefMaps/XRefArchive.cs index b63ad979c3c..5ced03b9db9 100644 --- a/src/Docfx.Build/XRefMaps/XRefArchive.cs +++ b/src/Docfx.Build/XRefMaps/XRefArchive.cs @@ -13,7 +13,6 @@ public sealed class XRefArchive : IXRefContainer, IDisposable #region Consts / Fields public const string MajorFileName = "xrefmap.yml"; - private readonly object _syncRoot = new(); private readonly XRefArchiveMode _mode; private readonly ZipArchive _archive; private readonly List _entries; diff --git a/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs b/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs index 4e8658a653b..5ae0583481f 100644 --- a/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs +++ b/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs @@ -5,7 +5,6 @@ using Docfx.Plugins; using Docfx.Tests.Common; using Xunit; -using Xunit.Abstractions; using DocumentType = Docfx.DataContracts.Common.Constants.DocumentType; namespace Docfx.Build.Engine.Tests; @@ -13,13 +12,6 @@ namespace Docfx.Build.Engine.Tests; [Collection("docfx STA")] public class SitemapGeneratorTests : TestBase { - private readonly ITestOutputHelper _output; - - public SitemapGeneratorTests(ITestOutputHelper output) - { - _output = output; - } - public override void Dispose() { base.Dispose(); diff --git a/test/docfx.Tests/JsonSchemaTest.cs b/test/docfx.Tests/JsonSchemaTest.cs index fc4e24847a5..43bec4c851f 100644 --- a/test/docfx.Tests/JsonSchemaTest.cs +++ b/test/docfx.Tests/JsonSchemaTest.cs @@ -6,7 +6,6 @@ using Docfx.DataContracts.Common; using Docfx.Tests.Common; using FluentAssertions; -using Xunit.Abstractions; using YamlDotNet.Serialization; namespace Docfx.Tests; @@ -14,13 +13,6 @@ namespace Docfx.Tests; [Collection("docfx STA")] public class JsonSchemaTest : TestBase { - private readonly ITestOutputHelper output; - - public JsonSchemaTest(ITestOutputHelper output) - { - this.output = output; - } - [Theory] [InlineData("docs/docfx.json")] [InlineData("samples/csharp/docfx.json")] From 7f3efd859df661da027d0543f1ceac66b2f92e20 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Tue, 4 Mar 2025 14:56:33 +0900 Subject: [PATCH 19/27] chore: suppress IDE0058 messages --- .editorconfig | 1 + .../CodeSnippet/HtmlCodeSnippetRenderer.cs | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/.editorconfig b/.editorconfig index 711ffa681ab..3c6e7e29ea6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -158,6 +158,7 @@ dotnet_diagnostic.IDE0005.severity = warning # IDE0005: Remove unnecessary im dotnet_diagnostic.IDE0035.severity = suggestion # IDE0035: Remove unreachable code dotnet_diagnostic.IDE0051.severity = suggestion # IDE0051: Remove unused private member dotnet_diagnostic.IDE0052.severity = suggestion # IDE0052: Remove unread private member +dotnet_diagnostic.IDE0058.severity = silent # IDE0058: Remove unnecessary expression value dotnet_diagnostic.IDE0080.severity = suggestion # IDE0080: Remove unnecessary suppression operator dotnet_diagnostic.IDE0100.severity = suggestion # IDE0100: Remove unnecessary equality operator dotnet_diagnostic.IDE0110.severity = suggestion # IDE0110: Remove unnecessary discard diff --git a/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs b/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs index b047d008377..dee29927b80 100644 --- a/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs +++ b/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs @@ -418,20 +418,6 @@ private static string CountAndReplaceIndentSpaces(string line, out int count) return sb.ToString(); } - private static bool IsLineInRange(int lineNumber, List allCodeRanges) - { - if (allCodeRanges.Count == 0) return true; - - for (int rangeNumber = 0; rangeNumber < allCodeRanges.Count; rangeNumber++) - { - var range = allCodeRanges[rangeNumber]; - if (lineNumber >= range.Start && lineNumber <= range.End) - return true; - } - - return false; - } - private string GetWarning() { var warningTitle = _context.GetToken(WarningTitleId) ?? DefaultWarningTitle; From 8e2a79702bcc4b431accf947e30584bf95ea192f Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 09:19:49 +0900 Subject: [PATCH 20/27] chore: suppress IDE0130 messages --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 3c6e7e29ea6..f9d4bba31a7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -162,6 +162,7 @@ dotnet_diagnostic.IDE0058.severity = silent # IDE0058: Remove unnecessary ex dotnet_diagnostic.IDE0080.severity = suggestion # IDE0080: Remove unnecessary suppression operator dotnet_diagnostic.IDE0100.severity = suggestion # IDE0100: Remove unnecessary equality operator dotnet_diagnostic.IDE0110.severity = suggestion # IDE0110: Remove unnecessary discard +dotnet_diagnostic.IDE0130.severity = silent # IDE0130: Namespace does not match folder structure dotnet_diagnostic.IDE0240.severity = suggestion # IDE0240: Nullable directive is redundant dotnet_diagnostic.IDE0241.severity = suggestion # IDE0241: Nullable directive is unnecessary From be80196adba5550db08f8010bf73ea9262a661fd Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 09:45:22 +0900 Subject: [PATCH 21/27] chore: suppress IDE0530 messages --- src/Docfx.Common/YamlDeserializerWithFallback.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Docfx.Common/YamlDeserializerWithFallback.cs b/src/Docfx.Common/YamlDeserializerWithFallback.cs index ac34aaeab9b..7573e0e6454 100644 --- a/src/Docfx.Common/YamlDeserializerWithFallback.cs +++ b/src/Docfx.Common/YamlDeserializerWithFallback.cs @@ -19,9 +19,8 @@ private YamlDeserializerWithFallback( } public static YamlDeserializerWithFallback Create() => - new( - (Func tr) => YamlUtility.Deserialize(tr()), - (string path) => YamlUtility.Deserialize(path)); + new(tr => YamlUtility.Deserialize(tr()), + path => YamlUtility.Deserialize(path)); public YamlDeserializerWithFallback WithFallback() => new( From 72292ac648ecbbdb6cde54a9c25b59af379e3a8b Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 09:48:26 +0900 Subject: [PATCH 22/27] chore: suppress SYSLIB1045 messages --- src/Docfx.Build/PostProcessors/ExtractSearchIndex.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Docfx.Build/PostProcessors/ExtractSearchIndex.cs b/src/Docfx.Build/PostProcessors/ExtractSearchIndex.cs index ff8a7f9470d..4b966b2cf38 100644 --- a/src/Docfx.Build/PostProcessors/ExtractSearchIndex.cs +++ b/src/Docfx.Build/PostProcessors/ExtractSearchIndex.cs @@ -18,7 +18,9 @@ partial class ExtractSearchIndex : IPostProcessor [GeneratedRegex(@"\s+")] private static partial Regex s_regexWhiteSpace(); - private static readonly Regex s_regexCase = new(@"[a-z0-9]+|[A-Z0-9]+[a-z0-9]*|[0-9]+", RegexOptions.Compiled); + + [GeneratedRegex(@"[a-z0-9]+|[A-Z0-9]+[a-z0-9]*|[0-9]+")] + private static partial Regex s_regexCase(); private static readonly HashSet s_htmlInlineTags = new(StringComparer.OrdinalIgnoreCase) { @@ -185,7 +187,7 @@ private static string[] GetStems(string str) return [string.Empty]; } str = WebUtility.HtmlDecode(str); - return s_regexCase.Matches(str).Select(m => m.Value).ToArray(); + return s_regexCase().Matches(str).Select(m => m.Value).ToArray(); } private static List GetStemAggregations(string str) From 201160ce080af834227350a926e145744f017b9c Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 10:09:50 +0900 Subject: [PATCH 23/27] chore: suppress xUnit2022 messages --- test/Docfx.Build.Tests/DocumentBuilderTest.cs | 2 +- test/docfx.Tests/DocsetBuildTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Docfx.Build.Tests/DocumentBuilderTest.cs b/test/Docfx.Build.Tests/DocumentBuilderTest.cs index 69ec1562538..98a7478e338 100644 --- a/test/Docfx.Build.Tests/DocumentBuilderTest.cs +++ b/test/Docfx.Build.Tests/DocumentBuilderTest.cs @@ -273,7 +273,7 @@ public void TestBuild() Assert.True(File.Exists(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension))); var meta = JsonUtility.Deserialize>(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension)); Assert.Single(meta); - Assert.True(!meta.ContainsKey("meta")); + Assert.False(meta.ContainsKey("meta")); } { diff --git a/test/docfx.Tests/DocsetBuildTest.cs b/test/docfx.Tests/DocsetBuildTest.cs index b49110d0ac8..b07ec876457 100644 --- a/test/docfx.Tests/DocsetBuildTest.cs +++ b/test/docfx.Tests/DocsetBuildTest.cs @@ -229,7 +229,7 @@ public static async Task Build_With_RedirectUri_Files() // Test redirect page.is excluded from sitemap. var sitemapXml = outputs["sitemap.xml"](); var urls = XDocument.Parse(sitemapXml).Root.Elements(); - Assert.True(!urls.Any()); + Assert.False(urls.Any()); } [Fact] From 4d0df7c4c41e7a23ad33d235e099e2f5330684d2 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 10:14:19 +0900 Subject: [PATCH 24/27] chore: suppress xUnit2024 messages --- test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs | 2 +- test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs b/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs index 630ff1c7c5e..c7a5f1eeae3 100644 --- a/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs +++ b/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs @@ -384,7 +384,7 @@ Some content // Test `manifest.json` content var manifest = GetOutputManifest(); - Assert.True(manifest.Files.Count == 1); + Assert.Single(manifest.Files); Assert.True(manifest.Files[0].Type == Constants.DocumentType.Redirection); } diff --git a/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs b/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs index 5ae0583481f..68860158bfb 100644 --- a/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs +++ b/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs @@ -59,7 +59,7 @@ public void TestSitemapGenerator() var sitemap = XDocument.Load(sitemapPath); var ns = sitemap.Root.Name.Namespace; var urls = sitemap.Root.Elements(ns + "url").ToArray(); - Assert.True(urls.Length == 4); + Assert.Equal(4, urls.Length); // URLs are ordered based on HTML output's RelativePath. Assert.EndsWith("/Conceptual.html", urls[0].Element(ns + "loc").Value); From 554a387f5229c8b57ec7cb8c7e65d91debb02ff0 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 10:18:25 +0900 Subject: [PATCH 25/27] chore: suppress IDE0303 messages --- .../FileMetadataHelperTest.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/Docfx.Build.Tests/FileMetadataHelperTest.cs b/test/Docfx.Build.Tests/FileMetadataHelperTest.cs index 2768b57ea0a..72d6703db72 100644 --- a/test/Docfx.Build.Tests/FileMetadataHelperTest.cs +++ b/test/Docfx.Build.Tests/FileMetadataHelperTest.cs @@ -15,26 +15,26 @@ public void TestGetChangedGlobs_AllTheSame() var baseDir = "inputFolder"; var left = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = [ new FileMetadataItem(new GlobMatcher("*.md"), "meta", 1L), new FileMetadataItem(new GlobMatcher("*.m"), "meta", true), new FileMetadataItem(new GlobMatcher("abc"), "meta", "string"), new FileMetadataItem(new GlobMatcher("/[]\\*.cs"), "meta", new Dictionary { ["key"] = "2" }), new FileMetadataItem(new GlobMatcher("*/*.cs"), "meta", new object[] { "1", "2" }), new FileMetadataItem(new GlobMatcher("**"), "meta", new Dictionary { ["key"] = new object[] { "1", "2" } }) - ) + ] }); var right = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = [ new FileMetadataItem(new GlobMatcher("*.md"), "meta", 1L), new FileMetadataItem(new GlobMatcher("*.m"), "meta", true), new FileMetadataItem(new GlobMatcher("abc"), "meta", "string"), new FileMetadataItem(new GlobMatcher("/[]\\*.cs"), "meta", new Dictionary { ["key"] = "2" }), new FileMetadataItem(new GlobMatcher("*/*.cs"), "meta", new object[] { "1", "2" }), new FileMetadataItem(new GlobMatcher("**"), "meta", new Dictionary { ["key"] = new object[] { "1", "2" } }) - ) + ] }); var actual = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); @@ -48,26 +48,26 @@ public void TestGetChangedGlobs_AllChanged_With_DifferentBaseDir() var patterns = new string[] { "*md", "*.m", "abc", "/[]\\*.cs", "*/*.cs", "**" }; var left = new FileMetadata("inputFolder1", new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true), new FileMetadataItem(new GlobMatcher(patterns[2]), "meta", "string"), new FileMetadataItem(new GlobMatcher(patterns[3]), "meta", new Dictionary { ["key"] = "2" }), new FileMetadataItem(new GlobMatcher(patterns[4]), "meta", new object[] { "1", "2" }), new FileMetadataItem(new GlobMatcher(patterns[5]), "meta", new Dictionary { ["key"] = new object[] { "1", "2" } }) - ) + ] }); var right = new FileMetadata("inputFolder2", new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true), new FileMetadataItem(new GlobMatcher(patterns[2]), "meta", "string"), new FileMetadataItem(new GlobMatcher(patterns[3]), "meta", new Dictionary { ["key"] = "2" }), new FileMetadataItem(new GlobMatcher(patterns[4]), "meta", new object[] { "1", "2" }), new FileMetadataItem(new GlobMatcher(patterns[5]), "meta", new Dictionary { ["key"] = new object[] { "1", "2" } }) - ) + ] }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); @@ -83,26 +83,26 @@ public void TestGetChangedGlobs_AllChanged_With_DifferentPattern() var patternsB = new string[] { "*mdB", "*.mB", "abcB", "/[]\\*.csB", "*/*.csB", "**B" }; var left = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = [ new FileMetadataItem(new GlobMatcher(patternsA[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patternsA[1]), "meta", true), new FileMetadataItem(new GlobMatcher(patternsA[2]), "meta", "string"), new FileMetadataItem(new GlobMatcher(patternsA[3]), "meta", new Dictionary { ["key"] = "2" }), new FileMetadataItem(new GlobMatcher(patternsA[4]), "meta", new object[] { "1", "2" }), new FileMetadataItem(new GlobMatcher(patternsA[5]), "meta", new Dictionary { ["key"] = new object[] { "1", "2" } }) - ) + ] }); var right = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = [ new FileMetadataItem(new GlobMatcher(patternsB[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patternsB[1]), "meta", true), new FileMetadataItem(new GlobMatcher(patternsB[2]), "meta", "string"), new FileMetadataItem(new GlobMatcher(patternsB[3]), "meta", new Dictionary { ["key"] = "2" }), new FileMetadataItem(new GlobMatcher(patternsB[4]), "meta", new object[] { "1", "2" }), new FileMetadataItem(new GlobMatcher(patternsB[5]), "meta", new Dictionary { ["key"] = new object[] { "1", "2" } }) - ) + ] }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); @@ -230,13 +230,13 @@ public void TestGetChangedGlobs_Changed() var right = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true), new FileMetadataItem(new GlobMatcher(patterns[2]), "meta", "string"), new FileMetadataItem(new GlobMatcher(patterns[3]), "meta", new Dictionary { ["key"] = "2" }), new FileMetadataItem(new GlobMatcher(patterns[4]), "meta", new object[] { "1", "2" }) - ) + ] }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); From c331117552a38ddde534d45eead2ddd8ae32fadb Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 10:20:30 +0900 Subject: [PATCH 26/27] chore: suppress IDE0036 messages --- test/Docfx.Tests.Common/TestListenerScope.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Docfx.Tests.Common/TestListenerScope.cs b/test/Docfx.Tests.Common/TestListenerScope.cs index e5be72d50e2..7b955459c19 100644 --- a/test/Docfx.Tests.Common/TestListenerScope.cs +++ b/test/Docfx.Tests.Common/TestListenerScope.cs @@ -7,7 +7,7 @@ namespace Docfx.Tests.Common; public class TestListenerScope : ILoggerListener, IDisposable { - private readonly static AsyncLocal> s_items = new(); + private static readonly AsyncLocal> s_items = new(); private readonly LogLevel _logLevel; public List Items => s_items.Value; From a3920b80c709d1532e05a6ae83d21044190dbcac Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 8 Mar 2025 14:33:10 +0900 Subject: [PATCH 27/27] chore: suppress xUnit1033 messages --- test/Docfx.Tests.Common/TestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Docfx.Tests.Common/TestBase.cs b/test/Docfx.Tests.Common/TestBase.cs index b778e191d4f..750958e7297 100644 --- a/test/Docfx.Tests.Common/TestBase.cs +++ b/test/Docfx.Tests.Common/TestBase.cs @@ -6,7 +6,7 @@ namespace Docfx.Tests.Common; -public class TestBase : IClassFixture, IDisposable +public class TestBase : IDisposable { private readonly List _folderCollection = []; private readonly object _locker = new();