Skip to content

Commit 90fa9d5

Browse files
committed
Update shared infra and fix styles
1 parent e38bc79 commit 90fa9d5

40 files changed

Lines changed: 203 additions & 194 deletions

.editorconfig

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:war
104104
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
105105
dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion
106106
# Expression-level preferences
107-
dotnet_style_object_initializer = true:warning
108-
dotnet_style_collection_initializer = true:warning
107+
dotnet_style_object_initializer = true:error
108+
dotnet_style_collection_initializer = true:error
109109
dotnet_style_explicit_tuple_names = true:warning
110110
dotnet_style_prefer_inferred_tuple_names = true:warning
111111
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
@@ -135,9 +135,9 @@ csharp_style_prefer_null_check_over_type_check = true:warning
135135
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules
136136
[*.{cs,csx,cake}]
137137
# 'var' preferences
138-
csharp_style_var_for_built_in_types = false:warning
139-
csharp_style_var_when_type_is_apparent = false:warning
140-
csharp_style_var_elsewhere = false:warning
138+
csharp_style_var_for_built_in_types = false:error
139+
csharp_style_var_when_type_is_apparent = false:error
140+
csharp_style_var_elsewhere = false:error
141141
# Expression-bodied members
142142
csharp_style_expression_bodied_methods = true:warning
143143
csharp_style_expression_bodied_constructors = true:warning
@@ -160,7 +160,10 @@ csharp_style_pattern_local_over_anonymous_function = true:warning
160160
csharp_style_deconstructed_variable_declaration = true:warning
161161
csharp_style_prefer_index_operator = true:warning
162162
csharp_style_prefer_range_operator = true:warning
163-
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
163+
csharp_style_implicit_object_creation_when_type_is_apparent = true:error
164+
# ReSharper inspection severities
165+
resharper_arrange_object_creation_when_type_evident_highlighting = error
166+
resharper_arrange_object_creation_when_type_not_evident_highlighting = error
164167
# "Null" checking preferences
165168
csharp_style_throw_expression = true:warning
166169
csharp_style_conditional_delegate_call = true:warning
@@ -172,6 +175,11 @@ dotnet_diagnostic.IDE0063.severity = suggestion
172175
csharp_using_directive_placement = outside_namespace:warning
173176
# Modifier preferences
174177
csharp_prefer_static_local_function = true:warning
178+
# Primary constructor preferences
179+
csharp_style_prefer_primary_constructors = false:none
180+
# Collection preferences
181+
dotnet_style_prefer_collection_expression = true:error
182+
resharper_use_collection_expression_highlighting =true:error
175183

176184
##########################################
177185
# Unnecessary Code Rules

src/ImageSharp.Web/Caching/HexEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static unsafe string Encode(ReadOnlySpan<byte> bytes)
3232
{
3333
return string.Create(bytes.Length * 2, (Ptr: (IntPtr)bytesPtr, bytes.Length), (chars, args) =>
3434
{
35-
var ros = new ReadOnlySpan<byte>((byte*)args.Ptr, args.Length);
35+
ReadOnlySpan<byte> ros = new((byte*)args.Ptr, args.Length);
3636
EncodeToUtf16(ros, chars);
3737
});
3838
}

