A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rubocop/rubocop/issues/14236 below:

Style/SafeNavigation fails with TypeError · Issue #14236 · rubocop/rubocop · GitHub

❌ After upgrading to 1.76.0, the next error occurs

Inspecting 1 file
An error occurred while Style/SafeNavigation cop was inspecting /workspace/app/models/user.rb:110:4.
To see the complete backtrace run rubocop -d.
W

Offenses:

app/models/user.rb:110:22: W: Lint/Void: Literal nil used in void context.
    a.timeout.nil? ? nil : a.timeout * 60
                     ^^^

1 file inspected, 1 offense detected

1 error occurred:
An error occurred while Style/SafeNavigation cop was inspecting app/models/user.rb:110:4.

✅ It works well if I swap 60 and a.timeout

a.timeout.nil? ? nil : 60 * a.timeout 
a.timeout ? 60 * a.timeout : nil

Possible cause of problem: #14216

Expected behavior

Style/SafeNavigation should not fail on this code.

a.timeout.nil? ? nil : a.timeout * 60
Actual behavior
/usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/corrector.rb:111:in `to_range': Expected a Parser::Source::Range, Comment or RuboCop::AST::Node, got NilClass (TypeError)
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/corrector.rb:120:in `check_range_validity'
        from /usr/local/bundle/gems/parser-3.3.8.0/lib/parser/source/tree_rewriter.rb:398:in `combine'
        from /usr/local/bundle/gems/parser-3.3.8.0/lib/parser/source/tree_rewriter.rb:207:in `wrap'
        from /usr/local/bundle/gems/parser-3.3.8.0/lib/parser/source/tree_rewriter.rb:231:in `insert_before'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/style/safe_navigation.rb:153:in `block in on_if'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/style/safe_navigation.rb:193:in `block in report_offense'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/base.rb:426:in `correct'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/base.rb:210:in `add_offense'
        from /usr/local/bundle/gems/rubocop-rails-2.32.0/lib/rubocop/rails/migration_file_skippable.rb:29:in `add_offense'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/style/safe_navigation.rb:185:in `report_offense'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/style/safe_navigation.rb:152:in `on_if'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:107:in `public_send'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:105:in `each'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:69:in `on_if'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:146:in `block in on_dstr'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:146:in `each'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:146:in `on_dstr'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:163:in `on_def'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:71:in `on_def'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:146:in `block in on_dstr'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:146:in `each'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:146:in `on_dstr'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:163:in `on_class'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:71:in `on_class'
        from /usr/local/bundle/gems/rubocop-ast-1.45.0/lib/rubocop/ast/traversal.rb:20:in `walk'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/commissioner.rb:87:in `investigate'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/team.rb:174:in `investigate_partial'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cop/team.rb:108:in `investigate'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:348:in `block in inspect_file'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:347:in `each'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:347:in `flat_map'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:347:in `inspect_file'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:290:in `block in do_inspection_loop'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:324:in `block in iterate_until_no_changes'
        from <internal:kernel>:187:in `loop'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:317:in `iterate_until_no_changes'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:286:in `do_inspection_loop'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:167:in `block in file_offenses'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:192:in `file_offense_cache'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:166:in `file_offenses'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:154:in `process_file'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:134:in `each'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:134:in `reduce'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:120:in `inspect_files'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/runner.rb:73:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli/command.rb:11:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli/environment.rb:18:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli.rb:122:in `run_command'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli.rb:129:in `execute_runners'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli.rb:51:in `block in run'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli.rb:81:in `profile_if_needed'
        from /usr/local/bundle/gems/rubocop-1.76.0/lib/rubocop/cli.rb:43:in `run'
        from /usr/local/bundle/gems/rubocop-1.76.0/exe/rubocop:19:in `<top (required)>'
        from bin/rubocop:8:in `load'
        from bin/rubocop:8:in `<main>'
Steps to reproduce the problem
echo 'a.timeout.nil? ? nil : a.timeout * 60' > test.rb
➜ bundle exec rubocop --only Style/SafeNavigation test.rb

Inspecting 1 file
An error occurred while Style/SafeNavigation cop was inspecting /workspace/test.rb:1:0.
To see the complete backtrace run rubocop -d.
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Style/SafeNavigation cop was inspecting /workspace/test.rb:1:0.
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.0 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.0, analyzing as Ruby 3.3, running on ruby 3.3.5) [aarch64-linux]
RuboCop version
$ [bundle exec] rubocop -V
1.76.0 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.0, analyzing as Ruby 3.3, running on ruby 3.3.5) [aarch64-linux]
  - rubocop-performance 1.25.0
  - rubocop-rails 2.32.0

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4