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

Rubocop Updates #462

Merged
merged 28 commits into from
Mar 11, 2025
Merged

Rubocop Updates #462

merged 28 commits into from
Mar 11, 2025

Conversation

bobbrodie
Copy link
Member

@bobbrodie bobbrodie commented Mar 9, 2025

Overview

This PR updates Rubocop to pass, and addresses a number of temporarily disabled rules.

What's Changed

  • Remove files from CodeQL that no longer exist
  • Remove files from Rubocop that no longer exist
  • Switch rubocop-rspec to plugin instead of require
  • Fixed and enabled the following cops that were temporarily disabled
    • Layout/HashAlignment and
    • Lint/RedundantCopDisableDirective
    • Lint/UselessAssignment
    • Naming/BlockForwarding
    • RSpec/AnyInstance
    • RSpec/BeEq
    • RSpec/MessageChain
    • RSpec/NoExpectationExample
    • RSpec/PredicateMatcher
    • RSpec/RepeatedSubjectCall
    • Style/CaseEquality (there was only one and we should keep it)
    • Style/ClassAndModuleChildren
  • Enabled the following cops that were temporarily disabled (there were no offenses)
    • RSpec/ContextWording
    • RSpec/VerifiedDoubleReference
    • Style/ArgumentsForwarding
  • Bump version to 3.0.0.beta2

@bobbrodie
Copy link
Member Author

@marlinpierce since you're actively involved with the gem, I'm curious what your thoughts are on predicate method naming. We currently have this default cop disabled:

Naming/PredicateName:
  Enabled: false

If we enable these, we would need to change our method names, for example

Old Name New Name
has_one one?
has_many many?
has_errors? errors?

Since we're bumping a major version (3.0.0) and expect some backwards incompatibility, do you have an opinion on this? I don't want to make headaches for folks, but we could add the new methods and mark the old ones deprecated for later removal.

p-maguire
p-maguire previously approved these changes Mar 10, 2025
@bobbrodie bobbrodie added this to the v3.0.0 milestone Mar 11, 2025
@bobbrodie bobbrodie requested a review from p-maguire March 11, 2025 02:15
@marlinpierce
Copy link
Contributor

@bobbrodie I have never seen methods one? and many?. Further, searching on the web I see documentation of has_one and has_many but not those. Also, the method name ending in a question mark is strange here, as it is not a test, (as for if it has related objects).

I see the issue here, that rubocop is saying methods, has_one, has_many, and has_errors are reserved as they are common in ActiveRecord, and so they are misleading.

Documentation for Active Model show a comment that the attr_accessor emulates the has_many, there is an example of good practice to not use the reserved method names even when emulating them.

Since you are using these self defined methods to emulate the Active Record counterparts, I think this is appropriate and is another place where rubocop may be wrong by restricting a reasonable practice. I say, go ahead and use the method names you have. It makes the code clear and readable, which is the goal. When rubocop defeats that goal instead of supporting it, it is reasonable to make an exception to robocop.

If you do rename the methods, I suggest, has_one_resource, and has_many_resources. (I don't know what to suggest for has_errors.)

@bobbrodie bobbrodie merged commit bc9e406 into sumoheavy:master Mar 11, 2025
7 checks passed
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.

3 participants