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

I got an error while Rails/RootPathnameMethods cop running. #870

Closed
epaew opened this issue Nov 21, 2022 · 0 comments · Fixed by #872
Closed

I got an error while Rails/RootPathnameMethods cop running. #870

epaew opened this issue Nov 21, 2022 · 0 comments · Fixed by #872
Labels
bug Something isn't working

Comments

@epaew
Copy link

epaew commented Nov 21, 2022

The cop Rails/RootPathnameMethods run failed with error when it targets below ruby code.

I think it happens when call Rails.root.join(some_variable_or_method) within Dir.glob.

# frozen_string_literal: true
# db/seeds.rb
Dir.glob(Rails.root.join("db", "seeds", Rails.env, "*.rb")).sort.each do |file|
  load file
end

Expected behavior

No error has occurred.

Actual behavior

RuboCop run failed with error message: (click to expand)
bundle exec rubocop --debug --require rubocop-rails --only Rails/RootPathnameMethods db/seeds.rb

For /Users/epaew/workspace/private/rubocop-rails-reissue-rootpathnamemethods: Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/epaew/workspace/private/rubocop-rails-reissue-rootpathnamemethods/db/seeds.rb
An error occurred while Rails/RootPathnameMethods cop was inspecting /Users/epaew/workspace/private/rubocop-rails-reissue-rootpathnamemethods/db/seeds.rb:3:0.
undefined method `value' for s(:send,
  s(:const, nil, :Rails), :env):RuboCop::AST::SendNode
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.17.3/lib/rubocop/cop/rails/root_pathname_methods.rb:218:in `map'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.17.3/lib/rubocop/cop/rails/root_pathname_methods.rb:218:in `join_arguments'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.17.3/lib/rubocop/cop/rails/root_pathname_methods.rb:192:in `build_path_glob_replacement'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.17.3/lib/rubocop/cop/rails/root_pathname_methods.rb:167:in `block (2 levels) in on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/base.rb:346:in `correct'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/base.rb:127:in `add_offense'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.17.3/lib/rubocop/cop/rails/root_pathname_methods.rb:165:in `block in on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.17.3/lib/rubocop/cop/rails/root_pathname_methods.rb:183:in `evidence'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.17.3/lib/rubocop/cop/rails/root_pathname_methods.rb:164:in `on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:134:in `each'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:158:in `block in on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:155:in `each'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:155:in `each_with_index'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:155:in `on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:158:in `block in on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:155:in `each'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:155:in `each_with_index'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:155:in `on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:153:in `on_block'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/team.rb:154:in `investigate_partial'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cop/team.rb:82:in `investigate'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:315:in `inspect_file'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:259:in `block in do_inspection_loop'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:293:in `block in iterate_until_no_changes'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:286:in `loop'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:138:in `block in file_offenses'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:163:in `file_offense_cache'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:137:in `file_offenses'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:128:in `process_file'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:109:in `block in each_inspected_file'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:108:in `each'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:108:in `reduce'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:108:in `each_inspected_file'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:94:in `inspect_files'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/runner.rb:47:in `run'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli.rb:72:in `run_command'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli.rb:79:in `execute_runners'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/lib/rubocop/cli.rb:48:in `run'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/exe/rubocop:19:in `block in <top (required)>'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.39.0/exe/rubocop:19:in `<top (required)>'
/Users/epaew/.rbenv/versions/2.7.5/bin/rubocop:23:in `load'
/Users/epaew/.rbenv/versions/2.7.5/bin/rubocop:23:in `<top (required)>'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/cli/exec.rb:58:in `load'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/cli/exec.rb:58:in `kernel_load'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/cli/exec.rb:23:in `run'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/cli.rb:484:in `exec'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/cli.rb:31:in `dispatch'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/cli.rb:25:in `start'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/exe/bundle:48:in `block in <top (required)>'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
/Users/epaew/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bundler-2.3.8/exe/bundle:36:in `<top (required)>'
/Users/epaew/.rbenv/versions/2.7.5/bin/bundle:23:in `load'
/Users/epaew/.rbenv/versions/2.7.5/bin/bundle:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/RootPathnameMethods cop was inspecting /Users/epaew/workspace/private/rubocop-rails-reissue-rootpathnamemethods/db/seeds.rb:3:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.39.0 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 2.7.5) [arm64-darwin21]
Finished in 0.2995489999993879 seconds

Steps to reproduce the problem

#!/bin/sh -ex

mkdir -p db
cat <<RUBY > db/seeds.rb
Dir.glob(Rails.root.join("db", "seeds", Rails.env, "*.rb"))
RUBY
bundle exec rubocop --require rubocop-rails --only Rails/RootPathnameMethods db/seeds.rb

RuboCop version

$ bundle exec rubocop --require rubocop-rails -V
1.39.0 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 2.7.5) [arm64-darwin21]
  - rubocop-rails 2.17.3
@koic koic added the bug Something isn't working label Nov 21, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Nov 21, 2022
Fixes rubocop#870.

This PR fixes an error for `Rails/RootPathnameMethods`
when using `Rails.env` argument within `Dir.glob`.
@koic koic closed this as completed in #872 Nov 24, 2022
koic added a commit that referenced this issue Nov 24, 2022
…e_methods

[Fix #870] Fix an error for `Rails/RootPathnameMethods`
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