Sha256: 485f0a921b8637731ea40713a7dafe27e0fd400ac8a2fe5cc1390abd6d1235c6

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Platanus
      # Usage of PowerTypes::Command is no longer recommended. Rails
      # ApplicationJob should be used instead.
      #
      # @example
      #
      #   # bad
      #   class ExecuteSomeAction < PowerTypes::Command.new(:foo, :bar)
      #     def perform
      #       # Command code goes here
      #     end
      #    end
      #
      #   # good
      #   class GuestsCleanupJob < ApplicationJob
      #     def perform
      #       # Job code goes here
      #     end
      #   end
      #
      class NoCommand < Base
        MSG = 'Use `ApplicationJob` instead of `PowerTypes::Command`.'

        # @!method uses_powertypes_command?(node)
        def_node_matcher :uses_powertypes_command?, <<~PATTERN
          (class _ (send (const (const _ :PowerTypes) :Command) :new ...) _)
        PATTERN

        def on_class(node)
          return unless uses_powertypes_command?(node)

          add_offense(node)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-platanus-0.2.0 lib/rubocop/cop/platanus/no_command.rb
rubocop-platanus-0.1.0 lib/rubocop/cop/platanus/no_command.rb