• Stars
    star
    262
  • Rank 156,136 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 11 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Guard plugin for RuboCop

Gem Version CI Coverage Status Code Climate

guard-rubocop

guard-rubocop allows you to automatically check Ruby code style with RuboCop when files are modified.

Tested on MRI 2.5 - 3.1.

Installation

Please make sure to have Guard installed before continue.

Add guard-rubocop to your Gemfile:

group :development do
  gem 'guard-rubocop'
end

and then execute:

$ bundle install

or install it yourself as:

$ gem install guard-rubocop

Add the default Guard::RuboCop definition to your Guardfile by running:

$ guard init rubocop

Usage

Please read the Guard usage documentation.

Options

You can pass some options in Guardfile like the following example:

guard :rubocop, all_on_start: false, cli: ['--format', 'clang', '--rails'] do
  # ...
end

Available Options

all_on_start: true     # Check all files at Guard startup.
                       #   default: true
cli: '--rails'         # Pass arbitrary RuboCop CLI arguments.
                       # An array or string is acceptable.
                       #   default: nil
cmd: './bin/rubocop'   # Pass custom cmd to run rubocop.
                       #   default: rubocop

hide_stdout: false     # Do not display console output (in case outputting to file).
                       #   default: false
keep_failed: true      # Keep failed files until they pass.
                       #   default: true
notification: :failed  # Display Growl notification after each run.
                       #   true    - Always notify
                       #   false   - Never notify
                       #   :failed - Notify only when failed
                       #   default: :failed
launchy: nil           # Filename to launch using Launchy after RuboCop runs.
                       #   default: nil

Using Launchy to view results

guard-rubocop can be configured to launch a results file in lieu of or in addition to outputing results to the terminal. Configure your Guardfile with the launchy option:

guard :rubocop, cli: %w(--format fuubar --format html -o ./tmp/rubocop_results.html), launchy: './tmp/rubocop_results.html' do
  # ...
end

Advanced Tips

If you're using a testing Guard plugin such as guard-rspec together with guard-rubocop in the TDD way (the red-green-refactor cycle), you might be uncomfortable with the offense reports from RuboCop in the red-green phase:

  • In the red-green phase, you're not necessarily required to write clean code – you just focus writing code to pass the test. It means, in this phase, guard-rspec should be run but guard-rubocop should not.
  • In the refactor phase, you're required to make the code clean while keeping the test passing. In this phase, both guard-rspec and guard-rubocop should be run.

In this case, you may consider making use of the group method in your Guardfile:

# This group allows to skip running RuboCop when RSpec failed.
group :red_green_refactor, halt_on_fail: true do
  guard :rspec do
    # ...
  end

  guard :rubocop do
    # ...
  end
end

Note: You need to use guard-rspec 4.2.3 or later due to a bug where it unintentionally fails when there are no spec files to be run.

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 new Pull Request

License

Copyright (c) 2013–2020 Yuji Nakayama

See the LICENSE.txt for details.

More Repositories

1

ruby-style-guide

A community-driven Ruby coding style guide
16,439
star
2

rubocop

A Ruby static code analyzer and formatter, based on the community Ruby style guide.
Ruby
12,608
star
3

rails-style-guide

A community-driven Ruby on Rails style guide
6,469
star
4

rspec-style-guide

Best practices for writing your specs!
952
star
5

rubocop-rspec

Code style checking for RSpec files.
Ruby
804
star
6

rubocop-rails

A RuboCop extension focused on enforcing Rails best practices and coding conventions.
Ruby
799
star
7

rubocop-performance

An extension of RuboCop focused on code performance checks.
Ruby
665
star
8

rubocop-minitest

Code style checking for Minitest files.
Ruby
140
star
9

rubocop-emacs

An Emacs interface for RuboCop
Emacs Lisp
128
star
10

rubocop-ast

RuboCop's AST extensions and NodePattern functionality
Ruby
99
star
11

rubocop-rake

A RuboCop plugin for Rake
Ruby
75
star
12

rubocop-md

RuboCop for Markdown code snippets
Ruby
73
star
13

minitest-style-guide

Best practices for writing your tests
68
star
14

rubocop-jp

A place for RuboCop discussions in Japanese
55
star
15

vscode-rubocop

The official VS Code extension for the RuboCop linter and code formatter.
TypeScript
50
star
16

rubocop-extension-generator

A generator of RuboCop's custom cops gem.
Ruby
48
star
17

rubocop-factory_bot

Code style checking for factory_bot files.
Ruby
44
star
18

rubocop-capybara

Code style checking for Capybara files.
Ruby
39
star
19

rubocop-sequel

Code style checking for Sequel
Ruby
28
star
20

rubocop-rubycw

Wrap ruby -cw by RuboCop
Ruby
26
star
21

rubocop-rspec_rails

Code style checking for Rails-related RSpec files.
Ruby
14
star
22

blog.rubystyle.guide

A companion blog to the community Ruby, Rails and RSpec guides
HTML
7
star
23

packaging-style-guide

Best practices for writing downstream compatible code!
6
star
24

docs.rubocop.org

RuboCop's documentation site
Handlebars
4
star
25

circleci-ruby-snapshot-image

Builds a Ruby nightly image and publishes it to Docker Hub
Ruby
3
star
26

.github

2
star
27

capybara-style-guide

A community-driven Capybara coding style guide
1
star