Enhance coding conventions and static analysis setup; update .editorconfig, scanner.sh, and various C# files for improved readability and performance

This commit is contained in:
Miha Kralj
2025-12-04 14:36:00 -08:00
parent 967096d4f5
commit ee358bfdd9
9 changed files with 31 additions and 4 deletions
+10
View File
@@ -13,3 +13,13 @@ insert_final_newline = true
# Suppress SonarQube S3776 - Cognitive Complexity
# High-performance SIMD code intentionally has complex control flow
dotnet_diagnostic.S3776.severity = none
#### C# Coding Conventions ####
# "var" preferences
# Prefer explicit types for built-in types (e.g. int, double, string) - reduces noise in math-heavy code
csharp_style_var_for_built_in_types = false:silent
# Prefer var when the type is already mentioned on the right side (e.g. new List<int>())
csharp_style_var_when_type_is_apparent = true:suggestion
# Prefer explicit types in other cases to improve readability of math formulas
csharp_style_var_elsewhere = false:silent
+6
View File
@@ -200,6 +200,12 @@ if [ "$SKIP_QODANA" = false ]; then
if command -v qodana &> /dev/null; then
log_info "Starting Qodana analysis..."
# Install dependencies required for Qodana (IntelliJ) on minimal Debian
if ! dpkg -s libfreetype6 fontconfig &> /dev/null; then
log_info "Installing missing dependencies (libfreetype6, fontconfig)..."
apt-get update && apt-get install -y libfreetype6 fontconfig
fi
export CI=true
qodana scan --within-docker=false -l qodana-dotnet --coverage-dir "$COVERAGE_DIR" || true
-2
View File
@@ -164,8 +164,6 @@
"dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true,
"dotnet.server.useOmnisharp": false,
"testing.automaticallyOpenPeekView": "never",
"testing.openTesting": "neverOpen",
"sonarlint.connectedMode.project": {
"connectionId": "mihakralj-quantalib",
"projectKey": "mihakralj_QuanTAlib"
+3
View File
@@ -1,3 +1,4 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -300,6 +301,7 @@ public sealed class Sma
}
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
#pragma warning disable S6640 // Unsafe code is required for high-performance SIMD operations
private static unsafe void CalculateSimdCore(ReadOnlySpan<double> source, Span<double> output, int period)
{
int len = source.Length;
@@ -370,6 +372,7 @@ public sealed class Sma
}
}
}
#pragma warning restore S6640
/// <summary>
/// Checks if span contains any non-finite values (NaN or Infinity).
+3
View File
@@ -1,3 +1,4 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -285,6 +286,7 @@ public sealed class Wma
}
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
#pragma warning disable S6640 // Unsafe code is required for high-performance SIMD operations
private static unsafe void CalculateSimdCore(ReadOnlySpan<double> source, Span<double> output, int period)
{
int len = source.Length;
@@ -466,6 +468,7 @@ public sealed class Wma
}
}
}
#pragma warning restore S6640
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool HasNonFiniteValues(ReadOnlySpan<double> span)
+2 -1
View File
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -466,7 +467,7 @@ public sealed class RingBuffer : IEnumerable<double>
_start == other._start &&
_count == other._count &&
_index == other._index &&
_current == other._current;
_current.Equals(other._current);
public override readonly bool Equals(object? obj) =>
obj is Enumerator other && Equals(other);
+2
View File
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+1 -1
View File
@@ -8,7 +8,7 @@ namespace QuanTAlib;
/// Stateless design - only maintains minimal state needed for price continuity.
/// </summary>
[SkipLocalsInit]
// Types should be named in PascalCase - GBM is a standard acronym
#pragma warning disable S101 // Rename class 'GBM' to match pascal case naming rules
public class GBM : IFeed
#pragma warning restore S101
{
+4
View File
@@ -96,6 +96,7 @@ public class IndicatorExtensionsTests
}
[Fact]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public void PaintMethods_DoNotThrow_WithValidGraphics()
{
// This test attempts to verify that paint methods don't crash.
@@ -144,5 +145,8 @@ public class IndicatorExtensionsTests
// Test DrawText
IndicatorExtensions.DrawText(indicator, args, "Test Text");
// Assert that we reached the end without throwing
Assert.True(true);
}
}