Skip to content

An automated code linting bot that integrates various code lint tools with github pull requests.

License

Notifications You must be signed in to change notification settings

colindecarlo/lint-review

 
 

Repository files navigation

Lint Review

Lint Review helps automate a tedious part of code review - enforcing coding standards. By using the github API Lint Review runs a repository's configured linters and updates pull requests with line comments where lint errors would be introduced.

Lint Review requires:

  • Python 2.7 (It will probably work in 2.6, but I've only tested 2.7)
  • RabbitMQ (or any other Message broker that is compatible with Celery)
  • A publically addressable hostname/IP that either github or your github:enterprise can reach.
  • A github account with read/write access to the repositories you want linted. This account is used to post comments on pull reviews.

Lint Review runs as two processes. A web process handles accepting webhooks from github, and a celery process handles cloning repositories and running lint tools. You'll also need to have rabbitmq-server running.

Installation

You install Lint Review by cloning the repository and installing dependecies. Its recommended that you use virtualenv to save shaving yaks down the road.

git clone git://github.com/markstory/lint-review.git
virtualenv env
source env/bin/activate
pip install .

In addtion to installing the dependencies for lint-review you will also need to install the various lint tools you want to use. Lint-review requires that lint tools be installed system wide and on the $PATH of the user who runs the application. pep8 and flake8 will be installed as dependencies for lint-review, but any other tools will need to be installed manually.

Once the dependencies are installed you should configure the lint review applications.

Lint Review Configuration

Lint review is configured through a settings file. Both the web app and celery process share the same configuration file, so configuration is easier to manage and share.

  • Copy the settings.sample.py to settings.py

  • Edit the required configuration options.

  • Set the LINTREVIEW_SETTINGS environment variable to the path of your configuration files. In *nix system this can be done via:

    export LINTREVIEW_SETTINGS='/path/to/settings.py'
    
  • You can skip setting LINTREVIEW_SETTINGS if you're running lintreview from a directory containing your settings.py file.

Setting up Repositories

Once you've configured the server processes, it is time to setup some repositories to be checked.

Installing github hooks

Before Lint Review can check pull requests on a repository webhooks will need to be installed. You can install webhooks by running the built-in command line tool:

source env/bin/activate
lintreview register mark awesome-stuff

The above register webhooks for the given user & repository. You can use the --user and --password options to provide the repository admin credentials if the user lint-review runs as does not have admin access to the repository. You can also use the cli tool to remove webhooks:

source env/bin/activate
lintreview unregister mark awesome-stuff

Warning The current web server name will be registered with github. Make sure it is configured properly configured before registering hooks, or you'll need to remove any registered hooks and start over.

.lintrc files

Lint Review use hidden ini files to configure the tools used on each project. The .lintrc file defines the various linting tools and any arguments for each one. Lint tools must be tools Lint Review knows about. See lint tools for available tools. A sample .lintrc file would look like.

[tools]
linters = pep8, jshint

[tool_pep8]
ignore = 'W2,E401'

[tool_jshint]
config = path/to/jshint.json

The [tools] section is required, and linters should be a list of linters your project uses. Each tool can also have a section prefixed with tool_ to define additional configuration options for each tool. The documentation for each tool outlines which options are supported.

Running Lint Review

After setting up configuration you'll need to start up both processes:

source env/bin/activate
gunicorn -c settings.py lintreview.web:app
celery -A lintreview.tasks worker

Now when ever a pull request is opened or updated for a registered repository new jobs will be spun up and lint will be checked and commented on.

Lint tools

Python:

Flake8

Uses the flake8 module to check code.

Options

  • ignore Set which pep8 error codes you wish to ignore.

pep8

Uses the pep8 module to check code.

Options

  • ignore Set which pep8 error codes you wish to ignore.

PHP

PHPCS

Uses the phpcs PEAR library to do style checks on PHP, Javascript and or CSS files.

Options

  • standard The coding standard to use. By default the PEAR standard is used. You can use any of the built-in standards or provide your own inside your project directory.
  • extensions The extensions to check. By default only .php files will be checked.
  • tab_width The number of spaces to convert tabs into, this is useful for projects using tabs for indentation.

Javascript:

JSHint

Uses the jshint npm module to check javascript files. Before you can use this linter you'll need to install nodejs and the jshint npm package:

cd path/tp/lintreview
npm install jshint

Options

  • config Provide a path to the json config file for jshint.

CSS:

CSSHint

Uses the csslint npm module to check javascript files. Before you can use this linter you'll need to install nodejs and the jshint npm package:

cd path/tp/lintreview
npm install csslint

Both warnings and errors will be turned into code review comments. If you don't want code review comments for specific rules, you should ignore them.

Options

  • ignore A comma separated list of rule ids to ignore.

About

An automated code linting bot that integrates various code lint tools with github pull requests.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published