Skip to content

Instantly share code, notes, and snippets.

@terraboops
Created May 1, 2019 00:36
Show Gist options
  • Save terraboops/f8624c31a6137c1e37f64ff83c2a6cb0 to your computer and use it in GitHub Desktop.
Save terraboops/f8624c31a6137c1e37f64ff83c2a6cb0 to your computer and use it in GitHub Desktop.
Using code-forensics to get insights on a codebase

Intro

This is a brief description of how to get insights on a codebase using code-forensics.

For more information - please see the repo here: https://github.com/smontanari/code-forensics

Dependencies

  • Node.js v11.x or greater installed
  • gulp installed (npm install -g gulp)

Procedure

Check out the repo you want to investigate locally. Then, in a new project folder somewhere outside the repo, create these files:

gulpfile.js

require('code-forensics').configure(
  {
    repository: {
      rootPath: "/path/to/your/repository"
    }
  }
);

package.json

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "dependencies": {
    "code-forensics": "^2.1.1"
  },
  "devDependencies": {},
  "scripts": {},
  "author": "",
  "license": "ISC"
}

Now you should be able to run npm install and you will see code-forensics is downloaded. You're ready to do some investigating!

If you run gulp list-analysis-tasks you should see some output like this:

$ gulp list-analysis-tasks
[17:31:40] Using gulpfile /some/path/gulpfile.js
[17:31:40] Starting 'list-analysis-tasks'...
[17:31:40] 
Analysis tasks
* sloc-trend-analysis                 : Analyse the sloc trend in time for a particular file
* javascript-complexity-trend-analysis: Analyse the complexity trend in time for a particular javascript file
* ruby-complexity-trend-analysis      : Analyse the complexity trend in time for a particular ruby file
* sum-of-coupling-analysis            : Analyse the sum of coupling for each file
* temporal-coupling-analysis          : Analyse the evolution of coupling in time for a particular file
* hotspot-analysis                    : Analyse the complexity and churn of source code to identify hotspots
* commit-message-analysis             : Analyse the number of occurrencies of commit message words
* developer-effort-analysis           : Analyse the distribution of effort (revisions) amongst developers/teams
* developer-coupling-analysis         : Analyse the ownership and communication coupling between developers
* knowledge-map-analysis              : Analyse the distribution of knowledge amongst developers/teams for each file
* system-evolution-analysis           : Analyse the evolution and the coupling in time of different parts of your system
[17:31:40] Finished 'list-analysis-tasks' after 3.32 ms

Then you can run reports like this: gulp hotspot-analysis --dateFrom=2016-01-01

... or even better, run all of the reports in one for loop:

for report in sloc-trend-analysis sum-of-coupling-analysis commit-message-analysis developer-effort-analysis developer-coupling-analysis knowledge-map-analysis system-evolution-analysis; do gulp $report --dateFrom=2016-01-01; done

Now you can view the reports - run: gulp webserver and open up http://localhost:3000! 💥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment