Class: Ruumba::RubocopRunner
- Inherits:
-
Object
- Object
- Ruumba::RubocopRunner
- Defined in:
- lib/ruumba/rubocop_runner.rb
Overview
Runs rubocop on the files in the given target_directory
Instance Method Summary collapse
-
#execute ⇒ Object
Executes rubocop, updating filenames in the output if needed.
-
#initialize(arguments, current_directory, target_directory, stdin, rb_extension_enabled) ⇒ RubocopRunner
constructor
A new instance of RubocopRunner.
Constructor Details
#initialize(arguments, current_directory, target_directory, stdin, rb_extension_enabled) ⇒ RubocopRunner
Returns a new instance of RubocopRunner.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruumba/rubocop_runner.rb', line 8 def initialize(arguments, current_directory, target_directory, stdin, rb_extension_enabled) @arguments = Array(arguments) @current_directory = current_directory @rb_extension_enabled = rb_extension_enabled @stdin = stdin @target_directory = target_directory @replacements = [] # if adding the .rb extension is enabled, remove the extension again from # any output so it matches the actual files names we are linting @replacements << [/\.erb\.rb/, '.erb'] if rb_extension_enabled end |
Instance Method Details
#execute ⇒ Object
Executes rubocop, updating filenames in the output if needed.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruumba/rubocop_runner.rb', line 23 def execute args = ['rubocop'] + arguments todo = target_directory.join('.rubocop_todo.yml') results = Dir.chdir(target_directory) do replacements.unshift([/^#{Regexp.quote(Dir.pwd)}/, current_directory.to_s]) stdout, stderr, status = Open3.capture3(*args, stdin_data: stdin) [munge_output(stdout), munge_output(stderr), status.exitstatus] end # copy the todo file back for the case where we've used --auto-gen-config FileUtils.cp(todo, current_directory) if todo.exist? results end |