Sha256: 05de76f846bb831e8b7aa1ce5aa959e81509b495ef29c77d3971874289a8612c

Contents?: true

Size: 853 Bytes

Versions: 10

Compression:

Stored size: 853 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 < Base
        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

10 entries across 10 versions & 1 rubygems

Version Path
rubocop-discourse-3.10.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.9.3 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.9.2 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.9.1 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.9.0 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.8.6 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.8.5 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.8.4 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.8.3 lib/rubocop/cop/discourse/no_chdir.rb
rubocop-discourse-3.8.2 lib/rubocop/cop/discourse/no_chdir.rb