Sha256: 6e46766c99517d9710acf37d261e7fa070447534e361d2023380e41be8c38d55

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module RailsBestPractices
  module Reviews
    # Find out unused methods in helpers.
    #
    # Implementation:
    #
    # Review process:
    #   remember all method calls in helpers.
    #   if they are not called in views, helpers, or controllers
    #   then they are unused methods in helpers.
    class RemoveUnusedMethodsInHelpersReview < Review
      include Moduleable
      include Callable
      include Exceptable

      interesting_files HELPER_FILES, VIEW_FILES, CONTROLLER_FILES

      def initialize(options = {})
        super
        @helper_methods = Prepares.helper_methods
        self.class.interesting_files *Prepares.helpers.map(&:descendants)
      end

      # get all unused methods at the end of review process
      add_callback :after_check do
        @helper_methods.get_all_unused_methods.each do |method|
          next if excepted?(method)

          add_error "remove unused methods (#{method.class_name}##{method.method_name})",
                    method.file,
                    method.line_number
        end
      end

      protected

      def methods
        @helper_methods
      end

      def internal_except_methods
        ['*#url_for']
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb
rails_best_practices-1.23.1 lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb
rails_best_practices-1.23.0 lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb
rails_best_practices-1.22.1 lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb
rails_best_practices-1.22.0 lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb
rails_best_practices-1.21.0 lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb
rails_best_practices-1.20.1 lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb