Skip to content

Commit 47d0ffd

Browse files
General Improvements (#635)
* More collection expression improvements * Remove previous false-positive exception * Fix `maxEnumerations` * Disable `xUnit1042` * General style improvements
1 parent d8fd221 commit 47d0ffd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+403
-276
lines changed

.editorconfig

+158-57
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,17 @@ root = true
55
[*]
66
indent_style = tab
77
insert_final_newline = true
8-
9-
# Build scripts
10-
[*.{yml,yaml}]
11-
indent_style = spaces
12-
indent_size = 2
13-
14-
# XML project files
15-
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
16-
indent_size = 2
17-
18-
# Code files
19-
[*.cs]
20-
indent_size = 4
218
tab_width = 4
22-
charset = utf-8-bom
23-
24-
## Dotnet code style settings:
25-
26-
# Sort using and Import directives with System.* appearing first
27-
dotnet_sort_system_directives_first = true
28-
dotnet_separate_import_directive_groups = false
29-
30-
# require accessibility modifiers
31-
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error
32-
33-
# Avoid "this." and "Me." if not necessary
34-
dotnet_style_qualification_for_field = false:refactoring
35-
dotnet_style_qualification_for_property = false:refactoring
36-
dotnet_style_qualification_for_method = false:refactoring
37-
dotnet_style_qualification_for_event = false:refactoring
9+
indent_size = 4
10+
charset = utf-8
3811

39-
# Use language keywords instead of framework type names for type references
40-
dotnet_style_predefined_type_for_locals_parameters_members = true:error
41-
dotnet_style_predefined_type_for_member_access = true:suggestion
4212

43-
# Suggest more modern language features when available
44-
dotnet_style_object_initializer = true:suggestion
45-
dotnet_style_collection_initializer = true:suggestion
46-
dotnet_style_coalesce_expression = true:suggestion
47-
dotnet_style_null_propagation = true:suggestion
48-
dotnet_style_explicit_tuple_names = true:suggestion
49-
dotnet_style_prefer_compound_assignment = true:warning
13+
### Naming rules: ###
5014

5115
# Constants are PascalCase
5216
dotnet_naming_rule.constants_should_be_pascal_case.severity = suggestion
5317
dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants
54-
dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style
18+
dotnet_naming_rule.constants_should_be_pascal_case.style = non_private_static_field_style
5519

5620
dotnet_naming_symbols.constants.applicable_kinds = field, local
5721
dotnet_naming_symbols.constants.required_modifiers = const
@@ -61,7 +25,7 @@ dotnet_naming_style.constant_style.capitalization = pascal_case
6125
# Non-private readonly fields are PascalCase
6226
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.severity = suggestion
6327
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.symbols = non_private_readonly_fields
64-
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.style = non_private_readonly_field_style
28+
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.style = non_private_static_field_style
6529

6630
dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field
6731
dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected
@@ -113,7 +77,7 @@ dotnet_naming_style.camel_case_style.capitalization = camel_case
11377
# Local functions are PascalCase
11478
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
11579
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
116-
dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style
80+
dotnet_naming_rule.local_functions_should_be_pascal_case.style = non_private_static_field_style
11781

11882
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
11983

@@ -122,12 +86,85 @@ dotnet_naming_style.local_function_style.capitalization = pascal_case
12286
# By default, name items with PascalCase
12387
dotnet_naming_rule.members_should_be_pascal_case.severity = suggestion
12488
dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members
125-
dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style
89+
dotnet_naming_rule.members_should_be_pascal_case.style = non_private_static_field_style
12690

12791
dotnet_naming_symbols.all_members.applicable_kinds = *
12892

12993
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
13094

95+
96+
### Dotnet code style settings: ###
97+
98+
# Sort using and Import directives with System.* appearing first
99+
dotnet_sort_system_directives_first = true
100+
dotnet_separate_import_directive_groups = false
101+
102+
# require accessibility modifiers
103+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error
104+
105+
# Avoid "this." and "Me." if not necessary
106+
dotnet_style_qualification_for_field = false:refactoring
107+
dotnet_style_qualification_for_property = false:refactoring
108+
dotnet_style_qualification_for_method = false:refactoring
109+
dotnet_style_qualification_for_event = false:refactoring
110+
111+
# Use language keywords instead of framework type names for type references
112+
dotnet_style_predefined_type_for_locals_parameters_members = true:error
113+
dotnet_style_predefined_type_for_member_access = true:suggestion
114+
115+
# Initializers
116+
dotnet_style_object_initializer = true:suggestion
117+
dotnet_style_collection_initializer = true:suggestion
118+
dotnet_style_prefer_collection_expression = when_types_loosely_match:warning
119+
120+
# Null checks
121+
dotnet_style_coalesce_expression = true:suggestion
122+
dotnet_style_null_propagation = true:suggestion
123+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
124+
125+
# Tuple Naming
126+
dotnet_style_explicit_tuple_names = true:suggestion
127+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
128+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
129+
130+
# Assignments
131+
dotnet_style_prefer_conditional_expression_over_assignment = true:error
132+
dotnet_style_prefer_conditional_expression_over_return = true:warning
133+
dotnet_style_prefer_compound_assignment = true:warning
134+
135+
# Parenthesis
136+
dotnet_code_quality_unused_parameters = all:suggestion
137+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
138+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
139+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
140+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
141+
142+
# Miscellaneous
143+
dotnet_style_prefer_auto_properties = true:warning
144+
dotnet_style_prefer_simplified_boolean_expressions = true:warning
145+
dotnet_style_prefer_simplified_interpolation = true:warning
146+
dotnet_style_namespace_match_folder = true:warning
147+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
148+
dotnet_style_readonly_field = true:warning
149+
150+
# New-line preferences
151+
dotnet_style_allow_multiple_blank_lines_experimental = false:warning
152+
dotnet_style_allow_statement_immediately_after_block_experimental = false:warning
153+
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false:warning
154+
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false:warning
155+
156+
# Build scripts
157+
[*.{yml,yaml}]
158+
indent_style = spaces
159+
indent_size = 2
160+
161+
# XML project files
162+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
163+
indent_size = 2
164+
165+
# Code files
166+
[*.cs]
167+
131168
## C# style settings:
132169

133170
# Newline settings
@@ -165,16 +202,6 @@ csharp_style_expression_bodied_properties = true:suggestion
165202
csharp_style_expression_bodied_indexers = true:suggestion
166203
csharp_style_expression_bodied_accessors = true:suggestion
167204

168-
# Suggest more modern language features when available
169-
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
170-
csharp_style_pattern_matching_over_as_with_null_check = true:warning
171-
csharp_style_inlined_variable_declaration = true:warning
172-
csharp_style_throw_expression = true:warning
173-
csharp_style_conditional_delegate_call = true:warning
174-
csharp_style_prefer_switch_expression = true:warning
175-
csharp_prefer_simple_using_statement = true:suggestion
176-
csharp_style_namespace_declarations = file_scoped:error
177-
178205
# Space preferences
179206
csharp_space_after_cast = false
180207
csharp_space_after_colon_in_inheritance_clause = true
@@ -204,12 +231,60 @@ csharp_prefer_braces = when_multiline:silent
204231
csharp_preserve_single_line_blocks = true:silent
205232
csharp_preserve_single_line_statements = true:silent
206233

234+
# Pattern Matching
235+
csharp_style_prefer_pattern_matching = true:warning
236+
csharp_style_prefer_not_pattern = true:warning
237+
csharp_style_prefer_extended_property_pattern = true:warning
238+
csharp_style_pattern_matching_over_as_with_null_check = true:warning
239+
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
240+
241+
# Namespace
242+
csharp_style_namespace_declarations = file_scoped:error
243+
csharp_using_directive_placement = outside_namespace:warning
244+
245+
# Suggest more modern language features when available
246+
csharp_prefer_simple_default_expression = true:warning
247+
csharp_prefer_simple_using_statement = true:suggestion
248+
csharp_prefer_static_local_function = true:suggestion
249+
csharp_style_conditional_delegate_call = true:warning
250+
csharp_style_deconstructed_variable_declaration = true:warning
251+
csharp_style_expression_bodied_lambdas = true:suggestion
252+
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
253+
csharp_style_inlined_variable_declaration = true:warning
254+
csharp_style_prefer_index_operator = true:suggestion
255+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
256+
csharp_style_prefer_method_group_conversion = true:silent
257+
csharp_style_prefer_null_check_over_type_check = true:suggestion
258+
csharp_style_prefer_primary_constructors = true:warning
259+
csharp_style_prefer_range_operator = true:suggestion
260+
csharp_style_prefer_readonly_struct = true:suggestion
261+
csharp_style_prefer_readonly_struct_member = true:suggestion
262+
csharp_style_prefer_switch_expression = true:warning
263+
csharp_style_prefer_top_level_statements = true:silent
264+
csharp_style_prefer_tuple_swap = true:suggestion
265+
csharp_style_prefer_utf8_string_literals = true:suggestion
266+
csharp_style_throw_expression = true:warning
267+
csharp_style_unused_value_assignment_preference = discard_variable:warning
268+
csharp_style_unused_value_expression_statement_preference = discard_variable:warning
269+
270+
# New Lines
271+
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
272+
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
273+
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
274+
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
275+
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
276+
277+
207278
# Style Analytics
208279
dotnet_analyzer_diagnostic.category-Style.severity = warning
280+
dotnet_analyzer_diagnostic.category-Globalization.severity = error
209281

210282
dotnet_diagnostic.IDE0011.severity = silent # IDE0011: Add braces
211283
dotnet_diagnostic.IDE0046.severity = silent # IDE0046: Convert to conditional expression
212-
dotnet_diagnostic.IDE0028.severity = none # IDE0028: Simplify collection initialization
284+
dotnet_diagnostic.IDE0043.severity = error # IDE0043: Format string contains invalid placeholder
285+
dotnet_diagnostic.IDE0051.severity = warning # IDE0051: Remove unused private member
286+
dotnet_diagnostic.IDE0052.severity = warning # IDE0052: Remove unread private member
287+
dotnet_diagnostic.IDE0076.severity = warning # IDE0076: Remove invalid global 'SuppressMessageAttribute'
213288
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Simplify collection initialization
214289

215290
# XML Documentation
@@ -229,9 +304,6 @@ dotnet_diagnostic.CA2000.severity = error # CA2000: Dispose object
229304
dotnet_diagnostic.CA2007.severity = none # CA2007: Consider calling ConfigureAwait on the awaited task
230305
dotnet_diagnostic.CA5394.severity = none # CA5394: Random is an insecure random number generator. Use cryptographically secure random number generators when randomness is required for security.
231306

232-
# False Positive
233-
dotnet_diagnostic.IDE0251.severity = none # IDE0251: Make member readonly
234-
235307
# Public API Documentation
236308
dotnet_diagnostic.RS0016.severity = error # RS0016: Add public types and members to the declared API
237309
dotnet_diagnostic.RS0017.severity = error # RS0017: Remove deleted types and members from the declared API
@@ -246,3 +318,32 @@ dotnet_diagnostic.CS9107.severity = error # CS9107: Parameter is captured int
246318
dotnet_diagnostic.CS9113.severity = error # CS9113: Your class never references the primary constructor
247319
dotnet_diagnostic.CS9124.severity = error # CS9124: Parameter is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event
248320
dotnet_diagnostic.CS9179.severity = error # CS9179: Primary constructor parameter is shadowed by a member from base
321+
322+
# Regex (can't use generated regex on pre-net7)
323+
dotnet_diagnostic.SYSLIB1045.severity = none # SYSLIB1045: Use GeneratedRegexAttribute to generate the regular expression implementation at compile time.
324+
325+
# Miscellaneous analyzers
326+
dotnet_diagnostic.CA1051.severity = error # CA1051: Do not declare visible instance fields
327+
dotnet_diagnostic.CA1307.severity = error # CA1307: Specify StringComparison for clarity
328+
dotnet_diagnostic.CA1507.severity = warning # CA1507: Use `nameof` in place of string
329+
dotnet_diagnostic.CA1510.severity = error # CA1510: Use `ArgumentNullException` throw helper
330+
dotnet_diagnostic.CA1511.severity = error # CA1511: Use `ArgumentException` throw helper
331+
dotnet_diagnostic.CA1512.severity = error # CA1512: Use `ArgumentOutOfRangeException` throw helper
332+
dotnet_diagnostic.CA1513.severity = error # CA1513: Use `ObjectDisposedException` throw helper
333+
dotnet_diagnostic.CA1822.severity = warning # CA1822: Mark members as static
334+
dotnet_diagnostic.CA1825.severity = error # CA1825: Avoid zero-length array allocations
335+
dotnet_diagnostic.CA1826.severity = warning # CA1826: Use property instead of Linq Enumerable method
336+
dotnet_diagnostic.CA1827.severity = warning # CA1827: Do not use Count()/LongCount() when Any() can be used
337+
dotnet_diagnostic.CA1828.severity = warning # CA1828: Do not use CountAsync/LongCountAsync when AnyAsync can be used
338+
dotnet_diagnostic.CA1829.severity = warning # CA1829: Use Length/Count property instead of Enumerable.Count method
339+
dotnet_diagnostic.CA1841.severity = error # CA1841: Prefer Dictionary Contains methods
340+
dotnet_diagnostic.CA1845.severity = warning # CA1845: Use span-based 'string.Concat'
341+
dotnet_diagnostic.CA1852.severity = warning # CA1852: CA1852: Seal internal types
342+
dotnet_diagnostic.CA1853.severity = warning # CA1853: Unnecessary call to 'Dictionary.ContainsKey(key)'
343+
dotnet_diagnostic.CA1854.severity = warning # CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
344+
dotnet_diagnostic.CA1862.severity = warning # CA1862: Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
345+
dotnet_diagnostic.CA1863.severity = warning # CA1863: Use 'CompositeFormat'
346+
dotnet_diagnostic.CA1864.severity = warning # CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
347+
dotnet_diagnostic.CA1868.severity = warning # CA1868: Unnecessary call to 'Contains' for sets
348+
dotnet_diagnostic.CA2014.severity = error # CA2014: Do not use stackalloc in loops
349+
dotnet_diagnostic.CA2016.severity = error # CA2016: Forward the CancellationToken parameter to methods that take one

Source/SuperLinq.Async/Buffer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static async IAsyncEnumerable<IList<TSource>> Core(
6868
await foreach (var el in source.WithCancellation(cancellationToken).ConfigureAwait(false))
6969
{
7070
if (i++ % skip == 0)
71-
lists.Enqueue(new());
71+
lists.Enqueue([]);
7272

7373
foreach (var l in lists)
7474
l.Add(el);

Source/SuperLinq.Async/DensePartialSort.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static async IAsyncEnumerable<TSource> Core(IAsyncEnumerable<TSource> source, in
265265
if (top.Count < count)
266266
{
267267
_ = top.Add(key);
268-
dic[key] = new() { item, };
268+
dic[key] = [item];
269269
continue;
270270
}
271271

@@ -276,7 +276,7 @@ static async IAsyncEnumerable<TSource> Core(IAsyncEnumerable<TSource> source, in
276276
_ = dic.Remove(max);
277277
_ = top.Remove(max);
278278
_ = top.Add(key);
279-
dic[key] = new() { item, };
279+
dic[key] = [item];
280280
}
281281

282282
foreach (var entry in top)

Source/SuperLinq.Async/Do.cs

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static async IAsyncEnumerable<TSource> Core(
9898
await onNext(el).ConfigureAwait(false);
9999
yield return el;
100100
}
101+
101102
await onCompleted().ConfigureAwait(false);
102103
}
103104
}
@@ -220,6 +221,7 @@ static async IAsyncEnumerable<TSource> Core(
220221
await onNext(current).ConfigureAwait(false);
221222
yield return current;
222223
}
224+
223225
await onCompleted().ConfigureAwait(false);
224226
}
225227
}

