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

Autocorrection broke code #3263

Closed
thehappycoder opened this issue Jun 29, 2016 · 2 comments
Closed

Autocorrection broke code #3263

thehappycoder opened this issue Jun 29, 2016 · 2 comments
Labels

Comments

@thehappycoder
Copy link

rubocop 0.41.1 (ruby 1.9.3)

turned this code

def unit_kmg(s)
    s = s.to_f
    unless(s.nil? || s.blank? || s == 0)
      if(s / 1024 / 1024 >=  1)
        speed = [s/1024/1024, "G"]
      elsif(s / 1024 >= 1)
        speed = [s/1024, "M"]
      else
        speed = [s, "k"]
      end
    else
      speed = [s, ""]
    end
    speed[0] = floating(speed[0]).to_s
    return speed
  end

to:

def unit_kmg(s)
    s = s.to_f
    if(s / 1024 / 1024 >=  1)
        speed = [s/1024/1024, "G"]
      elsif(s / 1024 >= 1)
        speed = [s/1024, "M"]
      else
        speed = [s, "k"]
      endunless (s.nil? || s.blank? || s == 0)
      elsif(s / 1024 >= 1)
        speed = [s/1024, "M"]
      else
        speed = [s, "k"]
    else
      [s, ""]
                                                                                                                                                                       end
    speed[0] = floating(speed[0]).to_s
    speed
  end

And it doesn't work due to syntax error:

expected keyword_elsif, expecting keyword_end (SyntaxError)
      elsif (s / 1024 >= 1)

Not my code :-)

@tejasbubane
Copy link
Contributor

I can confirm that this is an issue. There are multiple cops into play here: Style/ConditionalAssignment,
Style/SpaceAroundKeyword, Style/UnlessElse, Style/SpaceAroundOperators and Style/ExtraSpacing.

This is not because of Style/UnlessElse only: tejasbubane@463f7b7. Reason might be more than one cops altering the same code.

@jonas054
Copy link
Collaborator

jonas054 commented Jul 7, 2016

I've found that Style/ConditionalAssignment on its own creates that syntax error.

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

4 participants