Code Climate : CLI : Custom Analysis Engine : Customize CLI to support your custom engine

Overview

Code Climate is a command line interface for the Code Climate analysis platform. It allows you to run Code Climate engines on your local machine inside of Docker containers. After reading this post you will get how to customize the Code Climate CLI to make it support your Analysis Engine.

Main Point

It has been announced that Code Climate is free for open source projects. Many open source projects were added during the closed beta, and you can see them all on the new Explore page. (To learn more about what Code Climate provides and how it works, check out the homepage.)

Problem You might face

If you are familiar to making custom engines for CodeClimate then you might have also faced an issue that no matter what the CodeClimate CLI does not list out your engine when you execute the following command $ sudo codeclimate engines:list.

Reason

As far as I understand to get your engine listed in engine list you need to create a developer account and then submit them link to your Engine-image. They will then verify the integrity and may list your engine in the configs they release. After your Engine Image is approved you need to update the Code Climate CLI to reflect the changes.

Solution

Well, since the Code Climate CLI is opensource you can fork it to your plate and start hacking it. An example of Hack is here.

https://github.com/balabhadra/codeclimate

specially the configuration file

https://github.com/balabhadra/codeclimate/blob/master/config/engines.yml

example snippet you need to add into the file config/engines.yml

debug_sniffer:
  image: balabhadra/debug_sniffer 
  description: Debug Code Sniffer
  community: true
  enable_regexps:
    - \.rb$
    - \.js$ 
    - \.erb$
  default_ratings_paths:
    - "**.rb"
    - "**.js"
    - "**.erb"

Build your changes to image

$ sudo docker build -t <user_name_you_like>/codeclimate .

then you need to modify the /Makefile too

Example:

https://github.com/balabhadra/codeclimate/blob/master/Makefile

PREFIX ?= /usr/local

install:
 bin/check
 docker pull <user_name_you_like>/codeclimate:latest
 mkdir -p $(DESTDIR)$(PREFIX)/bin
 install -m 0755 codeclimate-wrapper $(DESTDIR)$(PREFIX)/bin/codeclimate

uninstall:
 $(RM) $(DESTDIR)$(PREFIX)/bin/codeclimate
 docker rmi <user_name_you_like>/codeclimate:latest

.PHONY: install uninstall

The above make file after it has been executed, makes sure that Code Climate CLI could be accessed just by typing $ sudo codeclimate rather than the long code like

docker run \
  --interactive --tty --rm \
  --env CODE_PATH="$PWD" \
  --volume "$PWD":/code \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --volume /tmp/cc:/tmp/cc \
  <user_name_you_like>/codeclimate help

now Make

# Get into the Code Climate Dir you are currently editing on
$ cd codeclimate 

# Make the software easily accessible to CLI / terminal
#   Execute the instruction for installation
$ sudo make install

# Similarly to uninstall you can execute
#  Uninstallation guidelines are also added in the Makefile
$ sudo make uninstall

Now you can see your engine listed by executing

$ sudo codeclimate engines:list.

Sources:

http://blog.codeclimate.com/blog/2012/07/10/code-climate-is-free-for-open-source/

https://github.com/codeclimate/spec

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s