Skip to content

Commit

Permalink
chore: Suppress messages generated by CodeAnalyzers (dotnet#9224)
Browse files Browse the repository at this point in the history
* chore: suppress CA1018 message

* chore: suppress CA1041 message

* chore: suppress CA1050 message

* chore: suppress CA1507 message

* chore: suppress CA1822 message

* chore: suppress CA1825 message

* chore: suppress CA1827 message

* chore: suppress CA1829 message

* chore: suppress CA1830 message

* chore: suppress CA1834 message

* chore: suppress CA1836 message

* chore: suppress CA1841 message

* chore: suppress CA1846 message

* chore: suppress CA1847 message

* chore: suppress CA1850 message

* chore: suppress CA2208 message

* chore: suppress CA2249 message

* chore: suppress IDE0001 message

* chore: suppress IDE0002 message

* chore: suppress IDE0003 message

* chore: suppress IDE0004 message

* chore: suppress IDE0005 message

* chore: suppress IDE0007/IDE0008 message

* chore: suppress IDE0017 message

* chore: suppress IDE0018 message

* chore: suppress IDE0019 message

* chore: suppress IDE0029 message

* chore: suppress IDE0031 message

* chore: suppress IDE0034 message

* chore: suppress IDE0036 message

* chore: suppress IDE0038 message

* chore: suppress IDE0039 message

* chore: suppress IDE0041 message

* chore: suppress IDE0044 message

* chore: suppress IDE0049 message

* chore: suppress IDE0054 message

* chore: suppress IDE0058 message for test projects

* chore: suppress IDE0059 for test projects

* chore: suppress IDE0062 message

* chore: suppress IDE0065 message

* chore: suppress IDE0071 message

* chore: suppress IDE0079 message

* chore: suppress IDE0083 message

* chore: suppress IDE0090 message

* chore: suppress IDE0110 message

* chore: suppress IDE0161 message

* chore: suppress IDE0200 message

* chore: suppress IDE1006 message

* chore: revert wrong code and add message suppression

* chore: fix infinite recursion problem reported as CA2011
  • Loading branch information
filzrev authored and p-kostov committed Jun 28, 2024
1 parent e620327 commit 116bc84
Show file tree
Hide file tree
Showing 216 changed files with 884 additions and 931 deletions.
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion # IDE1005: Use conditional delegate call

# 'var' preferences
csharp_style_var_for_built_in_types = false:suggestion # IDE0007: Use var instead of explicit type / IDE0008: Use explicit type instead of var
csharp_style_var_for_built_in_types = false:silent # IDE0007: Use var instead of explicit type / IDE0008: Use explicit type instead of var
csharp_style_var_when_type_is_apparent = false:none # IDE0007: Use var instead of explicit type / IDE0008: Use explicit type instead of var
csharp_style_var_elsewhere = false:suggestion # IDE0007: Use var instead of explicit type / IDE0008: Use explicit type instead of var
csharp_style_var_elsewhere = true:silent # IDE0007: Use var instead of explicit type / IDE0008: Use explicit type instead of var

# Expression-bodied-members
csharp_style_expression_bodied_constructors = true:silent # IDE0021: Use expression body for constructors
Expand Down Expand Up @@ -240,7 +240,7 @@ dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.severity = silent
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
Expand All @@ -250,7 +250,7 @@ dotnet_naming_style.static_prefix_style.required_prefix = s_
dotnet_naming_style.static_prefix_style.capitalization = camel_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = silent
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override IEnumerable<FileModel> Prebuild(ImmutableList<FileModel> models,
return collection;
}

private Tuple<List<FileModel>, List<TreeItemRestructure>> SplitModelToOperationGroup(FileModel model)
private static Tuple<List<FileModel>, List<TreeItemRestructure>> SplitModelToOperationGroup(FileModel model)
{
if (model.Type != DocumentType.Article)
{
Expand Down Expand Up @@ -88,15 +88,15 @@ private Tuple<List<FileModel>, List<TreeItemRestructure>> SplitModelToOperationG
// Support both restructure by TopicHref and TopicUid
var treeItemRestructions = new List<TreeItemRestructure>
{
new TreeItemRestructure
new()
{
ActionType = TreeItemActionType.AppendChild,
Key = model.Key,
TypeOfKey = TreeItemKeyType.TopicHref,
RestructuredItems = treeItems.OrderBy(s => s.Metadata[Constants.PropertyName.Name]).ToImmutableList(),
SourceFiles = new FileAndType[] { model.OriginalFileAndType }.ToImmutableList(),
},
new TreeItemRestructure
new()
{
ActionType = TreeItemActionType.AppendChild,
Key = content.Uid,
Expand All @@ -109,7 +109,7 @@ private Tuple<List<FileModel>, List<TreeItemRestructure>> SplitModelToOperationG
return Tuple.Create(splittedModels, treeItemRestructions);
}

private IEnumerable<RestApiRootItemViewModel> GenerateOperationModels(RestApiRootItemViewModel root)
private static IEnumerable<RestApiRootItemViewModel> GenerateOperationModels(RestApiRootItemViewModel root)
{
foreach (var child in root.Children)
{
Expand Down Expand Up @@ -145,7 +145,7 @@ private IEnumerable<RestApiRootItemViewModel> GenerateOperationModels(RestApiRoo
}
}

private FileModel GenerateNewFileModel(FileModel model, RestApiRootItemViewModel operationModel)
private static FileModel GenerateNewFileModel(FileModel model, RestApiRootItemViewModel operationModel)
{
var originalFile = model.FileAndType.File;
var fileExtension = Path.GetExtension(originalFile);
Expand All @@ -167,7 +167,7 @@ private FileModel GenerateNewFileModel(FileModel model, RestApiRootItemViewModel
return newModel;
}

private TreeItem ConvertToTreeItem(RestApiRootItemViewModel root, string fileKey)
private static TreeItem ConvertToTreeItem(RestApiRootItemViewModel root, string fileKey)
{
return new TreeItem
{
Expand All @@ -179,7 +179,7 @@ private TreeItem ConvertToTreeItem(RestApiRootItemViewModel root, string fileKey
};
}

private Dictionary<string, object> MergeChildMetadata(RestApiRootItemViewModel root, RestApiChildItemViewModel child)
private static Dictionary<string, object> MergeChildMetadata(RestApiRootItemViewModel root, RestApiChildItemViewModel child)
{
var result = new Dictionary<string, object>(child.Metadata);
foreach (var pair in root.Metadata)
Expand Down
14 changes: 7 additions & 7 deletions plugins/Docfx.Build.TagLevelRestApi/SplitRestApiToTagLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override IEnumerable<FileModel> Prebuild(ImmutableList<FileModel> models,
return collection;
}

private Tuple<List<FileModel>, TreeItemRestructure> SplitModelToOperationGroup(FileModel model)
private static Tuple<List<FileModel>, TreeItemRestructure> SplitModelToOperationGroup(FileModel model)
{
if (model.Type != DocumentType.Article)
{
Expand Down Expand Up @@ -102,7 +102,7 @@ private Tuple<List<FileModel>, TreeItemRestructure> SplitModelToOperationGroup(F
return Tuple.Create(splittedModels, treeItemRestruction);
}

private IEnumerable<RestApiRootItemViewModel> GenerateTagModels(RestApiRootItemViewModel root)
private static IEnumerable<RestApiRootItemViewModel> GenerateTagModels(RestApiRootItemViewModel root)
{
foreach (var tag in root.Tags)
{
Expand All @@ -125,7 +125,7 @@ private IEnumerable<RestApiRootItemViewModel> GenerateTagModels(RestApiRootItemV
}
}

private IEnumerable<RestApiChildItemViewModel> GetChildrenByTag(RestApiRootItemViewModel root, string tagName)
private static IEnumerable<RestApiChildItemViewModel> GetChildrenByTag(RestApiRootItemViewModel root, string tagName)
{
// Only group children into first tag, to keep cross reference unique
var children = root.Children.Where(child => child.Tags != null && tagName == child.Tags.FirstOrDefault());
Expand All @@ -136,7 +136,7 @@ private IEnumerable<RestApiChildItemViewModel> GetChildrenByTag(RestApiRootItemV
}
}

private FileModel GenerateNewFileModel(FileModel model, RestApiRootItemViewModel tagModel)
private static FileModel GenerateNewFileModel(FileModel model, RestApiRootItemViewModel tagModel)
{
var originalFile = model.FileAndType.File;
var fileExtension = Path.GetExtension(originalFile);
Expand All @@ -158,7 +158,7 @@ private FileModel GenerateNewFileModel(FileModel model, RestApiRootItemViewModel
return newModel;
}

private IEnumerable<string> CalculateUids(RestApiRootItemViewModel root)
private static IEnumerable<string> CalculateUids(RestApiRootItemViewModel root)
{
if (!string.IsNullOrEmpty(root.Uid))
{
Expand All @@ -173,7 +173,7 @@ private IEnumerable<string> CalculateUids(RestApiRootItemViewModel root)
}
}

private TreeItem ConvertToTreeItem(RestApiRootItemViewModel root, string fileKey)
private static TreeItem ConvertToTreeItem(RestApiRootItemViewModel root, string fileKey)
{
return new TreeItem
{
Expand All @@ -185,7 +185,7 @@ private TreeItem ConvertToTreeItem(RestApiRootItemViewModel root, string fileKey
};
}

private Dictionary<string, object> MergeTagMetadata(RestApiRootItemViewModel root, RestApiTagViewModel tag)
private static Dictionary<string, object> MergeTagMetadata(RestApiRootItemViewModel root, RestApiTagViewModel tag)
{
var result = new Dictionary<string, object>(tag.Metadata);
foreach (var pair in root.Metadata)
Expand Down
1 change: 0 additions & 1 deletion src/Docfx.App/Config/BuildJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Docfx.Plugins;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Docfx;

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 @@ -15,7 +15,7 @@ namespace Docfx;
internal class FileMetadataPairs
{
// Order matters, the latter one overrides the former one
private List<FileMetadataPairsItem> _items;
private readonly List<FileMetadataPairsItem> _items;

/// <summary>
/// Gets FileMetadataPairs items.
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/Config/FileMetadataPairsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
{
jItems = JContainer.Load(reader);
}
else throw new JsonReaderException($"{reader.TokenType.ToString()} is not a valid {objectType.Name}.");
else throw new JsonReaderException($"{reader.TokenType} is not a valid {objectType.Name}.");
return new FileMetadataPairs(jItems.Select(ParseItem).ToList());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/Docset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static Task Pdf(string configPath, BuildOptions options)
configPath,
options,
"pdf",
(config, exeOptions, configDirectory, outputDirectory) => RunPdf.Exec(config, exeOptions, configDirectory, outputDirectory));
RunPdf.Exec);
}

private static Task Exec<TConfig>(
Expand Down
8 changes: 2 additions & 6 deletions src/Docfx.App/Helpers/DocumentBuilderWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using System.Net;
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
Expand All @@ -12,8 +11,6 @@

namespace Docfx;

#pragma warning disable CS0618 // Type or member is obsolete

internal static class DocumentBuilderWrapper
{
private static readonly Assembly[] s_pluginAssemblies = LoadPluginAssemblies(AppContext.BaseDirectory).ToArray();
Expand Down Expand Up @@ -135,11 +132,10 @@ private static List<DocumentBuildParameters> ConfigToParameter(BuildJsonConfig c
SitemapOptions = config.SitemapOptions,
DisableGitFeatures = config.DisableGitFeatures,
ConfigureMarkdig = options.ConfigureMarkdig,
Metadata = GetGlobalMetadata(config),
FileMetadata = GetFileMetadata(baseDirectory, config),
};

parameters.Metadata = GetGlobalMetadata(config);
parameters.FileMetadata = GetFileMetadata(baseDirectory, config);

if (config.PostProcessors != null)
{
parameters.PostProcessors = config.PostProcessors.ToImmutableArray();
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 @@ -132,7 +132,7 @@ private void InitTable(FileModel model, ImmutableList<string> metaNames)
}
}

private Dictionary<string, object> GetTableItem(IReadOnlyDictionary<string, object> metadata, ImmutableList<string> metaNames)
private static Dictionary<string, object> GetTableItem(IReadOnlyDictionary<string, object> metadata, ImmutableList<string> metaNames)
{
var tableItem = new Dictionary<string, object>();
foreach (var metaName in metaNames)
Expand Down Expand Up @@ -163,7 +163,7 @@ private void CopyMetadataToTocItem(TocItemViewModel item)
ApplyTocMetadata(item, _propTable);
}

private void ApplyTocMetadata(TocItemViewModel item, Dictionary<string, Dictionary<string, object>> table)
private static void ApplyTocMetadata(TocItemViewModel item, Dictionary<string, Dictionary<string, object>> table)
{
if (table.TryGetValue(item.Uid, out Dictionary<string, object> metadata))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class BaseModelAttributeHandler<T> : IModelAttributeHandler wher
private const int MaximumNestedLevel = 32;
private readonly TypeInfo _typeInfo;
protected readonly IModelAttributeHandler Handler;
private Type _type;
private readonly Type _type;
protected BaseModelAttributeHandler(Type type, IModelAttributeHandler handler)
{
ArgumentNullException.ThrowIfNull(type);
Expand Down Expand Up @@ -93,7 +93,7 @@ protected virtual object HandleDictionaryType(object currentObj, HandleModelAttr
{
return null;
}
Func<object, object> handler = s => Handler.Handle(s, context);
object handler(object s) => Handler.Handle(s, context);
if (!HandleGenericItemsHelper.EnumerateIDictionary(currentObj, handler))
{
HandleGenericItemsHelper.EnumerateIReadonlyDictionary(currentObj, handler);
Expand All @@ -112,7 +112,7 @@ protected virtual object HandleIEnumerableType(object currentObj, HandleModelAtt
{
return null;
}
Func<object, object> handler = s => Handler.Handle(s, context);

HandleGenericItemsHelper.EnumerateIEnumerable(currentObj, s => Handler.Handle(s, context));
return currentObj;
}
Expand All @@ -135,7 +135,7 @@ protected virtual object ProcessPrimitiveType(object currentObj, HandleModelAttr
protected virtual object ProcessNonPrimitiveType(object currentObj, HandleModelAttributesContext context)
{
// skip string type
if (currentObj != null && !(currentObj is string))
if (currentObj != null && currentObj is not string)
{
foreach (var prop in _typeInfo.PropInfos)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Docfx.Build.Common;

public class CompositeModelAttributeHandler : IModelAttributeHandler
{
private IModelAttributeHandler[] _handlers;
private readonly IModelAttributeHandler[] _handlers;
public CompositeModelAttributeHandler(params IModelAttributeHandler[] handlers)
{
_handlers = handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public HandleIListItems(IList<T> list)

public void Handle(Func<object, object> handler)
{
Handle(s => (T)handler((T)s));
Handle(s => (T)handler(s));
}

private void Handle(Func<T, T> handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where prop.Prop.GetSetMethod() != null
select prop;
}

private string Markup(string content, HandleModelAttributesContext context)
private static string Markup(string content, HandleModelAttributesContext context)
{
if (string.IsNullOrEmpty(content))
{
Expand All @@ -127,7 +127,7 @@ private string Markup(string content, HandleModelAttributesContext context)
return MarkupCore(content, context);
}

private bool TryMarkupPlaceholderContent(string currentValue, HandleModelAttributesContext context, out string result)
private static bool TryMarkupPlaceholderContent(string currentValue, HandleModelAttributesContext context, out string result)
{
result = null;
if (context.EnableContentPlaceholder && IsPlaceholderContent(currentValue))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ where prop.Prop.GetSetMethod() != null
select prop;
}

private string GetHrefFromRoot(string originalHref, HandleModelAttributesContext context)
private static string GetHrefFromRoot(string originalHref, HandleModelAttributesContext context)
{
if (context.FileAndType == null || string.IsNullOrEmpty(originalHref) || !RelativePath.IsRelativePath(originalHref))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static Func<object[], object> GetCreateInstanceFunc(Tuple<Type, Type[],
var argumentTypes = tuple.Item3;
if (type == typeof(void))
{
return _ => { throw new ArgumentException("Void is not allowed.", nameof(type)); };
return _ => { throw new ArgumentException("Void is not allowed for type.", nameof(tuple)); };
}
if (type.IsValueType)
{
Expand All @@ -62,7 +62,7 @@ private static Func<object[], object> GetCreateInstanceFunc(Tuple<Type, Type[],
}
if (Array.IndexOf(typeArguments, typeof(void)) != -1)
{
return _ => { throw new ArgumentException("Void is not allowed.", nameof(typeArguments)); };
return _ => { throw new ArgumentException("Void is not allowed for typeArguments.", nameof(tuple)); };
}
var typeArgument = Array.Find(typeArguments, t => !t.IsVisible);
if (typeArgument != null)
Expand Down Expand Up @@ -111,7 +111,7 @@ private static Func<object[], object> GetCreateInstanceFunc(Tuple<Type, Type[],
var ctor = finalType.GetConstructor(argumentTypes);
if (ctor == null)
{
return _ => { throw new ArgumentException(nameof(argumentTypes)); };
return _ => { throw new ArgumentException("Failed to get ctor of argumentTypes", nameof(tuple)); };
}
return GetCreateInstanceFuncCore(ctor, argumentTypes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

using System.Collections.Immutable;
using System.Composition;
using System.Text;

using Docfx.Build.Common;
using Docfx.Common;
using Docfx.DataContracts.Common;
using Docfx.Plugins;

using Newtonsoft.Json;

namespace Docfx.Build.ConceptualDocuments;

[Export(typeof(IDocumentProcessor))]
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.Engine/CompilePhaseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static void Prebuild(HostService hostService)
using (new LoggerPhaseScope(buildStep.Name, LogLevel.Verbose))
{
var models = buildStep.Prebuild(hostService.Models, hostService);
if (!object.ReferenceEquals(models, hostService.Models))
if (!ReferenceEquals(models, hostService.Models))
{
Logger.LogVerbose($"Processor {hostService.Processor.Name}, step {buildStep.Name}: Reloading models...");
hostService.Reload(models);
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Build.Engine/DocumentBuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ internal void SaveExternalXRefSpec(TextWriter writer)

internal void LoadExternalXRefSpec(TextReader reader)
{
if (ExternalXRefSpec.Count > 0)
if (!ExternalXRefSpec.IsEmpty)
{
throw new InvalidOperationException("Cannot load after reporting external xref spec.");
}
Expand Down Expand Up @@ -482,7 +482,7 @@ public IImmutableList<TocInfo> GetTocInfo()
return _tableOfContents.Values.ToImmutableList();
}

private ImmutableDictionary<string, FileAndType> GetAllSourceFiles(IEnumerable<FileAndType> allSourceFiles)
private static ImmutableDictionary<string, FileAndType> GetAllSourceFiles(IEnumerable<FileAndType> allSourceFiles)
{
var dict = new Dictionary<string, FileAndType>(FilePathComparer.OSPlatformSensitiveStringComparer);
foreach (var item in allSourceFiles)
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.Engine/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private List<IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuil
}
}

private MarkdigMarkdownService CreateMarkdigMarkdownService(DocumentBuildParameters parameters, CompositeResourceReader resourceProvider)
private static MarkdigMarkdownService CreateMarkdigMarkdownService(DocumentBuildParameters parameters, CompositeResourceReader resourceProvider)
{
return new MarkdigMarkdownService(
new MarkdownServiceParameters
Expand Down
Loading

0 comments on commit 116bc84

Please sign in to comment.