Sha256: 7fac50e9972482355976f86757924ee03360f2a882eae6867cf8ba7893d800da
Contents?: true
Size: 956 Bytes
Versions: 1
Compression:
Stored size: 956 Bytes
Contents
# frozen_string_literal: true module RuboCop module Cop module ThreadSafety # Avoid using `Dir.chdir` due to its process-wide effect. # # @example # # bad # Dir.chdir("/var/run") # # # bad # FileUtils.chdir("/var/run") class DirChdir < Base MESSAGE = 'Avoid using `%<module>s.%<method>s` due to its process-wide effect.' RESTRICT_ON_SEND = %i[chdir cd].freeze # @!method chdir?(node) def_node_matcher :chdir?, <<~MATCHER { (send (const {nil? cbase} {:Dir :FileUtils}) :chdir ...) (send (const {nil? cbase} :FileUtils) :cd ...) } MATCHER def on_send(node) chdir?(node) do add_offense( node, message: format(MESSAGE, module: node.receiver.short_name, method: node.method_name) ) end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop-thread_safety-0.6.0 | lib/rubocop/cop/thread_safety/dir_chdir.rb |