Skip to content

Enable Rubocop predicate naming check and fix a few#10990

Merged
zachmargolis merged 8 commits intomainfrom
margolis-rubocop-predicate
Jul 29, 2024
Merged

Enable Rubocop predicate naming check and fix a few#10990
zachmargolis merged 8 commits intomainfrom
margolis-rubocop-predicate

Conversation

@zachmargolis
Copy link
Contributor

One style guide suggestion for Ruby is to avoid prefixing predicate methods, and Rubocop has an option to enforce this

I tried enabling it, and I like most of the results. The SimpleForm gem has a has_errors? method so I was a little hesitant to rename some of our own usages of it.

However, I left a few since I think they might read better as is, open to feedback on what others think. These are the ones I didn't rename that will fail the build:

  • has_errors?
  • has_hint?
  • has_remember_device_auth_event?
  • has_other_auth_methods?
  • has_minimum_required_mfa_methods?
  • has_in_person_enrollment?
  • has_establishing_in_person_enrollment_safe?
  • has_pii_from_user_in_flow_session?

changelog: Internal, Source code, Add and fix predicate naming lint
@zachmargolis zachmargolis requested a review from a team July 26, 2024 17:53
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@n1zyy n1zyy left a comment

Choose a reason for hiding this comment

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

I think I agree that several of these are made more clear with your change.

I don't think I would vote to enforce this via rubocop, but I also won't protest if others decide we should.

private

def is_pending_and_established_between(early_benchmark, late_benchmark)
def pending_and_established_between(early_benchmark, late_benchmark)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change makes a lot more sense to me and is more in keeping with the spirit. The "is" for something that's not a boolean is confusing; this makes it much clearer. 👍

:user_agent

delegate :two_factor_enabled?, to: :mfa_policy
delegate :has_gov_or_mil_email?, to: :user, prefix: :user
Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like this was complete unused

@zachmargolis
Copy link
Contributor Author

I think I agree that several of these are made more clear with your change.

I don't think I would vote to enforce this via rubocop, but I also won't protest if others decide we should.

I think it's important that if we have a rule, it be enforced in code as much as possible! Then we don't have to have unreliable humans opining.

Since has_ seemed more unclear, I updated the configs to prevent is_ and have_, but lets has_ through for now

@mitchellhenke
Copy link
Contributor

I lean towards agreement with @n1zyy. I agree that if there's a rule, it should be enforced automatically if possible, but I don't know if this is something that should be automatically enforced.

@zachmargolis
Copy link
Contributor Author

I lean towards agreement with @n1zyy. I agree that if there's a rule, it should be enforced automatically if possible, but I don't know if this is something that should be automatically enforced.

I think the PR in its current state is a good middle ground/compromise state so I think I'm ready to merge it? We can always revert if it causes a lot of headaches or eye rolls

@zachmargolis zachmargolis merged commit 59c5507 into main Jul 29, 2024
@zachmargolis zachmargolis deleted the margolis-rubocop-predicate branch July 29, 2024 15:40
mitchellhenke pushed a commit that referenced this pull request Jul 31, 2024
changelog: Internal, Source code, Add and fix predicate naming lint

* Add back prefix for has_gov_or_mil_email?

* Allow has_ prefix for predicate names


Co-authored-by: Andrew Duthie <1779930+aduth@users.noreply.github.com>

* Clean up other request method name

* Remove unused delegator on TwoFactorOptionsPresenter

- Old method name: user_has_gov_or_mil_email?

* Bring back a has_

---------

Co-authored-by: Andrew Duthie <1779930+aduth@users.noreply.github.com>
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.

4 participants