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

Add AllowParenthesesInCamelCaseMethod option #6643

Merged
merged 1 commit into from Jan 22, 2019

Conversation

dazuma
Copy link
Contributor

@dazuma dazuma commented Jan 9, 2019

This adds the option AllowParenthesesInCamelCaseMethod to the Style/MethodCallWithArgsParentheses cop, which takes effect when EnforcedStyle: omit_parentheses. When this option is set to true, methods whose name begins with a capital letter (i.e. which look like constants/modules) may be called using parentheses even when taking arguments. When this option is set to false (the default, and identical to previous behavior), such methods may be called using parentheses when taking no arguments but must omit the parentheses when taking arguments.

This style (always using parens when calling such methods) is useful in the omit_parentheses case because even though it is not actually syntactically ambiguous when arguments are present, it still it makes it syntactically more obvious that a method is being called rather than a constant being invoked.


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.

@dazuma dazuma changed the title Honor AllowParenthesesInCamelCaseMethod option Add AllowParenthesesInCamelCaseMethod option Jan 11, 2019
@dazuma dazuma force-pushed the camel-case-parens branch 5 times, most recently from 6c239a0 to 8f8a688 Compare January 14, 2019 04:43
@dazuma dazuma force-pushed the camel-case-parens branch 2 times, most recently from 4168467 to be7bfae Compare January 16, 2019 23:58
@Drenmi
Copy link
Collaborator

Drenmi commented Jan 21, 2019

More specifically, this is PascalCase, not camelCase? 🙂

@dazuma
Copy link
Contributor Author

dazuma commented Jan 22, 2019

@Drenmi This is true. (Or I've also seen the term UpperCamelCase.)

The naming I've chosen, however, follows the existing internal naming convention (i.e. the existing methods refer to these simply as "camel_case_method_calls".) Additionally, it seems that when the term "camel-case" is used in the Ruby community, it most often refers specifically to UpperCamelCase, because that convention is actually used in the Ruby language conventions (whereas lowerCamelCase is not). A good example is ActiveSupport's "camelize" in which the default option is upper.

Copy link
Collaborator

@Drenmi Drenmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this addition. I just cut a new release, so you'll need to rebase this on the latest version of master, and fix the CHANGELOG. 🙂

Thank you for your contribution! 🙇

This option on the Style/MethodCallWithArgsParentheses cop takes effect
when EnforcedStyle:omit_parentheses. If true, CamelCase methods (with
names beginning with a capital letter) may be called with parentheses
even when taking arguments. Even though this case isn't syntactically
ambiguous, it is sometimes preferred in order to make it more obvious
that a method is being called rather than a constant referenced.
@dazuma
Copy link
Contributor Author

dazuma commented Jan 22, 2019

Thanks much! Rebased and resolved conflicts. bundle update && bundle exec rake default is clean on Ruby 2.5.3.

@Drenmi Drenmi merged commit 3e11526 into rubocop:master Jan 22, 2019
@dazuma dazuma deleted the camel-case-parens branch January 22, 2019 22:30
@pocke pocke mentioned this pull request Jan 30, 2019
8 tasks
@Drenmi Drenmi mentioned this pull request Feb 10, 2019
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

3 participants