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

False positive of `IfUnlessModifier` for array elements #8226

Closed
AlexWayfer opened this issue Jun 30, 2020 · 0 comments
Closed

False positive of `IfUnlessModifier` for array elements #8226

AlexWayfer opened this issue Jun 30, 2020 · 0 comments
Labels
bug

Comments

@AlexWayfer
Copy link
Contributor

@AlexWayfer AlexWayfer commented Jun 30, 2020

Hello. I've found a false positive of IfUnlessModifier for array elements with conditions.

You can write an array element with multi-line condition, and with one-line condition, but only with parentheses, without them there is a syntax error:

unexpected `if' modifier, expecting ']'

But IfUnlessModifier doesn't count this specific condition (for conditions), and offenses a multi-line condition, which can be placed into one line with syntax error, but with parentheses it already exceeds LineLength.


Expected behavior

No offenses for multi-line condition in array, which can't be placed into one line without LineLength offense.

Actual behavior

There is a "fork" with offenses in any case.

Steps to reproduce the problem

Layout/LineLength:
  Max: 12
Style/FrozenStringLiteralComment:
  Enabled: false
[
  if foo
    bar
  end
]
rubocop/test.rb:2:3: C: Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
  if foo
  ^^
[
  (bar if foo)
]
rubocop/test.rb:2:8: C: Style/IfUnlessModifier: Modifier form of if makes the line too long.
  (bar if foo)
       ^^
rubocop/test.rb:2:13: C: Layout/LineLength: Line is too long. [14/12]
  (bar if foo)
            ^^

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

0.86.0 (using Parser 2.7.1.4, rubocop-ast 0.1.0, running on ruby 2.7.1 x86_64-linux)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.