Class: RuboCop::RakeTask
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Rake::TaskLib
|
|
Instance Chain:
self,
Rake::TaskLib
|
|
Inherits: |
Rake::TaskLib
|
Defined in: | lib/rubocop/rake_task.rb |
Overview
Provides a custom rake task.
require 'rubocop/rake_task' RuboCop::RakeTask.new
Use global Rake namespace here to avoid namespace issues with custom rubocop-rake tasks
Class Method Summary
Instance Attribute Summary
- #fail_on_error rw
- #formatters rw
- #name rw
- #options rw
- #patterns rw
- #requires rw
- #verbose rw
Instance Method Summary
- #full_options private
- #perform(option) private
- #run_cli(verbose, options) private
- #setup_ivars(name) private
-
#setup_subtasks(name, *args, &task_block)
private
Metrics/MethodLength.
Constructor Details
.new(name = :rubocop, *args, &task_block) ⇒ RakeTask
# File 'lib/rubocop/rake_task.rb', line 17
def initialize(name = :rubocop, *args, &task_block) super() setup_ivars(name) desc 'Run RuboCop' unless ::Rake.application.last_description task(name, *args) do |_, task_args| RakeFileUtils.verbose(verbose) do yield(*[self, task_args].slice(0, task_block.arity)) if task_block run_cli(verbose, ) end end setup_subtasks(name, *args, &task_block) end
Instance Attribute Details
#fail_on_error (rw)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 15
attr_accessor :name, :verbose, :fail_on_error, :patterns, :formatters, :requires, :
#formatters (rw)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 15
attr_accessor :name, :verbose, :fail_on_error, :patterns, :formatters, :requires, :
#name (rw)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 15
attr_accessor :name, :verbose, :fail_on_error, :patterns, :formatters, :requires, :
#options (rw)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 15
attr_accessor :name, :verbose, :fail_on_error, :patterns, :formatters, :requires, :
#patterns (rw)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 15
attr_accessor :name, :verbose, :fail_on_error, :patterns, :formatters, :requires, :
#requires (rw)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 15
attr_accessor :name, :verbose, :fail_on_error, :patterns, :formatters, :requires, :
#verbose (rw)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 15
attr_accessor :name, :verbose, :fail_on_error, :patterns, :formatters, :requires, :
Instance Method Details
#full_options (private)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 55
def formatters.map { |f| ['--format', f] }.flatten .concat(requires.map { |r| ['--require', r] }.flatten) .concat( .flatten) .concat(patterns) end
#perform(option) (private)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 35
def perform(option) = .unshift(option) # `parallel` will automatically be removed from the options internally. # This is a nice to have to suppress the warning message # about --parallel and --autocorrect not being compatible. .delete('--parallel') run_cli(verbose, ) end
#run_cli(verbose, options) (private)
[ GitHub ]# File 'lib/rubocop/rake_task.rb', line 44
def run_cli(verbose, ) # We lazy-load RuboCop so that the task doesn't dramatically impact the # load time of your Rakefile. require_relative '../rubocop' cli = CLI.new puts 'Running RuboCop...' if verbose result = cli.run( ) abort('RuboCop failed!') if result.nonzero? && fail_on_error end
#setup_ivars(name) (private)
[ GitHub ]#setup_subtasks(name, *args, &task_block) (private)
Metrics/MethodLength
# File 'lib/rubocop/rake_task.rb', line 72
def setup_subtasks(name, *args, &task_block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength namespace(name) do # rubocop:todo Naming/InclusiveLanguage task(:auto_correct, *args) do require 'rainbow' warn Rainbow( 'rubocop:auto_correct task is deprecated; ' \ 'use rubocop:autocorrect task or rubocop:autocorrect_all task instead.' ).yellow RakeFileUtils.verbose(verbose) do yield(*[self, task_args].slice(0, task_block.arity)) if task_block perform('--autocorrect') end end # rubocop:enable Naming/InclusiveLanguage desc "Autocorrect RuboCop offenses (only when it's safe)." task(:autocorrect, *args) do |_, task_args| RakeFileUtils.verbose(verbose) do yield(*[self, task_args].slice(0, task_block.arity)) if task_block perform('--autocorrect') end end desc 'Autocorrect RuboCop offenses (safe and unsafe).' task(:autocorrect_all, *args) do |_, task_args| RakeFileUtils.verbose(verbose) do yield(*[self, task_args].slice(0, task_block.arity)) if task_block perform('--autocorrect-all') end end end end