Skip to content

Commit

Permalink
Merge pull request #768 from nevir/rake-requires
Browse files Browse the repository at this point in the history
Rake task now supports `requires` and `options`
  • Loading branch information
bbatsov committed Jan 26, 2014
2 parents d390302 + a0b57b0 commit 4a30ec9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* [#714](https://github.com/bbatsov/rubocop/issues/714): New cop `RequireParentheses` checks for method calls without parentheses together with a boolean operator indicating that a mistake about precedence may have been made. ([@jonas054][])
* [#743](https://github.com/bbatsov/rubocop/issues/743): `WordArray` cop does auto-correction. ([@jonas054][])
* [#768](https://github.com/bbatsov/rubocop/issues/768): Rake task now supports `requires` and `options`. ([@nevir][])

### Changes

Expand Down
20 changes: 17 additions & 3 deletions lib/rubocop/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
require 'rake'
require 'rake/tasklib'

require 'rubocop/options'

module Rubocop
# Provides a custom rake task.
#
Expand All @@ -16,6 +14,8 @@ class RakeTask < Rake::TaskLib
attr_accessor :fail_on_error
attr_accessor :patterns
attr_accessor :formatters
attr_accessor :requires
attr_accessor :options

def initialize(*args, &task_block)
setup_ivars(args)
Expand All @@ -39,17 +39,31 @@ def run_task(verbose)

cli = CLI.new
puts 'Running RuboCop...' if verbose
result = cli.run([formatters.map { |f| ['-f', f] }, patterns])
result = cli.run(full_options)
abort('RuboCop failed!') if fail_on_error unless result == 0
end

private

def full_options
[].tap do |options|
options.concat(formatters.map { |f| ['--format', f] }.flatten)
options.concat(requires.map { |r| ['--require', r] }.flatten)
options.concat(options)
options.concat(patterns)
end
end

def setup_ivars(args)
# More lazy-loading to keep load time down.
require 'rubocop/options'

@name = args.shift || :rubocop
@verbose = true
@fail_on_error = true
@patterns = []
@requires = []
@options = []
@formatters = [Rubocop::Options::DEFAULT_FORMATTER]
end
end
Expand Down

0 comments on commit 4a30ec9

Please sign in to comment.