Running Code Climate Locally

NOTE – This information is archival and no longer supported.

If you encounter a repo with a codeclimate.yml, please delete it.


Prerequisites

To run code climate locally, grab an existing plugin or theme’s .codeclimate.yml file (if you don’t already have one) and place it in the root of your repository:

Next, follow the instructions listed on the Code Climate repo, or continue by installing the prerequisites that are listed:

Installation

Note: All of this information is available on the Code Climate repo. To continue, make sure you have Docker, or Docker for Mac for macOS.

1. Install Docker Image

To run Code Climate reports locally, the Docker image must be installed on your machine.

Run the following command in a Terminal session to pull down the Docker image:

docker pull codeclimate/codeclimate

This will download the Docker image that code climate will use to run its analysis tools.

After that finishes, code climate can now be run using the following example command:

docker run \

  –interactive –tty –rm \

  –env CODECLIMATE_CODE=”$PWD” \

  –volume “$PWD”:/code \

  –volume /var/run/docker.sock:/var/run/docker.sock \

  –volume /tmp/cc:/tmp/cc \

  codeclimate/codeclimate help

 

But since that’s a burden to type each time, it is preferred to use Code Climate’s wrapper scripts. Follow either of the options in step 2 to install the codeclimate command.

2. Install codeclimate command

For macOS using Homebrew

The easiest way to install the codeclimate command on macOS is with the homebrew package manager. Install homebrew before continuing. Otherwise, continue on to the next step.

In a Terminal session, run the following commands:

  1. brew tap codeclimate/formulae
  2. brew install codeclimate

For any OS (Windows, Linux, etc)

If on Windows or another operating system, run the following commands:

  1. curl -L https://github.com/codeclimate/codeclimate/archive/master.tar.gz | tar xvz
  2. cd codeclimate-* && sudo make install

Usage

Example commands

If using the wrapper scripts, the codeclimate command should be available. Test it by running codeclimate version.

A list of commands is available on the Code Climate GitHub page. The following commands can be run in the root of your repository:

Analyze the entire repo

codeclimate analyze

Analyze just one file

codeclimate analyze includes/functions.php

Validate the contents of your codeclimate file

codeclimate validate-config

Troubleshooting

You can debug and modify how your commands run by adding additional flags. See the Code Climate repo for official definitions of each flag. As an overview, these are the following known flags:

Run codeclimate in debug mode

CODECLIMATE_DEBUG=1 codeclimate analyze

Prints additional information about the analysis steps, including any stderr produced by engines.

Increase timeout

To increase the amount of time each engine container may run (default 15 min):

# 30 minutes

CONTAINER_TIMEOUT_SECONDS=1800 codeclimate analyze

Increase memory

You can also configure the default alotted memory with which each engine runs (default is 1,024,000,000 bytes):

# 2,000,000,000 bytes

ENGINE_MEMORY_LIMIT_BYTES=2000000000 codeclimate analyze

The analyze script is taking forever to run

This could be due to a variety of factors:

  • It could be hanging up on installing engines. Try running codeclimate engines:install first, before running codeclimate analyze
  • There are a very large number of files in your repository that Code Climate is trying to analyze at once. Be sure to specify all files and directories you want Code Climate to skip using the exclude_patterns key in the yaml config file.
  • It could be hanging up on some assets that its trying to download in the prepare > fetch key in the yaml config file. Make sure the repos are all public.