Skip to content

Commit 19d192a

Browse files
scottamplitudeSimon Renoult
authored andcommitted
Created CVS export option
1 parent 8b5e760 commit 19d192a

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# code-complexity
22

3-
> Measure the churn/complexity score. Higher values mean hotspots where
3+
> Measure the churn/complexity score. Higher values mean hotspots where
44
> refactorings should happen.
55
66
[![Build Status][travis-image]][travis-url]
@@ -10,13 +10,13 @@
1010

1111
Quoting Michael Feathers (source [here][michael-feathers-source]):
1212

13-
*Often when we refactor, we look at local areas of code. If we take a wider
14-
view, using information from our version control systems, we can get a better
13+
*Often when we refactor, we look at local areas of code. If we take a wider
14+
view, using information from our version control systems, we can get a better
1515
sense of the effects of our refactoring efforts.*
1616

1717

18-
Note: `code-complexity` currently measures complexity using lines of code count.
19-
While imperfect, this measure gives a good enough idea of what's going on.
18+
Note: `code-complexity` currently measures complexity using lines of code count.
19+
While imperfect, this measure gives a good enough idea of what's going on.
2020

2121
## Usage
2222

@@ -28,21 +28,21 @@ $ npx code-complexity <path-to-git-directory or URL>
2828

2929
```text
3030
Usage: code-complexity <target> [options]
31-
31+
3232
Measure the churn/complexity score. Higher values mean hotspots where refactorings should happen.
33-
33+
3434
Options:
3535
-V, --version output the version number
3636
--filter <strings> list of globs (comma separated) to filter
37-
-f, --format [format] format results using table or json
37+
-f, --format [format] format results using table, json or csv
3838
-l, --limit [limit] limit the number of files to output
3939
-i, --since [since] limit the age of the commit analyzed
4040
-s, --sort [sort] sort results (allowed valued: score,
4141
churn, complexity or file)
4242
-h, --help display help for command
43-
43+
4444
Examples:
45-
45+
4646
$ code-complexity .
4747
$ code-complexity https://github.com/simonrenoult/code-complexity
4848
$ code-complexity foo --limit 3

src/io/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function getRawCli(
4646
.option(
4747
"-f, --format [format]",
4848
"format results using table or json",
49-
/^(table|json)$/i
49+
/^(table|json|csv)$/i
5050
)
5151
.option(
5252
"-l, --limit [limit]",

src/io/output.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ function render(
2424
case "json":
2525
stdout = toJson(values);
2626
break;
27+
case "csv":
28+
stdout = toCSV(values);
29+
break;
2730
default:
2831
stdout = toTable(values);
2932
}
@@ -50,3 +53,13 @@ function toTable(statistics: Statistics[]): string {
5053

5154
return table.toString();
5255
}
56+
57+
function toCSV(statistics: Statistics[]): string {
58+
let csv = "file,complexity,churn,score\n";
59+
statistics.forEach((stat) => {
60+
csv +=
61+
[stat.path, stat.complexity, stat.churn, stat.score].join(",") + "\n";
62+
});
63+
64+
return csv;
65+
}

src/lib/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { URL } from "url";
22

33
export type Path = string;
44
export type Sort = "score" | "churn" | "complexity" | "file" | "ratio";
5-
export type Format = "table" | "json";
5+
export type Format = "table" | "json" | "csv";
66
export type Options = {
77
target: string | URL;
88
directory: string;

0 commit comments

Comments
 (0)