Skip to content

Empty function - Redundant Parenthesis? #7574

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

Closed
hernang25 opened this issue Dec 18, 2019 · 1 comment · Fixed by #7575
Closed

Empty function - Redundant Parenthesis? #7574

hernang25 opened this issue Dec 18, 2019 · 1 comment · Fixed by #7575
Labels

Comments

@hernang25
Copy link

Hello! Hope it helps, maybe its already detected, I don't know!
Message from rubocop:

An error occurred while Style/GuardClause cop was inspecting...
To see the complete backtrace run rubocop -d.

configuration from /Library/Ruby/Gems/2.3.0/gems/rubocop-performance-1.5.1/config/default.yml
configuration from /Library/Ruby/Gems/2.3.0/gems/rubocop-performance-1.5.1/config/default.yml
Default configuration from /Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/config/default.yml
configuration from /Library/Ruby/Gems/2.3.0/gems/rubocop-rails-2.2.1/config/default.yml
configuration from /Library/Ruby/Gems/2.3.0/gems/rubocop-rails-2.2.1/config/default.yml
Inspecting 1 file
Scanning /.../main_packer.rb
An error occurred while Style/GuardClause cop was inspecting /.../main_packer.rb:150:4.
undefined method `if_type?' for nil:NilClass
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/style/guard_clause.rb:52:in `on_def'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:57:in `block (2 levels) in trigger_responding_cops'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:136:in `with_cop_error_handling'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:56:in `block in trigger_responding_cops'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:55:in `each'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:55:in `trigger_responding_cops'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:32:in `block (2 levels) in <class:Commissioner>'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/ast/traversal.rb:50:in `each'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/ast/traversal.rb:50:in `on_begin'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/ast/traversal.rb:92:in `on_class'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/ast/traversal.rb:13:in `walk'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/commissioner.rb:44:in `investigate'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/team.rb:124:in `investigate'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/team.rb:112:in `offenses'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:296:in `inspect_file'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:244:in `block in do_inspection_loop'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:276:in `block in iterate_until_no_changes'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:269:in `loop'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:269:in `iterate_until_no_changes'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:240:in `do_inspection_loop'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:119:in `block in file_offenses'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:143:in `file_offense_cache'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:117:in `file_offenses'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:108:in `process_file'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:86:in `each'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:86:in `reduce'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:73:in `inspect_files'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/runner.rb:39:in `run'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cli/command.rb:10:in `run'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cli/environment.rb:17:in `run'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cli.rb:65:in `run_command'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/lib/rubocop/cli.rb:41:in `run'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/exe/rubocop:13:in `block in <top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
/Library/Ruby/Gems/2.3.0/gems/rubocop-0.77.0/exe/rubocop:12:in `<top (required)>'
/usr/local/bin/rubocop:22:in `load'
/usr/local/bin/rubocop:22:in `<main>'
W

Offenses:

app/domain/packers/main_packer.rb:39:5: C: Metrics/AbcSize: Assignment Branch Condition size for kits_mediator is too high. [<25, 24, 9> 35.81/15]
    def kits_mediator(net_weight) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/domain/packers/main_packer.rb:151:7: W: Lint/EmptyExpression: Avoid empty expressions.
      ()
      ^^

1 file inspected, 2 offenses detected

1 error occurred:
An error occurred while Style/GuardClause cop was inspecting /.../main_packer.rb:150:4.

1 error occurred:
An error occurred while Style/GuardClause cop was inspecting /.../main_packer.rb:150:4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.77.0 (using Parser 2.6.3.0, running on ruby 2.3.7 universal.x86_64-darwin18)


Expected behavior

Maybe the expected behavior need to be.. unnecessary parenthesis? I really don't know, I am very new in Ruby - Rails.

Actual behavior

I didn't want to save the file but.. just cutted the content from the parenthesis and saved the file, and the error appears.

Steps to reproduce the problem

Adding () in another line will reproduce the problem in rubocop!

def function
      ()
end

RuboCop version

0.77.0

$ [bundle exec] rubocop -V
0.77.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-linux)
@koic koic added the bug label Dec 18, 2019
@buehmann
Copy link
Contributor

I am preparing a fix.

buehmann added a commit to buehmann/rubocop that referenced this issue Dec 18, 2019
koic added a commit to koic/rubocop that referenced this issue Dec 18, 2019
Fix rubocop#7574.

This PR fixes the following error for `Style/GuardClause`
when expressing nil in a method using `()`.

```console
% cat example.rb
def foo
  ()
end

% rubocop -V
0.77.0 (using Parser 2.6.5.0, running on ruby 2.6.5 x86_64-darwin17)

% rubocop --only Style/GuardClause -d

(snip)

An error occurred while Style/GuardClause cop was inspecting
/Users/koic/src/github.com/koic/rubocop-issues/7574/example.rb:1:0.
undefined method `if_type?' for nil:NilClass
```

These differ from AST as follows.

```console
% ruby -e 'p nil.class'
NilClass
% ruby-parse -e 'nil'
(nil)

% ruby -e 'p ().class'
NilClass
% ruby-parse -e '()'
(begin)
```

`()` is tricky, but I don't think it is handled by this cop.
koic added a commit that referenced this issue Dec 18, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
[Fix #7574] Fix corner case in Style/GuardClause
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.

3 participants