Skip to content

Rails/StrongParametersExpect errors when permit does not have parameters #1423

@tagliala

Description

@tagliala

Dependabot tried to update rubocop-rails and I've notice this error

An error occurred while Rails/StrongParametersExpect cop was inspecting ~/myapp/controllers/test_controller.rb:5:4.

I've also checked the main branch


Expected behavior

Do not raise an error

Actual behavior

Raises an error

Steps to reproduce the problem

create a file under app/controllers/test.rb

# frozen_string_literal: true

class TargetsController < ApplicationController
  def target_params
    params.require(:target).permit
  end
end
rubocop -d app/controllers/test_controller.rb 

RuboCop version

Mention the following information in the issue report:
1.70.0 (using Parser 3.3.7.0, rubocop-ast 1.37.0, analyzing as Ruby 2.7, running on ruby 3.3.6) [x86_64-darwin24]

1.70.0 (using Parser 3.3.7.0, rubocop-ast 1.37.0, analyzing as Ruby 3.3, running on ruby 3.3.6) [x86_64-darwin24]
  - rubocop-capybara 2.21.0
  - rubocop-factory_bot 2.26.1
  - rubocop-performance 1.23.1
  - rubocop-rails 2.29.0 (from main branch)
  - rubocop-rspec 3.3.0
  - rubocop-rspec_rails 2.30.0

Log

rubocop -d app/controllers/test_controller.rb 
For ~/myapp: configuration from ~/myapp/.rubocop.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-capybara-2.21.0/config/default.yml
Default configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-capybara-2.21.0/lib/../config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-factory_bot-2.26.1/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-factory_bot-2.26.1/lib/../config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-performance-1.23.1/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-performance-1.23.1/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/bundler/gems/rubocop-rails-e5dce3a0c27e/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/bundler/gems/rubocop-rails-e5dce3a0c27e/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-rspec-3.3.0/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-rspec-3.3.0/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-rspec_rails-2.30.0/config/default.yml
configuration from ~/.rvm/gems/ruby-3.3.6/gems/rubocop-rspec_rails-2.30.0/lib/../config/default.yml
Inheriting configuration from ~/myapp/.rubocop_todo.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning ~/myapp/app/controllers/test_controller.rb
An error occurred while Rails/StrongParametersExpect cop was inspecting ~/myapp/app/controllers/test_controller.rb:5:4.
Expected a Parser::Source::Range, Comment or RuboCop::AST::Node, got NilClass
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/corrector.rb:111:in `to_range'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/corrector.rb:120:in `check_range_validity'
~/.rvm/gems/ruby-3.3.6/gems/parser-3.3.7.0/lib/parser/source/tree_rewriter.rb:398:in `combine'
~/.rvm/gems/ruby-3.3.6/gems/parser-3.3.7.0/lib/parser/source/tree_rewriter.rb:207:in `wrap'
~/.rvm/gems/ruby-3.3.6/gems/parser-3.3.7.0/lib/parser/source/tree_rewriter.rb:231:in `insert_before'
~/.rvm/gems/ruby-3.3.6/bundler/gems/rubocop-rails-e5dce3a0c27e/lib/rubocop/cop/rails/strong_parameters_expect.rb:65:in `block in on_send'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/base.rb:426:in `correct'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/base.rb:210:in `add_offense'
~/.rvm/gems/ruby-3.3.6/bundler/gems/rubocop-rails-e5dce3a0c27e/lib/rubocop/rails/migration_file_skippable.rb:29:in `add_offense'
~/.rvm/gems/ruby-3.3.6/bundler/gems/rubocop-rails-e5dce3a0c27e/lib/rubocop/cop/rails/strong_parameters_expect.rb:61:in `on_send'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:143:in `public_send'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:143:in `block (2 levels) in trigger_restricted_cops'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:142:in `block in trigger_restricted_cops'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:141:in `each'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:141:in `trigger_restricted_cops'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-ast-1.37.0/lib/rubocop/ast/traversal.rb:154:in `on_def'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:71:in `on_def'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-ast-1.37.0/lib/rubocop/ast/traversal.rb:154:in `on_class'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:71:in `on_class'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-ast-1.37.0/lib/rubocop/ast/traversal.rb:20:in `walk'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/commissioner.rb:87:in `investigate'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/team.rb:174:in `investigate_partial'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cop/team.rb:108:in `investigate'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:348:in `block in inspect_file'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:347:in `each'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:347:in `flat_map'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:347:in `inspect_file'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:290:in `block in do_inspection_loop'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:324:in `block in iterate_until_no_changes'
<internal:kernel>:187:in `loop'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:317:in `iterate_until_no_changes'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:286:in `do_inspection_loop'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:167:in `block in file_offenses'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:192:in `file_offense_cache'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:166:in `file_offenses'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:154:in `process_file'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:134:in `each'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:134:in `reduce'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:120:in `inspect_files'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/runner.rb:73:in `run'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli/command.rb:11:in `run'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli/environment.rb:18:in `run'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli.rb:122:in `run_command'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli.rb:129:in `execute_runners'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli.rb:51:in `block in run'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli.rb:81:in `profile_if_needed'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/lib/rubocop/cli.rb:43:in `run'
~/.rvm/gems/ruby-3.3.6/gems/rubocop-1.70.0/exe/rubocop:19:in `<top (required)>'
~/.rvm/gems/ruby-3.3.6/bin/rubocop:25:in `load'
~/.rvm/gems/ruby-3.3.6/bin/rubocop:25:in `<main>'
~/.rvm/gems/ruby-3.3.6/bin/ruby_executable_hooks:22:in `eval'
~/.rvm/gems/ruby-3.3.6/bin/ruby_executable_hooks:22:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/StrongParametersExpect cop was inspecting ~/myapp/app/controllers/test_controller.rb:5:4.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy