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

maxh
Copy link
Contributor

@maxh maxh 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/multiline-element-line-breaks branch from 6249fbc to 8233d33 Compare March 10, 2019 23:41
@TSMMark
Copy link
Contributor

TSMMark 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
Copy link
Contributor Author

maxh 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
Copy link
Contributor

TSMMark 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
Copy link
Contributor

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

@bbatsov bbatsov merged commit ad5c5f9 into rubocop:master Apr 4, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 4, 2019

Nicely done! And sorry for the slow turnaround here!

@maxh maxh changed the title [Fix #5184] Add new multiline element line break cops [Fix #5184] Add new MultilineElementLineBreaks break cops Apr 5, 2019
@maxh maxh deleted the maxh/multiline-element-line-breaks branch February 16, 2023 03:14
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 this pull request may close these issues.

None yet

4 participants