Skip to content

A set of code analyses that assist you in tackling software complexity

License

Notifications You must be signed in to change notification settings

ag91/code-compass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code compass

This package shall guide you in your software development within Emacs. For example, it will point at the code that requires your changes the most and it will suggest you who to ask for help when you are lost.

I have presented some of the capabilities of code-compass in this talk of EmacsConf2020.

Credits

A significant part of this project relies on code-maat and the bright mind of his author Adam Tornhill. His books are inspiring and a suggested read.

Features

Use code-compass-cheatsheet to have a quick reference of the available commands and their aim. Check the Release Checklist heading for more information about them.

Installation and Dependencies

Please run =code-compass-doctor= if you encounter errors in running this tool

Note: I label dependencies as optional when the commands needing the dependency warn you they cannot execute because the dependency is missing.

This project depends on the following external dependencies:

  • Git
  • Python 3
  • Java 8 or above
  • code-maat
  • cloc
  • graph-cli (optional - only few commands will not succeed)
  • gource (optional)

And the following Emacs packages:

  • async.el
  • dash.el
  • f.el
  • s.el
  • simple-httpd

If you use use-package and you are on a Linux system, this will take care of the Emacs installation:

(use-package async)
(use-package dash)
(use-package f)
(use-package s)
(use-package simple-httpd)

(use-package code-compass
  :load-path "~/.emacs.d/lisp")

For Docker, the Code Maat image, cloc and graph-cli run the following script:

# Docker is only necessary if you want to use that instead of the (automatically downloaded) JAR file
# see here for how to install in systems different from Linux Debian: https://gist.github.com/rstacruz/297fc799f094f55d062b982f7dac9e41
#sudo apt install docker.io;
#sudo systemctl start docker;
# after you manage to run docker successfully
#git clone https://github.com/adamtornhill/code-maat.git;
#cd code-maat;
#docker build -t code-maat-app .

sudo apt install cloc;

cd /tmp;
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py; # from here https://pip.pypa.io/en/stable/installing/
python get-pip.py --user
pip3 install --user graph-cli # https://github.com/mcastorina/graph-cli

For trying things out in a clean Emacs:

(require 'package)
(eval-and-compile
  (setq
   package-archives
   '(("melpa-stable" . "https://stable.melpa.org/packages/")
     ("melpa" . "https://melpa.org/packages/")
     ("marmalade"   . "https://marmalade-repo.org/packages/")
     ("org"         . "https://orgmode.org/elpa/")
     ("gnu"         . "https://elpa.gnu.org/packages/"))))
(package-initialize)

 ;;; Bootstrap use-package
;; Install use-package if it's not already installed.
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(setq use-package-always-ensure 't)
(require 'use-package)
(require 'diminish)
(require 'bind-key)
(use-package async)
(use-package dash)
(use-package f)
(use-package s)
(use-package simple-httpd)
emacs -Q -l /tmp/code-compass-minimal-setup.el -l ./code-compass.el

Limitations

The limitations I know:

  1. only Git support for now, but I am open to PRs (should be easy because code-maat partially support other VCS already)
  2. Adam said that code-maat may fail for code bases larger than 5 million lines. Please report if you observe that is the case, we will find a solution.
  3. most likely others I will eventually discover from the issues ;)

Release Checklist

Releasing this in the wild is exciting, but it will take some time. Here what you can expect.

install instructions and dependencies

hotspots

software complexity

code churn

change coupling

use case of coupling: find coupled files

code communication

code knowledge

code stability

fragmentation

https://ag91.github.io/blog/2021/02/11/emacs-as-your-code-compass-how-fragmented-is-the-knowledge-of-this-file/

word analysis

use case of coupling: generate todos for current file

integrate gource

https://ag91.github.io/blog/2021/03/19/emacs-as-your-code-compass-watch-history-with-gource/

file-churn icon

main contributors notification

code refactoring

https://ag91.github.io/blog/2022/11/23/emacs-as-your-code-compass-who-is-the-person-who-refactored-most-in-this-project/

functions complexity

oh well I needed tree-sitter for this, see here: https://github.com/ag91/moldable-emacs/blob/master/molds/contrib.el#L242

License

GPLv3

Dependencies

d3:

License: BSD-3

Copyright 2010-2020 Mike Bostock

Contributing

If you have ideas or wishes, just open an issue and I will look into it! Thanks for caring.

Testing

Functions without side effects have tests in their documentation.

To run those install https://github.com/ag91/doctest (at the time of writing my fork as enhancements over the original) and run doctest.

Alternatives

  • CodeScene: this is the code analysis tool of Adam Tornhill which organizations can use to manage their software and organizational complexity. Code-compass learns from CodeScene and adapts to empower you.
  • code-risk: this is a set of scripts Noah Sussman’s uses to find quality issues in repositories. Code-compass includes these and make them easily accessible to you.
  • code-forensics: this makes available code-maat analyses in a node application. Code-compass offers a subset of these for now and focuses more on supporting you while you edit your project. (Thanks @BlankSpruce to share this repository!)
  • git-deps: this shows you dependencies between git commits. Hopefully code-compass will integrate this project to help you when, for example, you are struggling to identify the commit that broke your release.
  • ???

About

A set of code analyses that assist you in tackling software complexity

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published