Git Product home page Git Product logo

guard-rubocop's Introduction

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.4 - 2.7.

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
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.

guard-rubocop's People

Contributors

yujinakayama avatar bbatsov avatar ic avatar hakanensari avatar novtopro avatar robindaugherty avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.