Sha256: 4eb352d9de8f9ba0b053e9b635053007f7710b84953d34a25457f401f94529c9

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module RailsBestPractices
  module Reviews
    # Review a helper file to make sure it is not an empty moduel.
    #
    # See the best practice details here https://rails-bestpractices.com/posts/2011/04/09/remove-empty-helpers/
    #
    # Implementation:
    #
    # Review process:
    #   check all helper files, if the body of module is nil, then the helper file should be removed.
    class RemoveEmptyHelpersReview < Review
      interesting_nodes :module
      interesting_files HELPER_FILES
      url 'https://rails-bestpractices.com/posts/2011/04/09/remove-empty-helpers/'

      # check the body of module node, if it is nil, then it should be removed.
      add_callback :start_module do |module_node|
        if module_node.module_name.to_s != 'ApplicationHelper' && empty_body?(module_node)
          add_error 'remove empty helpers'
        end
      end

      protected

      def empty_body?(module_node)
        s(:bodystmt, s(:stmts_add, s(:stmts_new), s(:void_stmt)), nil, nil, nil) == module_node.body
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.23.1 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.23.0 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.22.1 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.22.0 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.21.0 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.20.1 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.20.0 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.19.5 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
rails_best_practices-1.19.4 lib/rails_best_practices/reviews/remove_empty_helpers_review.rb