You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's an error being produced by Style/IfUnlessModifier cop when inspecting code such as this:
ifsome_condition?my_callable.(attr:)end
It doesn't fail if I either:
Use call explicitly: my_callable.call(attr:), or
Remove all arguments: my_callable.()
Expected behavior
Shouldn't get an error from Style/IfUnlessModifier cop in either case.
Actual behavior
Error is raised:
Here, I used the default config by just modifying TargetRubyVersion: ~ -> TargetRubyVersion: 3.3. I didn't see a way to specify target ruby version on the rubocop command line.
$ rubocop -d --config=/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/config/default.yml rubocop.rb
configuration from /Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/config/default.yml
Default configuration from /Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/paul/dev/rubocop.rb
An error occurred while Style/IfUnlessModifier cop was inspecting /Users/paul/dev/rubocop.rb:1:0.
undefined method `end_pos' for nil
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/mixin/statement_modifier.rb:68:in `method_source'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/mixin/statement_modifier.rb:61:in `if_body_source'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/mixin/statement_modifier.rb:52:in `to_modifier_form'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/mixin/statement_modifier.rb:47:in `length_in_modifier_form'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/mixin/statement_modifier.rb:41:in `modifier_fits_on_single_line?'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/mixin/statement_modifier.rb:17:in `single_line_as_modifier?'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/style/if_unless_modifier.rb:125:in `message'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/style/if_unless_modifier.rb:84:in `on_if'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:107:in `public_send'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:105:in `each'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:69:in `on_if'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-ast-1.32.3/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/team.rb:168:in `investigate_partial'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cop/team.rb:102:in `investigate'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:349:in `block in inspect_file'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:348:in `each'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:348:in `flat_map'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:348:in `inspect_file'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:291:in `block in do_inspection_loop'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:325:in `block in iterate_until_no_changes'
<internal:kernel>:187:in `loop'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:318:in `iterate_until_no_changes'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:287:in `do_inspection_loop'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:168:in `block in file_offenses'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:193:in `file_offense_cache'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:167:in `file_offenses'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:158:in `process_file'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:139:in `block in each_inspected_file'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:138:in `each'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:138:in `reduce'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:138:in `each_inspected_file'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:124:in `inspect_files'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/runner.rb:77:in `run'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli.rb:122:in `run_command'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli.rb:129:in `execute_runners'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli.rb:51:in `block in run'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli.rb:81:in `profile_if_needed'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/lib/rubocop/cli.rb:43:in `run'
/Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/exe/rubocop:19:in `<top (required)>'
/Users/paul/.gem/ruby/3.3.4/bin/rubocop:25:in `load'
/Users/paul/.gem/ruby/3.3.4/bin/rubocop:25:in `<main>'
C
Offenses:
rubocop.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
if some_condition?
^
rubocop.rb:2:3: C: [Correctable] Style/LambdaCall: Prefer the use of my_callable.call(attr:) over my_callable.(attr:).
my_callable.(attr:)
^^^^^^^^^^^^^^^^^^^
1 file inspected, 2 offenses detected, 2 offenses autocorrectable
1 error occurred:
An error occurred while Style/IfUnlessModifier cop was inspecting /Users/paul/dev/rubocop.rb:1:0.
configuration from /Users/paul/.gem/ruby/3.3.4/gems/rubocop-1.66.1/config/default.yml
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.66.1 (using Parser 3.3.5.0, rubocop-ast 1.32.3, running on ruby 3.3.4) [arm64-darwin23]
Finished in 0.1894209999591112 seconds
Steps to reproduce the problem
# This reproduces the errorifsome_condition?my_callable.(attr:)end# Works fineifsome_condition?my_callable.()end# Works fineifsome_condition?my_callable.call(attr:)end
Fixesrubocop#13235.
This PR fixes an error for `Style/IfUnlessModifier`
when multiline `if` that fits on one line and using implicit method call with hash value omission syntax.
Fixesrubocop#13235.
This PR fixes an error for `Style/IfUnlessModifier`
when multiline `if` that fits on one line and using implicit method call with hash value omission syntax.
There's an error being produced by Style/IfUnlessModifier cop when inspecting code such as this:
It doesn't fail if I either:
call
explicitly:my_callable.call(attr:)
, ormy_callable.()
Expected behavior
Shouldn't get an error from Style/IfUnlessModifier cop in either case.
Actual behavior
Error is raised:
Here, I used the default config by just modifying
TargetRubyVersion: ~
->TargetRubyVersion: 3.3
. I didn't see a way to specify target ruby version on therubocop
command line.Steps to reproduce the problem
RuboCop version
The text was updated successfully, but these errors were encountered: