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

[Fix #5184] Add new `MultilineElementLineBreaks` break cops #6824

Merged
merged 2 commits into from Apr 4, 2019

Conversation

Projects
None yet
4 participants
@maxh
Copy link
Contributor

commented Mar 10, 2019

Update, these cops are now available in 0.67:

https://rubocop.readthedocs.io/en/latest/cops_layout/#layoutmultilinearraylinebreaks
https://rubocop.readthedocs.io/en/latest/cops_layout/#layoutmultilinehashkeylinebreaks
https://rubocop.readthedocs.io/en/latest/cops_layout/#layoutmultilinemethodargumentlinebreaks

Original PR:

Fixes #5184 by adding support for autocorrecting cops that ensure that individual elements in multiline arrays, hashes, and method calls each start on separate lines.

# bad:
[
  a, b,
  c
]

# good:
[
  a,
  b,
  c
]

Open sourced from a Flexport-internal Ruby formatting project.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@maxh maxh force-pushed the maxh:maxh/multiline-element-line-breaks branch from 6249fbc to 8233d33 Mar 10, 2019

@TSMMark

This comment has been minimized.

Copy link

commented Mar 12, 2019

This looks great! Thank you for doing this. I managed to find some time today to run a mass auto-correct from this branch on our medium sized ruby codebase. It works very well!

I did notice one thing, which I'm not sure if it is intended or not. Ptal:

# bad:
hash[:foo] = {
  :bar => true,
  :baz => false,
}
# good:
hash[:foo] =
  {
    :bar => true,
    :baz => false,
  }

I'm fine with this ruling but wanted to point it out in case it was unintentional.

@maxh

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Thanks for trying it out! I've seen that as well. Just wrote some quick unit tests locally and confirmed this cop is working as intended:

image

I think it might be due to unexpected interaction during autocorrect with this cop:

https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/FirstHashElementLineBreak

Two questions:

  1. If you disable FirstHashElementLineBreak cop, does the issue still appear? My hypothesis: no.
  2. If you manually fix it to the "bad" case, does the code get autocorrected back to the good? My hypothesis: no, the "bad" is allowed after manual fixing.
@TSMMark

This comment has been minimized.

Copy link

commented Mar 12, 2019

@maxh I will have to try that when I get a chance, but if your local unit test passes then I'm confident you're right. Good to know thank you

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor

commented Mar 23, 2019

Thanks so much for adding this @maxh, I really like this new family of cops! :)

@bbatsov bbatsov merged commit ad5c5f9 into rubocop-hq:master Apr 4, 2019

1 check was pending

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
@bbatsov

This comment has been minimized.

Copy link
Collaborator

commented Apr 4, 2019

Nicely done! And sorry for the slow turnaround here!

@maxh maxh referenced this pull request Apr 4, 2019

Closed

Add new `Layout/AutocorrectableLineLength` cop #6883

8 of 8 tasks complete

@maxh maxh changed the title [Fix #5184] Add new multiline element line break cops [Fix #5184] Add new `MultilineElementLineBreaks` break cops Apr 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.