Skip to content

Update shared infra and fix styles #387

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 14 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:war
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion
# Expression-level preferences
dotnet_style_object_initializer = true:warning
dotnet_style_collection_initializer = true:warning
dotnet_style_object_initializer = true:error
dotnet_style_collection_initializer = true:error
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
Expand Down Expand Up @@ -135,9 +135,9 @@ csharp_style_prefer_null_check_over_type_check = true:warning
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules
[*.{cs,csx,cake}]
# 'var' preferences
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:error
csharp_style_var_when_type_is_apparent = false:error
csharp_style_var_elsewhere = false:error
# Expression-bodied members
csharp_style_expression_bodied_methods = true:warning
csharp_style_expression_bodied_constructors = true:warning
Expand All @@ -160,7 +160,10 @@ csharp_style_pattern_local_over_anonymous_function = true:warning
csharp_style_deconstructed_variable_declaration = true:warning
csharp_style_prefer_index_operator = true:warning
csharp_style_prefer_range_operator = true:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:error
# ReSharper inspection severities
resharper_arrange_object_creation_when_type_evident_highlighting = error
resharper_arrange_object_creation_when_type_not_evident_highlighting = error
# "Null" checking preferences
csharp_style_throw_expression = true:warning
csharp_style_conditional_delegate_call = true:warning
Expand All @@ -172,6 +175,11 @@ dotnet_diagnostic.IDE0063.severity = suggestion
csharp_using_directive_placement = outside_namespace:warning
# Modifier preferences
csharp_prefer_static_local_function = true:warning
# Primary constructor preferences
csharp_style_prefer_primary_constructors = false:none
# Collection preferences
dotnet_style_prefer_collection_expression = true:error
resharper_use_collection_expression_highlighting =true:error

##########################################
# Unnecessary Code Rules
Expand Down
30 changes: 22 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,37 @@ jobs:
matrix:
options:
- os: ubuntu-latest
framework: net7.0
framework: net9.0
sdk: 9.0.x
sdk-preview: true
runtime: -x64
codecov: false
- os: macos-latest
framework: net7.0
framework: net9.0
sdk: 9.0.x
sdk-preview: true
runtime: -x64
codecov: false
- os: windows-latest
framework: net7.0
framework: net9.0
sdk: 9.0.x
sdk-preview: true
runtime: -x64
codecov: true

- os: ubuntu-latest
framework: net6.0
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false
- os: macos-latest
framework: net6.0
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false
- os: windows-latest
framework: net6.0
framework: net8.0
sdk: 8.0.x
runtime: -x64
codecov: false

Expand Down Expand Up @@ -112,11 +119,18 @@ jobs:
s3rver -d . &

