Skip to content

Commit 67889cd

Browse files
authored
Resolve ReSharper 2025.2 warnings (#85)
1 parent 0a6c870 commit 67889cd

File tree

10 files changed

+42
-28
lines changed

10 files changed

+42
-28
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ csharp_style_var_for_built_in_types = false:none
5757
csharp_style_var_when_type_is_apparent = true:suggestion
5858
csharp_style_var_elsewhere = true:none
5959
csharp_style_namespace_declarations = file_scoped
60+
csharp_style_prefer_utf8_string_literals = false:suggestion
6061
csharp_prefer_braces = when_multiline:suggestion
6162

6263
dotnet_sort_system_directives_first = true
@@ -67,4 +68,9 @@ dotnet_style_qualification_for_field = false:suggestion
6768
dotnet_style_qualification_for_method = false:suggestion
6869
dotnet_style_qualification_for_property = false:suggestion
6970

71+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
72+
73+
resharper_remove_redundant_braces_highlighting=none # Not compatible with using no braces when throwing.
74+
resharper_arrange_redundant_parentheses_highlighting=none # Complains about parentheses with mixed operators.
75+
7076

.globalconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ dotnet_diagnostic.IDE0046.severity = none
6868
# IDE0010: Add missing swtich cases
6969
# Rational: Conflicts with code coverage.
7070
dotnet_diagnostic.IDE0010.severity = none
71+
72+
# IDE0011: Add braces
73+
# Rational: Cannot handle that mixed usage of single line, multi line and non for throwing exceptions.
74+
dotnet_diagnostic.IDE0011.severity = none
75+
76+
# IDE0011: Remove unnecessary parentheses
77+
# Rational: dotnet_style_parentheses_in_arithmetic_binary_operators doesn't always work
78+
dotnet_diagnostic.IDE0047.severity = none

CharLSDotNet.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeRedundantParentheses/@EntryIndexedValue">DO_NOT_SHOW</s:String>
23
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
34
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ParameterOnlyUsedForPreconditionCheck_002ELocal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
45
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BT/@EntryIndexedValue">BT</s:String>

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
44
<PackageVersion Include="SharpFuzz" Version="2.2.0" />
55
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
6-
<PackageVersion Include="xunit.v3" Version="3.0.0" />
7-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.3" />
6+
<PackageVersion Include="xunit.v3" Version="3.0.1" />
7+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
88
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
99
<PackageVersion Include="BenchmarkDotNet" Version="0.15.2" />
1010
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />

benchmark/Micro/Abs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace CharLS.Managed.Benchmark.Micro;
88

99
public class Abs
1010
{
11-
private int[] _source = default!;
12-
private int[] _destination = default!;
11+
private int[] _source = null!;
12+
private int[] _destination = null!;
1313

1414
[Params(65536)]
1515
public int BufferCount { get; set; }
@@ -70,7 +70,7 @@ public void InRangeWithNoAbs()
7070
{
7171
for (int i = 0; i != _source.Length; i++)
7272
{
73-
if (_source![i] < 5000 || _source[i]> 5000)
73+
if (_source[i] is < 5000 or > 5000)
7474
{
7575
_destination[i] = _source[i];
7676
}

benchmark/Micro/BlockCopy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace CharLS.Managed.Benchmark.Micro;
99

1010
public class BlockCopy
1111
{
12-
private byte[] _source = default!;
13-
private byte[] _destination = default!;
12+
private byte[] _source = null!;
13+
private byte[] _destination = null!;
1414

1515
[Params(65536)]
1616
public int BufferCount { get; set; }

benchmark/Micro/ComputeReconstructedSample.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ namespace CharLS.Managed.Benchmark.Micro;
77

88
public class ComputeReconstructedSample
99
{
10-
private Traits _traits = default!;
11-
private Traits _traitsLossy = default!;
12-
private Traits _losslessTraits = default!;
13-
private Traits _losslessTraits8 = default!;
14-
private Traits _losslessTraits16 = default!;
10+
private Traits _traits = null!;
11+
private Traits _traitsLossy = null!;
12+
private Traits _losslessTraits = null!;
13+
private Traits _losslessTraits8 = null!;
14+
private Traits _losslessTraits16 = null!;
1515
private int _predictedValue;
1616
private int _errorValue;
1717

benchmark/Micro/GenericColorTransformation.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ internal TripletByte(byte v1, byte v2, byte v3)
4040

4141
public class ColorTransformation
4242
{
43-
private byte[] _source = default!;
44-
private byte[] _destination = default!;
43+
private byte[] _source = null!;
44+
private byte[] _destination = null!;
4545

4646
[Params(2000)]
4747
public int PixelCount { get; set; }
@@ -81,7 +81,7 @@ internal static int TransformHP1IntParametersReturnUint(int red, int green, int
8181
const int range = 1 << (sizeof(byte) * 8);
8282

8383
return
84-
(((byte)(red - green + (range / 2))) << 16) |
84+
((byte)(red - green + (range / 2)) << 16) |
8585
((byte)green << 8) |
8686
(byte)(blue - green + (range / 2));
8787
}
@@ -164,15 +164,15 @@ public void TransformHP1ExplicitIntParametersWithRef()
164164
[Benchmark]
165165
public unsafe void TransformHP1ExplicitIntParametersWithPointers()
166166
{
167-
fixed (byte* bptr = _source, pd = _destination)
167+
fixed (byte* source = _source, pd = _destination)
168168
{
169-
var sourcePTr = (Triplet<byte>*)bptr;
169+
var sourcePtr = (Triplet<byte>*)source;
170170
var destinationPtr = (Triplet<byte>*)pd;
171-
Triplet<byte>* endPtr = sourcePTr + PixelCount;
171+
Triplet<byte>* endPtr = sourcePtr + PixelCount;
172172

173-
for (; sourcePTr != endPtr; sourcePTr++, destinationPtr++)
173+
for (; sourcePtr != endPtr; sourcePtr++, destinationPtr++)
174174
{
175-
*destinationPtr = TransformHP1IntParameters(sourcePTr->V1, sourcePTr->V2, sourcePTr->V3);
175+
*destinationPtr = TransformHP1IntParameters(sourcePtr->V1, sourcePtr->V2, sourcePtr->V3);
176176
}
177177
}
178178
}

samples/Convert/Program.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Team CharLS.
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
using System.Diagnostics.CodeAnalysis;
54
using System.Drawing;
65
using System.Drawing.Imaging;
76
using CharLS.Managed;
@@ -84,7 +83,7 @@
8483
// chose for the in-memory representation of the bitmap data.
8584
// PNG 8bits/grayscale is loaded as PixelFormat32bppARGB
8685
// JPG/TIFF 8bits/grayscale are loaded as PixelFormat8bppIndexed
87-
bool TryGetFrameInfoAndPixelFormat(Image sourceImage, [NotNullWhen(true)] out FrameInfo frameInfo, out PixelFormat filePixelFormat)
86+
static bool TryGetFrameInfoAndPixelFormat(Image sourceImage, out FrameInfo frameInfo, out PixelFormat filePixelFormat)
8887
{
8988
var pixelFormat = sourceImage.PixelFormat;
9089
var flags = sourceImage.Flags;
@@ -117,18 +116,18 @@ bool TryGetFrameInfoAndPixelFormat(Image sourceImage, [NotNullWhen(true)] out Fr
117116
return filePixelFormat != default;
118117
}
119118

120-
string GetOutputPath(string inputPathArg)
119+
static string GetOutputPath(string inputPathArg)
121120
{
122121
return Path.ChangeExtension(inputPathArg, ".jls");
123122
}
124123

125-
void Save(string path, ReadOnlySpan<byte> encodedData)
124+
static void Save(string path, ReadOnlySpan<byte> encodedData)
126125
{
127126
using FileStream output = new(path, FileMode.OpenOrCreate);
128127
output.Write(encodedData);
129128
}
130129

131-
bool TryParseArguments(IReadOnlyList<string> args, out string inputPathArg)
130+
static bool TryParseArguments(IReadOnlyList<string> args, out string inputPathArg)
132131
{
133132
if (args.Count != 1)
134133
{
@@ -140,7 +139,7 @@ bool TryParseArguments(IReadOnlyList<string> args, out string inputPathArg)
140139
return true;
141140
}
142141

143-
void ConvertBgrToRgb(Span<byte> pixels, int width, int height, int stride)
142+
static void ConvertBgrToRgb(Span<byte> pixels, int width, int height, int stride)
144143
{
145144
const int bytesPerRgbPixel = 3;
146145

@@ -158,7 +157,7 @@ void ConvertBgrToRgb(Span<byte> pixels, int width, int height, int stride)
158157
}
159158
}
160159

161-
SpiffColorSpace MapComponentCountToSpiffColorSpace(int componentCount)
160+
static SpiffColorSpace MapComponentCountToSpiffColorSpace(int componentCount)
162161
{
163162
return componentCount switch
164163
{

test/TraitsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void ModuloRange()
2525
{
2626
var errorValue = traits.ModuloRange(i);
2727
const int range = 24 + 1;
28-
Assert.True(errorValue is >= (-range / 2) and <= (((range + 1) / 2) - 1));
28+
Assert.True(errorValue is >= -range / 2 and <= ((range + 1) / 2) - 1);
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)