src/ImageSharp.Web/Commands/CommandCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public IEnumerable<string> Keys
6666
{
6767
if (this.TryGetValue(key, out KeyValuePair<string, string?> item))
6868
{
69-
this.SetItem(this.IndexOf(item), new(key, value));
69+
this.SetItem(this.IndexOf(item), new KeyValuePair<string, string?>(key, value));
7070
}
7171
else
7272
{
@@ -81,7 +81,7 @@ public IEnumerable<string> Keys
8181
/// <param name="key">The <see cref="string"/> to use as the key of the element to add.</param>
8282
/// <param name="value">The <see cref="string"/> to use as the value of the element to add.</param>
8383
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
84-
public void Add(string key, string value) => this.Add(new(key, value));
84+
public void Add(string key, string value) => this.Add(new KeyValuePair<string, string?>(key, value));
8585

8686
/// <summary>
8787
/// Inserts an element into the <see cref="CommandCollection"/> at the
@@ -91,7 +91,7 @@ public IEnumerable<string> Keys
9191
/// <param name="key">The <see cref="string"/> to use as the key of the element to insert.</param>
9292
/// <param name="value">The <see cref="string"/> to use as the value of the element to insert.</param>
9393
/// <exception cref="ArgumentOutOfRangeException">index is less than zero. -or- index is greater than <see cref="P:CommandCollection.Count"/>.</exception>
94-
public void Insert(int index, string key, string value) => this.Insert(index, new(key, value));
94+
public void Insert(int index, string key, string value) => this.Insert(index, new KeyValuePair<string, string?>(key, value));
9595

9696
/// <summary>
9797
/// Gets the value associated with the specified key.

src/ImageSharp.Web/Commands/Converters/ConverterUtility.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Runtime.InteropServices;
77

88
namespace SixLabors.ImageSharp.Web.Commands.Converters;
9+
910
internal static class ConverterUtility
1011
{
1112
/// <summary>

src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public CommandCollection ParseRequestCommands(HttpContext context)
3636
|| !queryCollection.ContainsKey(QueryKey))
3737
{
3838
// We return new here and below to ensure the collection is still mutable via events.
39-
return new();
39+
return new CommandCollection();
4040
}
4141

4242
StringValues query = queryCollection[QueryKey];
@@ -46,7 +46,7 @@ public CommandCollection ParseRequestCommands(HttpContext context)
4646
return collection;
4747
}
4848

49-
return new();
49+
return new CommandCollection();
5050
}
5151

5252
private static IDictionary<string, CommandCollection> ParsePresets(

src/ImageSharp.Web/Commands/QueryCollectionRequestParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public CommandCollection ParseRequestCommands(HttpContext context)
1818
if (query is null || query.Count == 0)
1919
{
2020
// We return new to ensure the collection is still mutable via events.
21-
return new();
21+
return new CommandCollection();
2222
}
2323

2424
CommandCollection transformed = new();

src/ImageSharp.Web/DependencyInjection/ImageSharpBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public static IImageSharpBuilder AddProvider<TProvider>(this IImageSharpBuilder
164164
public static IImageSharpBuilder InsertProvider<TProvider>(this IImageSharpBuilder builder, int index)
165165
where TProvider : class, IImageProvider
166166
{
167-
var descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList();
167+
List<ServiceDescriptor> descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList();
168168
descriptors.RemoveAll(x => x.GetImplementationType() == typeof(TProvider));
169169
descriptors.Insert(index, ServiceDescriptor.Singleton<IImageProvider, TProvider>());
170170

@@ -185,7 +185,7 @@ public static IImageSharpBuilder InsertProvider<TProvider>(this IImageSharpBuild
185185
public static IImageSharpBuilder InsertProvider<TProvider>(this IImageSharpBuilder builder, int index, Func<IServiceProvider, TProvider> implementationFactory)
186186
where TProvider : class, IImageProvider
187187
{
188-
var descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList();
188+
List<ServiceDescriptor> descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList();
189189
descriptors.RemoveAll(x => x.GetImplementationType() == typeof(TProvider));
190190
descriptors.Insert(index, ServiceDescriptor.Singleton<IImageProvider>(implementationFactory));
191191

src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private async Task ProcessRequestAsync(
346346
{
347347
// TODO: Do we need some way to set options based upon processors?
348348
DecoderOptions decoderOptions = await this.options.OnBeforeLoadAsync.Invoke(imageCommandContext, this.options.Configuration)
349-
?? new() { Configuration = this.options.Configuration };
349+
?? new DecoderOptions { Configuration = this.options.Configuration };
350350

351351
FormattedImage? image = null;
352352
try

src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ImageSharpMiddlewareOptions
4141
/// Gets or sets the recyclable memorystream manager used for managing pooled stream
4242
/// buffers independently from image buffer pooling.
4343
/// </summary>
44-
public RecyclableMemoryStreamManager MemoryStreamManager { get; set; } = new RecyclableMemoryStreamManager();
44+
public RecyclableMemoryStreamManager MemoryStreamManager { get; set; } = new();
4545

4646
/// <summary>
4747
/// Gets or sets a value indicating whether to use culture-independent (invariant)

0 commit comments

Comments
 (0)