Class: PolishGeeks::DevTools::Commands::Rubocop

Inherits:
Base
  • Object
show all
Defined in:
lib/polish_geeks/dev_tools/commands/rubocop.rb

Overview

Command wrapper for Rubocop validation It informs us if code is formatted in a proper way

Constant Summary collapse

FILES_REGEXP =

Regexp used to get number of inspected files

/(\d+) files inspected/
OFFENSES_REGEXP =

Regexp used to get number of offenses detected

/(\d+) offense.* detected/

Constants inherited from Base

Base::TYPES

Instance Attribute Summary

Attributes inherited from Base

#output, #stored_output

Instance Method Summary collapse

Methods inherited from Base

#ensure_executable!, #error_message

Instance Method Details

#executeString

Executes this command

Returns:

  • (String)

    command output



17
18
19
20
21
22
23
# File 'lib/polish_geeks/dev_tools/commands/rubocop.rb', line 17

def execute
  cmd = ["bundle exec rubocop #{PolishGeeks::DevTools.app_root}"]
  cmd << "-c #{self.class.config_manager.path}" if self.class.config_manager.present?
  cmd << '--require rubocop-rspec' if Config.config.rubocop_rspec?
  cmd << '--display-cop-names'
  @output = Shell.new.execute(cmd.join(' '))
end

#labelString

Returns default label for this command.

Returns:

  • (String)

    default label for this command



31
32
33
34
35
36
37
# File 'lib/polish_geeks/dev_tools/commands/rubocop.rb', line 31

def label
  msg = []
  msg << 'Rubocop'
  msg << 'with RSpec' if Config.config.rubocop_rspec?
  msg << "(#{files_count} files, #{offenses_count} offenses)"
  msg.join(' ')
end

#valid?Boolean

Returns true if there were no Rubocop offenses detected.

Returns:

  • (Boolean)

    true if there were no Rubocop offenses detected



26
27
28
# File 'lib/polish_geeks/dev_tools/commands/rubocop.rb', line 26

def valid?
  offenses_count.zero?
end