KEMBAR78
Style/DoubleNegation `allowed_in_returns` doesn't handle line-breaks · Issue #14553 · rubocop/rubocop · GitHub
Skip to content

Style/DoubleNegation allowed_in_returns doesn't handle line-breaks #14553

@inkstak

Description

@inkstak

Expected behavior

Style/DoubleNegation provides EnforcedStyle: allowed_in_returns to allow double negation in contexts that use boolean as a return value.
It should allow all the following methods:

def foo?
  !!@foo 
end

def mixed_condition?
  !!@foo && another_condition?
end

def long_condition?
  !!@foo && one_long_long_condition? &&
    another_long_long_condition?
end

def long_condition?
  !!@foo &&
    one_long_long_condition? &&
    another_long_long_condition?
end

Actual behavior

It works with single-line conditions but rejects multi-lines conditions :

C: [Correctable] Style/DoubleNegation: Avoid the use of double negation (!!). (https://rubystyle.guide#no-bang-bang)
      !!@foo && one_long_long_condition? &&
      ^

C: [Correctable] Style/DoubleNegation: Avoid the use of double negation (!!). (https://rubystyle.guide#no-bang-bang)
      !!@foo &&
      ^

Steps to reproduce the problem

See expected behavior

RuboCop version

$ bundle exec rubocop -V
1.80.2 (using Parser 3.3.9.0, Prism 1.4.0, rubocop-ast 1.46.0, analyzing as Ruby 3.4, running on ruby 3.4.4) +server [arm64-darwin24]
  - rubocop-performance 1.26.0
  - rubocop-rails 2.33.3
  - rubocop-rspec 3.7.0
  - rubocop-factory_bot 2.27.1
  - rubocop-capybara 2.22.1
  - rubocop-rspec_rails 2.31.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions