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 #7320] support Naming/MethodName for attr_reader / attr_writer / attr_accessor #7372

Merged
merged 3 commits into from Mar 21, 2020

Conversation

denys281
Copy link
Contributor

Resolves #7320


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.

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 20, 2019

I still don't see any tests covering the use of attr directly. Apart from this the PR looks good to me.


MSG = 'Use %<style>s for method names.'

def_node_matcher :attr?, <<~PATTERN
Copy link
Collaborator

Choose a reason for hiding this comment

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

Btw, there's also define_method that should be considered. In general it might be a good idea be able to provide a list of method names that define methods via configuration so custom macros could be accounted as well.

@denys281
Copy link
Contributor Author

@bbatsov added. But.... It works only when you pass symbols, but should it also support strings ?

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 22, 2019

I guess it should handle strings as well.

it 'registers an offense for camel case methods names in attr.' do
expect_offense(<<~RUBY)
attr :my_method, :myMethod
^^^^^^^^^^^^^^^^^^^^^ Use #{enforced_style} for method names.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we highlight just the second symbol here?

Copy link
Contributor Author

@denys281 denys281 Sep 23, 2019

Choose a reason for hiding this comment

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

Will check it. Do you know maybe some cops that have similar behavior?

So it should be something like that ?

attr :my_method, :myMethod, my_snake_method, :myCamelMethod
                 ^^^^^^^^^^                  ^^^^^^^^^^^^^^ Use #{enforced_style} for method names.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep. See #7385

cdmo pushed a commit to psu-libraries/myaccount that referenced this pull request Nov 15, 2019
…wasn't caught by rubocop but will in the future with this rubocop/rubocop#7372
@bbatsov bbatsov merged commit ac577f8 into rubocop:master Mar 21, 2020
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.

Naming/MethodName doesn't flag attr_reader / attr_writer / attr_accessor
2 participants