From 1466228d3d39fb282ba26c7c9de74d8f4eb62563 Mon Sep 17 00:00:00 2001
From: filzrev <103790468+filzrev@users.noreply.github.com>
Date: Sat, 14 Dec 2024 22:33:17 +0900
Subject: [PATCH] chore: apply code formatter for IDE0028, and IDE0300-IDE0304
---
.editorconfig | 3 +-
src/Docfx.App/Config/BuildJsonConfig.cs | 6 +-
src/Docfx.App/Config/FileMetadataPairs.cs | 2 +-
src/Docfx.App/Config/GroupConfig.cs | 2 +-
.../Helpers/DocumentBuilderWrapper.cs | 4 +-
src/Docfx.App/Helpers/MetadataMerger.cs | 4 +-
src/Docfx.App/PdfBuilder.cs | 2 +-
src/Docfx.App/RunBuild.cs | 2 +-
src/Docfx.App/RunMerge.cs | 2 +-
src/Docfx.Build.Common/MarkdownReader.cs | 2 +-
.../HandleModelAttributesContext.cs | 10 +-
.../Handlers/UrlContentHandler.cs | 2 +-
.../Reference/OverwriteDocumentModel.cs | 10 +-
.../ApplyPlatformVersion.cs | 2 +-
.../BuildOutputs/ApiBuildOutput.cs | 2 +-
.../BuildOutputs/ApiReferenceBuildOutput.cs | 2 +-
.../FillReferenceInformation.cs | 2 +-
.../MergeManagedReferenceDocument.cs | 2 +-
.../SplitClassPageToMemberLevel.cs | 12 +-
.../SplitRestApiToOperationLevel.cs | 10 +-
.../MarkdownFragmentsCreator.cs | 2 +-
.../OverwriteDocumentModelCreator.cs | 4 +-
.../OverwriteUtility.cs | 2 +-
.../Rules/YamlCodeBlockRule.cs | 2 +-
.../BuildRestApiDocument.cs | 2 +-
src/Docfx.Build.RestApi/Swagger/InfoObject.cs | 2 +-
.../Swagger/Internals/SwaggerArray.cs | 2 +-
.../Swagger/Internals/SwaggerObject.cs | 2 +-
.../Swagger/OperationObject.cs | 2 +-
.../Swagger/ParameterObject.cs | 2 +-
.../Swagger/PathItemObject.cs | 2 +-
.../Swagger/ResponseObject.cs | 2 +-
.../Swagger/SwaggerModel.cs | 2 +-
.../Swagger/TagItemObject.cs | 2 +-
.../SwaggerModelConverter.cs | 4 +-
.../Models/DocumentSchema.cs | 2 +-
.../Models/JsonPointer.cs | 4 +-
.../Processors/Helper.cs | 4 +-
.../Processors/ProcessContext.cs | 14 +-
.../Processors/XrefInterpreter.cs | 2 +-
.../Processors/XrefPropertiesInterpreter.cs | 2 +-
.../ValidateFragmentsHandler.cs | 2 +-
.../SplitRestApiToTagLevel.cs | 6 +-
.../BuildOutputs/ApiBuildOutput.cs | 2 +-
.../ApiExceptionInfoBuildOutput.cs | 2 +-
.../ApiInheritanceTreeBuildOutput.cs | 2 +-
.../BuildOutputs/ApiNames.cs | 2 +-
.../BuildOutputs/ApiParameterBuildOutput.cs | 2 +-
.../BuildOutputs/ApiSyntaxBuildOutput.cs | 2 +-
.../ModelConverter.cs | 6 +-
src/Docfx.Build/CompilePhaseHandler.cs | 2 +-
src/Docfx.Build/DocumentBuildContext.cs | 4 +-
src/Docfx.Build/DocumentBuilder.cs | 2 +-
src/Docfx.Build/FileCollection.cs | 2 +-
src/Docfx.Build/HostService.cs | 4 +-
src/Docfx.Build/LinkPhaseHandler.cs | 2 +-
src/Docfx.Build/ManifestProcessor.cs | 2 +-
src/Docfx.Build/MarkupResultUtility.cs | 2 +-
.../PostProcessors/HtmlPostProcessor.cs | 2 +-
.../PostProcessors/ValidateBookmark.cs | 2 +-
.../LocalFileResourceReader.cs | 2 +-
src/Docfx.Build/SingleDocumentBuilder.cs | 12 +-
.../TableOfContents/BuildTocDocument.cs | 2 +-
.../TableOfContents/MarkdownTocReader.cs | 4 +-
.../TableOfContents/TocResolver.cs | 2 +-
.../TableOfContents/TocRestructureUtility.cs | 6 +-
.../TemplateModelTransformer.cs | 4 +-
src/Docfx.Build/XRefMaps/XRefArchive.cs | 4 +-
src/Docfx.Build/XRefMaps/XRefCollection.cs | 4 +-
src/Docfx.Build/XRefMaps/XRefMap.cs | 2 +-
src/Docfx.Common/CompositeDictionary.cs | 2 +-
.../FileAbstractLayer/EmptyFileReader.cs | 2 +-
src/Docfx.Common/FileMapping.cs | 2 +-
.../NewtonsoftJson/ConvertToObjectHelper.cs | 4 +-
.../Loggers/CompositeLogListener.cs | 2 +-
.../ResourcePools/ResourcePoolManager.cs | 2 +-
.../ExternalReferencePackageReader.cs | 2 +-
.../ReferenceViewModel.cs | 10 +-
.../TocItemViewModel.cs | 2 +-
.../RestApiItemViewModelBase.cs | 2 +-
.../RestApiParameterViewModel.cs | 2 +-
.../RestApiResponseViewModel.cs | 2 +-
.../RestApiTagViewModel.cs | 2 +-
.../ApiParameter.cs | 2 +-
.../ArgumentInfo.cs | 2 +-
.../AttributeInfo.cs | 2 +-
.../ExceptionInfo.cs | 2 +-
.../InheritanceTree.cs | 2 +-
.../ItemViewModel.cs | 40 ++---
.../LinkInfo.cs | 2 +-
.../NamedArgumentInfo.cs | 2 +-
.../PageViewModel.cs | 6 +-
.../SyntaxDetailViewModel.cs | 4 +-
src/Docfx.Dotnet/DotnetApiCatalog.Compile.cs | 6 +-
.../DotnetApiCatalog.ManagedReference.cs | 10 +-
src/Docfx.Dotnet/DotnetApiCatalog.Toc.cs | 6 +-
.../Filters/AttributeFilterInfo.cs | 2 +-
src/Docfx.Dotnet/Filters/ConfigFilterRule.cs | 4 +-
.../ManagedReference/Models/ItemViewModel.cs | 8 +-
.../ManagedReference/Models/PageViewModel.cs | 6 +-
.../Models/SyntaxDetailViewModel.cs | 2 +-
.../Resolvers/ResolveReference.cs | 2 +-
.../Resolvers/SetDerivedClass.cs | 4 +-
.../Resolvers/YamlMetadataResolver.cs | 20 +--
.../Visitors/SymbolVisitorAdapter.cs | 54 +++----
.../TypeGenericParameterNameVisitor.cs | 2 +-
.../Visitors/YamlModelGenerator.cs | 30 ++--
src/Docfx.Dotnet/Parsers/XHtmlWriter.cs | 2 +-
.../SymbolUrlResolver.SourceLink.cs | 2 +-
src/Docfx.Dotnet/YamlViewModelExtensions.cs | 4 +-
src/Docfx.Glob/FileGlob.cs | 4 +-
src/Docfx.Glob/GlobMatcher.cs | 18 +--
.../CodeSnippet/HtmlCodeSnippetRenderer.cs | 22 +--
.../TabGroup/ActiveAndVisibleRewriter.cs | 2 +-
src/Docfx.Plugins/FileModel.cs | 4 +-
src/Docfx.Plugins/GroupInfo.cs | 2 +-
src/Docfx.Plugins/Manifest.cs | 2 +-
src/Docfx.Plugins/ManifestGroupInfo.cs | 2 +-
src/Docfx.Plugins/ManifestItem.cs | 4 +-
src/Docfx.Plugins/OutputFileInfo.cs | 2 +-
src/Docfx.Plugins/TreeItem.cs | 2 +-
src/Docfx.Plugins/XRefSpec.cs | 2 +-
.../EmitGenericCollectionNodeDeserializer.cs | 6 +-
.../EmitGenericDictionaryNodeDeserializer.cs | 6 +-
.../DefaultEmitObjectFactory.cs | 2 +-
.../FullObjectGraphTraversalStrategy.cs | 6 +-
.../TypeInspectors/EmitTypeInspector.cs | 4 +-
.../YamlDeserializer.cs | 12 +-
src/docfx/Models/BuildCommand.cs | 4 +-
src/docfx/Models/TemplateCommand.cs | 2 +-
.../MarkdownReaderTest.cs | 2 +-
.../ModelAttributeHandlerTest.cs | 20 +--
.../OverwriteDocumentModelCreatorTest.cs | 35 ++---
.../SplitRestApiToOperationLevelTest.cs | 2 +-
.../SchemaFragmentsIteratorTest.cs | 2 +-
.../ConceptualDocumentProcessorTest.cs | 2 +-
test/Docfx.Build.Tests/DocumentBuilderTest.cs | 82 +++++-----
.../DocumentProcessors/YamlDocumentModel.cs | 4 +-
.../FileMetadataHelperTest.cs | 58 ++++---
.../JintProcessorHelperTest.cs | 2 +-
.../TemplateProcessorUnitTest.cs | 2 +-
.../TocDocumentProcessorTest.cs | 142 +++++++++---------
test/Docfx.Build.Tests/TocRestructureTest.cs | 8 +-
.../XRefMapSerializationTest.cs | 12 +-
...UniversalReferenceDocumentProcessorTest.cs | 2 +-
.../CompositeDictionaryTest.cs | 6 +-
.../ConvertToObjectHelperTest.cs | 8 +-
test/Docfx.Common.Tests/PathUtilityTest.cs | 6 +-
.../YamlSerializationTest.cs | 8 +-
test/Docfx.Dotnet.Tests/ApiFilterUnitTest.cs | 2 +-
.../GenerateMetadataFromCSUnitTest.cs | 2 +-
.../GenerateMetadataFromVBUnitTest.cs | 2 +-
.../TestUtility.cs | 6 +-
.../TestUtility/TestLoggerListener.cs | 2 +-
test/Docfx.Tests.Common/TestBase.cs | 2 +-
test/Docfx.Tests.Common/TestListenerScope.cs | 2 +-
test/Docfx.Tests.Common/TestLoggerListener.cs | 2 +-
157 files changed, 516 insertions(+), 516 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index f8ad6ea8e56..9e4042e0a42 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -78,7 +78,8 @@ csharp_prefer_static_local_function = true:suggestion
dotnet_diagnostic.IDE0010.severity = suggestion # IDE0010: Add missing cases to switch statement
dotnet_style_object_initializer = true:suggestion # IDE0017: Use object initializers
csharp_style_inlined_variable_declaration = true:suggestion # IDE0018: Inline variable declaration
-dotnet_style_collection_initializer = true:suggestion # IDE0028: Use collection initializers
+dotnet_style_collection_initializer = true:suggestion # IDE0028: Use collection initializers or expressions
+dotnet_style_prefer_collection_expression = true:suggestion # IDE0028: Use collection initializers or expressions
dotnet_style_prefer_auto_properties = true:suggestion # IDE0032: Use auto-implemented property
dotnet_style_explicit_tuple_names = true:suggestion # IDE0033: Use explicitly provided tuple name
csharp_prefer_simple_default_expression = true:suggestion # IDE0034: Simplify default expression
diff --git a/src/Docfx.App/Config/BuildJsonConfig.cs b/src/Docfx.App/Config/BuildJsonConfig.cs
index c9dd2a4003a..ed4b395004f 100644
--- a/src/Docfx.App/Config/BuildJsonConfig.cs
+++ b/src/Docfx.App/Config/BuildJsonConfig.cs
@@ -72,7 +72,7 @@ internal class BuildJsonConfig
///
[JsonProperty("globalMetadataFiles")]
[JsonPropertyName("globalMetadataFiles")]
- public ListWithStringFallback GlobalMetadataFiles { get; set; } = new();
+ public ListWithStringFallback GlobalMetadataFiles { get; set; } = [];
///
/// Metadata that applies to some specific files.
@@ -99,7 +99,7 @@ internal class BuildJsonConfig
///
[JsonProperty("template")]
[JsonPropertyName("template")]
- public ListWithStringFallback Template { get; set; } = new();
+ public ListWithStringFallback Template { get; set; } = [];
///
/// The themes applied to the documentation.
@@ -123,7 +123,7 @@ internal class BuildJsonConfig
///
[JsonProperty("postProcessors")]
[JsonPropertyName("postProcessors")]
- public ListWithStringFallback PostProcessors { get; set; } = new();
+ public ListWithStringFallback PostProcessors { get; set; } = [];
///
/// Run in debug mode. With debug mode, raw model and view model will be exported
diff --git a/src/Docfx.App/Config/FileMetadataPairs.cs b/src/Docfx.App/Config/FileMetadataPairs.cs
index 7390e638ad1..b816e909576 100644
--- a/src/Docfx.App/Config/FileMetadataPairs.cs
+++ b/src/Docfx.App/Config/FileMetadataPairs.cs
@@ -39,7 +39,7 @@ public FileMetadataPairs(IEnumerable items)
///
public FileMetadataPairs(FileMetadataPairsItem item)
{
- _items = new List { item };
+ _items = [item];
}
///
diff --git a/src/Docfx.App/Config/GroupConfig.cs b/src/Docfx.App/Config/GroupConfig.cs
index c6346938de3..f443a717c1a 100644
--- a/src/Docfx.App/Config/GroupConfig.cs
+++ b/src/Docfx.App/Config/GroupConfig.cs
@@ -23,5 +23,5 @@ internal class GroupConfig
///
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
- public Dictionary Metadata { get; set; } = new();
+ public Dictionary Metadata { get; set; } = [];
}
diff --git a/src/Docfx.App/Helpers/DocumentBuilderWrapper.cs b/src/Docfx.App/Helpers/DocumentBuilderWrapper.cs
index 2bafb81bef6..c9324530912 100644
--- a/src/Docfx.App/Helpers/DocumentBuilderWrapper.cs
+++ b/src/Docfx.App/Helpers/DocumentBuilderWrapper.cs
@@ -263,7 +263,7 @@ private static FileMetadata GetFileMetadata(string baseDirectory, BuildJsonConfi
{
foreach (var (key, value) in config.FileMetadata)
{
- var list = result.TryGetValue(key, out var items) ? items : result[key] = new();
+ var list = result.TryGetValue(key, out var items) ? items : result[key] = [];
foreach (var pair in value.Items)
{
list.Add(new FileMetadataItem(pair.Glob, key, pair.Value));
@@ -277,7 +277,7 @@ private static FileMetadata GetFileMetadata(string baseDirectory, BuildJsonConfi
{
foreach (var (key, value) in JsonUtility.Deserialize>(path))
{
- var list = result.TryGetValue(key, out var items) ? items : result[key] = new();
+ var list = result.TryGetValue(key, out var items) ? items : result[key] = [];
foreach (var pair in value.Items)
{
list.Add(new FileMetadataItem(pair.Glob, key, pair.Value));
diff --git a/src/Docfx.App/Helpers/MetadataMerger.cs b/src/Docfx.App/Helpers/MetadataMerger.cs
index 2dee2e496f3..c4b80118d2f 100644
--- a/src/Docfx.App/Helpers/MetadataMerger.cs
+++ b/src/Docfx.App/Helpers/MetadataMerger.cs
@@ -14,8 +14,8 @@ namespace Docfx;
internal class MetadataMerger
{
- private readonly Dictionary> _metaTable = new();
- private readonly Dictionary> _propTable = new();
+ private readonly Dictionary> _metaTable = [];
+ private readonly Dictionary> _propTable = [];
public void Merge(MetadataMergeParameters parameters)
{
diff --git a/src/Docfx.App/PdfBuilder.cs b/src/Docfx.App/PdfBuilder.cs
index 2e4123f6a3b..9cef7a4696b 100644
--- a/src/Docfx.App/PdfBuilder.cs
+++ b/src/Docfx.App/PdfBuilder.cs
@@ -297,7 +297,7 @@ await Parallel.ForEachAsync(pages, async (item, _) =>
var key = CleanUrl(url);
if (!pagesByUrl.TryGetValue(key, out var dests))
- pagesByUrl[key] = dests = new();
+ pagesByUrl[key] = dests = [];
dests.Add((node, document.Structure.Catalog.GetNamedDestinations()));
pageBytes[node] = bytes;
diff --git a/src/Docfx.App/RunBuild.cs b/src/Docfx.App/RunBuild.cs
index 5501ae9e856..0549827bfd3 100644
--- a/src/Docfx.App/RunBuild.cs
+++ b/src/Docfx.App/RunBuild.cs
@@ -21,7 +21,7 @@ public static string Exec(BuildJsonConfig config, BuildOptions options, string c
var stopwatch = Stopwatch.StartNew();
if (config.Template == null || config.Template.Count == 0)
{
- config.Template = new ListWithStringFallback { "default" };
+ config.Template = ["default"];
}
var baseDirectory = Path.GetFullPath(string.IsNullOrEmpty(configDirectory) ? Directory.GetCurrentDirectory() : configDirectory);
diff --git a/src/Docfx.App/RunMerge.cs b/src/Docfx.App/RunMerge.cs
index 76df5b5ed51..1b6ed57744a 100644
--- a/src/Docfx.App/RunMerge.cs
+++ b/src/Docfx.App/RunMerge.cs
@@ -56,7 +56,7 @@ private static MetadataMergeParameters ConfigToParameter(MergeJsonItemConfig con
OutputBaseDir = outputDirectory,
Metadata = config.GlobalMetadata?.ToImmutableDictionary() ?? ImmutableDictionary.Empty,
FileMetadata = ConvertToFileMetadataItem(baseDirectory, config.FileMetadata),
- TocMetadata = config.TocMetadata?.ToImmutableList() ?? ImmutableList.Empty,
+ TocMetadata = config.TocMetadata?.ToImmutableList() ?? [],
Files = GetFileCollectionFromFileMapping(
baseDirectory,
DocumentType.Article,
diff --git a/src/Docfx.Build.Common/MarkdownReader.cs b/src/Docfx.Build.Common/MarkdownReader.cs
index 1aae2b1eaf8..66e9a40fc33 100644
--- a/src/Docfx.Build.Common/MarkdownReader.cs
+++ b/src/Docfx.Build.Common/MarkdownReader.cs
@@ -13,7 +13,7 @@ namespace Docfx.Build.Common;
public class MarkdownReader
{
- private static readonly ImmutableList RequiredProperties = ImmutableList.Create(Constants.PropertyName.Uid);
+ private static readonly ImmutableList RequiredProperties = [Constants.PropertyName.Uid];
public static IEnumerable ReadMarkdownAsOverwrite(IHostService host, FileAndType ft)
{
diff --git a/src/Docfx.Build.Common/ModelAttributeHandlers/HandleModelAttributesContext.cs b/src/Docfx.Build.Common/ModelAttributeHandlers/HandleModelAttributesContext.cs
index 10f37bc5c1c..87a6811be05 100644
--- a/src/Docfx.Build.Common/ModelAttributeHandlers/HandleModelAttributesContext.cs
+++ b/src/Docfx.Build.Common/ModelAttributeHandlers/HandleModelAttributesContext.cs
@@ -14,11 +14,11 @@ public class HandleModelAttributesContext
public bool EnableContentPlaceholder { get; set; }
public string PlaceholderContent { get; set; }
public bool ContainsPlaceholder { get; set; }
- public HashSet Dependency { get; set; } = new();
+ public HashSet Dependency { get; set; } = [];
public FileAndType FileAndType { get; set; }
public HashSet LinkToFiles { get; set; } = new(FilePathComparer.OSPlatformSensitiveStringComparer);
- public HashSet LinkToUids { get; set; } = new();
- public List Uids { get; set; } = new();
- public Dictionary> UidLinkSources { get; set; } = new();
- public Dictionary> FileLinkSources { get; set; } = new();
+ public HashSet LinkToUids { get; set; } = [];
+ public List Uids { get; set; } = [];
+ public Dictionary> UidLinkSources { get; set; } = [];
+ public Dictionary> FileLinkSources { get; set; } = [];
}
diff --git a/src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/UrlContentHandler.cs b/src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/UrlContentHandler.cs
index 369a59e41f3..9cd182da3fa 100644
--- a/src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/UrlContentHandler.cs
+++ b/src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/UrlContentHandler.cs
@@ -98,7 +98,7 @@ private static string GetHrefFromRoot(string originalHref, HandleModelAttributes
if (!context.FileLinkSources.TryGetValue(file, out List sources))
{
- sources = new List();
+ sources = [];
context.FileLinkSources[file] = sources;
}
sources.Add(new LinkSourceInfo
diff --git a/src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs b/src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs
index 8ac8f568cbb..90d9118ba0c 100644
--- a/src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs
+++ b/src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs
@@ -17,7 +17,7 @@ public class OverwriteDocumentModel
[ExtensibleMember]
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
- public Dictionary Metadata { get; set; } = new();
+ public Dictionary Metadata { get; set; } = [];
///
/// The uid for this overwrite document, as defined in YAML header
@@ -49,7 +49,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
- public HashSet LinkToFiles { get; set; } = new();
+ public HashSet LinkToFiles { get; set; } = [];
///
/// Links to other Uids
@@ -57,7 +57,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
- public HashSet LinkToUids { get; set; } = new();
+ public HashSet LinkToUids { get; set; } = [];
///
/// Link sources information for file
@@ -65,7 +65,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
- public Dictionary> FileLinkSources { get; set; } = new();
+ public Dictionary> FileLinkSources { get; set; } = [];
///
/// Link sources information for Uid
@@ -73,7 +73,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
- public Dictionary> UidLinkSources { get; set; } = new();
+ public Dictionary> UidLinkSources { get; set; } = [];
///
/// Dependencies extracted from the markdown content
diff --git a/src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs b/src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs
index 9135d8c370a..87da14659f5 100644
--- a/src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs
+++ b/src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs
@@ -60,7 +60,7 @@ private static List GetPlatformVersionFromMetadata(object value)
{
if (value is string text)
{
- return new List { text };
+ return [text];
}
if (value is IEnumerable