Sha256: e66afb4bf481b507d805fe875a4fa63d06b05feebe33ec2ca43a99a3f576229a

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

#!/usr/bin/env ruby
#
# Wrapper for the CodeClimate integration.

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

# 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 = [
    '-f', 'code_climate',
    '--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

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

exit application.execute

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-3.11 bin/code_climate_reek
reek-3.10.2 bin/code_climate_reek