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

OSOE-867: Addressing analyzer warnings #171

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 7 additions & 3 deletions Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services;
using Microsoft.AspNetCore.Mvc;
using OrchardCore;
using OrchardCore.Modules;
Expand All @@ -18,8 +18,12 @@ public ContentSetController(IContentSetManager contentSetManager, IOrchardHelper
_orchardHelper = orchardHelper;
}

public async Task<IActionResult> Create(string fromContentItemId, string fromPartName, string newKey) =>
await _contentSetManager.CloneContentItemAsync(fromContentItemId, fromPartName, newKey) is { } content
public async Task<IActionResult> Create(string fromContentItemId, string fromPartName, string newKey)
{
if (!ModelState.IsValid) return BadRequest(ModelState);

return await _contentSetManager.CloneContentItemAsync(fromContentItemId, fromPartName, newKey) is { } content
? Redirect(_orchardHelper.GetItemEditUrl(content))
: NotFound();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public OrchardRecipeMigrationAdminController(
[ValidateAntiForgeryToken]
public async Task<IActionResult> Convert(IFormFile file)
{
if (!ModelState.IsValid) return BadRequest(ModelState);

Stream stream;
string json;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ContentSetIndexProvider(IServiceProvider provider) =>
public override void Describe(DescribeContext<ContentItem> context) =>
context.For<ContentSetIndex>().Map(async contentItem =>
{
if (!contentItem.Latest) return Enumerable.Empty<ContentSetIndex>();
if (!contentItem.Latest) return [];

using var scope = _provider.CreateScope();
var contentDefinitionManager = scope.ServiceProvider.GetRequiredService<IContentDefinitionManager>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services;
using Microsoft.AspNetCore.Mvc.ModelBinding;
Expand All @@ -24,7 +24,7 @@ public class ContentSetPartViewModel
public ContentSetPart ContentSetPart { get; set; }

[BindNever]
public IEnumerable<ContentSetLinkViewModel> MemberLinks { get; set; } = Enumerable.Empty<ContentSetLinkViewModel>();
public IEnumerable<ContentSetLinkViewModel> MemberLinks { get; set; } = [];

[BindNever]
public bool IsNew { get; set; }
Expand Down Expand Up @@ -84,13 +84,12 @@ public async ValueTask InitializeAsync(
pair.Key));
options.AddRange(inapplicableSetMembers, link => link.Key);

MemberLinks = options
MemberLinks = [.. options
Piedone marked this conversation as resolved.
Show resolved Hide resolved
.Values
.Where(link => link.Key != Key && link.ContentItemId != part.ContentItem.ContentItemId)
.OrderBy(link => string.IsNullOrEmpty(link.ContentItemId) ? 1 : 0)
.ThenBy(link => link.IsDeleted ? 1 : 0)
.ThenBy(link => link.DisplayText)
.ToList();
.ThenBy(link => link.DisplayText)];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public OrchardExportToRecipeConverter(
public async Task<string> ConvertAsync(XDocument export)
{
var contentItems = new List<ContentItem>();
var contents = export.XPathSelectElement("//Content")?.Elements() ?? Enumerable.Empty<XElement>();
var contents = export.XPathSelectElement("//Content")?.Elements() ?? [];
var contentTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync())
.Select(definition => definition.Name)
.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class StrictSecurityPermissionAuthorizationHandler : AuthorizationHandler
.PermissionTemplates
.ToDictionary(
pair => pair.Key,
pair => GetPermissionTemplates(pair.Value, new List<string>()));
pair => GetPermissionTemplates(pair.Value, []));

private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Fluid;
using Fluid;
using Fluid.Values;
using Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels;
using Lombiq.HelpfulLibraries.OrchardCore.Liquid;
Expand Down Expand Up @@ -59,9 +59,9 @@ public ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArguments argu
FluidValues.Object => input!.ToObjectValue() switch
{
IEnumerable<MenuItem> enumerable => enumerable.AsList(),
MenuItem single => new[] { single },
MenuItem single => [single],
JArray jArray => jArray.ToObject<IList<MenuItem>>(serializer),
JObject jObject => new[] { jObject.ToObject<MenuItem>(serializer) },
JObject jObject => [jObject.ToObject<MenuItem>(serializer)],
_ => null,
},
_ => null,
Expand All @@ -74,7 +74,7 @@ public ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArguments argu
model =>
{
model.NoWrapper = noWrapper;
model.MenuItems = menuItems ?? Array.Empty<MenuItem>();
model.MenuItems = menuItems ?? [];
model.HtmlClasses = classes;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using OrchardCore.Navigation;
using OrchardCore.Navigation;
using System.Collections.Generic;
using System.Linq;

namespace Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels;

Expand All @@ -13,14 +12,14 @@ public class MenuWidgetViewModel
public string HtmlClasses { get; set; } = string.Empty;

public MenuWidgetViewModel()
: this(noWrapper: false, menuItems: Enumerable.Empty<MenuItem>())
: this(noWrapper: false, menuItems: [])
{
}

public MenuWidgetViewModel(bool noWrapper, IEnumerable<MenuItem> menuItems)
{
NoWrapper = noWrapper;
MenuItems = menuItems ?? Enumerable.Empty<MenuItem>();
MenuItems = menuItems ?? [];
}

public MenuWidgetViewModel(dynamic model)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels;

Expand All @@ -8,6 +8,6 @@ public class MvcConditionViewModel
public string Controller { get; set; }
public string Action { get; set; }

public IList<string> OtherRouteNames { get; } = new List<string>();
public IList<string> OtherRouteValues { get; } = new List<string>();
public IList<string> OtherRouteNames { get; } = [];
public IList<string> OtherRouteValues { get; } = [];
}