Skip to content

Commit ff86c2b

Browse files
author
MPCoreDeveloper
committed
fix(sonar): resolve final 9 issues (S6549/S2077/S125/S4143/S1172)
- S6549: justified NOSONAR for user-configured storage roots with fixed filenames - S2077: NOSONAR moved to the execution (sink) lines in DapperAsyncExtensions - S125: rephrased comments that looked like commented-out code - S4143: justified NOSONAR for the intentional community-restore assignment in Louvain - S1172: justified NOSONAR for the API-symmetry query parameter in the demo
1 parent 856fb87 commit ff86c2b

8 files changed

Lines changed: 13 additions & 13 deletions

File tree

Examples/SharpCoreDB.GraphRAG.AIAssistant/Services/DocumentationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task<List<GraphRAGResult>> VectorOnlySearchAsync(
9999
/// Performs vector similarity search using embeddings.
100100
/// </summary>
101101
private async Task<List<GraphRAGResult>> VectorSearchAsync(
102-
string query,
102+
string query, // NOSONAR:S1172 - kept for API symmetry; the demo uses mock embeddings.
103103
int topK,
104104
CancellationToken ct)
105105
{

src/SharpCoreDB.Extensions/DapperAsyncExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,13 @@ public static async Task<PagedResult<T>> QueryPagedAsync<T>(
239239
: null;
240240

241241
// Get total count
242-
var countSql = $"SELECT COUNT(*) FROM ({sql}) AS CountQuery"; // NOSONAR:S2077 - 'sql' is the caller's own (already parameterized) query wrapped in a COUNT(*) subquery; it cannot itself be bound as a parameter.
243-
var totalCount = await connection.ExecuteScalarAsync<long>(countSql, parameters);
242+
var countSql = $"SELECT COUNT(*) FROM ({sql}) AS CountQuery";
243+
var totalCount = await connection.ExecuteScalarAsync<long>(countSql, parameters); // NOSONAR:S2077 - 'sql' is the caller's own (already parameterized) query wrapped in a COUNT(*) subquery; it cannot itself be bound as a parameter.
244244

245245
// Get paged data
246246
var offset = (pageNumber - 1) * pageSize;
247-
var pagedSql = $"{sql} LIMIT {pageSize} OFFSET {offset}"; // NOSONAR:S2077 - 'sql' is the caller's own query; pageSize/offset are validated integers.
248-
var items = await connection.QueryAsync<T>(pagedSql, parameters);
247+
var pagedSql = $"{sql} LIMIT {pageSize} OFFSET {offset}";
248+
var items = await connection.QueryAsync<T>(pagedSql, parameters); // NOSONAR:S2077 - 'sql' is the caller's own query; pageSize/offset are validated integers.
249249

250250
return new PagedResult<T>
251251
{

src/SharpCoreDB.Graph.Advanced/CommunityDetection/LouvainAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public async Task<CommunityDetectionResult> ExecuteAsync(GraphData graphData, Ca
8282
}
8383

8484
// Restore old community for next test
85-
communities[i] = oldComm;
85+
communities[i] = oldComm; // NOSONAR:S4143 - intentional: restore the previous community before testing the next candidate.
8686
}
8787

8888
// Apply best move

src/SharpCoreDB.VectorSearch/Index/HnswIndex.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public HnswIndex(HnswConfig config, int? seed = null)
3838
ArgumentNullException.ThrowIfNull(config);
3939
config.Validate();
4040
_config = config;
41-
// Random is used only for HNSW graph level assignment (non-security);
42-
// a seed is supported for deterministic testing.
41+
// Random is used only for HNSW level assignment (not security);
42+
// a seed is supported for deterministic tests.
4343
_levelRng = seed.HasValue ? new Random(seed.Value) : new Random(); // NOSONAR:S2245
4444
}
4545

src/SharpCoreDB/Database/Core/Database.Core.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private void Load()
229229
else
230230
{
231231
// ✅ Legacy: Use IStorage (file-based)
232-
var metaPath = Path.Combine(_dbPath, PersistenceConstants.MetaFileName);
232+
var metaPath = Path.Combine(_dbPath, PersistenceConstants.MetaFileName); // NOSONAR:S6549 - _dbPath is the user-configured storage root; derived paths use fixed filenames.
233233
metaExists = File.Exists(metaPath);
234234

235235
#if DEBUG

src/SharpCoreDB/Services/QueryCompiler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,8 @@ void AddColumn(string? column)
656656

657657
AddColumn(orderByColumn);
658658

659-
// local function 'AddColumn' mutates the captured 'columns' list;
660-
// SonarC# cannot track the side effect and wrongly reports the loop as unreachable.
659+
// Note: the local AddColumn helper mutates the captured columns list; SonarC#
660+
// cannot track that side effect and wrongly reports the loop as unreachable.
661661
for (int i = 0; i < columns.Count; i++) // NOSONAR:S2583
662662
{
663663
indices[columns[i]] = i;

src/SharpCoreDB/Storage/Engines/AppendOnlyEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public AppendOnlyEngine(IStorage storage, string databasePath)
4646
this.storage = storage ?? throw new ArgumentNullException(nameof(storage));
4747
this.databasePath = Path.GetFullPath(databasePath ?? throw new ArgumentNullException(nameof(databasePath)));
4848

49-
if (!Directory.Exists(databasePath))
49+
if (!Directory.Exists(databasePath)) // NOSONAR:S6549 - databasePath is the user-configured storage root.
5050
{
5151
Directory.CreateDirectory(databasePath);
5252
}

src/SharpCoreDB/Storage/Engines/PageBasedEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public PageBasedEngine(string databasePath, DatabaseConfig? config = null)
5757
this.databasePath = Path.GetFullPath(databasePath ?? throw new ArgumentNullException(nameof(databasePath)));
5858
this.config = config; // ✅ NEW: Store config
5959

60-
if (!Directory.Exists(databasePath))
60+
if (!Directory.Exists(databasePath)) // NOSONAR:S6549 - databasePath is the user-configured storage root.
6161
{
6262
Directory.CreateDirectory(databasePath);
6363
}

0 commit comments

Comments
 (0)