Skip to content

Commit c48ec85

Browse files
aksOpsclaude
andcommitted
fix: resolve SonarCloud reliability bugs, unused imports, string constants, dead code
Reliability bugs (8 fixed): - S2159: GitHubActionsDetector equals() on unrelated types (Boolean vs String) - S5998: NestJSControllerDetector, RawSqlDetector regex stack overflow risk (added possessive quantifiers) - S5850: CSharpStructuresDetector regex precedence (explicit grouping) - S5855: GrpcServiceDetector redundant regex alternative Unused imports (S1128, ~113 removed across 76 files) String literal constants (S1192, ~281 constants extracted across 75 files): - PROP_FRAMEWORK, PROP_AUTH_TYPE, PROP_TOPIC, etc. Dead code cleanup: - S1481: Removed ~20 unused local variables - S1854: Removed ~16 dead stores - S1172: Removed ~20 unused method parameters (private methods only) - S1130: Removed ~18 unnecessary throws declarations - S1659: Split ~18 multi-variable declarations - S108: Added comments in ~13 empty blocks Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 51f659f commit c48ec85

75 files changed

Lines changed: 1338 additions & 1003 deletions

File tree

Some content is hidden

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

src/main/java/io/github/randomcodespace/iq/analyzer/Analyzer.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
*/
6262
@Service
6363
public class Analyzer {
64+
private static final String PROP_FRAMEWORK = "framework";
65+
private static final String PROP_ROOT = "root";
66+
private static final String PROP_SERVICE = "service";
67+
6468

6569
private static final Logger log = LoggerFactory.getLogger(Analyzer.class);
6670

@@ -335,7 +339,7 @@ private AnalysisResult runWithCache(Path root, Integer parallelism, AnalysisCach
335339
// 5b. Detect service boundaries and create SERVICE nodes
336340
report.accept("Detecting service boundaries...");
337341
var serviceDetector = new ServiceDetector();
338-
String projectDirName = root.getFileName() != null ? root.getFileName().toString() : "root";
342+
String projectDirName = root.getFileName() != null ? root.getFileName().toString() : PROP_ROOT;
339343
var serviceResult = serviceDetector.detect(allNodes, builder.getEdges(), projectDirName, root);
340344
if (!serviceResult.serviceNodes().isEmpty()) {
341345
serviceResult.serviceNodes().forEach(n -> n.setProvenance(builder.getProvenance()));
@@ -348,7 +352,7 @@ private AnalysisResult runWithCache(Path root, Integer parallelism, AnalysisCach
348352
String serviceName = config.getServiceName();
349353
if (serviceName != null && !serviceName.isBlank()) {
350354
for (CodeNode node : allNodes) {
351-
node.getProperties().put("service", serviceName);
355+
node.getProperties().put(PROP_SERVICE, serviceName);
352356
}
353357
}
354358

@@ -381,7 +385,7 @@ private AnalysisResult runWithCache(Path root, Integer parallelism, AnalysisCach
381385
// 7b. Compute framework breakdown from node properties
382386
Map<String, Integer> frameworkBreakdown = new HashMap<>();
383387
for (CodeNode node : allNodes) {
384-
Object fw = node.getProperties().get("framework");
388+
Object fw = node.getProperties().get(PROP_FRAMEWORK);
385389
if (fw != null && !fw.toString().isEmpty()) {
386390
frameworkBreakdown.merge(fw.toString(), 1, Integer::sum);
387391
}
@@ -611,13 +615,13 @@ private AnalysisResult runBatchedWithCache(Path root, Integer parallelism, int b
611615
String svcName = config.getServiceName();
612616
if (svcName != null && !svcName.isBlank()) {
613617
for (CodeNode node : result.nodes()) {
614-
node.getProperties().put("service", svcName);
618+
node.getProperties().put(PROP_SERVICE, svcName);
615619
}
616620
}
617621
// Track breakdowns
618622
for (CodeNode node : result.nodes()) {
619623
nodeBreakdown.merge(node.getKind().getValue(), 1, Integer::sum);
620-
Object fw = node.getProperties().get("framework");
624+
Object fw = node.getProperties().get(PROP_FRAMEWORK);
621625
if (fw != null && !fw.toString().isEmpty()) {
622626
frameworkBreakdown.merge(fw.toString(), 1, Integer::sum);
623627
}
@@ -971,12 +975,12 @@ private int[] processSmartBatch(
971975
String svcName = config.getServiceName();
972976
if (svcName != null && !svcName.isBlank()) {
973977
for (CodeNode node : result.nodes()) {
974-
node.getProperties().put("service", svcName);
978+
node.getProperties().put(PROP_SERVICE, svcName);
975979
}
976980
}
977981
for (CodeNode node : result.nodes()) {
978982
nodeBreakdown.merge(node.getKind().getValue(), 1, Integer::sum);
979-
Object fw = node.getProperties().get("framework");
983+
Object fw = node.getProperties().get(PROP_FRAMEWORK);
980984
if (fw != null && !fw.toString().isEmpty()) {
981985
frameworkBreakdown.merge(fw.toString(), 1, Integer::sum);
982986
}
@@ -1001,7 +1005,7 @@ private int[] processSmartBatch(
10011005
* Partition discovered files into modules based on build-file boundary markers.
10021006
* <p>
10031007
* Files are assigned to the deepest module directory that contains them.
1004-
* Files with no matching module are placed in a {@code "root"} partition.
1008+
* Files with no matching module are placed in a {@code PROP_ROOT} partition.
10051009
* The returned map is a {@link TreeMap} for deterministic iteration.
10061010
*
10071011
* @param root absolute repository root (used only for logging)
@@ -1021,7 +1025,7 @@ Map<String, List<DiscoveredFile>> detectModules(Path root, List<DiscoveredFile>
10211025
// If no module boundaries found, treat everything as root
10221026
if (moduleDirs.isEmpty()) {
10231027
Map<String, List<DiscoveredFile>> single = new TreeMap<>();
1024-
single.put("root", new ArrayList<>(files));
1028+
single.put(PROP_ROOT, new ArrayList<>(files));
10251029
return single;
10261030
}
10271031

@@ -1045,7 +1049,7 @@ Map<String, List<DiscoveredFile>> detectModules(Path root, List<DiscoveredFile>
10451049
}
10461050
}
10471051

1048-
String key = bestModule != null ? bestModule : "root";
1052+
String key = bestModule != null ? bestModule : PROP_ROOT;
10491053
result.computeIfAbsent(key, k -> new ArrayList<>()).add(file);
10501054
}
10511055

0 commit comments

Comments
 (0)