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

Regression: IfUnlessModifier and RedundantCopDisableDirective contradict #8576

Closed
FeepingCreature opened this issue Aug 24, 2020 · 2 comments · Fixed by #8577
Closed

Regression: IfUnlessModifier and RedundantCopDisableDirective contradict #8576

FeepingCreature opened this issue Aug 24, 2020 · 2 comments · Fixed by #8577

Comments

@FeepingCreature
Copy link

FeepingCreature commented Aug 24, 2020

Steps to reproduce the problem

Consider this code:

rubocop.yml:

Layout/LineLength:
Max: 120

test.rb:

# frozen_string_literal: true

def bla
  if i > 1 # rubocop:disable Style/IfUnlessModifier
    raise '_____________________________________________________________'
  end

  raise
end

Actual behavior

When run with 0.89.1 and rubocop -c rubocop.yml test.rb, rubocop claims "Unnecessary disabling of Style/IfUnlessModifier". However, if I remove the disable line, it says "Favor modifier if usage when having a single-line body."

Expected behavior

Rubocop should stop trying to gaslight me about its warnings. :)

RuboCop version

0.89.1 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.5.1 x86_64-linux-gnu)

Further notes

The test works in 0.88.0 and fails in 0.89.0.

@FeepingCreature FeepingCreature changed the title IfUnlessModifier and RedundantCopDisableDirective contradict Regression: IfUnlessModifier and RedundantCopDisableDirective contradict Aug 24, 2020
@FeepingCreature
Copy link
Author

ping @dmytro-savochkin This may be related to your #8435 ?

@dmytro-savochkin
Copy link

ping @dmytro-savochkin This may be related to your #8435 ?

Yeah, it's related. Probably we should ignore comments that are # rubocop: disable ... when calculating the length of if-end construct while considering conversion to its modifier form. I am preparing a fix now.

dmytro-savochkin pushed a commit to dmytro-savochkin/rubocop that referenced this issue Aug 24, 2020
… comment directives when considering conversion to modifier form
bbatsov pushed a commit that referenced this issue Sep 23, 2020
…t directives when considering conversion to modifier form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants