Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Control flow keywords should begin their line#785

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Drenmi wants to merge1 commit intorubocop:master
base:master
Choose a base branch
Loading
fromDrenmi:rule/control-flow-keywords

Conversation

Drenmi
Copy link
Contributor

Rationale

Breaking control flow is almost certainly the most significant thing that is going on in that line of code, and so it deserves the most prominent spot, at the beginning of the line.

Hiding away control flow in the middle of a long line makes it unnecessarily hard to parse, and Ruby gives us a slew of forms in which we can rewrite the line with the change in flow emphasized.

@DrenmiDrenmi changed the titleAdd rule stating control flow keywords should begin their lineControl flow keywords should begin their lineDec 31, 2019
@koic
Copy link
Member

The following idioms exist forreturn and raise in Ruby.

  • do_something and return
  • do_something || raise

For example, Rails framework will show users an error message using this idiom.

"redirect_to(...) and return\"

https://github.com/rails/rails/blob/v6.0.2.1/actionpack/lib/abstract_controller/rendering.rb#L10

So I think these cases need to be accepted.

@bbatsov
Copy link
Collaborator

Agreed. I guess we can word this better and provide more examples.

@Drenmi
Copy link
ContributorAuthor

Hm. I would add a note about its usage in Rails, but I would be hesitant to recommend it in the style guide. It being used in the wild I think should not be seen as an indication that it's good. 😬

I would further argueand return is a Rails idiom, not a Ruby one. (At least I've only ever seen it in Rails codebases.) It is generally also not needed. I've worked with Rails full time for the past 6 years, and never writtenand return. 🙂

Will update the PR with the rationale for this rule, as well as notes on the usage ofand return.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@Drenmi@koic@bbatsov

[8]ページ先頭

©2009-2025 Movatter.jp