AdvertileCop

20% MonkeyPatch, 80% YAML, 100% Style

AdvertileCop uses RuboCop to enforce Advertile Mobiles's style guidelines.

"What are the guidelines?", I hear you below. Well, check out our commented settings file for more information.

Installation

Add this line to your application's Gemfile:

gem 'advertilecop', require: false

And then execute:

$ bundle

Or install it globally with:

$ gem install advertilecop

Usage

In a Rakefile:

require 'advertilecop/rake_task'
AdvertileCop::RakeTask.new(:advertilecop)

This can be quite dramatic if you haven't been using a style checker previously and you have, say, 10 years of code written. Why not only lint files changed in the last N commits? This also makes advertilecop much faster in large codebases as you only have to lint recently changed files.

require 'advertilecop/rake_task'
AdvertileCop::RakeTask.new(:advertilecop) do |task|
  task.patterns = advertilecop_files(5)
  task.options = ['-D'] # Dispays name of failing cop in output. 
  exit if task.patterns == []
end

def advertilecop_files(pedantry)
  `git diff-tree --no-commit-id --name-only -r HEAD~#{pedantry} HEAD`
    .split("\n").select { |f| f.match(/(\.rb\z)|Rakefile/) && File.exist?(f) && !f.match(/db/) }
end

You can also use AdvertileCop stand-alone:

$ advertilecop

If you are introducing advertilecop to an existing project, or bumping the advertilecop version try:

$ advertilecop -a

Anything that can be auto corrected will be, this will save you a lot of time!

Overriding tests

It is possible to override specific Rubocop settings by having a .rubocop.yml in the project root. When present, advertilecop uses this file instead of advertilecop.yml. This file can, however, the settings of advertilecop.yml by having the following lines:

inherit_gem:
  advertilecop: ./lib/advertilecop.yml

Configuring / Contributing

  1. You can't configure this, thats the point.
  2. If you need to change our style guidelines, update the lib/advertilecop.yml file and open a pull request.
  3. If you have a good reason to break the guidelines, you can switch off the cop for the code like this.
  4. Please don't open a pull request unless you work at Advertile Mobile