Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Apply code formatting rules (IDE0028, and IDE0300-IDE0304) #10458

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Docfx.App/Config/BuildJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class BuildJsonConfig
/// </summary>
[JsonProperty("globalMetadataFiles")]
[JsonPropertyName("globalMetadataFiles")]
public ListWithStringFallback GlobalMetadataFiles { get; set; } = new();
public ListWithStringFallback GlobalMetadataFiles { get; set; } = [];

/// <summary>
/// Metadata that applies to some specific files.
Expand All @@ -99,7 +99,7 @@ internal class BuildJsonConfig
/// </summary>
[JsonProperty("template")]
[JsonPropertyName("template")]
public ListWithStringFallback Template { get; set; } = new();
public ListWithStringFallback Template { get; set; } = [];

/// <summary>
/// The themes applied to the documentation.
Expand All @@ -123,7 +123,7 @@ internal class BuildJsonConfig
/// </example>
[JsonProperty("postProcessors")]
[JsonPropertyName("postProcessors")]
public ListWithStringFallback PostProcessors { get; set; } = new();
public ListWithStringFallback PostProcessors { get; set; } = [];

/// <summary>
/// Run in debug mode. With debug mode, raw model and view model will be exported
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/Config/FileMetadataPairs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public FileMetadataPairs(IEnumerable<FileMetadataPairsItem> items)
/// </summary>
public FileMetadataPairs(FileMetadataPairsItem item)
{
_items = new List<FileMetadataPairsItem> { item };
_items = [item];
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/Config/GroupConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ internal class GroupConfig
/// </summary>
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, object> Metadata { get; set; } = new();
public Dictionary<string, object> Metadata { get; set; } = [];
}
4 changes: 2 additions & 2 deletions src/Docfx.App/Helpers/DocumentBuilderWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -277,7 +277,7 @@ private static FileMetadata GetFileMetadata(string baseDirectory, BuildJsonConfi
{
foreach (var (key, value) in JsonUtility.Deserialize<Dictionary<string, FileMetadataPairs>>(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));
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.App/Helpers/MetadataMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Docfx;

internal class MetadataMerger
{
private readonly Dictionary<string, Dictionary<string, object>> _metaTable = new();
private readonly Dictionary<string, Dictionary<string, object>> _propTable = new();
private readonly Dictionary<string, Dictionary<string, object>> _metaTable = [];
private readonly Dictionary<string, Dictionary<string, object>> _propTable = [];

public void Merge(MetadataMergeParameters parameters)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/PdfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/RunBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/RunMerge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static MetadataMergeParameters ConfigToParameter(MergeJsonItemConfig con
OutputBaseDir = outputDirectory,
Metadata = config.GlobalMetadata?.ToImmutableDictionary() ?? ImmutableDictionary<string, object>.Empty,
FileMetadata = ConvertToFileMetadataItem(baseDirectory, config.FileMetadata),
TocMetadata = config.TocMetadata?.ToImmutableList() ?? ImmutableList<string>.Empty,
TocMetadata = config.TocMetadata?.ToImmutableList() ?? [],
Files = GetFileCollectionFromFileMapping(
baseDirectory,
DocumentType.Article,
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.Common/MarkdownReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Docfx.Build.Common;

public class MarkdownReader
{
private static readonly ImmutableList<string> RequiredProperties = ImmutableList.Create(Constants.PropertyName.Uid);
private static readonly ImmutableList<string> RequiredProperties = [Constants.PropertyName.Uid];

public static IEnumerable<OverwriteDocumentModel> ReadMarkdownAsOverwrite(IHostService host, FileAndType ft)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class HandleModelAttributesContext
public bool EnableContentPlaceholder { get; set; }
public string PlaceholderContent { get; set; }
public bool ContainsPlaceholder { get; set; }
public HashSet<string> Dependency { get; set; } = new();
public HashSet<string> Dependency { get; set; } = [];
public FileAndType FileAndType { get; set; }
public HashSet<string> LinkToFiles { get; set; } = new(FilePathComparer.OSPlatformSensitiveStringComparer);
public HashSet<string> LinkToUids { get; set; } = new();
public List<UidDefinition> Uids { get; set; } = new();
public Dictionary<string, List<LinkSourceInfo>> UidLinkSources { get; set; } = new();
public Dictionary<string, List<LinkSourceInfo>> FileLinkSources { get; set; } = new();
public HashSet<string> LinkToUids { get; set; } = [];
public List<UidDefinition> Uids { get; set; } = [];
public Dictionary<string, List<LinkSourceInfo>> UidLinkSources { get; set; } = [];
public Dictionary<string, List<LinkSourceInfo>> FileLinkSources { get; set; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static string GetHrefFromRoot(string originalHref, HandleModelAttributes

if (!context.FileLinkSources.TryGetValue(file, out List<LinkSourceInfo> sources))
{
sources = new List<LinkSourceInfo>();
sources = [];
context.FileLinkSources[file] = sources;
}
sources.Add(new LinkSourceInfo
Expand Down
10 changes: 5 additions & 5 deletions src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class OverwriteDocumentModel
[ExtensibleMember]
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, object> Metadata { get; set; } = new();
public Dictionary<string, object> Metadata { get; set; } = [];

/// <summary>
/// The uid for this overwrite document, as defined in YAML header
Expand Down Expand Up @@ -49,31 +49,31 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public HashSet<string> LinkToFiles { get; set; } = new();
public HashSet<string> LinkToFiles { get; set; } = [];

/// <summary>
/// Links to other Uids
/// </summary>
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public HashSet<string> LinkToUids { get; set; } = new();
public HashSet<string> LinkToUids { get; set; } = [];

/// <summary>
/// Link sources information for file
/// </summary>
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public Dictionary<string, List<LinkSourceInfo>> FileLinkSources { get; set; } = new();
public Dictionary<string, List<LinkSourceInfo>> FileLinkSources { get; set; } = [];

/// <summary>
/// Link sources information for Uid
/// </summary>
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public Dictionary<string, List<LinkSourceInfo>> UidLinkSources { get; set; } = new();
public Dictionary<string, List<LinkSourceInfo>> UidLinkSources { get; set; } = [];

/// <summary>
/// Dependencies extracted from the markdown content
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static List<string> GetPlatformVersionFromMetadata(object value)
{
if (value is string text)
{
return new List<string> { text };
return [text];
}

if (value is IEnumerable<object> collection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public class ApiBuildOutput
[ExtensibleMember]
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, object> Metadata { get; set; } = new();
public Dictionary<string, object> Metadata { get; set; } = [];

public static ApiBuildOutput FromModel(PageViewModel model)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public class ApiReferenceBuildOutput
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
[System.Text.Json.Serialization.JsonPropertyName("__metadata__")]
public Dictionary<string, object> Metadata { get; set; } = new();
public Dictionary<string, object> Metadata { get; set; } = [];

[EditorBrowsable(EditorBrowsableState.Never)]
[YamlIgnore]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Docfx.Build.ManagedReference;
[Export(nameof(ManagedReferenceDocumentProcessor), typeof(IDocumentBuildStep))]
public class FillReferenceInformation : BaseDocumentBuildStep
{
private readonly Dictionary<string, SourceInfo> _items = new();
private readonly Dictionary<string, SourceInfo> _items = [];

public override string Name => nameof(FillReferenceInformation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static PageViewModel ConvertToVM(MergeItem mergeItem)
{
var vm = new PageViewModel
{
Items = new List<ItemViewModel>(),
Items = [],
References = mergeItem.References?.Values.ToList(),
Metadata = mergeItem.Metadata,
};
Expand Down
12 changes: 6 additions & 6 deletions src/Docfx.Build.ManagedReference/SplitClassPageToMemberLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class SplitClassPageToMemberLevel : BaseDocumentBuildStep
private const string SplitFromPropertyName = "_splitFrom";
private const string IsOverloadPropertyName = "_isOverload";
private const int MaximumFileNameLength = 180;
private static readonly List<string> EmptyList = new();
private static readonly string[] EmptyArray = Array.Empty<string>();
private static readonly List<string> EmptyList = [];
private static readonly string[] EmptyArray = [];

public override string Name => nameof(SplitClassPageToMemberLevel);

Expand Down Expand Up @@ -95,7 +95,7 @@ private static void RenewDupeFileModels(FileModel dupeModel, Dictionary<string,
}

var newFilePath = GetUniqueFilePath(dupeModel.File, newFileName, newFilePaths, modelsDict);
var newModel = GenerateNewFileModel(dupeModel, page, Path.GetFileNameWithoutExtension(newFilePath), new Dictionary<string, int> { });
var newModel = GenerateNewFileModel(dupeModel, page, Path.GetFileNameWithoutExtension(newFilePath), []);
modelsDict[newFilePath] = newModel;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ private SplittedResult SplitModelToOverloadLevel(FileModel model, Dictionary<str
// Convert children to references
page.References = itemsToSplit.Select(ConvertToReference).Concat(page.References).ToList();

page.Items = new List<ItemViewModel> { primaryItem };
page.Items = [primaryItem];
page.Metadata[SplitReferencePropertyName] = true;
page.Metadata[SplitFromPropertyName] = true;

Expand Down Expand Up @@ -210,7 +210,7 @@ private static IEnumerable<PageViewModel> GetNewPages(PageViewModel page)
{
foreach (var item in overload)
{
yield return ExtractPageViewModel(page, new List<ItemViewModel> { item });
yield return ExtractPageViewModel(page, [item]);
}
}
else
Expand Down Expand Up @@ -296,7 +296,7 @@ private static List<string> GetVersionFromMetadata(object value)
{
if (value is string text)
{
return new List<string> { text };
return [text];
}

return GetListFromObject(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ private static Tuple<List<FileModel>, List<TreeItemRestructure>> SplitModelToOpe
}

// Reset children
content.Children = new List<RestApiChildItemViewModel>();
content.Children = [];
content.Metadata["_isSplittedByOperation"] = true;
content.Tags = new List<RestApiTagViewModel>();
content.Tags = [];
model.Content = content;

// Reset uid definition
Expand Down Expand Up @@ -123,8 +123,8 @@ private static IEnumerable<RestApiRootItemViewModel> GenerateOperationModels(Res
Summary = child.Summary,
Remarks = child.Remarks,
Documentation = child.Documentation,
Children = new List<RestApiChildItemViewModel> { child },
Tags = new List<RestApiTagViewModel>(),
Children = [child],
Tags = [],
Metadata = MergeChildMetadata(root, child)
};

Expand All @@ -139,7 +139,7 @@ private static IEnumerable<RestApiRootItemViewModel> GenerateOperationModels(Res
child.Description = null;
child.Summary = null;
child.Remarks = null;
child.Tags = new List<string>();
child.Tags = [];

yield return model;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private List<MarkdownPropertyModel> PropertySection()
{
PropertyName = key,
PropertyNameSource = Next(),
PropertyValue = new List<Block>(),
PropertyValue = [],
};
Block block;
while ((block = Peek()) != null && !_inlineCodeHeadingRule.Parse(block, out var _))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static Dictionary<object, object> ConvertYamlCodeBlock(string yamlCodeB
{
if (string.IsNullOrEmpty(yamlCodeBlock) || yamlCodeBlockSource == null)
{
return new Dictionary<object, object>();
return [];
}

using var reader = new StringReader(yamlCodeBlock);
Expand Down Expand Up @@ -202,7 +202,7 @@ private MarkdownDocument CreateDocument(MarkdownPropertyModel model)

private static Dictionary<object, object> CreateDictionaryObject()
{
return new Dictionary<object, object>();
return [];
}

private static List<object> CreateDictionaryArrayObject(OPathSegment segment)
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.OverwriteDocuments/OverwriteUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void AddOrUpdateFragmentEntity(this Dictionary<string, MarkdownFra
value = new MarkdownFragment
{
Uid = uid,
Properties = new Dictionary<string, MarkdownProperty>(),
Properties = [],
Metadata = metadata
};
fragments.Add(uid, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed class YamlCodeBlockRule : IOverwriteBlockRule
{
public string TokenName => "YamlCodeBlock";

private static readonly List<string> _allowedLanguages = new() { "yaml", "yml" };
private static readonly List<string> _allowedLanguages = ["yaml", "yml"];

public bool Parse(Block block, out string value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.RestApi/BuildRestApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Docfx.Build.RestApi;
[Export(nameof(RestApiDocumentProcessor), typeof(IDocumentBuildStep))]
public class BuildRestApiDocument : BuildReferenceDocumentBase
{
private static readonly HashSet<string> MarkupKeys = new() { "description" };
private static readonly HashSet<string> MarkupKeys = ["description"];

public override string Name => nameof(BuildRestApiDocument);

Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.RestApi/Swagger/InfoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public class InfoObject
[ExtensibleMember]
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, object> PatternedObjects { get; set; } = new();
public Dictionary<string, object> PatternedObjects { get; set; } = [];
}
2 changes: 1 addition & 1 deletion src/Docfx.Build.RestApi/Swagger/Internals/SwaggerArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class SwaggerArray : SwaggerObjectBase
{
public override SwaggerObjectType ObjectType => SwaggerObjectType.Array;

public List<SwaggerObjectBase> Array { get; set; } = new();
public List<SwaggerObjectBase> Array { get; set; } = [];

public override SwaggerObjectBase Clone()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.RestApi/Swagger/Internals/SwaggerObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class SwaggerObject : SwaggerObjectBase
{
public override SwaggerObjectType ObjectType => SwaggerObjectType.Object;

public Dictionary<string, SwaggerObjectBase> Dictionary { get; set; } = new();
public Dictionary<string, SwaggerObjectBase> Dictionary { get; set; } = [];

public override SwaggerObjectBase Clone()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.RestApi/Swagger/OperationObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ public class OperationObject
[ExtensibleMember]
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, object> Metadata { get; set; } = new();
public Dictionary<string, object> Metadata { get; set; } = [];
}
Loading
Loading