Sha256: 9c42e56126817b049d3a948913b8538982e1ac060f76c63a9581ad2c048ae5c6

Contents?: true

Size: 852 Bytes

Versions: 30

Compression:

Stored size: 852 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Discourse
      # Avoid using chdir - it is not thread safe.
      #
      # Instead, you may be able to use:
      # Discourse::Utils.execute_command(chdir: "test") do |runner|
      #   runner.exec("pwd")
      # end
      #
      # @example
      #   # bad
      #   Dir.chdir("test")
      class NoChdir < Cop
        MSG = "Chdir is not thread safe."

        def_node_matcher :using_dir_chdir?, <<-MATCHER
          (send (const nil? :Dir) :chdir ...)
        MATCHER

        def_node_matcher :using_fileutils_cd?, <<-MATCHER
          (send (const nil? :FileUtils) :cd ...)
        MATCHER

        def on_send(node)
          return if !(using_dir_chdir?(node) || using_fileutils_cd?(node))
          add_offense(node, message: MSG)
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rubocop-discourse-3.8.1 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.7.1 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.7.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.6.1 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.6.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.5.1 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.5.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.4.1 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.4.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.3.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.2.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.1.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.0.3 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.0.2 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.0.1 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-2.6.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-2.5.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-2.4.2 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-2.4.1 lib/rubocop/cop/discourse/no_chdir.rb