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

Inconsistent formatting on nested hashes #285

Open
searls opened this issue Apr 14, 2021 · 6 comments
Open

Inconsistent formatting on nested hashes #285

searls opened this issue Apr 14, 2021 · 6 comments
Labels
rule change 👩‍⚖️ Suggest a style guide rule change

Comments

@searls
Copy link
Contributor

searls commented Apr 14, 2021

I just wrote this and the indentation level of the interior map seemed un-standard-like in how deep it was. I would have expected it to close (})) in alignment with the start of the key symbols.

Actual behavior:

  def test_something
    # …
    workweek = New.new(Workweek,
      started_on: START_DATE,
      ended_on: END_DATE,
      entries: ((START_DATE + 2)..END_DATE).map { |date|
                 New.new(Entry,
                   user: user,
                   project: project,
                   location: location,
                   assignment: assignment,
                   notes: "Some notes",
                   hours: 8,
                   entered_in_half_days: false)
               })
    # …
  end

Expected Behavior

Standard says:

```ruby
  def test_something
    # …
    workweek = New.new(Workweek,
      started_on: START_DATE,
      ended_on: END_DATE,
      entries: ((START_DATE + 2)..END_DATE).map { |date|
      entries: ((START_DATE + 2)..END_DATE).map { |date|
        New.new(Entry,
          user: user,
          project: project,
          location: location,
          assignment: assignment,
          notes: "Some notes",
          hours: 8,
          entered_in_half_days: false)
        })

    # …
  end

More general/typical case

Even if you eliminate the leading argument (which is on the same line as the invocation), the map block is indented unusually for Standard, which generally favors at most one level of additional indentation for everything

Actual behavior:

    workweek = New.new(
      started_on: START_DATE,
      ended_on: END_DATE,
      entries: ((START_DATE + 2)..END_DATE).map { |date|
                 New.new(Entry,
                   user: user,
                   project: project,
                   location: location,
                   assignment: assignment,
                   notes: "Some notes",
                   hours: 8,
                   entered_in_half_days: false)
               }
    )

Expected behavior:

    workweek = New.new(
      started_on: START_DATE,
      ended_on: END_DATE,
      entries: ((START_DATE + 2)..END_DATE).map { |date|
        New.new(Entry,
          user: user,
          project: project,
          location: location,
          assignment: assignment,
          notes: "Some notes",
          hours: 8,
          entered_in_half_days: false)
      }
    )

Thoughts on this? If anyone knows the Rubocop rule to fiddle with to achieve this, please enlighten me!

@searls searls added the rule change 👩‍⚖️ Suggest a style guide rule change label Apr 14, 2021
@searls
Copy link
Contributor Author

searls commented Apr 14, 2021

Huh, it looks like if I manually format it how I'd want to see it, Standard doesn't change it back, at least. This could be a case of Standard allowing both formats and ruby-vim just stubbornly indenting stuff way deeper than I'd like…

    workweek = New.new(Workweek,
      started_on: START_DATE,
      ended_on: END_DATE,
      entries: ((START_DATE + 2)..END_DATE).map { |date|
        New.new(Entry,
          user: user,
          project: project,
          location: location,
          assignment: assignment,
          notes: "Some notes",
          hours: 8,
          entered_in_half_days: false)
      })

@jasonkarns
Copy link
Collaborator

I've also seen inconsistent behavior from vim-ruby like this but haven't dug deeper.

@JoshCheek
Copy link
Contributor

Try :let g:ruby_indent_hanging_elements = 0

vim-indentation

@searls
Copy link
Contributor Author

searls commented Apr 15, 2021

@JoshCheek thanks! I'll give this a try

@JoshCheek
Copy link
Contributor

@jmkoni
Copy link
Contributor

jmkoni commented Jun 25, 2021

Huh, it looks like if I manually format it how I'd want to see it, Standard doesn't change it back, at least. This could be a case of Standard allowing both formats and ruby-vim just stubbornly indenting stuff way deeper than I'd like…

I think this is an issue of standard/rubocop allowing both of these (given https://docs.rubocop.org/rubocop/1.17/cops_layout.html#enforcedlastargumenthashstyle-always_inspect-default)

@jasonkarns jasonkarns added this to Backlog in Test Double Trouble Oct 1, 2021
@searls searls removed this from Backlog in Test Double Trouble Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule change 👩‍⚖️ Suggest a style guide rule change
Projects
None yet
Development

No branches or pull requests

4 participants