class RuboCop::Cop::Style::Dir
This cop checks for places where the `#__dir__` method can replace more complex constructs to retrieve a canonicalized absolute path to the current file.
@example
# bad path = File.expand_path(File.dirname(__FILE__)) # bad path = File.dirname(File.realpath(__FILE__)) # good path = __dir__
Constants
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/style/dir.rb, line 34 def autocorrect(node) lambda do |corrector| corrector.replace(node.source_range, '__dir__') end end
on_send(node)
click to toggle source
# File lib/rubocop/cop/style/dir.rb, line 28 def on_send(node) dir_replacement?(node) do add_offense(node) end end
Private Instance Methods
file_keyword?(node)
click to toggle source
# File lib/rubocop/cop/style/dir.rb, line 42 def file_keyword?(node) node.str_type? && node.source_range.is?('__FILE__') end