Using Pronto to Introduce Style to Your Rails App
I believe most developers know that code style matters. It helps the code base feel clean and consistent. I've worked on a number of projects where teams are working without a style guide due to all of the style debt that's been accrued. Thanks to Pronto, style guides can be adopted without forcing you to pay off that debt immediately.
Pronto is a tool that runs linters on "relevant" changes (lines you've added or changed) in your project. This means you can incrementally introduce a style guide since it only comments on new code and existing code that you've changed.
Pronto can be run locally, but really shines when run in CI. When run in CI pronto will comment on lines in pull requests with the output from the tool it's running. This moves the responsibility of policing style from members of the team to Pronto during code review.
Setting up Style Linting in Rails
group :development, :test do gem 'rubocop', '~> 0.55.0', require: false end group :test do gem 'pronto' gem 'pronto-rubocop', require: false end
It's that easy! If you have an existing Rubocop config you can add it, if not I recommend starting with a blank slate and opening pull requests to change rules as you go.
If you want to give it a try, run
bundle pronto run and it will start linting
added files and changes.
Configuring for CircleCI
Unfortunately good documentation on setting up Pronto in CircleCI is hard to find. Here are the steps I followed to configure Pronto to work with CircleCI 2.0.
- Generate an OAuth token in Github
- Add a project level environment
PRONTO_GITHUB_ACCESS_TOKENusing the token created in the first step.
sudo apt-get install cmakeas one of the steps in
bundle. build a pronto dependency.
- Add the configuration below to
.circleci/config.ymlto run pronto on the correct pull request.
- run: echo 'export PRONTO_PULL_REQUEST_ID=$CIRCLE_PR_NUMBER' >> $BASH_ENV - run: if [ $PRONTO_PULL_REQUEST_ID != false ]; then pronto run -f github_pr_review -c origin/master; fi
Now whenever a pull request is opened pronto will run and use Github's review feature to comment on style violations in the pull request.
Pronto is a great way to introduce a style guide to your team without having to spend a significant amount of time getting the existing code base to conform to it. It's a great compromise between improving the code base and productivity.
If all of that sounds great but you can't, or don't want to setup Pronto HoundCI is a hosted alternative that provides the same functionality.