Skip to content

Commit 88510e2

Browse files
committed
Add analyzers
1 parent 2ce5380 commit 88510e2

7 files changed

Lines changed: 318 additions & 16 deletions

File tree

.editorconfig

Lines changed: 286 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dotnet_style_null_propagation = true:suggestion
4242
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
4343
dotnet_style_prefer_auto_properties = true:silent
4444
dotnet_style_object_initializer = true:suggestion
45-
dotnet_style_prefer_collection_expression = true:suggestion
45+
dotnet_style_prefer_collection_expression = when_types_exactly_match:suggestion
4646
dotnet_style_collection_initializer = true:suggestion
4747
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
4848
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
@@ -156,3 +156,288 @@ dotnet_style_qualification_for_method = false:silent
156156
dotnet_style_qualification_for_property = false:silent
157157
dotnet_style_qualification_for_event = false:silent
158158
indent_style = tab
159+
160+
roslynator_refactorings.enabled = true
161+
roslynator_compiler_diagnostic_fixes.enabled = true
162+
roslynator_refactoring.remove_all_comments.enabled = true
163+
164+
165+
166+
# Roslynator settings
167+
168+
roslynator_accessibility_modifiers = explicit
169+
# Applicable to: rcs1018
170+
171+
roslynator_accessor_braces_style = single_line_when_expression_is_on_single_line
172+
# Default: multi_line
173+
# Applicable to: rcs0020
174+
175+
roslynator_array_creation_type_style = implicit
176+
# Applicable to: rcs1014
177+
178+
roslynator_arrow_token_new_line = before
179+
# Applicable to: rcs0032
180+
181+
roslynator_binary_operator_new_line = before
182+
# Applicable to: rcs0027
183+
184+
roslynator_blank_line_after_file_scoped_namespace_declaration = true
185+
# Applicable to: rcs0060
186+
187+
roslynator_blank_line_between_closing_brace_and_switch_section = false
188+
# Applicable to: rcs0014, rcs1036
189+
190+
roslynator_conditional_operator_condition_parentheses_style = omit
191+
# Applicable to: rcs1051
192+
193+
roslynator_conditional_operator_new_line = before
194+
# Applicable to: rcs0028
195+
196+
roslynator_configure_await = true
197+
# Applicable to: rcs1090
198+
199+
roslynator_doc_comment_summary_style = multi_line
200+
# Applicable to: rcs1253
201+
202+
roslynator_empty_string_style = field
203+
# Applicable to: rcs1078
204+
205+
roslynator_enum_flag_value_style = shift_operator
206+
# Applicable to: rcs1254
207+
208+
roslynator_enum_has_flag_style = method
209+
# Applicable to: rcs1096
210+
211+
roslynator_infinite_loop_style = while
212+
# Applicable to: rcs1252
213+
214+
roslynator_null_check_style = pattern_matching
215+
# Applicable to: rcs1248
216+
217+
roslynator_null_conditional_operator_new_line = before
218+
# Applicable to: rcs0059
219+
220+
roslynator_object_creation_parentheses_style = omit
221+
# Applicable to: rcs1050
222+
223+
roslynator_object_creation_type_style = implicit
224+
# Applicable to: rcs1250
225+
226+
roslynator_prefix_field_identifier_with_underscore = true
227+
228+
roslynator_trailing_comma_style = include
229+
# Applicable to: rcs1260
230+
231+
roslynator_use_anonymous_function_or_method_group = method_group
232+
# Applicable to: rcs1207
233+
234+
roslynator_use_block_body_when_declaration_spans_over_multiple_lines = true
235+
# Applicable to: rcs1016
236+
237+
roslynator_use_block_body_when_expression_spans_over_multiple_lines = true
238+
# Applicable to: rcs1016
239+
240+
roslynator_use_collection_expression = true
241+
# Applicable to: rcs1014, rcs1250
242+
243+
roslynator_use_var = always
244+
# Applicable to: rcs1264
245+
246+
roslynator_use_var_instead_of_implicit_object_creation = true
247+
# Applicable to: rcs1250
248+
249+
250+
# Analyzers
251+
252+
# Add blank line after embedded statement
253+
dotnet_diagnostic.rcs0001.severity = warning
254+
255+
# Add blank line after using directive list
256+
dotnet_diagnostic.rcs0003.severity = suggestion
257+
258+
# Add blank line between closing brace and next statement
259+
dotnet_diagnostic.rcs0008.severity = suggestion
260+
261+
# Add blank line between declaration and documentation comment
262+
dotnet_diagnostic.rcs0009.severity = suggestion
263+
264+
# Format accessor's braces on a single line or multiple lines
265+
dotnet_diagnostic.rcs0020.severity = suggestion
266+
# Options: roslynator_accessor_braces_style
267+
268+
# Format block's braces on a single line or multiple lines
269+
dotnet_diagnostic.rcs0021.severity = suggestion
270+
# Options: roslynator_block_braces_style
271+
272+
# Put full accessor on its own line
273+
dotnet_diagnostic.rcs0025.severity = warning
274+
275+
# Place new line after/before binary operator
276+
dotnet_diagnostic.rcs0027.severity = suggestion
277+
# Options: roslynator_binary_operator_new_line
278+
279+
# Place new line after/before '?:' operator
280+
dotnet_diagnostic.rcs0028.severity = suggestion
281+
# Options: roslynator_conditional_operator_new_line
282+
283+
# Put enum member on its own line
284+
dotnet_diagnostic.rcs0031.severity = suggestion
285+
286+
# Place new line after/before arrow token
287+
dotnet_diagnostic.rcs0032.severity = suggestion
288+
# Options: roslynator_arrow_token_new_line
289+
290+
# Put statement on its own line
291+
dotnet_diagnostic.rcs0033.severity = error
292+
293+
# Put type parameter constraint on its own line
294+
dotnet_diagnostic.rcs0034.severity = suggestion
295+
296+
# Remove new line between 'if' keyword and 'else' keyword
297+
dotnet_diagnostic.rcs0041.severity = warning
298+
299+
# Put auto-accessors on a single line
300+
dotnet_diagnostic.rcs0042.severity = suggestion
301+
302+
# Fix formatting of a binary expression chain
303+
dotnet_diagnostic.rcs0055.severity = suggestion
304+
305+
# Place new line after/before null-conditional operator
306+
dotnet_diagnostic.rcs0059.severity = suggestion
307+
# Options: roslynator_null_conditional_operator_new_line
308+
309+
# Add/remove line after file scoped namespace declaration
310+
dotnet_diagnostic.rcs0060.severity = suggestion
311+
# Options: roslynator_blank_line_after_file_scoped_namespace_declaration
312+
313+
# Simplify nested using statement
314+
dotnet_diagnostic.rcs1005.severity = suggestion
315+
316+
# Use predefined type
317+
dotnet_diagnostic.rcs1013.severity = suggestion
318+
319+
# Use explicitly/implicitly typed array
320+
dotnet_diagnostic.rcs1014.severity = suggestion
321+
# Options: roslynator_array_creation_type_style, roslynator_use_collection_expression
322+
323+
# Use block body or expression body
324+
dotnet_diagnostic.rcs1016.severity = suggestion
325+
# Options: roslynator_body_style, roslynator_use_block_body_when_declaration_spans_over_multiple_lines, roslynator_use_block_body_when_expression_spans_over_multiple_lines
326+
327+
# Add/remove accessibility modifiers
328+
dotnet_diagnostic.rcs1018.severity = suggestion
329+
# Options: roslynator_accessibility_modifiers
330+
331+
# Order modifiers
332+
dotnet_diagnostic.rcs1019.severity = suggestion
333+
334+
# Remove 'partial' modifier from type with a single part
335+
dotnet_diagnostic.rcs1043.severity = warning
336+
337+
# Include/omit parentheses when creating new object
338+
dotnet_diagnostic.rcs1050.severity = suggestion
339+
# Options: roslynator_object_creation_parentheses_style
340+
341+
# Add/remove parentheses from condition in conditional operator
342+
dotnet_diagnostic.rcs1051.severity = suggestion
343+
# Options: roslynator_conditional_operator_condition_parentheses_style
344+
345+
# Unnecessary semicolon at the end of declaration
346+
dotnet_diagnostic.rcs1055.severity = suggestion
347+
348+
# Remove redundant constructor
349+
dotnet_diagnostic.rcs1074.severity = suggestion
350+
351+
# Use "" or 'string.Empty'
352+
dotnet_diagnostic.rcs1078.severity = suggestion
353+
# Options: roslynator_empty_string_style
354+
355+
# Use 'Count/Length' property instead of 'Any' method
356+
dotnet_diagnostic.rcs1080.severity = suggestion
357+
358+
# Split variable declaration
359+
dotnet_diagnostic.rcs1081.severity = suggestion
360+
361+
# Add/remove 'ConfigureAwait(false)' call
362+
dotnet_diagnostic.rcs1090.severity = suggestion
363+
# Options: roslynator_configure_await
364+
365+
# Declare using directive on top level
366+
dotnet_diagnostic.rcs1094.severity = suggestion
367+
368+
# Use 'HasFlag' method or bitwise operator
369+
dotnet_diagnostic.rcs1096.severity = suggestion
370+
# Options: roslynator_enum_has_flag_style
371+
372+
# Declare type inside namespace
373+
dotnet_diagnostic.rcs1110.severity = warning
374+
375+
# Add braces to if-else
376+
dotnet_diagnostic.rcs1126.severity = suggestion
377+
378+
# Bitwise operation on enum without Flags attribute
379+
dotnet_diagnostic.rcs1130.severity = warning
380+
381+
# Remove redundant Dispose/Close call
382+
dotnet_diagnostic.rcs1133.severity = warning
383+
384+
# Remove redundant statement
385+
dotnet_diagnostic.rcs1134.severity = suggestion
386+
387+
# Add exception to documentation comment
388+
dotnet_diagnostic.rcs1140.severity = warning
389+
390+
# Value type object is never equal to null
391+
dotnet_diagnostic.rcs1166.severity = warning
392+
393+
# Parameter name differs from base name
394+
dotnet_diagnostic.rcs1168.severity = suggestion
395+
396+
# Remove redundant auto-property initialization
397+
dotnet_diagnostic.rcs1188.severity = suggestion
398+
399+
# Avoid unnecessary boxing of value type
400+
dotnet_diagnostic.rcs1198.severity = suggestion
401+
402+
# Avoid NullReferenceException
403+
dotnet_diagnostic.rcs1202.severity = warning
404+
405+
# Use anonymous function or method group
406+
dotnet_diagnostic.rcs1207.severity = suggestion
407+
# Options: roslynator_use_anonymous_function_or_method_group
408+
409+
# Reduce 'if' nesting
410+
dotnet_diagnostic.rcs1208.severity = suggestion
411+
412+
# Use async/await when necessary
413+
dotnet_diagnostic.rcs1229.severity = warning
414+
415+
# Duplicate enum value
416+
dotnet_diagnostic.rcs1234.severity = warning
417+
418+
# Avoid nested ?: operators
419+
dotnet_diagnostic.rcs1238.severity = warning
420+
421+
# Normalize null check
422+
dotnet_diagnostic.rcs1248.severity = suggestion
423+
# Options: roslynator_null_check_style
424+
425+
# Use implicit/explicit object creation
426+
dotnet_diagnostic.rcs1250.severity = suggestion
427+
# Options: roslynator_object_creation_type_style, roslynator_use_collection_expression, roslynator_use_var_instead_of_implicit_object_creation
428+
429+
# Simplify argument null check
430+
dotnet_diagnostic.rcs1255.severity = suggestion
431+
432+
# Add/remove trailing comma
433+
dotnet_diagnostic.rcs1260.severity = suggestion
434+
# Options: roslynator_trailing_comma_style
435+
436+
# Use 'var' or explicit type
437+
dotnet_diagnostic.rcs1264.severity = suggestion
438+
# Options: roslynator_use_var
439+
440+
# Refactorings
441+
442+
roslynator_refactoring.replace_method_with_property.enabled = true
443+
roslynator_refactoring.use_string_empty_instead_of_empty_string_literal.enabled = true

