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

DoubleNegation default style (allowed_in_returns) should allow methods with rescue blocks #10010

Closed
Drowze opened this issue Aug 13, 2021 · 1 comment · Fixed by #10015
Closed
Labels

Comments

@Drowze
Copy link
Contributor

Drowze commented Aug 13, 2021

obs.: This is probably more a feature request than a bug - please let me know your thoughts.

Expected behavior

Since RuboCop's Style/DoubleNegation cop default configuration (allowed_in_returns) allows this:

def db_ok?
  !!db.query('1 + 1')
end

I would expect it to also allow this use of double negation:

def safe_db_ok?
  !!db.query('1 + 1')
rescue DatabaseError
  false
end

That probably means to also allow this other usage:

def safe_db_ok?
  !!db.query('1 + 1')
rescue DatabaseError
  !!ENV['DATABASE_URL']
end

Actual behavior

RuboCop's Style/DoubleNegation flags the double negation usage on any method that contains a rescue block.

RuboCop version

1.19.0 (using Parser 3.0.2.0, rubocop-ast 1.10.0, running on ruby 2.7.3 x86_64-darwin20)
@koic
Copy link
Member

koic commented Aug 13, 2021

I think this is a false positive because it should be accepted as a similar semantics.

@koic koic added the bug label Aug 13, 2021
koic added a commit to koic/rubocop that referenced this issue Aug 15, 2021
Fixes rubocop#10010.

This PR fixes a false positive for `Style/DoubleNegation`
when `!!` is used at return location and before `rescue` keyword.
bbatsov pushed a commit that referenced this issue Aug 17, 2021
Fixes #10010.

This PR fixes a false positive for `Style/DoubleNegation`
when `!!` is used at return location and before `rescue` keyword.
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