Skip to content

Rails/SelectMap error - Expected a Parser::Source::Range, Comment or RuboCop::AST::Node, got NilClass (TypeError) #1569

@JasonBarnabe

Description

@JasonBarnabe

rubocop_test.rb:

active_product_ids = (PurchaseOrder.open.select(:product_id) + SalesOrder.open.select(:product_id)).map(&:product_id).uniq
$ rubocop -d --only Rails/SelectMap rubocop_test.rb 
For /www/seedex: configuration from /www/seedex/.rubocop.yml
Default configuration from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/config/default.yml
Plugin configuration from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-rails-2.34.2/config/default.yml
Plugin configuration from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-minitest-0.38.2/config/default.yml
Plugin configuration from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-performance-1.26.1/config/default.yml
Plugin configuration from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-capybara-2.22.1/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /www/seedex/rubocop_test.rb
An error occurred while Rails/SelectMap cop was inspecting /www/seedex/rubocop_test.rb:1:21.
/home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/corrector.rb:111:in 'RuboCop::Cop::Corrector#to_range': Expected a Parser::Source::Range, Comment or RuboCop::AST::Node, got NilClass (TypeError)
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/corrector.rb:120:in 'RuboCop::Cop::Corrector#check_range_validity'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/parser-3.3.10.0/lib/parser/source/tree_rewriter.rb:398:in 'Parser::Source::TreeRewriter#combine'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/parser-3.3.10.0/lib/parser/source/tree_rewriter.rb:194:in 'Parser::Source::TreeRewriter#replace'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/parser-3.3.10.0/lib/parser/source/tree_rewriter.rb:218:in 'Parser::Source::TreeRewriter#remove'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-rails-2.34.2/lib/rubocop/cop/rails/select_map.rb:57:in 'RuboCop::Cop::Rails::SelectMap#autocorrect'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-rails-2.34.2/lib/rubocop/cop/rails/select_map.rb:40:in 'block in RuboCop::Cop::Rails::SelectMap#on_send'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/base.rb:426:in 'RuboCop::Cop::Base#correct'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/base.rb:210:in 'RuboCop::Cop::Base#add_offense'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-rails-2.34.2/lib/rubocop/rails/migration_file_skippable.rb:29:in 'RuboCop::Rails::MigrationFileSkippable#add_offense'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-rails-2.34.2/lib/rubocop/cop/rails/select_map.rb:39:in 'RuboCop::Cop::Rails::SelectMap#on_send'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:143:in 'Kernel#public_send'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:143:in 'block (2 levels) in RuboCop::Cop::Commissioner#trigger_restricted_cops'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:171:in 'RuboCop::Cop::Commissioner#with_cop_error_handling'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:142:in 'block in RuboCop::Cop::Commissioner#trigger_restricted_cops'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:141:in 'Array#each'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:141:in 'RuboCop::Cop::Commissioner#trigger_restricted_cops'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:70:in 'RuboCop::Cop::Commissioner#on_send'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.48.0/lib/rubocop/ast/traversal.rb:170:in 'block in RuboCop::AST::Traversal#on_send'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.48.0/lib/rubocop/ast/traversal.rb:167:in 'Array#each'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.48.0/lib/rubocop/ast/traversal.rb:167:in 'Enumerable#each_with_index'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.48.0/lib/rubocop/ast/traversal.rb:167:in 'RuboCop::AST::Traversal#on_send'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_send'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.48.0/lib/rubocop/ast/traversal.rb:145:in 'RuboCop::AST::Traversal#on_lvasgn'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_lvasgn'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.48.0/lib/rubocop/ast/traversal.rb:20:in 'RuboCop::AST::Traversal#walk'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/commissioner.rb:87:in 'RuboCop::Cop::Commissioner#investigate'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/team.rb:174:in 'RuboCop::Cop::Team#investigate_partial'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cop/team.rb:108:in 'RuboCop::Cop::Team#investigate'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:350:in 'block in RuboCop::Runner#inspect_file'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:349:in 'Array#each'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:349:in 'Enumerable#flat_map'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:349:in 'RuboCop::Runner#inspect_file'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:291:in 'block in RuboCop::Runner#do_inspection_loop'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:326:in 'block in RuboCop::Runner#iterate_until_no_changes'
        from <internal:kernel>:168:in 'Kernel#loop'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:319:in 'RuboCop::Runner#iterate_until_no_changes'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:287:in 'RuboCop::Runner#do_inspection_loop'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:167:in 'block in RuboCop::Runner#file_offenses'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:192:in 'RuboCop::Runner#file_offense_cache'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:166:in 'RuboCop::Runner#file_offenses'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:154:in 'RuboCop::Runner#process_file'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:135:in 'block in RuboCop::Runner#each_inspected_file'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:134:in 'Array#each'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:134:in 'Enumerable#reduce'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:134:in 'RuboCop::Runner#each_inspected_file'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:120:in 'RuboCop::Runner#inspect_files'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/runner.rb:73:in 'RuboCop::Runner#run'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli/command/execute_runner.rb:26:in 'block in RuboCop::CLI::Command::ExecuteRunner#execute_runner'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli/command/execute_runner.rb:52:in 'RuboCop::CLI::Command::ExecuteRunner#with_redirect'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli/command/execute_runner.rb:25:in 'RuboCop::CLI::Command::ExecuteRunner#execute_runner'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli/command/execute_runner.rb:17:in 'RuboCop::CLI::Command::ExecuteRunner#run'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli/command.rb:11:in 'RuboCop::CLI::Command.run'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli/environment.rb:18:in 'RuboCop::CLI::Environment#run'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:128:in 'RuboCop::CLI#run_command'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:135:in 'RuboCop::CLI#execute_runners'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:54:in 'block in RuboCop::CLI#run'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:87:in 'RuboCop::CLI#profile_if_needed'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:45:in 'RuboCop::CLI#run'
        from /home/jason/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.81.7/exe/rubocop:15:in '<top (required)>'
        from /home/jason/.rbenv/versions/3.4.4/bin/rubocop:25:in 'Kernel#load'
        from /home/jason/.rbenv/versions/3.4.4/bin/rubocop:25:in '<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/SelectMap cop was inspecting /www/seedex/rubocop_test.rb:1:21.
configuration from /www/seedex/.rubocop.yml
Errors are usually caused by RuboCop bugs.
Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.81.7 (using Parser 3.3.10.0, Prism 1.6.0, rubocop-ast 1.48.0, analyzing as Ruby 3.4, running on ruby 3.4.4) [x86_64-linux]
Finished in 0.4640178399858996 seconds

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions