Rubocop: Offense Rails/FilePath for Rails.root misdetected

Created on 26 Jan 2017  路  3Comments  路  Source: rubocop-hq/rubocop

Rubocop version: 0.47.1

For example the following command is listed as offense, but there is no path to join

system "wheneverize '#{Rails.root}'" unless File.exist? @filepath

if I use rails_path = Rails.root there is no offense detected, so there must be a problem with the curly brackets I guess.

Most helpful comment

@dabroz Rubocop wants you to rewrite that example as:

Dir.glob(Rails.root.join('config', '**', "*.env.#{Rails.env}"), File::FNM_DOTMATCH))

I think the offense message needs changed somehow. I was confused by it recently, too.

All 3 comments

This issue looks like a duplicate of https://github.com/bbatsov/rubocop/issues/3947.

I have another example of misdetection:

Dir.glob(Rails.root.join("config/**/*.env.#{Rails.env}"), File::FNM_DOTMATCH))

@dabroz Rubocop wants you to rewrite that example as:

Dir.glob(Rails.root.join('config', '**', "*.env.#{Rails.env}"), File::FNM_DOTMATCH))

I think the offense message needs changed somehow. I was confused by it recently, too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikegee picture mikegee  路  3Comments

joromir picture joromir  路  3Comments

Ana06 picture Ana06  路  3Comments

millisami picture millisami  路  3Comments

ecbrodie picture ecbrodie  路  3Comments