Sha256: 2a7f5ef37f06cae741484ae994a8dc05423735e452c1604dc1ec5a8f3d72bea4

Contents?: true

Size: 1.53 KB

Versions: 28

Compression:

Stored size: 1.53 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'

# 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

28 entries across 28 versions & 1 rubygems

Version Path
reek-4.6.1 bin/code_climate_reek
reek-4.6.0 bin/code_climate_reek
reek-4.5.6 bin/code_climate_reek
reek-4.5.5 bin/code_climate_reek
reek-4.5.4 bin/code_climate_reek
reek-4.5.3 bin/code_climate_reek
reek-4.5.2 bin/code_climate_reek
reek-4.5.1 bin/code_climate_reek
reek-4.5.0 bin/code_climate_reek
reek-4.4.2 bin/code_climate_reek
reek-4.4.1 bin/code_climate_reek
reek-4.4.0 bin/code_climate_reek
reek-4.3.0 bin/code_climate_reek
reek-4.2.5 bin/code_climate_reek
reek-4.2.4 bin/code_climate_reek
reek-4.2.3 bin/code_climate_reek
reek-4.2.2 bin/code_climate_reek
reek-4.2.1 bin/code_climate_reek
reek-4.2.0 bin/code_climate_reek
reek-4.1.1 bin/code_climate_reek