Sha256: 516ce84ddef04fc501b3a99a2d116fcd1e98086643213dd4714fa95aebbd7ecc

Contents?: true

Size: 600 Bytes

Versions: 3

Compression:

Stored size: 600 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module ThreadSafety
      # Avoid starting new threads.
      #
      # Let a framework like Sidekiq handle the threads.
      #
      # @example
      #   # bad
      #   Thread.new { do_work }
      class NewThread < Cop
        MSG = 'Avoid starting new threads.'

        def_node_matcher :new_thread?, <<~MATCHER
          (send (const {nil? cbase} :Thread) :new)
        MATCHER

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

          add_offense(node, message: MSG)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-thread_safety-0.4.4 lib/rubocop/cop/thread_safety/new_thread.rb
rubocop-thread_safety-0.4.3 lib/rubocop/cop/thread_safety/new_thread.rb
rubocop-thread_safety-0.4.2 lib/rubocop/cop/thread_safety/new_thread.rb