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

AssertKindOf: also replace is_a? as well #298

Merged
merged 1 commit into from Jan 12, 2024

Conversation

amomchilov
Copy link
Contributor

@amomchilov amomchilov commented Jan 10, 2024

The Minitest/AssertKindOf would replace this code:

assert(object.kind_of?(Class))

... but not:

assert(object.is_a?(Class))

...even though they are practically the same, since #is_a? is an alias for #kind_of? (not to be confused with #instance_of?).

This PR simply extends Minitest/AssertKindOf to correct both.

I opted to modify the existing cop, rather than introducing a new cop like Minitest/AssertIsA, because it seems really unlikely to me that somebody would like to correct one, but not the other. Perhaps that's just a lack of imagination, let me know if there are any objections.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@amomchilov amomchilov changed the title AssertKindOf: also replace is_a? as well AssertKindOf: also replace is_a? as well Jan 10, 2024
@amomchilov amomchilov marked this pull request as ready for review January 10, 2024 22:00
@amomchilov
Copy link
Contributor Author

amomchilov commented Jan 10, 2024

  • TODO: make the same improvement to RefuteKindOf

config/default.yml Outdated Show resolved Hide resolved
config/default.yml Outdated Show resolved Hide resolved
@amomchilov amomchilov force-pushed the AssertKindOf-is_a branch 2 times, most recently from 2e86910 to 6a92336 Compare January 11, 2024 03:49
@koic
Copy link
Member

koic commented Jan 11, 2024

I've left two comments. Can you update these and squash this PR's commits into one?

... likewise for RefuteKindOf.
@amomchilov
Copy link
Contributor Author

@koic Fixed and squashed! Thanks for reviewing

@amomchilov amomchilov requested a review from koic January 11, 2024 22:00
@koic koic merged commit 4218ced into rubocop:master Jan 12, 2024
13 checks passed
@koic
Copy link
Member

koic commented Jan 12, 2024

Thanks!

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

2 participants