AsyncMemoryCache.Tests/AsyncMemoryCache.Tests.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
22-
<PrivateAssets>all</PrivateAssets>
23-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
</PackageReference>
2525
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3">
26-
<PrivateAssets>all</PrivateAssets>
27-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
26+
<PrivateAssets>all</PrivateAssets>
27+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2828
</PackageReference>
2929
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
3030
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.1.0" />
3131
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
3232
<PackageReference Include="NSubstitute" Version="5.1.0" />
33+
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
34+
<PrivateAssets>all</PrivateAssets>
35+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
36+
</PackageReference>
3337
<PackageReference Include="xunit" Version="2.6.6" />
3438
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
3539
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

AsyncMemoryCache/AsyncMemoryCache.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
6-
6+
77
<EnableNETAnalyzers>true</EnableNETAnalyzers>
88
<AnalysisLevel>preview</AnalysisLevel>
9-
9+
1010
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1111
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
1212
</PropertyGroup>
13-
13+
1414
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
1515
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1616
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
@@ -24,7 +24,7 @@
2424
<Authors>calledude</Authors>
2525

2626
<PublishRepositoryUrl>true</PublishRepositoryUrl>
27-
27+
2828
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2929
<PackageReadmeFile>README.md</PackageReadmeFile>
3030
<PackageTags>asyncmemorycache async cache lazy dispose</PackageTags>
@@ -37,6 +37,16 @@
3737
<ItemGroup>
3838
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
3939
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
40+
41+
<PackageReference Include="Roslynator.Analyzers" Version="4.10.0">
42+
<PrivateAssets>all</PrivateAssets>
43+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
44+
</PackageReference>
45+
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.10.0">
46+
<PrivateAssets>all</PrivateAssets>
47+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
48+
</PackageReference>
49+
4050
</ItemGroup>
4151

4252
<ItemGroup>

AsyncMemoryCache/CacheEntity.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ public sealed class CacheEntity<TKey, TValue>
1212
public CacheEntity(TKey key, Func<Task<TValue>> objectFactory, AsyncLazyFlags lazyFlags)
1313
{
1414
Key = key;
15-
ObjectFactory = new AsyncLazy<TValue>(objectFactory, lazyFlags);
15+
ObjectFactory = new(objectFactory, lazyFlags);
1616
}
1717

1818
public TKey Key { get; }
19-
2019
public AsyncLazy<TValue> ObjectFactory { get; }
2120

2221
private int _references;

0 commit comments

Comments
 (0)