Skip to content

Commit 7af6b86

Browse files
Copilotaskpt
andauthored
refactor: address PR review comments - remove duplicate tests, fix types, update docs (#116)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
1 parent feae3e6 commit 7af6b86

File tree

4 files changed

+17
-103
lines changed

4 files changed

+17
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,4 @@ obj/
132132
# Test results
133133
test-results/
134134
coverage/
135+
root/

samples/Test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ outer: // label
191191
return false
192192
}
193193

194-
// GotoExample demonstrates goto statement complexity (complexity: 1)
194+
// GotoExample demonstrates goto statement complexity (complexity: 3)
195195
func GotoExample(value int) string {
196196
if value < 0 {
197197
goto negative

src/metricsAnalyzer/metricsAnalyzerFactory.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ function createCSharpAnalyzer(): (
197197
* - Function boundaries (start/end line and column)
198198
*
199199
* @remarks
200-
* The analyzer dynamically requires the Go analyzer module and normalizes its output
201-
* from 0-based to 1-based line and column indexing for consistency.
200+
* The analyzer dynamically requires the Go analyzer module and normalizes the detail positions
201+
* (line and column in the details array) from 0-based to 1-based indexing for consistency
202+
* with the C# analyzer. Function boundary positions remain as returned by the analyzer.
202203
*/
203204
function createGoAnalyzer(): (sourceText: string) => UnifiedFunctionMetrics[] {
204205
return function (sourceText: string) {

src/unit/unit.test.ts

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { GoMetricsAnalyzer } from "../metricsAnalyzer/languages/goAnalyzer";
1111
import {
1212
MetricsAnalyzerFactory,
1313
UnifiedFunctionMetrics,
14+
UnifiedMetricsDetail,
1415
} from "../metricsAnalyzer/metricsAnalyzerFactory";
1516
import { SampleCSharpCode } from "../test/testUtils";
1617

@@ -123,11 +124,11 @@ func Method() {
123124
assert.strictEqual(results.length, 1);
124125
assert.ok(results[0].complexity > 0);
125126

126-
const forLoop = results[0].details.find((d: any) =>
127-
d.reason.includes("for")
127+
const forLoop = results[0].details.find(
128+
(d: UnifiedMetricsDetail) => d.reason.includes("for")
128129
);
129130
const innerForLoop = results[0].details.find(
130-
(d: any) => d.reason.includes("for") && d.nesting > 0
131+
(d: UnifiedMetricsDetail) => d.reason.includes("for") && d.nesting > 0
131132
);
132133

133134
assert.ok(forLoop);
@@ -156,8 +157,8 @@ func Method(val int) string {
156157

157158
assert.strictEqual(results.length, 1);
158159
assert.ok(results[0].complexity > 0);
159-
const switchDetail = results[0].details.find((d: any) =>
160-
d.reason.includes("switch")
160+
const switchDetail = results[0].details.find(
161+
(d: UnifiedMetricsDetail) => d.reason.includes("switch")
161162
);
162163
assert.ok(switchDetail);
163164
});
@@ -181,8 +182,8 @@ func Method(ch1, ch2 chan int) {
181182

182183
assert.strictEqual(results.length, 1);
183184
assert.ok(results[0].complexity > 0);
184-
const selectDetail = results[0].details.find((d: any) =>
185-
d.reason.includes("select")
185+
const selectDetail = results[0].details.find(
186+
(d: UnifiedMetricsDetail) => d.reason.includes("select")
186187
);
187188
assert.ok(selectDetail);
188189
});
@@ -310,100 +311,11 @@ func Subtract(a, b int) int {
310311
assert.strictEqual(results.length, 1);
311312
assert.ok(results[0].complexity > 0);
312313

313-
const forLoop = results[0].details.find((d: any) =>
314-
d.reason.includes("for")
314+
const forLoop = results[0].details.find(
315+
(d: UnifiedMetricsDetail) => d.reason.includes("for")
315316
);
316-
const whileLoop = results[0].details.find((d: any) =>
317-
d.reason.includes("while")
318-
);
319-
320-
assert.ok(forLoop);
321-
assert.ok(whileLoop);
322-
assert.ok(whileLoop.nesting > forLoop.nesting);
323-
});
324-
});
325-
326-
describe("CSharp Analyzer Core Logic", () => {
327-
it("should analyze simple method correctly", () => {
328-
const analyzer = new CSharpMetricsAnalyzer();
329-
const results = analyzer.analyzeFunctions(SampleCSharpCode.SIMPLE_METHOD);
330-
331-
assert.strictEqual(results.length, 1);
332-
assert.strictEqual(results[0].name, "Add");
333-
assert.strictEqual(results[0].complexity, 0);
334-
assert.strictEqual(results[0].details.length, 0);
335-
});
336-
337-
it("should analyze if statement correctly", () => {
338-
const analyzer = new CSharpMetricsAnalyzer();
339-
const results = analyzer.analyzeFunctions(SampleCSharpCode.SINGLE_IF);
340-
341-
assert.strictEqual(results.length, 1);
342-
assert.strictEqual(results[0].name, "Max");
343-
assert.strictEqual(results[0].complexity, 1);
344-
assert.strictEqual(results[0].details.length, 1);
345-
assert.strictEqual(results[0].details[0].reason, "if statement");
346-
});
347-
348-
it("should analyze nested complexity correctly", () => {
349-
const analyzer = new CSharpMetricsAnalyzer();
350-
const results = analyzer.analyzeFunctions(
351-
SampleCSharpCode.NESTED_COMPLEX
352-
);
353-
354-
assert.ok(results.length > 0);
355-
const mainMethod = results.find(
356-
(r: UnifiedFunctionMetrics) => r.name === "ComplexMethod"
357-
);
358-
assert.ok(mainMethod);
359-
assert.ok(mainMethod.complexity > 5); // Should have significant complexity
360-
});
361-
362-
it("should handle logical operators", () => {
363-
const sourceCode = `
364-
public class Test {
365-
public void Method(bool a, bool b, bool c) {
366-
if (a && b) {
367-
return;
368-
}
369-
if (b || c) {
370-
return;
371-
}
372-
}
373-
}
374-
`;
375-
376-
const analyzer = new CSharpMetricsAnalyzer();
377-
const results = analyzer.analyzeFunctions(sourceCode);
378-
379-
assert.strictEqual(results.length, 1);
380-
assert.strictEqual(results[0].complexity, 4); // 2 ifs + 1 && + 1 ||
381-
});
382-
383-
it("should handle loops correctly", () => {
384-
const sourceCode = `
385-
public class Test {
386-
public void Method() {
387-
for (int i = 0; i < 10; i++) {
388-
while (true) {
389-
break;
390-
}
391-
}
392-
}
393-
}
394-
`;
395-
396-
const analyzer = new CSharpMetricsAnalyzer();
397-
const results = analyzer.analyzeFunctions(sourceCode);
398-
399-
assert.strictEqual(results.length, 1);
400-
assert.ok(results[0].complexity > 0);
401-
402-
const forLoop = results[0].details.find((d: any) =>
403-
d.reason.includes("for")
404-
);
405-
const whileLoop = results[0].details.find((d: any) =>
406-
d.reason.includes("while")
317+
const whileLoop = results[0].details.find(
318+
(d: UnifiedMetricsDetail) => d.reason.includes("while")
407319
);
408320

409321
assert.ok(forLoop);

0 commit comments

Comments
 (0)