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

Style/IfWithSemicolon auto-correction produces invalid code when statement includes elsif #8820

Closed
Desentso opened this issue Sep 30, 2020 · 1 comment
Labels

Comments

@Desentso
Copy link

Style/IfWithSemicolon auto-correction produces syntactically invalid code when if semicolon statement also includes elsif semicolon statement.


Expected behavior

I would expect it to produce valid code or not try to auto-correct at all.

Actual behavior

Style/IfWithSemicolon auto-correction produces code that has syntax error.

In more detail, when trying to auto-correct statements that include if; and elsif; rubocop produces syntactically invalid code.

Steps to reproduce the problem

Run it on any file that contains structure similar to:

if x; "abc"
elsif y; "123"
end

You can then see that it produces =>

x ? "abc" : elsif y; "123"

which is obviously syntactically invalid.

RuboCop version

0.92.0 (using Parser 2.7.1.5, rubocop-ast 0.7.1, running on ruby 2.5.7 x86_64-darwin18)
@adrian-rivera
Copy link
Contributor

I've made a PR #8831 this tries to fix this issue in the following way:

if x; 'abc' elsif y; '123' end

if x
  'abc'
elsif y
  '123'
end

It also accepts multiple elsif statements and else statements.

adrian-rivera added a commit to adrian-rivera/rubocop that referenced this issue Oct 28, 2020
This change fixes autocorrection for Style/IfWithSemicolon when elsif present.

In case of one of more elsif conditions present, the autocorrector will create a full if, elsif, else structure.
dvandersluis pushed a commit to dvandersluis/rubocop that referenced this issue Nov 30, 2020
This change fixes autocorrection for Style/IfWithSemicolon when elsif present.

In case of one of more elsif conditions present, the autocorrector will create a full if, elsif, else structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants