Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error occurred while Rails/FilePath cop was inspecting String interpolation containing Rails.root #1066

Closed
liaham opened this issue Aug 13, 2023 · 0 comments · Fixed by #1068
Labels
bug Something isn't working

Comments

@liaham
Copy link

liaham commented Aug 13, 2023

Expected behavior

I expect rubocop to inspect String interpolation containing Rails.root without any error. This is the line causing the error:

msg = "Navigate to #{Rails.root}. Position is: #{Dir.pwd}"

Please note, the line belongs to a plugin located outside of a rails app when rubocop runs over it.

I expected this behavior because it was no problem in the past. Please don't ask me for the last rubocop version causing no error like that above. I don't know.

Actual behavior

An error occurred while Rails/FilePath cop was inspecting /home/path/to/file/data.rb:128:16.
undefined method `str_type?' for nil:NilClass

          return unless rails_root_node.arguments.last.str_type?
                                                      ^^^^^^^^^^
/home/of/user/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-rails-2.20.2/lib/rubocop/cop/rails/file_path.rb:166:in `autocorrect_extension_after_rails_root_join_in_dstr'

Steps to reproduce the problem

  1. Create a directory with a ruby file containing a line like that above.
  2. Create also .rubocop.yml with the following content:
---
inherit_from: .rubocop_todo.yml

AllCops:
  NewCops: enable
  DisplayCopNames: true
  DisplayStyleGuide: true
  TargetRubyVersion: 2.7

  Exclude:
    - '**/vendor/**/*'
    - '**/tmp/**/*'
    - '**/bin/**/*'
    - '**/extra/**/*'
    - '**/lib/generators/**/templates/*'
    - '**/lib/tasks/**/*'
    - '**/files/**/*'
    - '**/test/**/*'
    - '**/db/migrate/*'
    - 'db/schema.rb'
    - '**/*_patch.rb'

require:
  - rubocop-performance
  - rubocop-rails

Style/FrozenStringLiteralComment:
  Enabled: true
  EnforcedStyle: always
  Exclude:
    - 'db/**/*.rb'
    - 'Gemfile'
    - 'Rakefile'

Metrics/AbcSize:
  Exclude:
    - 'test/**/*'

Metrics/MethodLength:
  Exclude:
    - 'test/**/*'

Layout/LineLength:
  Max: 120

Style/Documentation:
  Enabled: false

Style/Encoding:
  Enabled: false

Layout/TrailingWhitespace:
  AllowInHeredoc: true

Rails/ApplicationRecord:
  Enabled: false

Naming/VariableNumber:
  Exclude:
    - 'test/**/*'
  
Rails/ActionControllerFlashBeforeRender:
 Enabled:   false

Rails/OutputSafety:
  Exclude:
    - 'app/presenters/**/*'
    - 'app/helpers/**/*'
  1. Install:
    • ruby 3.1.4
    • rubocop 1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.4) [x86_64-linux]
    • rubocop-rails 2.20.2

RuboCop version

$ rubocop -V
1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.4) [x86_64-linux]
  - rubocop-performance 1.18.0
  - rubocop-rails 2.20.2
@koic koic transferred this issue from rubocop/rubocop Aug 13, 2023
@koic koic added the bug Something isn't working label Aug 14, 2023
koic added a commit to koic/rubocop-rails that referenced this issue Aug 14, 2023
Fixes rubocop#1066.

This PR fixes an error for `Rails/FilePath`
when string interpolated `Rails.root` is followed by a message starting with `.`.
koic added a commit that referenced this issue Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants