Class: Pronto::Rubocop
- Inherits:
-
Runner
- Object
- Runner
- Pronto::Rubocop
- Defined in:
- lib/pronto/rubocop.rb
Instance Method Summary collapse
- #excluded?(patch) ⇒ Boolean
-
#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 9 |
# File 'lib/pronto/rubocop.rb', line 6 def initialize @config_store = ::RuboCop::ConfigStore.new @inspector = ::RuboCop::Runner.new({}, @config_store) end |
Instance Method Details
#excluded?(patch) ⇒ Boolean
40 41 42 43 |
# File 'lib/pronto/rubocop.rb', line 40 def excluded?(patch) path = patch.new_file_full_path.to_s @config_store.for(path).file_to_exclude?(path) end |
#inspect(patch) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/pronto/rubocop.rb', line 23 def inspect(patch) processed_source = ::RuboCop::ProcessedSource.from_file(patch.new_file_full_path) offences = @inspector.send(:inspect_file, processed_source).first offences.map do |offence| patch.added_lines.select { |line| line.new_lineno == offence.line } .map { |line| (offence, line) } end end |
#level(severity) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/pronto/rubocop.rb', line 45 def level(severity) case severity when :refactor, :convention :info when :warning, :error, :fatal severity end end |
#new_message(offence, line) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/pronto/rubocop.rb', line 33 def (offence, line) path = line.patch.delta.new_file[:path] level = level(offence.severity.name) Message.new(path, line, level, offence.) end |
#run(patches, _) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pronto/rubocop.rb', line 11 def run(patches, _) return [] unless patches valid_patches = patches.select do |patch| patch.additions > 0 && ruby_file?(patch.new_file_full_path) && !excluded?(patch) end valid_patches.map { |patch| inspect(patch) }.flatten.compact end |