Sha256: 8c5f4430464172be1967c75a78d61406ec20801bdb92184076de4b0b7b9122bc

Contents?: true

Size: 1.78 KB

Versions: 5

Compression:

Stored size: 1.78 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

#
# Wrapper for the CodeClimate integration.

require_relative '../lib/reek'
require_relative '../lib/reek/cli/application'
require_relative '../lib/reek/report/code_climate'

# Map input coming from CodeClimate to Reek.
class CodeClimateToReek
  # Following the spec (https://github.com/codeclimate/spec/blob/master/SPEC.md)
  # we have to exit with a zero for both failure and success.
  ENGINE_CONFIGURATION = [
    '--failure-exit-code', '0',
    '--success-exit-code', '0',
    '.'
  ].freeze

  attr_reader :configuration_file_path, :include_paths_key, :include_paths_default

  def initialize(configuration_file_path: '/config.json',
                 include_paths_key: 'include_paths',
                 include_paths_default: [])
    @configuration_file_path = configuration_file_path
    @include_paths_key       = include_paths_key
    @include_paths_default   = include_paths_default
  end

  def cli_arguments
    include_paths + ENGINE_CONFIGURATION
  end

  private

  def configuration_file_exists?
    Pathname.new(configuration_file_path).exist?
  end

  # The config.json file we try to read below might look like this:
  # {
  #   "include_paths":[
  #     "lib",
  #     "spec"
  #   ]
  # }
  def include_paths
    if configuration_file_exists?
      config = JSON.parse File.read(configuration_file_path)
      config.fetch include_paths_key, include_paths_default
    else
      include_paths_default
    end
  end
end

# Override for ReportCommand to force the use of CodeClimateReport.
module ReportClassOverride
  def report_class
    Reek::Report::CodeClimateReport
  end
end

Reek::CLI::Command::ReportCommand.prepend ReportClassOverride

application = Reek::CLI::Application.new(CodeClimateToReek.new.cli_arguments)

exit application.execute

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reek-6.0.4 bin/code_climate_reek
reek-6.0.3 bin/code_climate_reek
reek-6.0.2 bin/code_climate_reek
reek-6.0.1 bin/code_climate_reek
reek-6.0.0 bin/code_climate_reek