Source/SuperLinq.Async/FillBackward.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private static async IAsyncEnumerable<T> FillBackwardImpl<T>(IAsyncEnumerable<T>
219219
var isBlank = await predicate(item).ConfigureAwait(false);
220220
if (isBlank)
221221
{
222-
(blanks ??= new List<T>()).Add(item);
222+
(blanks ??= []).Add(item);
223223
}
224224
else
225225
{
@@ -234,6 +234,7 @@ private static async IAsyncEnumerable<T> FillBackwardImpl<T>(IAsyncEnumerable<T>
234234

235235
blanks.Clear();
236236
}
237+
237238
yield return item;
238239
}
239240
}

Source/SuperLinq.Async/GroupAdjacent.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private static async IAsyncEnumerable<TResult> GroupAdjacentImpl<TSource, TKey,
286286
{
287287
yield return resultSelector(k, members);
288288
k = key;
289-
members = new List<TElement> { element };
289+
members = [element];
290290
}
291291
}
292292

Source/SuperLinq.Async/Interleave.cs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static IAsyncEnumerable<T> Interleave<T>(this IAsyncEnumerable<T> source,
3131
return Interleave(otherSources.Prepend(source));
3232
}
3333

34-
3534
/// <summary>
3635
/// Interleaves the elements of two or more sequences into a single sequence, skipping sequences as they are consumed
3736
/// </summary>

