Sha256: 94d2ffb43ef49ecae775a088247526892e53437e58b0223f9c657dad05ec86cb

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Solidus
      # TODO: Write cop description and example of bad / good code. For every
      # `SupportedStyle` and unique configuration, there needs to be examples.
      # Examples must have valid Ruby syntax. Do not use upticks.
      #
      #
      # @example EnforcedStyle: SpreeClass
      #   # Description of the `SpreeClass` style.
      #
      #   # bad
      #   SpreeClass.class_eval do
      #   .
      #   .
      #   end
      #
      #
      #   # good
      #   module SpreeClassDecorator
      #   .
      #   .
      #   end
      #
      class ClassEvalDecorator < Base
        MSG = 'Do not use `class_eval` flag. Use a decorator module instead. Check this link for an example https://guides.solidus.io/cookbook/redefining-checkout-steps'

        # TODO: Don't call `on_send` unless the method name is in this list
        # If you don't need `on_send` in the cop you created, remove it.
        RESTRICT_ON_SEND = %i[class_eval].freeze

        # @!method on_class_eval?(node)
        def_node_matcher :on_class_eval?, <<~PATTERN
          (send  ($...) :class_eval)
        PATTERN

        def on_send(node)
          return unless on_class_eval?(node)

          add_offense(node)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-solidus-0.1.3 lib/rubocop/cop/solidus/class_eval_decorator.rb
rubocop-solidus-0.1.2 lib/rubocop/cop/solidus/class_eval_decorator.rb
rubocop-solidus-0.1.1 lib/rubocop/cop/solidus/class_eval_decorator.rb
rubocop-solidus-0.1.0 lib/rubocop/cop/solidus/class_eval_decorator.rb