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

alignment agnosticism #90

Closed
jrochkind opened this issue Mar 24, 2018 · 7 comments · Fixed by #216
Closed

alignment agnosticism #90

jrochkind opened this issue Mar 24, 2018 · 7 comments · Fixed by #216

Comments

@jrochkind
Copy link

jrochkind commented Mar 24, 2018

This is a great project, thanks. I like that it tries to respect some alignment choices agnostically, Unobtrusive by default.

Trying it out on my code, here is one choice where it doesn't:

something = if whatever
  "foo"
else
  "bar"
end

This seems reasonable to me, but rufo insists on:

something = if whatever
              "foo"
             else
               "bar"
             end

thoughts? Maybe I'm wrong that this is reasonable!

@gurgeous
Copy link
Contributor

For what it's worth, I agree with @jrochkind on this one. I have a ton of code like this (assignment with if, case, or begin). Though really I'm just happy to have auto-formatting of any kind :)

@martinos
Copy link

martinos commented May 7, 2018

What I do in case for the time being:

something =
  if whatever
    "foo"
  else
    "bar"
  end

This is reasonable for me.

@jrochkind
Copy link
Author

relevant: https://github.com/bbatsov/ruby-style-guide#indent-conditional-assignment

@jorroll
Copy link

jorroll commented Aug 31, 2018

I agree with the OP. Just opened up this duplicate issue before realizing that this issue already addresses it. You can see some specific examples where the current formatting is a real problem (at least from my perspective) here: #119

Personally, I can't use rufo with the current enforcement.

@rmosolgo
Copy link

rmosolgo commented Sep 4, 2018

I love rufo's approach, but won't continue with it because of this reason. In fact, I don't really care about indentation, but I found that it was indenting to places other than tab stops, so to add code, I couldn't simply tab over, instead, I had to occasionally add spaces to get between the tabs. What I mean is:

things = if xyz 
           abcd
         else 
           efgh
         end 

Since the number of spaces before abcd and else is odd, my editor's tab key doesn't align with them properly.

@gingermusketeer
Copy link
Member

Been looking into this issue and would like to get some feedback on what we should do here. I can see two options that seem like good approaches.

Option 1

The first is what @martinos suggests above:

a = 
  if true
    1
  else
    2
  end

a_really_long_name = 
  if true
    1
  else
    2
  end

Pros

  • Small and focused diffs for version control tools when changing a single line. See below.
< a =
---
> a_new_name =

Option 2

Keep the first line of the expression on the same line as the assignment.

a = if true
    1
  else
    2
  end

a_really_long_name = if true
    1
  else
    2
  end

Pros

  • Diff remains a single line:
< a = if true
---
> a_new_name = if true

Cons

  • Diff is not as small.

Option 3

a = if true
  1
else
  2
end

a_really_long_name = if true
  1
else
  2
end

Pros

  • Text editors have the correct indentation when pressing enter after the end keyword.

Cons

  • Indentation does not indicate clearly where the assignment statement ends.

@gingermusketeer
Copy link
Member

Decided to go with Option 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants