実装していたのは4日、5日前くらいで今回マージされた cop となる。
Ruby 2.0 で導入された擬似変数 __dir__ を File.expand_path や Pathname() の引数に使える局面で __FILE__ より好んで使いましょうということをチェックする。
PR の Description から引用するとこうなる。特に最後に示している引数が変数や式展開のケースは渡ってくるパスが特定できないのでチェックをしないようにしている。
Summary
This cop checks for use of the File.expand_path arguments.
# bad File.expand_path('..', __FILE__) # good File.expand_path(__dir__)
Likewise, it also checks for the Pathname.new argument.
# bad Pathname.new(__FILE__).parent.expand_path # good Pathname.new(__dir__).expand_path
Basically, replace __FILE__ with __dir_, but also warn about arguments that specify unnecessary current directory as follows.
# bad File.expand_path('.', __FILE__) # good File.expand_path(__FILE__)
This cop has autocorrect for these.
This commit autocorrected some offenses that had occurred in RuboCop itself using this Style/ExpandPathArguments cop.
Other Information
If other than str_type is used as an argument to expand_path, it will not be checked because the path cannot be determined.
For example, in the following cases.
File.expand_path(path, __FILE__) File.expand_path("#{path_to_file}.png", __FILE__)