Class: Pronto::Rubocop
- Inherits:
-
Runner
- Object
- Runner
- Pronto::Rubocop
- Defined in:
- lib/pronto/rubocop.rb
Instance Method Summary collapse
-
#initialize ⇒ Rubocop
constructor
A new instance of Rubocop.
- #inspect(patch) ⇒ Object
- #level(severity) ⇒ Object
- #new_message(offence, line) ⇒ Object
- #run(patches) ⇒ Object
Constructor Details
#initialize ⇒ Rubocop
Returns a new instance of Rubocop.
6 7 8 |
# File 'lib/pronto/rubocop.rb', line 6 def initialize @cli = ::Rubocop::CLI.new end |
Instance Method Details
#inspect(patch) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/pronto/rubocop.rb', line 19 def inspect(patch) offences = @cli.inspect_file(patch.new_file_full_path) offences.map do |offence| patch.added_lines.select { |line| line.new_lineno == offence.line } .map { |line| (offence, line) } end end |
#level(severity) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/pronto/rubocop.rb', line 35 def level(severity) case severity when :refactor, :convention :info when :warning, :error, :fatal severity end end |
#new_message(offence, line) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/pronto/rubocop.rb', line 28 def (offence, line) path = line.patch.delta.new_file[:path] level = level(offence.severity) Message.new(path, line, level, offence.) end |
#run(patches) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/pronto/rubocop.rb', line 10 def run(patches) return [] unless patches patches.select { |patch| patch.additions > 0 } .select { |patch| ruby_file?(patch.new_file_full_path) } .map { |patch| inspect(patch) } .flatten.compact end |