Sha256: 0d2a5001350c7717d23672ee26b1e938a6f8f2c4c226ce1d3ecf44983fc3e862

Contents?: true

Size: 1.82 KB

Versions: 10

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require_relative 'base_command'
require_relative '../../examiner'
require_relative '../../configuration/app_configuration'

module Reek
  module CLI
    module Command
      #
      # A command to collect smells from a set of sources and writes a configuration
      # file that can serve as a todo list.
      #
      class TodoListCommand < BaseCommand
        HEADER = "# Auto generated by Reeks --todo flag\n"
        EXISTING_FILE_MESSAGE = "\nExisting '#{DEFAULT_CONFIGURATION_FILE_NAME}' detected - aborting.\n"
        NO_SMELLS_FOUND_MESSAGE = "\nNo smells found - nothing to do, exiting.\n"

        def execute
          if smells.empty?
            puts NO_SMELLS_FOUND_MESSAGE
          elsif File.exist?(DEFAULT_CONFIGURATION_FILE_NAME)
            puts EXISTING_FILE_MESSAGE
          else
            write_to_file
            puts "\n'#{DEFAULT_CONFIGURATION_FILE_NAME}' generated! "\
              'You can now use this as a starting point.'
          end
          options.success_exit_code
        end

        private

        def smells
          @smells ||= sources.map do |source|
            Examiner.new(source, filter_by_smells: smell_names)
          end.map(&:smells).flatten
        end

        def groups
          @groups ||=
            begin
              todos = smells.group_by(&:smell_class).map do |smell_class, smells_for_class|
                smell_class.todo_configuration_for(smells_for_class)
              end
              todos.inject(&:merge)
            end
        end

        # :reek:FeatureEnvy
        def write_to_file
          File.open(DEFAULT_CONFIGURATION_FILE_NAME, 'w') do |configuration_file|
            configuration_file.write HEADER
            configuration_file.write({ DETECTORS_KEY => groups }.to_yaml)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 8 versions & 2 rubygems

Version Path
reek-5.4.0 lib/reek/cli/command/todo_list_command.rb
reek-5.3.2 lib/reek/cli/command/todo_list_command.rb
reek-5.3.1 lib/reek/cli/command/todo_list_command.rb
reek-5.3.0 lib/reek/cli/command/todo_list_command.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/cli/command/todo_list_command.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/cli/command/todo_list_command.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/cli/command/todo_list_command.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/cli/command/todo_list_command.rb
reek-5.2.0 lib/reek/cli/command/todo_list_command.rb
reek-5.1.0 lib/reek/cli/command/todo_list_command.rb