Class: StudFinder::Complexity

Inherits:
Object
  • Object
show all
Defined in:
lib/stud_finder/complexity.rb

Defined Under Namespace

Classes: Error, Result

Constant Summary collapse

COMPLEXITY_COP =
'Metrics/CyclomaticComplexity'
COMPLEXITY_PATTERN =
%r{\[(\d+)/0\]}
PARSE_ERROR_COPS =
%w[Lint/Syntax].freeze
RUBOCOP_CONFIG =
<<~YAML
  AllCops:
    DisabledByDefault: true
  Metrics/CyclomaticComplexity:
    Enabled: true
    Max: 0
YAML

Instance Method Summary collapse

Constructor Details

#initialize(repo_path:, files:, stderr: $stderr) ⇒ Complexity

Returns a new instance of Complexity.



24
25
26
27
28
# File 'lib/stud_finder/complexity.rb', line 24

def initialize(repo_path:, files:, stderr: $stderr)
  @repo_path = File.expand_path(repo_path)
  @files = files
  @stderr = stderr
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/stud_finder/complexity.rb', line 30

def call
  stdout, stderr, status = run_rubocop
  raise Error, fatal_message(stderr) if status.exitstatus == 2
  raise Error, fatal_message(stderr) unless [0, 1].include?(status.exitstatus)

  parse(stdout)
rescue Errno::ENOENT
  raise Error, 'Error: rubocop not found. Install it: gem install rubocop'
rescue JSON::ParserError => e
  raise Error, "Error: failed to parse RuboCop JSON output: #{e.message}"
end