Skip to content

Commit 1c627f5

Browse files
committedNov 2, 2024
fixed remaining warnings in integration tests
1 parent f745a69 commit 1c627f5

File tree

6 files changed

+75
-30
lines changed

6 files changed

+75
-30
lines changed
 

‎.editorconfig

+48-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
indent_style = space
2-
indent_size = 2
3-
4-
[*.{cs,vb}]
1+
[*.cs]
52
#### Naming styles ####
63

74
# Naming rules
@@ -64,6 +61,7 @@ dotnet_naming_style.pascal_case.capitalization = pascal_case
6461
dotnet_style_operator_placement_when_wrapping = beginning_of_line
6562
tab_width = 2
6663
indent_size = 2
64+
indent_style = space
6765
end_of_line = crlf
6866
dotnet_style_coalesce_expression = true:suggestion
6967
dotnet_style_null_propagation = true:suggestion
@@ -88,20 +86,15 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
8886
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
8987
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
9088
dotnet_code_quality_unused_parameters = all:suggestion
91-
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
92-
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
93-
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
9489
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
9590
dotnet_style_qualification_for_field = false:silent
9691
dotnet_style_qualification_for_property = false:silent
9792
dotnet_style_qualification_for_method = false:silent
9893
dotnet_style_qualification_for_event = false:silent
9994

100-
[*.cs]
10195
csharp_indent_labels = one_less_than_current
10296
csharp_using_directive_placement = outside_namespace:silent
10397
csharp_prefer_simple_using_statement = true:suggestion
104-
csharp_prefer_braces = true:suggestion
10598
csharp_style_namespace_declarations = block_scoped:silent
10699
csharp_style_prefer_method_group_conversion = true:silent
107100
csharp_style_prefer_top_level_statements = false:silent
@@ -143,9 +136,52 @@ csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
143136
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
144137
csharp_style_prefer_not_pattern = true:suggestion
145138
csharp_style_prefer_extended_property_pattern = true:suggestion
146-
csharp_style_var_for_built_in_types = false:silent
147-
csharp_style_var_when_type_is_apparent = false:silent
148-
csharp_style_var_elsewhere = false:silent
139+
140+
# Microsoft .NET properties
141+
csharp_new_line_before_members_in_object_initializers = false
142+
csharp_preferred_modifier_order = public, private, protected, internal, file, static, volatile, async, sealed, extern, virtual, abstract, new, unsafe, override, readonly, required:suggestion
143+
csharp_prefer_braces = true:none
144+
csharp_preserve_single_line_blocks = true
145+
csharp_style_var_elsewhere = false:suggestion
146+
csharp_style_var_for_built_in_types = false:suggestion
147+
csharp_style_var_when_type_is_apparent = false:suggestion
148+
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
149+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
150+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:none
151+
152+
# ReSharper properties
153+
resharper_align_multiline_binary_expressions_chain = false
154+
resharper_blank_lines_after_block_statements = 0
155+
resharper_blank_lines_after_start_comment = 0
156+
resharper_blank_lines_after_using_list = 0
157+
resharper_blank_lines_around_property = 0
158+
resharper_blank_lines_around_single_line_local_method = 1
159+
resharper_braces_redundant = true
160+
resharper_constructor_or_destructor_body = expression_body
161+
resharper_csharp_blank_lines_around_field = 0
162+
resharper_csharp_blank_lines_around_invocable = 0
163+
resharper_csharp_blank_lines_around_region = 0
164+
resharper_csharp_blank_lines_inside_region = 0
165+
resharper_csharp_empty_block_style = together
166+
resharper_csharp_indent_size = 2
167+
resharper_csharp_keep_existing_enum_arrangement = false
168+
resharper_csharp_remove_blank_lines_near_braces_in_declarations = false
169+
resharper_csharp_wrap_before_binary_opsign = true
170+
resharper_instance_members_qualify_declared_in =
171+
resharper_max_attribute_length_for_same_line = 70
172+
resharper_method_or_operator_body = expression_body
173+
resharper_parentheses_redundancy_style = remove
174+
resharper_place_accessorholder_attribute_on_same_line = false
175+
resharper_place_expr_accessor_on_single_line = true
176+
resharper_place_expr_property_on_single_line = true
177+
resharper_place_field_attribute_on_same_line = false
178+
resharper_place_simple_initializer_on_single_line = false
179+
resharper_space_between_attribute_sections = false
180+
resharper_use_roslyn_logic_for_evident_types = true
181+
resharper_wrap_after_primary_constructor_declaration_lpar = false
182+
resharper_wrap_before_arrow_with_expressions = true
183+
resharper_wrap_object_and_collection_initializer_style = chop_always
184+
resharper_wrap_primary_constructor_parameters_style = wrap_if_long
149185

