Sha256: d595a236a97c815f87c20ac2f0afaae13bf8a9493cbecc25dd02808f52f5efa8

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true
require 'rubycritic/analysers/helpers/reek'
require 'rubycritic/core/smell'
require 'rubycritic/colorize'

module RubyCritic
  module Analyser
    class ReekSmells
      include Colorize
      def initialize(analysed_modules)
        @analysed_modules = analysed_modules
      end

      def run
        @analysed_modules.each do |analysed_module|
          add_smells_to(analysed_module)
          print green '.'
        end
        puts ''
      end

      def to_s
        'reek smells'
      end

      private

      def add_smells_to(analysed_module)
        Reek.new(analysed_module.pathname).smells.each do |smell|
          analysed_module.smells << create_smell(smell)
        end
      end

      def create_smell(smell)
        Smell.new(
          locations: smell_locations(smell.source, smell.lines),
          context: smell.context,
          message: smell.message,
          type: smell.smell_type,
          analyser: 'reek',
          cost: 0
        )
      end

      def smell_locations(file_path, file_lines)
        file_lines.uniq.map do |file_line|
          Location.new(file_path, file_line)
        end.sort
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubycritic-3.2.0 lib/rubycritic/analysers/smells/reek.rb
rubycritic-3.1.3 lib/rubycritic/analysers/smells/reek.rb
rubycritic-3.1.2 lib/rubycritic/analysers/smells/reek.rb
rubycritic-3.1.1 lib/rubycritic/analysers/smells/reek.rb
rubycritic-3.1.0 lib/rubycritic/analysers/smells/reek.rb
rubycritic-3.0.0 lib/rubycritic/analysers/smells/reek.rb
rubycritic-2.9.4 lib/rubycritic/analysers/smells/reek.rb