Source/SuperLinq.Async/Memoize.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ IAsyncEnumerable<T> source
4141
private IAsyncEnumerable<T>? _source = source;
4242

4343
private IAsyncEnumerator<T>? _enumerator;
44-
private List<T> _buffer = new();
44+
private List<T> _buffer = [];
4545
private bool _initialized;
4646

4747
private ExceptionDispatchInfo? _exception;
@@ -62,7 +62,7 @@ public async ValueTask Reset(CancellationToken cancellationToken = default)
6262
if (_disposed)
6363
ThrowHelper.ThrowObjectDisposedException<IAsyncBuffer<T>>();
6464

65-
_buffer = new();
65+
_buffer = [];
6666
_initialized = false;
6767
if (_enumerator != null)
6868
await _enumerator.DisposeAsync().ConfigureAwait(false);

Source/SuperLinq.Async/Publish.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToke
100100
try
101101
{
102102
_enumerator = _source.GetAsyncEnumerator(cancellationToken);
103-
_buffers = new();
103+
_buffers = [];
104104
_initialized = true;
105105
}
106106
catch (Exception ex)

Source/SuperLinq.Async/Segment.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static async IAsyncEnumerable<IReadOnlyList<T>> Core(IAsyncEnumerable<T> source,
136136
if (await newSegmentPredicate(current, previous, index).ConfigureAwait(false))
137137
{
138138
yield return segment; // yield the completed segment
139-
segment = new List<T> { current }; // start a new segment
139+
segment = [current]; // start a new segment
140140
}
141141
else // not a new segment, append and continue
142142
{

0 commit comments

Comments
 (0)