Skip to content

Commit

Permalink
Merge pull request #141 from Lombiq/issue/OSOE-867
Browse files Browse the repository at this point in the history
OSOE-867: Addressing analyzer warnings
  • Loading branch information
Piedone authored Jun 11, 2024
2 parents 07fc8ff + 7305bc1 commit 9c9c6c6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
8 changes: 6 additions & 2 deletions Lombiq.VueJs.Samples/Controllers/QrCardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ public ActionResult Index()
});
}

public async Task<ActionResult> GetBusinessCard(string cardId) =>
await _contentManager.GetAsync(cardId) is { } businessCard
public async Task<ActionResult> GetBusinessCard(string cardId)
{
if (!ModelState.IsValid) return BadRequest(ModelState);

return await _contentManager.GetAsync(cardId) is { } businessCard
? Ok(businessCard)
: NotFound();
}
}
15 changes: 9 additions & 6 deletions Lombiq.VueJs.Samples/Controllers/VueSfcController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ public VueSfcController(IClock clock, IStringLocalizer<VueSfcController> stringL
// Here we show off a way of doing progressive enhancement. This first action has everything you need to access the
// page without JS.
// Open this from under /Lombiq.VueJs.Samples/VueSfc/EnhancedList
public ActionResult EnhancedList(int page = 1) => View(new EnhancedListViewModel
{
Page = page,
Data = GetDataForPage(page),
});
public ActionResult EnhancedList(int page = 1) =>
ModelState.IsValid
? View(new EnhancedListViewModel
{
Page = page,
Data = GetDataForPage(page),
})
: BadRequest(ModelState);

// This method returns JSON, providing an API equivalent for the EnhancedList action. The enhanced app will use that
// to update results asynchronously. Both use the same source of data.
public ActionResult GetList(int page = 1) => Json(GetDataForPage(page));
public ActionResult GetList(int page = 1) => ModelState.IsValid ? Json(GetDataForPage(page)) : BadRequest(ModelState);

// What is in this method isn't really important, just some sample data to show change.
[SuppressMessage("Security", "CA5394:Do not use insecure randomness", Justification = "It's not security critical.")]
Expand Down
5 changes: 2 additions & 3 deletions Lombiq.VueJs/Services/IVueSingleFileComponentShapeAmender.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Html;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Lombiq.VueJs.Services;
Expand All @@ -14,11 +13,11 @@ public interface IVueSingleFileComponentShapeAmender
/// Lets you prepend content to the Vue.js template outputted by the shape. The <paramref name="shapeName"/> is
/// provided to help limit the scope, but you can also ignore it to amend every Vue.js shape.
/// </summary>
ValueTask<IEnumerable<IHtmlContent>> PrependAsync(string shapeName) => new(Enumerable.Empty<IHtmlContent>());
ValueTask<IEnumerable<IHtmlContent>> PrependAsync(string shapeName) => new([]);

/// <summary>
/// Lets you append content to the Vue.js template outputted by the shape. The <paramref name="shapeName"/> is
/// provided to help limit the scope, but you can also ignore it to amend every Vue.js shape.
/// </summary>
ValueTask<IEnumerable<IHtmlContent>> AppendAsync(string shapeName) => new(Enumerable.Empty<IHtmlContent>());
ValueTask<IEnumerable<IHtmlContent>> AppendAsync(string shapeName) => new([]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Lombiq.VueJs.Services;
Expand Down Expand Up @@ -38,22 +37,22 @@ public abstract class ServerSideValuesVueSingleFileComponentShapeAmenderBase : I
/// </summary>
public async ValueTask<IEnumerable<IHtmlContent>> PrependAsync(string shapeName)
{
if (ShapeName != null && ShapeName != shapeName) return Enumerable.Empty<IHtmlContent>();
if (ShapeName != null && ShapeName != shapeName) return [];

var values = await GetPropertyValueAsync(shapeName);
var json = JsonConvert.SerializeObject(
values,
Formatting.None,
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });

return new[]
{
return
[
new HtmlString(
"<script>" +
"if (!window.Vue.$orchardCore) window.Vue.$orchardCore = {};" +
$"window.Vue.$orchardCore[{JsonConvert.SerializeObject(PropertyName)}] = {json};" +
"</script>"),
};
];
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ValueTask UpdateAsync(IDictionary<string, string> securityPolicies, HttpC
{
if (_state.Active)
{
ContentSecurityPolicyProvider.MergeDirectiveValues(securityPolicies, new[] { ScriptSrc }, UnsafeEval);
ContentSecurityPolicyProvider.MergeDirectiveValues(securityPolicies, [ScriptSrc], UnsafeEval);
}

return ValueTask.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class VueSingleFileComponentShapeTemplateViewEngine : IShapeTemplateViewE
private readonly IEnumerable<IVueSingleFileComponentShapeAmender> _amenders;
private readonly IEnumerable<IVueTemplateExpressionConverter> _converters;

public IEnumerable<string> TemplateFileExtensions { get; } = new[] { ".vue" };
public IEnumerable<string> TemplateFileExtensions { get; } = [".vue"];

public VueSingleFileComponentShapeTemplateViewEngine(
IShapeTemplateFileProviderAccessor fileProviderAccessor,
Expand Down
11 changes: 5 additions & 6 deletions Lombiq.VueJs/Services/VueSingleFileComponentTemplateHarvester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
using OrchardCore.Mvc.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Lombiq.VueJs.Services;

public class VueSingleFileComponentTemplateHarvester : IShapeTemplateHarvester
{
private const string SubPath = "Assets/Scripts/VueComponents";

public IEnumerable<string> SubPaths() => new[] { SubPath };
public IEnumerable<string> SubPaths() => [SubPath];

public IEnumerable<HarvestShapeHit> HarvestShape(HarvestShapeInfo info) =>
!info.SubPath.StartsWith(SubPath, StringComparison.OrdinalIgnoreCase)
? Enumerable.Empty<HarvestShapeHit>()
: new[]
{
? []
:
[
new HarvestShapeHit
{
ShapeType = "VueComponent-" + info.FileName.ToPascalCaseDash(),
},
};
];
}

0 comments on commit 9c9c6c6

Please # to comment.