Skip to content

Commit

Permalink
Fix some warnings and adjust others
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed May 15, 2024
1 parent ff1e9de commit 5b3288c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
13 changes: 8 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ csharp_style_var_elsewhere = true:suggestion
# Disallow throw expressions.
csharp_style_throw_expression = false:suggestion

# Ignore Use 'ArgumentNullException.ThrowIfNull'. We have to support older .net
dotnet_diagnostic.CA1510.severity = none

# Newline settings
csharp_new_line_before_open_brace = all

csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
Expand All @@ -53,7 +57,7 @@ csharp_new_line_before_members_in_anonymous_types = true
csharp_style_namespace_declarations = file_scoped

# Brace settings
csharp_prefer_braces = true # Prefer curly braces even for one line of code
csharp_prefer_braces = when_multiline

# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
Expand All @@ -66,11 +70,10 @@ dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case


[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
indent_size = 2
Expand Down Expand Up @@ -457,4 +460,4 @@ dotnet_diagnostic.IDE0161.severity = silent

[{**/Shared/**.cs,**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}]
# IDE0005: Remove unused usings. Ignore for shared src files since imports for those depend on the projects in which they are included.
dotnet_diagnostic.IDE0005.severity = silent
dotnet_diagnostic.IDE0005.severity = silent
1 change: 1 addition & 0 deletions src/Imageflow/Fluent/StreamDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void Write(ReadOnlySpan<byte> bytes)
public Task FlushAsync(CancellationToken cancellationToken)
{
ObjectDisposedHelper.ThrowIf(_underlying == null, this);
// Truncate the stream if it's seekable and we haven't written to the end
if (_underlying is { CanSeek: true, CanWrite: true }
&& _underlying.Position < _underlying.Length)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Imageflow.Test/Imageflow.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<PackageReference Include="Imageflow.NativeTool.win-x86" Version="2.0.0-preview8" />
<PackageReference Include="Imageflow.NativeTool.win-x86_64" Version="2.0.0-preview8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit" Version="2.*" />
<PackageReference Include="xunit.extensibility.execution" Version="2.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit.runner.visualstudio" Version="2.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -42,4 +42,4 @@
<ProjectReference Include="..\..\src\Imageflow.AllPlatforms\Imageflow.AllPlatforms.csproj" />
<ProjectReference Include="..\..\src\Imageflow\Imageflow.Net.csproj" />
</ItemGroup>
</Project>
</Project>
5 changes: 3 additions & 2 deletions tests/Imageflow.Test/NonSeekableReadStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class NonSeekableReadStream : Stream
{
private byte[] data;
private long position = 0; // Current position within the data
private long position; // =0 Current position within the data

public NonSeekableReadStream(byte[] dataSource)
{
Expand All @@ -33,7 +33,8 @@ public override void Flush()
public override int Read(byte[] buffer, int offset, int count)
{
if (buffer == null) throw new ArgumentNullException(nameof(buffer));

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)
if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException("offset or count is negative.");
if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset), "offset or count is negative.");
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), "count is negative.");
if (buffer.Length - offset < count) throw new ArgumentException("The sum of offset and count is greater than the buffer length.");

int available = data.Length - (int)position;
Expand Down
4 changes: 2 additions & 2 deletions tests/Imageflow.Test/TestApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TestApi(ITestOutputHelper output)

[Fact]
[Obsolete("Obsolete")]
public async void TestGetImageInfoLegacy()
public async Task TestGetImageInfoLegacy()
{
var imageBytes = Convert.FromBase64String(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=");
Expand All @@ -37,7 +37,7 @@ public async void TestGetImageInfoLegacy()

// test the new GetImageInfoAsync
[Fact]
public async void TestGetImageInfoAsync()
public async Task TestGetImageInfoAsync()
{
var imageBytes = Convert.FromBase64String(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=");
Expand Down

0 comments on commit 5b3288c

Please sign in to comment.