Project

policial

0.03
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Review pull requests for style guide violations.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.14
~> 2.0
~> 4.3
~> 0.39
 Project Readme

Policial 👮

Gem Version Build Status

Policial is a gem that investigates pull requests and accuses style guide violations. It is based on thoughtbot's Hound project. It currently supports RuboCop, SCSS and CoffeeLint.

Installation

Add this line to your application's Gemfile:

gem 'policial'

And then execute:

$ bundle

Or install it yourself as:

$ gem install policial

Usage

  1. First, instantiate a new Detective:
detective = Policial::Detective.new

You might need to pass an Octokit client with your GitHub credentials. For more information on this please check the Octokit README.

octokit = Octokit::Client.new(access_token: 'mygithubtoken666')
detective = Policial::Detective.new(octokit)

If you don't pass an Octokit client Policial will use the global Octokit configuration.

  1. Let's investigate! Start by briefing your detective about the pull request it will run an investigation against. You can setup a pull request manually:
detective.brief(
  repo: 'volmer/my_repo',
  number: 3,
  head_sha: 'headsha'
)

N. B. It's important to configure auto pagination for your client to receive reliable results on PRs with lot of files.

Or you can brief it with a GitHub pull_request webhook:

event = Policial::PullRequestEvent.new(webhook_payload)
detective.brief(event)
  1. Now you can run the investigation using the linters you want:
# Let's investigate this pull request and get a list of violations:
result = detective.investigate(linters: [Policial::Linters::RuboCop.new])
result.violations
# => [#<Policial::Violation:0x007ff0b5abad30 @filename="lib/test.rb", @line_number=1, ...>]

result.violations.first.message
"Prefer single-quoted strings when you don't need string interpolation or special symbols."

RuboCop

You can setup your RuboCop code style rules with a .rubocop.yml file in your repo. Please see RuboCop's README.

CoffeeLint

You can setup your CoffeeLint code style rules with a coffeelint.json file in your repo. For more information on how customize the linter rules please visit the Coffeelint website.

SCSS

SCSS linting is disabled by default. To enable it, you need to install the SCSS-Lint gem:

gem install scss_lint

Or add the following to your Gemfile and run bundle install:

gem 'scss_lint', require: false

The require: false is necessary because scss-lint monkey patches Sass. More info here.

Now you can use the SCSSLint linter when calling Detective#investigate:

violations = detective.investigate(linters: [Policial::Linters::SCSSLint.new])

You can setup your SCSS code style rules with a .scss-lint.yml file in your repo. For more information on how customize the linter rules please read SCSS-Lint's README.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request