Skip to content

An error occurred in Lint/UselessDefaultValueArgument cop #14260

@imadoki

Description

@imadoki

When defining a class method like the following, an error occurs with Lint/UselessDefaultValueArgument:

class Test
  def self.fetch_cache(key)
    Rails.cache.fetch(key, expires_in: 1.hour, race_condition_ttl: 10.seconds) do
      fetch(key)
    end
  end

  def self.fetch(key)
    "somethins_#{key}"
  end
end

Expected behavior

Rubocop inspection completes without any errors occurring.

Actual behavior

$ bundle exec rubocop --only Lint/UselessDefaultValueArgument test.rb -d
For /home/developer/src/app: configuration from /home/developer/src/app/.rubocop.yml
Default configuration from /usr/local/bundle/gems/rubocop-1.76.1/config/default.yml
Plugin configuration from /usr/local/bundle/gems/rubocop-performance-1.25.0/config/default.yml
Plugin configuration from /usr/local/bundle/gems/rubocop-rails-2.32.0/config/default.yml
Plugin configuration from /usr/local/bundle/gems/rubocop-rspec-3.6.0/config/default.yml
Inheriting configuration from /home/developer/src/app/.rubocop_documentation_method.yml
Inheriting configuration from /home/developer/src/app/.rubocop_rails_three_state_boolean_column.yml
Inheriting configuration from /home/developer/src/app/.rubocop/factory_bot.yml
Plugin configuration from /usr/local/bundle/gems/rubocop-factory_bot-2.27.1/config/default.yml
Inheriting configuration from /home/developer/src/app/.rubocop/rspec_rails.yml
Plugin configuration from /usr/local/bundle/gems/rubocop-rspec_rails-2.31.0/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /home/developer/src/app/test.rb
An error occurred while Lint/UselessDefaultValueArgument cop was inspecting /home/developer/src/app/test.rb:4:6.
/usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/mixin/allowed_receivers.rb:14:in `receiver_name': undefined method `receiver' for nil:NilClass (NoMethodError)

        if receiver.receiver && !receiver.receiver.const_type?
                   ^^^^^^^^^
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/mixin/allowed_receivers.rb:8:in `allowed_receiver?'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/lint/useless_default_value_argument.rb:70:in `on_send'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:143:in `public_send'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:143:in `block (2 levels) in trigger_restricted_cops'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:142:in `block in trigger_restricted_cops'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:141:in `each'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:141:in `trigger_restricted_cops'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:70:in `on_send'
        from /usr/local/bundle/gems/rubocop-ast-1.45.1/lib/rubocop/ast/traversal.rb:167:in `on_block'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:71:in `on_block'
        from /usr/local/bundle/gems/rubocop-ast-1.45.1/lib/rubocop/ast/traversal.rb:171:in `on_defs'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:71:in `on_defs'
        from /usr/local/bundle/gems/rubocop-ast-1.45.1/lib/rubocop/ast/traversal.rb:146:in `block in on_dstr'
        from /usr/local/bundle/gems/rubocop-ast-1.45.1/lib/rubocop/ast/traversal.rb:146:in `each'
        from /usr/local/bundle/gems/rubocop-ast-1.45.1/lib/rubocop/ast/traversal.rb:146:in `on_dstr'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
        from /usr/local/bundle/gems/rubocop-ast-1.45.1/lib/rubocop/ast/traversal.rb:163:in `on_class'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:71:in `on_class'
        from /usr/local/bundle/gems/rubocop-ast-1.45.1/lib/rubocop/ast/traversal.rb:20:in `walk'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/commissioner.rb:87:in `investigate'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/team.rb:174:in `investigate_partial'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cop/team.rb:108:in `investigate'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:348:in `block in inspect_file'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:347:in `each'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:347:in `flat_map'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:347:in `inspect_file'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:290:in `block in do_inspection_loop'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:324:in `block in iterate_until_no_changes'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:317:in `loop'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:317:in `iterate_until_no_changes'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:286:in `do_inspection_loop'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:167:in `block in file_offenses'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:192:in `file_offense_cache'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:166:in `file_offenses'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:154:in `process_file'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:134:in `each'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:134:in `reduce'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:134:in `each_inspected_file'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:120:in `inspect_files'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/runner.rb:73:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli/command.rb:11:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli/environment.rb:18:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli.rb:122:in `run_command'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli.rb:129:in `execute_runners'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli.rb:51:in `block in run'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli.rb:81:in `profile_if_needed'
        from /usr/local/bundle/gems/rubocop-1.76.1/lib/rubocop/cli.rb:43:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.1/exe/rubocop:19:in `<top (required)>'
        from /usr/local/bundle/bin/rubocop:25:in `load'
        from /usr/local/bundle/bin/rubocop:25:in `<top (required)>'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/cli/exec.rb:58:in `load'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/cli/exec.rb:58:in `kernel_load'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/cli/exec.rb:23:in `run'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/cli.rb:451:in `exec'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/cli.rb:34:in `dispatch'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/cli.rb:28:in `start'
        from /usr/local/bundle/gems/bundler-2.5.5/exe/bundle:28:in `block in <top (required)>'
        from /usr/local/bundle/gems/bundler-2.5.5/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
        from /usr/local/bundle/gems/bundler-2.5.5/exe/bundle:20:in `<top (required)>'
        from /usr/local/bundle/bin/bundle:25:in `load'
        from /usr/local/bundle/bin/bundle:25:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Lint/UselessDefaultValueArgument cop was inspecting /home/developer/src/app/test.rb:4:6.
configuration from /home/developer/src/app/.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.76.1 (using Parser 3.3.8.0, rubocop-ast 1.45.1, analyzing as Ruby 3.2, running on ruby 3.2.3) [x86_64-linux]
Finished in 1.280526076006936 seconds

Steps to reproduce the problem

  1. Create a file test.rb
class Test
  def self.fetch_cache(key)
    Rails.cache.fetch(key, expires_in: 1.hour, race_condition_ttl: 10.seconds) do
      fetch(key)
    end
  end

  def self.fetch(key)
    "somethins_#{key}"
  end
end
  1. bundle exec rubocop --only Lint/UselessDefaultValueArgument test.rb

RuboCop version

$ bundle exec rubocop -V
1.76.1 (using Parser 3.3.8.0, rubocop-ast 1.45.1, analyzing as Ruby 3.2, running on ruby 3.2.3) [x86_64-linux]
  - rubocop-performance 1.25.0
  - rubocop-rails 2.32.0
  - rubocop-rspec 3.6.0
  - rubocop-factory_bot 2.27.1
  - rubocop-rspec_rails 2.31.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    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