Class: Pronto::RubocopAutocorrect
- Inherits:
-
Runner
- Object
- Runner
- Pronto::RubocopAutocorrect
- Defined in:
- lib/pronto/rubocop-autocorrect.rb
Instance Method Summary collapse
- #config_store_for(patch) ⇒ Object
-
#initialize(_, _ = nil) ⇒ RubocopAutocorrect
constructor
A new instance of RubocopAutocorrect.
- #level(severity) ⇒ Object
- #new_message(offence, line) ⇒ Object
- #process(patch) ⇒ Object
- #processed_source_for(patch) ⇒ Object
- #run ⇒ Object
- #valid_patch?(patch) ⇒ Boolean
Constructor Details
#initialize(_, _ = nil) ⇒ RubocopAutocorrect
Returns a new instance of RubocopAutocorrect.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pronto/rubocop-autocorrect.rb', line 6 def initialize(_, _ = nil) super @auto_correct = true @config_store = ::RuboCop::ConfigStore.new if ENV['RUBOCOP_CONFIG'] @config_store. = ENV['RUBOCOP_CONFIG'] end = { auto_correct: @auto_correct } @inspector = ::RuboCop::Runner.new(, @config_store) end |
Instance Method Details
#config_store_for(patch) ⇒ Object
57 58 59 60 |
# File 'lib/pronto/rubocop-autocorrect.rb', line 57 def config_store_for(patch) path = patch.new_file_full_path.to_s @config_store.for(path) end |
#level(severity) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/pronto/rubocop-autocorrect.rb', line 67 def level(severity) case severity when :refactor, :convention :warning when :warning, :error, :fatal severity end end |
#new_message(offence, line) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pronto/rubocop-autocorrect.rb', line 46 def (offence, line) path = line.patch.delta.new_file[:path] level = level(offence.severity.name) = offence. if offence.corrected? = "[Corrected] #{}" level = :info end Message.new(path, line, level, , nil, self.class) end |
#process(patch) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/pronto/rubocop-autocorrect.rb', line 39 def process(patch) processed_source = processed_source_for(patch) file = patch.delta.new_file[:path] offences = @inspector.send(:do_inspection_loop, file, processed_source)[1] (offences, patch) end |
#processed_source_for(patch) ⇒ Object
62 63 64 65 |
# File 'lib/pronto/rubocop-autocorrect.rb', line 62 def processed_source_for(patch) path = patch.new_file_full_path.to_s ::RuboCop::ProcessedSource.from_file(path, RUBY_VERSION[0..2].to_f) end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/pronto/rubocop-autocorrect.rb', line 18 def run return [] unless @patches = @patches.select { |patch| valid_patch?(patch) } .map { |patch| process(patch) } .flatten.compact () if @auto_correct end |
#valid_patch?(patch) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pronto/rubocop-autocorrect.rb', line 28 def valid_patch?(patch) return false if patch.additions < 1 config_store = config_store_for(patch) path = patch.new_file_full_path return false if config_store.file_to_exclude?(path.to_s) return true if config_store.file_to_include?(path.to_s) ruby_file?(path) end |