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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Quoting Michael Feathers (source [here][michael-feathers-source]):
view, using information from our version control systems, we can get a better
sense of the effects of our refactoring efforts.*


Note: `code-complexity` currently measures complexity using either:
- lines of code count (all languages)
- cyclomatic complexity (JavaScript/TypeScript)
Expand Down Expand Up @@ -43,6 +42,7 @@ $ npx code-complexity <path-to-git-directory or URL> [options]
-u, --until [until] limit analysis to commits older in age than date
-s, --sort [sort] sort results (allowed valued: score, churn, complexity or file)
-d, --directories display values for directories instead of files
-mb, --max-buffer [maxBuffer] set the max buffer size for git log (in bytes)
-h, --help display help for command

Examples:
Expand All @@ -53,10 +53,11 @@ $ npx code-complexity <path-to-git-directory or URL> [options]
$ code-complexity ../foo --sort score
$ code-complexity /foo/bar --filter 'src/**,!src/front/**'
$ code-complexity . --limit 10 --sort score
$ code-complexity . --limit 10 --directories
$ code-complexity . --limit 10 --directories
$ code-complexity . --limit 10 --sort score -cs halstead
$ code-complexity . --since=2021-06-01 --limit 100
$ code-complexity . --since=2021-04-01 --until=2021-07-01
$ code-complexity . --max-buffer 64000000
```

## Output
Expand Down
7 changes: 7 additions & 0 deletions src/io/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ function getRawCli(
"-d, --directories",
"display values for directories instead of files"
)
.option(
"-mb, --max-buffer [maxBuffer]",
"set the max buffer size for git log (in bytes)",
parseInt
)
.on("--help", () => {
console.log();
console.log("Examples:");
Expand All @@ -94,6 +99,7 @@ function getRawCli(
"$ code-complexity . --limit 10 --sort score -cs halstead",
"$ code-complexity . --since=2021-06-01 --limit 100",
"$ code-complexity . --since=2021-04-01 --until=2021-07-01",
"$ code-complexity . --max-buffer 64000000",
].forEach((example) => console.log(example.padStart(2)));
});
}
Expand All @@ -113,6 +119,7 @@ function buildOptions(args: string[], options: any): Options {
complexityStrategy: options.complexityStrategy
? (String(options.complexityStrategy) as ComplexityStrategy)
: "sloc",
maxBuffer: options.maxBuffer ? Number(options.maxBuffer) : undefined,
};

// FIXME: I'm not a fan of pulling the code here but it's good enough.
Expand Down
3 changes: 2 additions & 1 deletion src/lib/githistory/githistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export default class GitHistory {
}

private executeGitLogCommand(gitLogCommand: string): string {
return execSync(gitLogCommand, { encoding: "utf8", maxBuffer: 32_000_000 });
const maxBuffer = this.options.maxBuffer ?? 32_000_000;
return execSync(gitLogCommand, { encoding: "utf8", maxBuffer });
}

private listFiles(): string[] {
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export type Options = {
complexityStrategy?: ComplexityStrategy;
filter?: string[];
format?: Format;
maxBuffer?: number;
};
21 changes: 21 additions & 0 deletions test/lib/statistics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,27 @@ describe("Statistics", () => {
});
});

context("options.maxBuffer", () => {
it("returns the appropriate elements", async () => {
// Given
const options: Options = { ...defaultOptions, maxBuffer: 64_000_000 };
new TestRepositoryFixture().addFile({ name: "a.js" }).writeOnDisk();

// When
const result = (await Statistics.compute(options)).list();

// Then
expect(result).to.deep.equal([
{
churn: 1,
complexity: 1,
path: "a.js",
score: 1,
},
]);
});
});

context("when file no longer exists", () => {
it("it is ignored", async () => {
// Given
Expand Down