- name: DotNet Setup
if: ${{ matrix.options.sdk-preview != true }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x

- name: DotNet Setup Preview
if: ${{ matrix.options.sdk-preview == true }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
7.0.x
6.0.x
9.0.x

- name: DotNet Build
if: ${{ matrix.options.sdk-preview != true }}
Expand Down
2 changes: 1 addition & 1 deletion samples/ImageSharp.Web.Sample/ImageSharp.Web.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Web.Caching.AWS;
/// </summary>
public class AWSS3StorageCache : IImageCache
{
private readonly IAmazonS3 amazonS3Client;
private readonly AmazonS3Client amazonS3Client;
private readonly string bucketName;
private readonly string cacheFolder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<Choose>
<When Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<Choose>
<When Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp.Web/Caching/HexEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static unsafe string Encode(ReadOnlySpan<byte> bytes)
{
return string.Create(bytes.Length * 2, (Ptr: (IntPtr)bytesPtr, bytes.Length), (chars, args) =>
{
var ros = new ReadOnlySpan<byte>((byte*)args.Ptr, args.Length);
ReadOnlySpan<byte> ros = new((byte*)args.Ptr, args.Length);
EncodeToUtf16(ros, chars);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp.Web/Commands/CommandCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public IEnumerable<string> Keys
{
if (this.TryGetValue(key, out KeyValuePair<string, string?> item))
{
this.SetItem(this.IndexOf(item), new(key, value));
this.SetItem(this.IndexOf(item), new KeyValuePair<string, string?>(key, value));
}
else
{
Expand All @@ -81,7 +81,7 @@ public IEnumerable<string> Keys
/// <param name="key">The <see cref="string"/> to use as the key of the element to add.</param>
/// <param name="value">The <see cref="string"/> to use as the value of the element to add.</param>
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
public void Add(string key, string value) => this.Add(new(key, value));
public void Add(string key, string value) => this.Add(new KeyValuePair<string, string?>(key, value));

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

/// <summary>
/// Gets the value associated with the specified key.
Expand Down
16 changes: 11 additions & 5 deletions src/ImageSharp.Web/Commands/Converters/ColorConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ namespace SixLabors.ImageSharp.Web.Commands.Converters;
/// <summary>
/// Allows the conversion of strings into rgba32 pixel colors.
/// </summary>
public sealed class ColorConverter : ICommandConverter<Color>
public sealed partial class ColorConverter : ICommandConverter<Color>
{
/// <summary>
/// The web color hexadecimal regex. Matches strings arranged
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </summary>
private static readonly Regex HexColorRegex = new("([0-9a-fA-F][^,;.-]\\B{3}){1,2}", RegexOptions.Compiled);
private static readonly Regex HexColorRegex = CreateHexColorRegex();

/// <summary>
/// The number color regex.
/// </summary>
private static readonly Regex NumberRegex = new(@"\d+", RegexOptions.Compiled);
private static readonly Regex NumberRegex = CreateNumberRegex();

/// <summary>
/// The color constants table map.
Expand Down Expand Up @@ -85,9 +85,9 @@ public Color ConvertFrom(CommandParser parser, CultureInfo culture, string? valu
return default;
}

private static IDictionary<string, Color> InitializeColorConstantsTable()
private static Dictionary<string, Color> InitializeColorConstantsTable()
{
IDictionary<string, Color> table = new Dictionary<string, Color>(StringComparer.OrdinalIgnoreCase);
Dictionary<string, Color> table = new(StringComparer.OrdinalIgnoreCase);

foreach (FieldInfo field in typeof(Color).GetFields(BindingFlags.Public | BindingFlags.Static))
{
Expand All @@ -99,4 +99,10 @@ private static IDictionary<string, Color> InitializeColorConstantsTable()

return table;
}

[GeneratedRegex(@"\d+", RegexOptions.Compiled)]
private static partial Regex CreateNumberRegex();

[GeneratedRegex("([0-9a-fA-F][^,;.-]\\B{3}){1,2}", RegexOptions.Compiled)]
private static partial Regex CreateHexColorRegex();
}
1 change: 1 addition & 0 deletions src/ImageSharp.Web/Commands/Converters/ConverterUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.InteropServices;

namespace SixLabors.ImageSharp.Web.Commands.Converters;

internal static class ConverterUtility
{
/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp.Web/Commands/Converters/EnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed class EnumConverter : ICommandConverter<object>
{
if (string.IsNullOrWhiteSpace(value))
{
return Activator.CreateInstance(propertyType);
return Enum.ToObject(propertyType, 0);
}

try
Expand All @@ -51,7 +51,7 @@ public sealed class EnumConverter : ICommandConverter<object>
catch
{
// Just return the default value
return Activator.CreateInstance(propertyType);
return Enum.ToObject(propertyType, 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Web.Commands;
/// </summary>
public class PresetOnlyQueryCollectionRequestParser : IRequestParser
{
private readonly IDictionary<string, CommandCollection> presets;
private readonly Dictionary<string, CommandCollection> presets;

/// <summary>
/// The command constant for the preset query parameter.
Expand All @@ -36,7 +36,7 @@ public CommandCollection ParseRequestCommands(HttpContext context)
|| !queryCollection.ContainsKey(QueryKey))
{
// We return new here and below to ensure the collection is still mutable via events.
return new();
return new CommandCollection();
}

StringValues query = queryCollection[QueryKey];
Expand All @@ -46,10 +46,10 @@ public CommandCollection ParseRequestCommands(HttpContext context)
return collection;
}

return new();
return new CommandCollection();
}

private static IDictionary<string, CommandCollection> ParsePresets(
private static Dictionary<string, CommandCollection> ParsePresets(
IDictionary<string, string> unparsedPresets) =>
unparsedPresets
.Select(keyValue =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CommandCollection ParseRequestCommands(HttpContext context)
if (query is null || query.Count == 0)
{
// We return new to ensure the collection is still mutable via events.
return new();
return new CommandCollection();
}

CommandCollection transformed = new();
Expand Down
Loading
Loading