Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style/OperatorMethodCall error on redundant dot in method call #12205

Closed
jcsjcs opened this issue Sep 18, 2023 · 1 comment · Fixed by #12207
Closed

Style/OperatorMethodCall error on redundant dot in method call #12205

jcsjcs opened this issue Sep 18, 2023 · 1 comment · Fixed by #12207
Labels

Comments

@jcsjcs
Copy link

jcsjcs commented Sep 18, 2023

Rubocop raises an error when it encounters a redundant dot offense inside a method call:

methodname(arg./100.0) # <= error
arg./100.0             # <= correctly reported as offense

Expected behavior

C: [Correctable] Style/OperatorMethodCall: Redundant dot detected.

Actual behavior

An error occurred while Style/OperatorMethodCall cop was inspecting
`Scanning /home/james/ra/crossbeams/framework/test_rubo.rb
An error occurred while Style/OperatorMethodCall cop was inspecting /home/james/ra/crossbeams/framework/test_rubo.rb:1:11.
Expected a Parser::Source::Range, Comment or RuboCop::AST::Node, got NilClass
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/corrector.rb:111:in `to_range'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/corrector.rb:120:in `check_range_validity'
/home/james/.gem/ruby/3.1.2/gems/parser-3.2.2.3/lib/parser/source/tree_rewriter.rb:398:in `combine'
/home/james/.gem/ruby/3.1.2/gems/parser-3.2.2.3/lib/parser/source/tree_rewriter.rb:194:in `replace'
/home/james/.gem/ruby/3.1.2/gems/parser-3.2.2.3/lib/parser/source/tree_rewriter.rb:218:in `remove'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/correctors/parentheses_corrector.rb:13:in `correct'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/style/operator_method_call.rb:60:in `wrap_in_parentheses_if_chained'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/style/operator_method_call.rb:34:in `block in on_send'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/base.rb:377:in `correct'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/base.rb:181:in `add_offense'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/style/operator_method_call.rb:33:in `on_send'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:143:in `public_send'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:143:in `block (2 levels) in trigger_restricted_cops'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:142:in `block in trigger_restricted_cops'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:141:in `each'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:141:in `trigger_restricted_cops'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/home/james/.gem/ruby/3.1.2/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:159:in `block in on_send'
/home/james/.gem/ruby/3.1.2/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:156:in `each'
/home/james/.gem/ruby/3.1.2/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:156:in `each_with_index'
/home/james/.gem/ruby/3.1.2/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:156:in `on_send'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/home/james/.gem/ruby/3.1.2/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/james/.gem/ruby/3.1.2/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/james/.gem/ruby/3.1.2/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/james/.gem/ruby/3.1.2/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/team.rb:156:in `investigate_partial'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cop/team.rb:98:in `investigate'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:345:in `block in inspect_file'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:344:in `each'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:344:in `flat_map'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:344:in `inspect_file'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:314:in `loop'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:164:in `block in file_offenses'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:189:in `file_offense_cache'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:163:in `file_offenses'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:154:in `process_file'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:134:in `each'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:134:in `reduce'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:134:in `each_inspected_file'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:120:in `inspect_files'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/runner.rb:73:in `run'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli/command.rb:11:in `run'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli/environment.rb:18:in `run'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli.rb:118:in `run_command'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli.rb:125:in `execute_runners'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli.rb:51:in `block in run'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli.rb:77:in `profile_if_needed'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/lib/rubocop/cli.rb:43:in `run'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/exe/rubocop:19:in `block in <top (required)>'
/home/james/.rubies/ruby-3.1.2/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/home/james/.gem/ruby/3.1.2/gems/rubocop-1.56.2/exe/rubocop:19:in `<top (required)>'
/home/james/.gem/ruby/3.1.2/bin/rubocop:25:in `load'
/home/james/.gem/ruby/3.1.2/bin/rubocop:25:in `<top (required)>'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/cli/exec.rb:58:in `load'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/cli/exec.rb:58:in `kernel_load'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/cli/exec.rb:23:in `run'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/cli.rb:486:in `exec'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/cli.rb:31:in `dispatch'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/cli.rb:25:in `start'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/exe/bundle:48:in `block in <top (required)>'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/lib/bundler/friendly_errors.rb:120:in `with_friendly_errors'
/home/james/.gem/ruby/3.1.2/gems/bundler-2.3.24/exe/bundle:36:in `<top (required)>'
/home/james/.gem/ruby/3.1.2/bin/bundle:25:in `load'
/home/james/.gem/ruby/3.1.2/bin/bundle:25:in `<main>'
C

Offenses:

test_rubo.rb:2:4: C: [Correctable] Style/OperatorMethodCall: Redundant dot detected.
arg./100.0
   ^

1 file inspected, 1 offense detected, 1 offense autocorrectable

1 error occurred:
An error occurred while Style/OperatorMethodCall cop was inspecting /home/james/ra/crossbeams/framework/test_rubo.rb:1:11.
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.56.2 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.2) [x86_64-linux]
Finished in 0.1355880319897551 seconds

Steps to reproduce the problem

> cat test_rubo.rb 
methodname(arg./100.0)
arg./100.0

> bundle exec rubocop -d test_rubo.rb

RuboCop version

1.56.2 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.2) [x86_64-linux]
@koic koic added the bug label Sep 18, 2023
koic added a commit to koic/rubocop that referenced this issue Sep 18, 2023
Fixes rubocop#12205.

This PR fixes an error for `Style/OperatorMethodCall`
when using `foo bar./ baz`.
@koic
Copy link
Member

koic commented Sep 18, 2023

Thank you for the feedback! I opened #12207 to solve the error.

arg./100.0 # <= correctly reported as offense

And I opened #12206 because this causes Lint/Syntax by autocorrection.

koic added a commit that referenced this issue Sep 19, 2023
…ethod_call

[Fix #12205] Fix an error for `Style/OperatorMethodCall`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants