Skip to content

Commit ce61fbf

Browse files
Install StyleCop.Analyzers and update code styling/documentation
1 parent dc2b1e2 commit ce61fbf

16 files changed

+288
-171
lines changed

.editorconfig

100755100644
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,26 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
102102
# CA1054: URI parameters should not be strings
103103
dotnet_diagnostic.CA1054.severity = suggestion
104104

105+
# CA1055: URI-like return values should not be strings
106+
dotnet_diagnostic.CA1055.severity = none
107+
105108
# RS0048: Missing shipped or unshipped public API file
106109
dotnet_public_api_analyzer.require_api_files = true
110+
111+
# SA1101: Prefix local calls with this
112+
dotnet_diagnostic.SA1101.severity = none
113+
114+
# SA1309: Field names should not begin with underscore
115+
dotnet_diagnostic.SA1309.severity = none
116+
117+
# SA1413: Use trailing comma in multi-line initializers
118+
dotnet_diagnostic.SA1413.severity = none
119+
120+
# SA1502: Element should not be on a single line
121+
dotnet_diagnostic.SA1502.severity = none
122+
123+
# SA1625: Element documentation should not be copied and pasted
124+
dotnet_diagnostic.SA1625.severity = none
125+
126+
# SA1633: File should have header
127+
dotnet_diagnostic.SA1633.severity = none

src/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.3" PrivateAssets="All" />
20+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.406" PrivateAssets="All" />
2021
</ItemGroup>
2122

2223
<PropertyGroup>

src/Umbraco.StorageProviders.AzureBlob/AzureBlobDirectoryContents.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ public sealed class AzureBlobDirectoryContents : IDirectoryContents
1717
private readonly BlobContainerClient _containerClient;
1818
private readonly IReadOnlyCollection<BlobHierarchyItem> _items;
1919

20-
/// <inheritdoc />
21-
public bool Exists { get; }
22-
2320
/// <summary>
2421
/// Initializes a new instance of the <see cref="AzureBlobDirectoryContents" /> class.
2522
/// </summary>
2623
/// <param name="containerClient">The container client.</param>
2724
/// <param name="items">The items.</param>
28-
/// <exception cref="System.ArgumentNullException">containerClient
29-
/// or
30-
/// items</exception>
25+
/// <exception cref="ArgumentNullException"><paramref name="containerClient"/> is <c>null</c>.</exception>
26+
/// <exception cref="ArgumentNullException"><paramref name="items"/> is <c>null</c>.</exception>
3127
public AzureBlobDirectoryContents(BlobContainerClient containerClient, IReadOnlyCollection<BlobHierarchyItem> items)
3228
{
3329
_containerClient = containerClient ?? throw new ArgumentNullException(nameof(containerClient));
@@ -36,12 +32,16 @@ public AzureBlobDirectoryContents(BlobContainerClient containerClient, IReadOnly
3632
Exists = items.Count > 0;
3733
}
3834

35+
/// <inheritdoc />
36+
public bool Exists { get; }
37+
3938
/// <inheritdoc />
4039
public IEnumerator<IFileInfo> GetEnumerator()
4140
=> _items.Select<BlobHierarchyItem, IFileInfo>(x => x.IsPrefix
4241
? new AzureBlobPrefixInfo(x.Prefix)
4342
: new AzureBlobItemInfo(_containerClient.GetBlobClient(x.Blob.Name), x.Blob.Properties)).GetEnumerator();
4443

44+
/// <inheritdoc/>
4545
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
4646
}
4747
}

src/Umbraco.StorageProviders.AzureBlob/AzureBlobFileProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public sealed class AzureBlobFileProvider : IFileProvider
2626
/// </summary>
2727
/// <param name="containerClient">The container client.</param>
2828
/// <param name="containerRootPath">The container root path.</param>
29-
/// <exception cref="System.ArgumentNullException">containerClient</exception>
29+
/// <exception cref="System.ArgumentNullException"><paramref name="containerClient" /> is <c>null</c>.</exception>
3030
public AzureBlobFileProvider(BlobContainerClient containerClient, string? containerRootPath = null)
3131
{
3232
_containerClient = containerClient ?? throw new ArgumentNullException(nameof(containerClient));
@@ -37,7 +37,7 @@ public AzureBlobFileProvider(BlobContainerClient containerClient, string? contai
3737
/// Initializes a new instance of the <see cref="AzureBlobFileProvider" /> class.
3838
/// </summary>
3939
/// <param name="options">The options.</param>
40-
/// <exception cref="System.ArgumentNullException">options</exception>
40+
/// <exception cref="System.ArgumentNullException"><paramref name="options" /> is <c>null</c>.</exception>
4141
public AzureBlobFileProvider(AzureBlobFileSystemOptions options)
4242
{
4343
ArgumentNullException.ThrowIfNull(options);

src/Umbraco.StorageProviders.AzureBlob/AzureBlobItemInfo.cs

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,13 @@ public sealed class AzureBlobItemInfo : IFileInfo
1414
{
1515
private readonly BlobClient _blobClient;
1616

17-
/// <inheritdoc />
18-
public bool Exists => true;
19-
20-
/// <inheritdoc />
21-
public bool IsDirectory => false;
22-
23-
/// <inheritdoc />
24-
public DateTimeOffset LastModified { get; }
25-
26-
/// <inheritdoc />
27-
public long Length { get; }
28-
29-
/// <inheritdoc />
30-
public string Name { get; }
31-
32-
/// <inheritdoc />
33-
public string PhysicalPath => null!;
34-
35-
/// <summary>
36-
/// Initializes a new instance of the <see cref="AzureBlobItemInfo" /> class.
37-
/// </summary>
38-
/// <param name="blobClient">The blob client.</param>
39-
/// <exception cref="System.ArgumentNullException">blobClient</exception>
40-
private AzureBlobItemInfo(BlobClient blobClient)
41-
{
42-
_blobClient = blobClient ?? throw new ArgumentNullException(nameof(blobClient));
43-
44-
Name = ParseName(blobClient.Name);
45-
}
46-
4717
/// <summary>
4818
/// Initializes a new instance of the <see cref="AzureBlobItemInfo" /> class.
4919
/// </summary>
5020
/// <param name="blobClient">The blob client.</param>
5121
/// <param name="properties">The properties.</param>
52-
/// <exception cref="System.ArgumentNullException">properties</exception>
22+
/// <exception cref="System.ArgumentNullException"><paramref name="blobClient" /> is <c>null</c>.</exception>
23+
/// <exception cref="System.ArgumentNullException"><paramref name="properties" /> is <c>null</c>.</exception>
5324
public AzureBlobItemInfo(BlobClient blobClient, BlobProperties properties)
5425
: this(blobClient)
5526
{
@@ -64,7 +35,8 @@ public AzureBlobItemInfo(BlobClient blobClient, BlobProperties properties)
6435
/// </summary>
6536
/// <param name="blobClient">The blob client.</param>
6637
/// <param name="properties">The properties.</param>
67-
/// <exception cref="System.ArgumentNullException">properties</exception>
38+
/// <exception cref="System.ArgumentNullException"><paramref name="blobClient" /> is <c>null</c>.</exception>
39+
/// <exception cref="System.ArgumentNullException"><paramref name="properties" /> is <c>null</c>.</exception>
6840
public AzureBlobItemInfo(BlobClient blobClient, BlobItemProperties properties)
6941
: this(blobClient)
7042
{
@@ -74,9 +46,46 @@ public AzureBlobItemInfo(BlobClient blobClient, BlobItemProperties properties)
7446
Length = properties.ContentLength.GetValueOrDefault(-1);
7547
}
7648

49+
/// <summary>
50+
/// Initializes a new instance of the <see cref="AzureBlobItemInfo" /> class.
51+
/// </summary>
52+
/// <param name="blobClient">The blob client.</param>
53+
/// <exception cref="System.ArgumentNullException"><paramref name="blobClient" /> is <c>null</c>.</exception>
54+
private AzureBlobItemInfo(BlobClient blobClient)
55+
{
56+
_blobClient = blobClient ?? throw new ArgumentNullException(nameof(blobClient));
57+
58+
Name = ParseName(blobClient.Name);
59+
}
60+
61+
/// <inheritdoc />
62+
public bool Exists => true;
63+
64+
/// <inheritdoc />
65+
public bool IsDirectory => false;
66+
67+
/// <inheritdoc />
68+
public DateTimeOffset LastModified { get; }
69+
70+
/// <inheritdoc />
71+
public long Length { get; }
72+
73+
/// <inheritdoc />
74+
public string Name { get; }
75+
76+
/// <inheritdoc />
77+
public string PhysicalPath => null!;
78+
7779
/// <inheritdoc />
7880
public Stream CreateReadStream() => _blobClient.OpenRead();
7981

82+
/// <summary>
83+
/// Parses the name from the file path.
84+
/// </summary>
85+
/// <param name="path">The file path.</param>
86+
/// <returns>
87+
/// The name.
88+
/// </returns>
8089
internal static string ParseName(string path) => path[(path.LastIndexOf('/') + 1)..];
8190
}
8291
}

src/Umbraco.StorageProviders.AzureBlob/AzureBlobPrefixInfo.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ namespace Umbraco.StorageProviders.AzureBlob
1010
/// <seealso cref="Microsoft.Extensions.FileProviders.IFileInfo" />
1111
public sealed class AzureBlobPrefixInfo : IFileInfo
1212
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="AzureBlobPrefixInfo"/> class.
15+
/// </summary>
16+
/// <param name="prefix">The prefix.</param>
17+
/// <exception cref="ArgumentNullException"><paramref name="prefix"/> is <c>null</c>.</exception>
18+
public AzureBlobPrefixInfo(string prefix)
19+
{
20+
ArgumentNullException.ThrowIfNull(prefix);
21+
22+
Name = ParseName(prefix);
23+
}
24+
1325
/// <inheritdoc />
1426
public bool Exists => true;
1527

@@ -28,17 +40,6 @@ public sealed class AzureBlobPrefixInfo : IFileInfo
2840
/// <inheritdoc />
2941
public string PhysicalPath => null!;
3042

31-
/// <summary>
32-
/// Initializes a new instance of the <see cref="AzureBlobPrefixInfo"/> class.
33-
/// </summary>
34-
/// <param name="prefix">The prefix.</param>
35-
public AzureBlobPrefixInfo(string prefix)
36-
{
37-
ArgumentNullException.ThrowIfNull(prefix);
38-
39-
Name = ParseName(prefix);
40-
}
41-
4243
/// <inheritdoc />
4344
public Stream CreateReadStream() => throw new InvalidOperationException();
4445

src/Umbraco.StorageProviders.AzureBlob/DependencyInjection/AzureBlobFileSystemExtensions.cs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,13 @@
44
using Microsoft.Extensions.Options;
55
using Umbraco.StorageProviders.AzureBlob.IO;
66

7-
// ReSharper disable once CheckNamespace
8-
// uses same namespace as Umbraco Core for easier discoverability
97
namespace Umbraco.Cms.Core.DependencyInjection
108
{
119
/// <summary>
1210
/// Extension methods to help registering Azure Blob Storage file systems.
1311
/// </summary>
1412
public static class AzureBlobFileSystemExtensions
1513
{
16-
internal static IUmbracoBuilder AddInternal(this IUmbracoBuilder builder, string name, Action<OptionsBuilder<AzureBlobFileSystemOptions>>? configure = null)
17-
{
18-
ArgumentNullException.ThrowIfNull(builder);
19-
ArgumentNullException.ThrowIfNull(name);
20-
21-
builder.Services.TryAddSingleton<IAzureBlobFileSystemProvider, AzureBlobFileSystemProvider>();
22-
23-
var optionsBuilder = builder.Services.AddOptions<AzureBlobFileSystemOptions>(name)
24-
.BindConfiguration($"Umbraco:Storage:AzureBlob:{name}")
25-
.ValidateDataAnnotations();
26-
27-
configure?.Invoke(optionsBuilder);
28-
29-
return builder;
30-
}
31-
3214
/// <summary>
3315
/// Registers a <see cref="IAzureBlobFileSystem" /> in the <see cref="IServiceCollection" />, with it's configuration
3416
/// loaded from <c>Umbraco:Storage:AzureBlob:{name}</c> where {name} is the value of the <paramref name="name" /> parameter.
@@ -38,10 +20,7 @@ internal static IUmbracoBuilder AddInternal(this IUmbracoBuilder builder, string
3820
/// <returns>
3921
/// The <see cref="IUmbracoBuilder" />.
4022
/// </returns>
41-
/// <exception cref="System.ArgumentNullException">builder
42-
/// or
43-
/// name</exception>
44-
/// <exception cref="System.ArgumentException">Value cannot be null or whitespace. - path</exception>
23+
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
4524
public static IUmbracoBuilder AddAzureBlobFileSystem(this IUmbracoBuilder builder, string name)
4625
=> builder.AddInternal(name);
4726

@@ -55,6 +34,8 @@ public static IUmbracoBuilder AddAzureBlobFileSystem(this IUmbracoBuilder builde
5534
/// <returns>
5635
/// The <see cref="IUmbracoBuilder" />.
5736
/// </returns>
37+
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
38+
/// <exception cref="System.ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
5839
public static IUmbracoBuilder AddAzureBlobFileSystem(this IUmbracoBuilder builder, string name, Action<AzureBlobFileSystemOptions> configure)
5940
=> builder.AddInternal(name, optionsBuilder => optionsBuilder.Configure(configure));
6041

@@ -68,6 +49,8 @@ public static IUmbracoBuilder AddAzureBlobFileSystem(this IUmbracoBuilder builde
6849
/// <returns>
6950
/// The <see cref="IUmbracoBuilder" />.
7051
/// </returns>
52+
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
53+
/// <exception cref="System.ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
7154
public static IUmbracoBuilder AddAzureBlobFileSystem(this IUmbracoBuilder builder, string name, Action<AzureBlobFileSystemOptions, IServiceProvider> configure)
7255
=> builder.AddInternal(name, optionsBuilder => optionsBuilder.Configure(configure));
7356

@@ -82,8 +65,38 @@ public static IUmbracoBuilder AddAzureBlobFileSystem(this IUmbracoBuilder builde
8265
/// <returns>
8366
/// The <see cref="IUmbracoBuilder" />.
8467
/// </returns>
68+
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
69+
/// <exception cref="System.ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
8570
public static IUmbracoBuilder AddAzureBlobFileSystem<TDep>(this IUmbracoBuilder builder, string name, Action<AzureBlobFileSystemOptions, TDep> configure)
8671
where TDep : class
8772
=> builder.AddInternal(name, optionsBuilder => optionsBuilder.Configure(configure));
73+
74+
/// <summary>
75+
/// Registers a <see cref="IAzureBlobFileSystem" /> in the <see cref="IServiceCollection" />, with it's configuration
76+
/// loaded from <c>Umbraco:Storage:AzureBlob:{name}</c> where {name} is the value of the <paramref name="name" /> parameter.
77+
/// </summary>
78+
/// <param name="builder">The <see cref="IUmbracoBuilder" />.</param>
79+
/// <param name="name">The name of the file system.</param>
80+
/// <param name="configure">An action used to configure the <see cref="AzureBlobFileSystemOptions" />.</param>
81+
/// <returns>
82+
/// The <see cref="IUmbracoBuilder" />.
83+
/// </returns>
84+
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
85+
/// <exception cref="System.ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
86+
internal static IUmbracoBuilder AddInternal(this IUmbracoBuilder builder, string name, Action<OptionsBuilder<AzureBlobFileSystemOptions>>? configure = null)
87+
{
88+
ArgumentNullException.ThrowIfNull(builder);
89+
ArgumentNullException.ThrowIfNull(name);
90+
91+
builder.Services.TryAddSingleton<IAzureBlobFileSystemProvider, AzureBlobFileSystemProvider>();
92+
93+
var optionsBuilder = builder.Services.AddOptions<AzureBlobFileSystemOptions>(name)
94+
.BindConfiguration($"Umbraco:Storage:AzureBlob:{name}")
95+
.ValidateDataAnnotations();
96+
97+
configure?.Invoke(optionsBuilder);
98+
99+
return builder;
100+
}
88101
}
89102
}

0 commit comments

Comments
 (0)