Skip to content

Releases: simonrenoult/code-complexity

v4.4.0

13 Nov 22:42
Compare
Choose a tag to compare

🦄 Analysis per directory, wow! 🦄

Make analyze available for directories in addition to files, eg npx code-complexity https://github.com/simonrenoult/code-complexity --directories.

This command will group results per directory, which is interesting in two ways:

  • complexity might be hidden behind several averagely complex files within the same module
  • it also opens new way of analyzing cohesion and coupling (for future releases).

Example of output:

$ npx code-complexity https://github.com/simonrenoult/code-complexity --directories --limit 5 --sort score

┌──────────┬────────────┬───────┬───────┐
│ file     │ complexity │ churn │ score │
├──────────┼────────────┼───────┼───────┤
│ src      │ 622        │ 58    │ 36076 │
├──────────┼────────────┼───────┼───────┤
│ test     │ 582        │ 26    │ 15132 │
├──────────┼────────────┼───────┼───────┤
│ src/lib  │ 376        │ 30    │ 11280 │
├──────────┼────────────┼───────┼───────┤
│ .idea    │ 474        │ 22    │ 10428 │
├──────────┼────────────┼───────┼───────┤
│ test/lib │ 400        │ 14    │ 5600  │
└──────────┴────────────┴───────┴───────┘

v4.3.1

11 Nov 11:45
Compare
Choose a tag to compare

✨ Complexity strategies, URL and more! ✨

  • Support for complexity strategies (cyclomatic + halstead): npx code-complexity https://github.com/simonrenoult/code-complexity -cs halstead
  • Support for URL in addition to directory: npx code-complexity https://github.com/simonrenoult/code-complexity
  • Support for CSV export: `npx code-complexity https://github.com/simonrenoult/code-complexity --format csv
  • Support for until to limit analyze date range: npx code-complexity https://github.com/simonrenoult/code-complexity --until 6.months

v4.0.0

03 May 10:13
Compare
Choose a tag to compare

Introducing code-complexity v4.0.0!

This releases offers a large amount of modifications: support for any type of file, better stdout, removal/addition of new flags and a rewrite of the code base to make it easier to navigate, yay!


Breaking changes

Revamped stdout

With the addition of the json format, I chose to make the default output cleaner. It is way easier to read this way! \o/

Note that this format is also available using the --format=table flag.

It looks like this:

$ npx code-complexity . --sort=ratio --limit=3

┌──────────────────────────────┬────────────┬───────┬───────┐
│ file                         │ complexity │ churn │ ratio │
├──────────────────────────────┼────────────┼───────┼───────┤
│ src/cli.ts                   │ 103        │ 8     │ 824   │
├──────────────────────────────┼────────────┼───────┼───────┤
│ test/code-complexity.test.ts │ 107        │ 7     │ 749   │
├──────────────────────────────┼────────────┼───────┼───────┤
│ .idea/workspace.xml          │ 123        │ 6     │ 738   │
└──────────────────────────────┴────────────┴───────┴───────┘

Removed --excludes and --includes flags

While handy, this solution was a rather naive approach to filtering. I've removed them in favor of a --filter flag supporting globs. The implementation is using micromatch.

Example:

$ npx code-complexity . --filter='!test/**','src/*.ts'

Removed --min and --max flags

While interesting, these flags were not adding much value since you usually want to list the highest ratio/churn/complexity values. A combination of --sort=ratio and --limit=5 would usually do the trick.

They'd be interesting if min/max could be targeted on a metric (eg: ratio, churn or complexity). But since they were only targeting ratios, I don't see them adding much value. And they add more code to maintain.

I'll add an issue about adding them back and wait to see if it gets traction.

Removed --sloc and --commit flags

The new table stdout is clearer to read and already show these information so we don't need these flags anymore. Yay, less code to maintain!

Removed --no-first-parent flags

Using --first-parent was causing problems where git log would not output all the files. Using no-first-parent is now the default.

Removed --details flag

With the addition of the json support, I chose to make the text output a bit more opinionated. Metrics like complexity, churn and ratio will always be shown from now on.

Additions

Added support for any type of file

We used to only consider JavaScript or TypeScript files. This is no longer the case. We're now trying to evaluate complexity and churn on all files. We default complexity and churn to 1 when they can't be measured.

Added json support

See --format.

Added --format flag

I've added this flag to support more output format. It currently allows table
and json.

The table format is the default one.
The json format will ease integration with other softwares.

Example with --format=table:

$ npx code-complexity . --sort=ratio --limit=3

┌──────────────────────────────┬────────────┬───────┬───────┐
│ file                         │ complexity │ churn │ ratio │
├──────────────────────────────┼────────────┼───────┼───────┤
│ src/cli.ts                   │ 103        │ 8     │ 824   │
├──────────────────────────────┼────────────┼───────┼───────┤
│ test/code-complexity.test.ts │ 107        │ 7     │ 749   │
├──────────────────────────────┼────────────┼───────┼───────┤
│ .idea/workspace.xml          │ 123        │ 6     │ 738   │
└──────────────────────────────┴────────────┴───────┴───────┘

Example with --format=json:

$ npx code-complexity . --format=json --limit=3

[{"path":"bin/code-complexity.ts","churn":1,"complexity":6,"ratio":6},{"path":".eslintignore","churn":1,"complexity":1,"ratio":1},{"path":".eslintrc.js","churn":1,"complexity":19,"ratio":19}]

I'm also thinking about an html format in order to display a complexity/churn graph but it's a bit of work so I'm not sure when that will lend.

Added --filter=<glob> flag

As mentioned above, it replaces both --excludes and --includes whil adding glob support using micromatch. Good job me!

Added debug support

If you're interested in metrics and what's going on without having to look at the source code, you can use the DEBUG=* environment variable.