Skip to content

Commit dbb6d7b

Browse files
authored
enable code analysis (#446)
1 parent 1352584 commit dbb6d7b

17 files changed

+51
-23
lines changed

.editorconfig

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
115115
# Wrapping preferences
116116
csharp_preserve_single_line_statements = true
117117
csharp_preserve_single_line_blocks = true
118-
###############################
119-
# VB Coding Conventions #
120-
###############################
121-
[*.vb]
122-
# Modifier preferences
123-
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion
118+
119+
# code analysis
120+
dotnet_diagnostic.IDE0079.severity = none
121+
dotnet_diagnostic.CA1805.severity = none
122+
dotnet_diagnostic.CA1815.severity = none

BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,10 +876,7 @@ private void VerifyHits(int iterations, int minSamples)
876876

877877
// verify this doesn't block or throw
878878
var b = cache.Scheduler as BackgroundThreadScheduler;
879-
if (b is not null)
880-
{
881-
b.Dispose();
882-
}
879+
b?.Dispose();
883880
}
884881

885882
private void LogLru()

BitFaster.Caching/Atomic/AsyncAtomicFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public async ValueTask<V> CreateValueAsync<TFactory>(K key, TFactory valueFactor
136136
return await synchronizedTask.ConfigureAwait(false);
137137
}
138138

139+
#pragma warning disable CA2002 // Do not lock on objects with weak identity
139140
private Task<V> DoubleCheck(Task<V> value)
140141
{
141142
// Fast path
@@ -155,6 +156,7 @@ private Task<V> DoubleCheck(Task<V> value)
155156

156157
return valueTask;
157158
}
159+
#pragma warning restore CA2002 // Do not lock on objects with weak identity
158160
}
159161
}
160162
}

BitFaster.Caching/Atomic/AtomicFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public override int GetHashCode()
133133
return ValueIfCreated.GetHashCode();
134134
}
135135

136+
#pragma warning disable CA2002 // Do not lock on objects with weak identity
136137
private class Initializer
137138
{
138139
private bool isInitialized;
@@ -153,5 +154,6 @@ public V CreateValue<TFactory>(K key, TFactory valueFactory) where TFactory : st
153154
}
154155
}
155156
}
157+
#pragma warning restore CA2002 // Do not lock on objects with weak identity
156158
}
157159
}

BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ public AtomicFactoryScopedAsyncCache(ICache<K, ScopedAsyncAtomicFactory<K, V>> c
5454
///<inheritdoc/>
5555
public ICollection<K> Keys => AtomicEx.FilterKeys<K, ScopedAsyncAtomicFactory<K, V>>(this.cache, v => v.IsScopeCreated);
5656

57+
#pragma warning disable CA2000 // Dispose objects before losing scope
5758
///<inheritdoc/>
5859
public void AddOrUpdate(K key, V value)
5960
{
6061
this.cache.AddOrUpdate(key, new ScopedAsyncAtomicFactory<K, V>(value));
6162
}
63+
#pragma warning restore CA2000 // Dispose objects before losing scope
6264

6365
///<inheritdoc/>
6466
public void Clear()
@@ -129,11 +131,13 @@ public bool TryRemove(K key)
129131
return this.cache.TryRemove(key);
130132
}
131133

134+
#pragma warning disable CA2000 // Dispose objects before losing scope
132135
///<inheritdoc/>
133136
public bool TryUpdate(K key, V value)
134137
{
135138
return this.cache.TryUpdate(key, new ScopedAsyncAtomicFactory<K, V>(value));
136139
}
140+
#pragma warning restore CA2000 // Dispose objects before losing scope
137141

138142
///<inheritdoc/>
139143
public IEnumerator<KeyValuePair<K, Scoped<V>>> GetEnumerator()

BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ public AtomicFactoryScopedCache(ICache<K, ScopedAtomicFactory<K, V>> cache)
5454
///<inheritdoc/>
5555
public ICollection<K> Keys => AtomicEx.FilterKeys<K, ScopedAtomicFactory<K, V>>(this.cache, v => v.IsScopeCreated);
5656

57+
#pragma warning disable CA2000 // Dispose objects before losing scope
5758
///<inheritdoc/>
5859
public void AddOrUpdate(K key, V value)
5960
{
6061
this.cache.AddOrUpdate(key, new ScopedAtomicFactory<K, V>(value));
6162
}
63+
#pragma warning restore CA2000 // Dispose objects before losing scope
6264

6365
///<inheritdoc/>
6466
public void Clear()
@@ -129,11 +131,13 @@ public bool TryRemove(K key)
129131
return this.cache.TryRemove(key);
130132
}
131133

134+
#pragma warning disable CA2000 // Dispose objects before losing scope
132135
///<inheritdoc/>
133136
public bool TryUpdate(K key, V value)
134137
{
135138
return this.cache.TryUpdate(key, new ScopedAtomicFactory<K, V>(value));
136139
}
140+
#pragma warning restore CA2000 // Dispose objects before losing scope
137141

138142
///<inheritdoc/>
139143
public IEnumerator<KeyValuePair<K, Scoped<V>>> GetEnumerator()

BitFaster.Caching/Atomic/ScopedAsyncAtomicFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public async ValueTask<Scoped<V>> CreateScopeAsync<TFactory>(K key, TFactory val
182182
return await synchronizedTask.ConfigureAwait(false);
183183
}
184184

185+
#pragma warning disable CA2002 // Do not lock on objects with weak identity
185186
private Task<Scoped<V>> DoubleCheck(Task<Scoped<V>> value)
186187
{
187188
// Fast path
@@ -201,6 +202,7 @@ private Task<Scoped<V>> DoubleCheck(Task<Scoped<V>> value)
201202

202203
return task;
203204
}
205+
#pragma warning restore CA2002 // Do not lock on objects with weak identity
204206

205207
// <remarks>
206208
// Let's say there are 2 threads, A and B:

BitFaster.Caching/Atomic/ScopedAtomicFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public void Dispose()
156156
scope.Dispose();
157157
}
158158

159+
#pragma warning disable CA2002 // Do not lock on objects with weak identity
159160
private class Initializer
160161
{
161162
private bool isInitialized;
@@ -196,5 +197,6 @@ public Scoped<V> TryCreateDisposedScope()
196197
}
197198
}
198199
}
200+
#pragma warning restore CA2002 // Do not lock on objects with weak identity
199201
}
200202
}

BitFaster.Caching/BitFaster.Caching.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
3636
</PropertyGroup>
3737

38+
<PropertyGroup>
39+
<AnalysisModePerformance>All</AnalysisModePerformance>
40+
<AnalysisModeDocumentation>All</AnalysisModeDocumentation>
41+
<AnalysisModeInteroperability>All</AnalysisModeInteroperability>
42+
<AnalysisModeReliability>All</AnalysisModeReliability>
43+
</PropertyGroup>
44+
3845
<ItemGroup>
3946
<None Include="..\LICENSE">
4047
<Pack>True</Pack>

BitFaster.Caching/Lfu/CmSketchCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace BitFaster.Caching.Lfu
2424
/// https://github.com/ben-manes/caffeine
2525
public class CmSketchCore<T, I> where I : struct, IsaProbe
2626
{
27-
private static readonly long ResetMask = 0x7777777777777777L;
28-
private static readonly long OneMask = 0x1111111111111111L;
27+
private const long ResetMask = 0x7777777777777777L;
28+
private const long OneMask = 0x1111111111111111L;
2929

3030
private long[] table;
3131
private int sampleSize;

0 commit comments

Comments
 (0)