Class: Rubocop::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/rubocop/rake_task.rb

Overview

Provides a custom rake task.

require 'rubocop/rake_task' Rubocop::RakeTask.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &task_block) ⇒ RakeTask

Returns a new instance of RakeTask.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/rake_task.rb', line 17

def initialize(*args, &task_block)
  setup_ivars(args)

  desc 'Run RuboCop' unless ::Rake.application.last_comment

  task(name, *args) do |_, task_args|
    RakeFileUtils.send(:verbose, verbose) do
      if task_block
        task_block.call(*[self, task_args].slice(0, task_block.arity))
      end
      run_task(verbose)
    end
  end
end

Instance Attribute Details

#fail_on_errorObject

Returns the value of attribute fail_on_error.



14
15
16
# File 'lib/rubocop/rake_task.rb', line 14

def fail_on_error
  @fail_on_error
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/rubocop/rake_task.rb', line 12

def name
  @name
end

#patternsObject

Returns the value of attribute patterns.



15
16
17
# File 'lib/rubocop/rake_task.rb', line 15

def patterns
  @patterns
end

#verboseObject

Returns the value of attribute verbose.



13
14
15
# File 'lib/rubocop/rake_task.rb', line 13

def verbose
  @verbose
end

Instance Method Details

#run_task(verbose) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/rake_task.rb', line 32

def run_task(verbose)
  # We lazy-load rubocop so that the task doesn't dramatically impact the
  # load time of your Rakefile.
  require 'rubocop'

  cli = CLI.new
  puts 'Running RuboCop...' if verbose
  result = cli.run(patterns)
  abort('RuboCop failed!') if fail_on_error unless result == 0
end