150186
# SYSLIB0003: Type or member is obsolete
151187
dotnet_diagnostic.SYSLIB0003.severity = none

‎src/integration-testing/log4net-611-lib/DerivedAppender.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using log4net.Appender;
1+
using System;
2+
using System.Diagnostics;
3+
using log4net.Appender;
24
using log4net.Core;
35

46
namespace log4net_611_lib;
@@ -7,6 +9,10 @@ public class DerivedAppender : RollingFileAppender
79
{
810
protected override void Append(LoggingEvent loggingEvent)
911
{
12+
if (loggingEvent is null)
13+
{
14+
throw new ArgumentNullException(nameof(loggingEvent));
15+
}
1016
loggingEvent.Properties["appender-class-name"] = nameof(DerivedAppender);
1117
base.Append(loggingEvent);
1218
}

‎src/integration-testing/log4net-672/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int CountIdentifierInLogs(Guid id)
7070
int CountIdentifierInFile(Guid id, string filePath)
7171
{
7272
var contents = File.ReadAllLines(filePath);
73-
return contents.Count(line => line.Contains(id.ToString()));
73+
return contents.Count(line => line.Contains(id.ToString(), StringComparison.Ordinal));
7474
}
7575

7676
int LogWith(Guid identifier, int howManyLogs)

‎src/integration-testing/log4net-673/Program.cs

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
using System.Threading;
55
using log4net;
66
using log4net.Config;
7+
using log4net.Repository;
78

8-
var appPath = new Uri(Assembly.GetExecutingAssembly().Location).LocalPath;
9-
var appFolder = Path.GetDirectoryName(appPath);
9+
string appPath = new Uri(Assembly.GetExecutingAssembly().Location).LocalPath;
10+
string appFolder = Path.GetDirectoryName(appPath);
1011
// force loading the assembly, otherwise the appender type isn't found later
1112
if (appFolder is null)
1213
{
1314
throw new InvalidOperationException("Can't find myself");
1415
}
1516

16-
var configFile = Path.Combine(appFolder, "log4net.config");
17+
string configFile = Path.Combine(appFolder, "log4net.config");
1718
if (!File.Exists(configFile))
1819
{
1920
throw new InvalidOperationException($"log4net.config not found at {configFile}");
@@ -22,28 +23,28 @@
2223
if (Directory.Exists("log"))
2324
{
2425
Console.WriteLine("Clearing out old logs...");
25-
foreach (var file in Directory.EnumerateFiles("log"))
26+
foreach (string file in Directory.EnumerateFiles("log"))
2627
{
2728
File.Delete(file);
2829
}
2930
}
3031

31-
var info = new FileInfo(configFile);
32-
var logRepo = LogManager.GetRepository(Assembly.GetExecutingAssembly());
32+
FileInfo info = new FileInfo(configFile);
33+
ILoggerRepository logRepo = LogManager.GetRepository(Assembly.GetExecutingAssembly());
3334
XmlConfigurator.ConfigureAndWatch(logRepo, info);
3435

35-
var logger = LogManager.GetLogger(typeof(Program));
36+
ILog logger = LogManager.GetLogger(typeof(Program));
3637

3738
Console.WriteLine("logging...");
38-
for (var i = 0; i < 10; i++)
39+
for (int i = 0; i < 10; i++)
3940
{
4041
logger.Info($"test log {i}");
4142
logger.Error($"error log {i}");
4243
logger.Warn($"warning log {i}");
4344
}
4445

4546

46-
foreach (var file in Directory.EnumerateFiles("log"))
47+
foreach (string file in Directory.EnumerateFiles("log"))
4748
{
4849
Console.WriteLine($"log file: {file}");
4950
TryDumpFile(file);
@@ -57,14 +58,14 @@ static void TryDumpFile(string at)
5758
return;
5859
}
5960

60-
for (var i = 0; i < 10; i++)
61+
for (int i = 0; i < 10; i++)
6162
{
6263
try
6364
{
6465
Console.WriteLine(File.ReadAllText(at));
6566
return;
6667
}
67-
catch
68+
catch(IOException)
6869
{
6970
Thread.Sleep(100);
7071
}

‎src/log4net.Tests/Appender/RollingFileAppenderTest.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static void CreateFile(int fileNumber)
171171
{
172172
fileStream.Close();
173173
}
174-
catch (Exception e) when (e is not null)
174+
catch (ObjectDisposedException)
175175
{
176176
// Ignore
177177
}
@@ -320,7 +320,7 @@ private RollingFileAppender CreateAppender(FileAppender.LockingModelBase lockMod
320320
/// Used for test purposes, a table of these objects can be used to identify
321321
/// any existing files and their expected length.
322322
/// </summary>
323-
private record RollFileEntry(string FileName, long FileLength);
323+
private sealed record RollFileEntry(string FileName, long FileLength);
324324

325325
/// <summary>
326326
/// Used for table-driven testing. This class holds information that can be used
@@ -334,7 +334,7 @@ private record RollFileEntry(string FileName, long FileLength);
334334
/// A table of entries showing files that should exist and their expected sizes
335335
/// after a message is logged
336336
/// </param>
337-
private record RollConditions(IList<RollFileEntry> PreLogFileEntries, IList<RollFileEntry> PostLogFileEntries);
337+
private sealed record RollConditions(IList<RollFileEntry> PreLogFileEntries, IList<RollFileEntry> PostLogFileEntries);
338338

339339
private static void VerifyExistenceAndRemoveFromList(List<string> existing,
340340
string fileName, FileInfo file, RollFileEntry entry)
@@ -481,6 +481,7 @@ private static List<RollFileEntry> MakeBackupFileEntriesFromBackupGroup(
481481
string backupGroup,
482482
int backupFileLength)
483483
{
484+
// ReSharper disable once ArrangeMethodOrOperatorBody
484485
return backupGroup.Split(' ')
485486
.Where(file => file.Trim().Length > 0)
486487
.Select(file => new RollFileEntry(file, backupFileLength))
@@ -527,6 +528,7 @@ private sealed record RollingStats(
527528
/// <summary>
528529
/// Number of total bytes a log file can reach.
529530
/// </summary>
531+
// ReSharper disable once MemberHidesStaticFromOuterClass
530532
public int MaximumFileSize => TotalMessageLength * MessagesPerFile;
531533

532534
/// <summary>

‎src/log4net.globalconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ dotnet_diagnostic.CA1064.severity = warning
7777
dotnet_diagnostic.CA1066.severity = warning
7878

7979
#CA1303: Do not pass literals as localized parameters
80-
dotnet_diagnostic.CA1303.severity = warning
80+
dotnet_diagnostic.CA1303.severity = none
8181

8282
#CA1307: Specify StringComparison for clarity
8383
dotnet_diagnostic.CA1307.severity = warning
@@ -137,7 +137,7 @@ dotnet_diagnostic.CA1802.severity = warning
137137
dotnet_diagnostic.CA1810.severity = warning
138138

139139
#CA1812: Avoid uninstantiated internal classes
140-
dotnet_diagnostic.CA1812.severity = warning
140+
dotnet_diagnostic.CA1812.severity = none
141141

142142
#CA1813: Avoid unsealed attributes
143143
dotnet_diagnostic.CA1813.severity = warning

0 commit comments

Comments
 (0)