Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/metricsAnalyzer/languages/csharpAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export class CSharpMetricsAnalyzer {
}

// Continue traversing child nodes
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
visit(child);
}
};
Expand Down Expand Up @@ -444,7 +445,8 @@ export class CSharpMetricsAnalyzer {
const isPreproc = node.type.startsWith("preproc_");
if (nests) { this.nesting++; }
if (isPreproc) { this.preprocessorDepth++; }
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
if (!this.isFunctionDeclaration(child)) {
this.visit(child);
}
Expand Down
9 changes: 6 additions & 3 deletions src/metricsAnalyzer/languages/goAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export class GoMetricsAnalyzer {
return;
}

for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
visit(child);
}
};
Expand Down Expand Up @@ -350,7 +351,8 @@ export class GoMetricsAnalyzer {
? node.childForFieldName("alternative")
: null;

for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
if (this.isFunctionDeclaration(child)) { continue; }
if (alternative && child === alternative) {
this.visitAlternative(child);
Expand Down Expand Up @@ -395,7 +397,8 @@ export class GoMetricsAnalyzer {
// (do NOT bump nesting again — the outer if already did).
// We must also intercept any nested alternative (further else-if/else chains).
const innerAlt = node.childForFieldName("alternative");
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
if (this.isFunctionDeclaration(child)) { continue; }
if (child.type === "else") { continue; } // skip the 'else' keyword token
if (innerAlt && child === innerAlt) {
Expand Down
9 changes: 6 additions & 3 deletions src/metricsAnalyzer/languages/javaAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export class JavaMetricsAnalyzer {
// Do not recurse into the method body again — analyzeMethod handles it
return;
}
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
visit(child);
}
};
Expand Down Expand Up @@ -222,7 +223,8 @@ export class JavaMetricsAnalyzer {
* @param node - The block or body node to visit
*/
private visitBody(node: Parser.SyntaxNode): void {
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
this.visit(child);
}
}
Expand Down Expand Up @@ -271,7 +273,8 @@ export class JavaMetricsAnalyzer {
// to avoid double-counting (the else_clause +1 already accounts for it).
const nests = this.increasesNesting(node);
if (nests) { this.nesting++; }
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
if (!this.isMethodDeclaration(child)) {
this.visit(child, elseBranchNode !== null && child === elseBranchNode);
}
Expand Down
6 changes: 4 additions & 2 deletions src/metricsAnalyzer/languages/jsLikeAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export class JsLikeMetricsAnalyzer {
this.details = savedDetails;
this.nesting = savedNesting;
} else {
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
this.collectFunctions(child, functions);
}
}
Expand Down Expand Up @@ -341,7 +342,8 @@ export class JsLikeMetricsAnalyzer {
this.nesting++;
}

for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
// Nested functions: add a nesting penalty and continue analyzing their body
// as part of the outer function at an increased nesting level, so that any
// complexity inside the nested body (ternaries, loops, etc.) counts toward
Expand Down
12 changes: 8 additions & 4 deletions src/metricsAnalyzer/languages/pythonAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export class PythonMetricsAnalyzer {
const name = nameNode
? this.sourceText.substring(nameNode.startIndex, nameNode.endIndex)
: "<class>";
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
visit(child, name);
}
return;
Expand All @@ -144,7 +145,8 @@ export class PythonMetricsAnalyzer {
return;
}

for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
visit(child, className);
}
};
Expand Down Expand Up @@ -231,7 +233,8 @@ export class PythonMetricsAnalyzer {
});
}
this.nesting++;
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
this.visit(child);
}
this.nesting--;
Expand All @@ -253,7 +256,8 @@ export class PythonMetricsAnalyzer {
// Conditionally bump nesting, iterate children once, then restore.
const nests = this.increasesNesting(node);
if (nests) { this.nesting++; }
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
this.visit(child);
}
if (nests) { this.nesting--; }
Expand Down
6 changes: 4 additions & 2 deletions src/metricsAnalyzer/languages/rustAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export class RustMetricsAnalyzer {
}
}
} else {
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
visit(child);
}
}
Expand Down Expand Up @@ -269,7 +270,8 @@ export class RustMetricsAnalyzer {
// shouldSkipChildStructuralIncrement handles else-if chains to avoid double-counting.
const nests = this.increasesNesting(node);
if (nests) { this.nesting++; }
for (const child of node.children) {
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i)!;
if (!this.isFunctionDeclaration(child)) {
this.visit(child, this.shouldSkipChildStructuralIncrement(node, child));
}
Expand Down