Skip to content

Commit

Permalink
Fixes Analyzer Rules (Core Projects) (#13964)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkech committed Jul 19, 2023
1 parent 0341ba7 commit db16075
Show file tree
Hide file tree
Showing 343 changed files with 1,804 additions and 2,069 deletions.
Expand Up @@ -33,8 +33,11 @@ public override async Task BuildIndexAsync(BagPart bagPart, BuildPartIndexContex
{
foreach (var contentItem in bagPart.ContentItems)
{
var keys = new List<string>();
keys.Add(contentItem.ContentType);
var keys = new List<string>
{
contentItem.ContentType,
};

foreach (var key in context.Keys)
{
keys.Add($"{key}.{contentItem.ContentType}");
Expand Down
Expand Up @@ -33,8 +33,11 @@ public override async Task BuildIndexAsync(FlowPart FlowPart, BuildPartIndexCont
{
foreach (var contentItem in FlowPart.Widgets)
{
var keys = new List<string>();
keys.Add(contentItem.ContentType);
var keys = new List<string>
{
contentItem.ContentType,
};

foreach (var key in context.Keys)
{
keys.Add($"{key}.{contentItem.ContentType}");
Expand Down
Expand Up @@ -16,7 +16,7 @@ public static class SignalExtensions
/// <summary>
/// Adds a Signal (if not already present) to be sent at the end of the shell scope.
/// </summary>
public static void DeferredSignalToken(this ISignal signal, string key)
public static void DeferredSignalToken(this ISignal _, string key)
{
ShellScope.AddDeferredSignal(key);
}
Expand Down
Expand Up @@ -28,7 +28,7 @@ public static IEnumerable<T> OrderByDependenciesAndPriorities<T>(this IEnumerabl
Add(node, result, nodes, hasDependency);
}

for (int index = 1; index < result.Count; index++)
for (var index = 1; index < result.Count; index++)
{
MoveUp(result, index, LowestIndex(result, index, hasDependency, getPriority));
}
Expand All @@ -55,8 +55,8 @@ private static int LowestIndex<T>(List<T> list, int index, Func<T, T, bool> hasD
{
double priority = getPriority(list[index]);

int lowestIndex = index;
for (int i = index - 1; i >= 0; i--)
var lowestIndex = index;
for (var i = index - 1; i >= 0; i--)
{
if (hasDependency(list[index], list[i]))
{
Expand All @@ -77,12 +77,12 @@ private static void MoveUp<T>(List<T> list, int index, int lowerIndex)
{
if (index < lowerIndex)
{
throw new ArgumentException("lowerIndex");
throw new ArgumentException("Should be higher or equal to 'lowerIndex'.", nameof(index));
}

if (index != lowerIndex)
{
T temp = list[index];
var temp = list[index];

for (; index > lowerIndex; index--)
{
Expand Down
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -15,7 +16,7 @@ public class Application

public const string ModuleName = "Application Main Feature";
public const string ModuleDescription = "Provides components defined at the application level.";
public static readonly string ModulePriority = int.MinValue.ToString();
public static readonly string ModulePriority = Int32.MinValue.ToString();
public const string ModuleCategory = "Application";

public const string DefaultFeatureId = "Application.Default";
Expand Down Expand Up @@ -48,7 +49,7 @@ public Module GetModule(string name)
{
if (!_modulesByName.TryGetValue(name, out var module))
{
return new Module(string.Empty);
return new Module(String.Empty);
}

return module;
Expand Down
10 changes: 6 additions & 4 deletions src/OrchardCore/OrchardCore.Abstractions/Modules/Asset.cs
@@ -1,3 +1,5 @@
using System;

namespace OrchardCore.Modules
{
public class Asset
Expand All @@ -9,13 +11,13 @@ public Asset(string asset)

if (index == -1)
{
ModuleAssetPath = string.Empty;
ProjectAssetPath = string.Empty;
ModuleAssetPath = String.Empty;
ProjectAssetPath = String.Empty;
}
else
{
ModuleAssetPath = asset.Substring(0, index);
ProjectAssetPath = asset.Substring(index + 1);
ModuleAssetPath = asset[..index];
ProjectAssetPath = asset[(index + 1)..];
}
}

Expand Down
Expand Up @@ -12,16 +12,13 @@ public static IEnumerable<string> ReadAllLines(this IFileInfo fileInfo)

if (fileInfo?.Exists ?? false)
{
using (var reader = fileInfo.CreateReadStream())
using var reader = fileInfo.CreateReadStream();
using var sr = new StreamReader(reader);

string line;
while ((line = sr.ReadLine()) != null)
{
using (var sr = new StreamReader(reader))
{
string line;
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
}
lines.Add(line);
}
}

Expand Down
Expand Up @@ -17,15 +17,15 @@ public static class NormalizedPaths
var folders = new HashSet<string>(StringComparer.Ordinal);

// Ensure a trailing slash.
if (folder[folder.Length - 1] != '/')
if (folder[^1] != '/')
{
folder = folder + '/';
folder += '/';
}

foreach (var path in normalizedPaths.Where(a => a.StartsWith(folder, StringComparison.Ordinal)))
{
// Resolve the subpath relative to the folder.
var subPath = path.Substring(folder.Length);
var subPath = path[folder.Length..];
var index = subPath.IndexOf('/');

// If no more slash.
Expand All @@ -37,7 +37,7 @@ public static class NormalizedPaths
else
{
// Otherwise add the 1st subfolder path.
folders.Add(subPath.Substring(0, index));
folders.Add(subPath[..index]);
}
}

Expand Down
Expand Up @@ -6,8 +6,6 @@ namespace OrchardCore.Modules.Manifest
{
using static StringSplitOptions;

#pragma warning disable IDE0049 // Use framework type
// #pragma warning restore IDE0049
/// <summary>
/// Defines a Feature in a Module, can be used multiple times.
/// If at least one Feature is defined, the Module default feature is ignored.
Expand Down Expand Up @@ -69,7 +67,7 @@ public FeatureAttribute()
/// <param name="defaultTenant">Whether considered default tenant only.</param>
/// <param name="alwaysEnabled">Whether feature is always enabled.</param>
/// <param name="enabledByDependencyOnly">Whether feature is enabled by dependency only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
public FeatureAttribute(
string id
, string description
Expand Down Expand Up @@ -101,11 +99,11 @@ string id
/// <param name="featureDependencies">Zero or more delimited feature dependencies,
/// corresponding to each of the feature <see cref="Name"/> properties.</param>
/// <param name="defaultTenant">Whether considered default tenant only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <param name="alwaysEnabled">Whether feature is always enabled.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <param name="enabledByDependencyOnly">Whether feature is enabled by dependency only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
public FeatureAttribute(
string id
, string name
Expand Down Expand Up @@ -140,11 +138,11 @@ string id
/// <param name="featureDependencies">Zero or more delimited feature dependencies,
/// corresponding to each of the feature <see cref="Name"/> properties.</param>
/// <param name="defaultTenant">Whether considered default tenant only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <param name="alwaysEnabled">Whether feature is always enabled.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <param name="enabledByDependencyOnly">Whether feature is enabled by dependency only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
public FeatureAttribute(
string id
, string name
Expand Down Expand Up @@ -203,12 +201,12 @@ public virtual string Id
private string _name;

/// <summary>
/// Returns the <see cref="string"/> <paramref name="s"/> as is, or <c>null</c> when that
/// Returns the <see cref="String"/> <paramref name="s"/> as is, or <c>null</c> when that
/// or <see cref="String.Empty"/>.
/// </summary>
/// <param name="s">The string value to consider.</param>
/// <returns>The <paramref name="s"/> value as is, or Null when either that or Empty.</returns>
/// <see cref="String.IsNullOrEmpty(string?)"/>
/// <see cref="String.IsNullOrEmpty(String?)"/>
internal static string StringOrNull(string s) => String.IsNullOrEmpty(s) ? null : s;

/// <summary>
Expand Down Expand Up @@ -267,7 +265,7 @@ internal virtual string Describe(params FeatureAttribute[] additionalFeatures)
/// perspective. Also common are comma (&apos;,&apos;) and space (&apos; &apos;)
/// delimiters.
/// </summary>
/// <see cref="String.Split(char[], StringSplitOptions)"/>
/// <see cref="String.Split(Char[], StringSplitOptions)"/>
internal protected static char[] ListDelims { get; } = GetValues(';', ',', ' ').ToArray();

/// <summary>
Expand Down Expand Up @@ -306,9 +304,9 @@ public virtual string[] Dependencies

/// <summary>
/// Gets the <see cref="Priority"/>, parsed and ready to go for Internal use. May yield
/// <c>null</c> when failing to <see cref="int.TryParse(string, out int)"/>.
/// <c>null</c> when failing to <see cref="Int32.TryParse(String, out Int32)"/>.
/// </summary>
internal virtual int? InternalPriority => int.TryParse(Priority, out var result) ? result : null;
internal virtual int? InternalPriority => Int32.TryParse(Priority, out var result) ? result : null;

/// <summary>
/// Prioritizes the Features starting with This one, concatenating
Expand Down
Expand Up @@ -52,14 +52,14 @@ public ModuleAttribute() : base()
/// properties.</param>
/// <param name="tags">Tags associated with the Module.</param>
/// <param name="defaultTenant">Whether considered default tenant only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <param name="alwaysEnabled">Whether feature is always enabled.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <see cref="!:https://semver.org">Semantic Versioning</see>
/// <remarks>At least <paramref name="author" /> expected herein to differentiate with
/// parameterless ctor.</remarks>
/// <param name="enabledByDependencyOnly">Whether feature is enabled by dependency only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
public ModuleAttribute(
string id
, string description
Expand Down Expand Up @@ -105,14 +105,14 @@ string id
/// properties.</param>
/// <param name="tags">Tags associated with the Module.</param>
/// <param name="defaultTenant">Whether considered default tenant only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <param name="alwaysEnabled">Whether feature is always enabled.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <see cref="!:https://semver.org">Semantic Versioning</see>
/// <remarks>At least <paramref name="author" /> expected herein to differentiate with
/// parameterless ctor.</remarks>
/// <param name="enabledByDependencyOnly">Whether feature is enabled by dependency only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
public ModuleAttribute(
string id
, string name
Expand Down Expand Up @@ -161,14 +161,14 @@ string id
/// <param name="websiteUrl">The module website URL.</param>
/// <param name="tags">Tags associated with the Module.</param>
/// <param name="defaultTenant">Whether considered default tenant only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <param name="alwaysEnabled">Whether feature is always enabled.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <see cref="!:https://semver.org">Semantic Versioning</see>
/// <remarks>At least <paramref name="author" /> expected herein to differentiate with
/// parameterless ctor.</remarks>
/// <param name="enabledByDependencyOnly">Whether feature is enabled by dependency only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
public ModuleAttribute(
string id
, string name
Expand Down Expand Up @@ -220,14 +220,14 @@ string id
/// <param name="websiteUrl">The module website URL.</param>
/// <param name="tags">Tags associated with the Module.</param>
/// <param name="defaultTenant">Whether considered default tenant only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <param name="alwaysEnabled">Whether feature is always enabled.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
/// <see cref="!:https://semver.org">Semantic Versioning</see>
/// <remarks>At least <paramref name="author" /> expected herein to differentiate with
/// parameterless ctor.</remarks>
/// <param name="enabledByDependencyOnly">Whether feature is enabled by dependency only.
/// Supported types are <see cref="string"/> and <see cref="bool"/> only.</param>
/// Supported types are <see cref="String"/> and <see cref="Boolean"/> only.</param>
public ModuleAttribute(
string id
, string name
Expand Down Expand Up @@ -276,7 +276,7 @@ protected internal static string GetAttributePrefix(Type attributeType)
// Drops the 'Attribute' suffix from the conventional abbreviation, or leaves it alone
static string GetTypeNamePrefix(string typeName) =>
typeName.EndsWith(attributeSuffix)
? typeName.Substring(0, typeName.Length - attributeSuffix.Length)
? typeName[..^attributeSuffix.Length]
: typeName
;

Expand Down
Expand Up @@ -16,7 +16,7 @@ public class ModularApplicationContext : IApplicationContext
private readonly IHostEnvironment _environment;
private readonly IEnumerable<IModuleNamesProvider> _moduleNamesProviders;
private Application _application;
private static readonly object _initLock = new object();
private static readonly object _initLock = new();

public ModularApplicationContext(IHostEnvironment environment, IEnumerable<IModuleNamesProvider> moduleNamesProviders)
{
Expand All @@ -39,18 +39,17 @@ private void EnsureInitialized()
{
lock (_initLock)
{
if (_application == null)
{
_application = new Application(_environment, GetModules());
}
_application ??= new Application(_environment, GetModules());
}
}
}

private IEnumerable<Module> GetModules()
{
var modules = new ConcurrentBag<Module>();
modules.Add(new Module(_environment.ApplicationName, true));
var modules = new ConcurrentBag<Module>
{
new Module(_environment.ApplicationName, true),
};

var names = _moduleNamesProviders
.SelectMany(p => p.GetModuleNames())
Expand Down
6 changes: 3 additions & 3 deletions src/OrchardCore/OrchardCore.Abstractions/Modules/Module.cs
Expand Up @@ -13,7 +13,7 @@ namespace OrchardCore.Modules
public class Module
{
public const string WebRootPath = "wwwroot";
public static string WebRoot = WebRootPath + "/";
public const string WebRoot = WebRootPath + "/";

private readonly string _baseNamespace;
private readonly DateTimeOffset _lastModified;
Expand All @@ -29,7 +29,7 @@ public class Module
/// <param name="isApplication">Whether the Module may be considered to be the &quot;Application&quot;.</param>
public Module(string assyName, bool isApplication = false)
{
if (!string.IsNullOrWhiteSpace(assyName))
if (!String.IsNullOrWhiteSpace(assyName))
{
Assembly = Assembly.Load(new AssemblyName(assyName));

Expand Down Expand Up @@ -107,7 +107,7 @@ public Module(string assyName, bool isApplication = false)
_baseNamespace = Name + '.';
_lastModified = DateTimeOffset.UtcNow;

if (!string.IsNullOrEmpty(Assembly?.Location))
if (!String.IsNullOrEmpty(Assembly?.Location))
{
try
{
Expand Down

0 comments on commit db16075

Please sign in to comment.