Skip to content

Commit

Permalink
Merge pull request #2 from pilotpirxie/v1.2
Browse files Browse the repository at this point in the history
Fix calling function on a path
  • Loading branch information
pilotpirxie committed Sep 14, 2023
2 parents 5a3c2c4 + da801f4 commit 0d51251
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["./src/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cyclomatic-complexity",
"description": "Tool for calculating cyclomatic complexity of a JavaScript and TypeScript code.",
"version": "1.0.0",
"version": "1.2.0",
"main": "./bin/index.js",
"repository": "https://github.com/pilotpirxie/cyclomatic-complexity.git",
"author": "pilotpirxie <10637666+pilotpirxie@users.noreply.github.com>",
Expand Down
8 changes: 4 additions & 4 deletions src/complexity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("complexity", () => {
]);
});

test("should return 1 for a function with a function call", () => {
test("should return 2 for a function with a function call", () => {
const code = `function a() {
if (true) {
return 1;
Expand All @@ -45,7 +45,7 @@ describe("complexity", () => {
const result = calculateComplexity(code);
expect(result).toEqual([
{ name: "global", complexity: 0 },
{ name: "a", complexity: 1 },
{ name: "a", complexity: 2 },
]);
});

Expand Down Expand Up @@ -73,8 +73,8 @@ describe("complexity", () => {
const result = calculateComplexity(code);
expect(result).toEqual([
{ name: "global", complexity: 0 },
{ name: "anonymous", complexity: 1 },
{ name: "anonymous", complexity: 1 },
{ name: "anonymous", complexity: 3 },
{ name: "anonymous", complexity: 3 },
]);
});
});
5 changes: 1 addition & 4 deletions src/complexity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export function calculateComplexity(code: string): FunctionComplexity[] {
const functionDetail = functionStack.find(
(f) => f.name === functionName,
);
if (functionDetail) {
functionDetail.complexity++;
} else if (!definedFunctions.has(functionName)) {
// Handle external function calls
if (!definedFunctions.has(functionName)) {
functionStack[functionStack.length - 1].complexity++;
}
}
Expand Down

0 comments on commit 0d51251

Please sign in to comment.