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 new Minitest/RedundantMessageArgument cop #272

Merged

Conversation

koic
Copy link
Member

@koic koic commented Oct 29, 2023

This PR adds new Minitest/RedundantMessageArgument cop that detects redundant message argument in assertion methods. The message argument nil is redundant because it is the default value.

# bad
assert_equal(expected, actual, nil)

# good
assert_equal(expected, actual)
assert_equal(expected, actual, 'message')

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.

@andyw8
Copy link
Contributor

andyw8 commented Oct 30, 2023

I'm curious about the context for this, where did you encounter it?

@koic
Copy link
Member Author

koic commented Oct 31, 2023

@andyw8
Copy link
Contributor

andyw8 commented Nov 1, 2023

I see. I'm wondering if it might be better for this to be in Minitest, e.g. it can raise if nil is given for that argument?

@koic
Copy link
Member Author

koic commented Nov 1, 2023

That's an interesting idea. If you're up for it, please propose it to Minitest.
Regardless, raise operates at runtime, while this cop is for static analysis, so the detection timing differs. It shouldn't detract from the value of this cop, I think.

@koic koic force-pushed the add_new_minitest_redundant_message_argument_cop branch 3 times, most recently from d518a1f to 32dd26d Compare November 28, 2023 03:18
This PR adds new `Minitest/RedundantMessageArgument` cop
that detects redundant message argument in assertion methods.
The message argument `nil` is redundant because it is the default value.

```ruby
# bad
assert_equal(expected, actual, nil)

# good
assert_equal(expected, actual)
assert_equal(expected, actual, 'message')
```
@koic koic force-pushed the add_new_minitest_redundant_message_argument_cop branch from 32dd26d to 6f03ce6 Compare November 28, 2023 03:21
@koic koic merged commit b446022 into rubocop:master Nov 29, 2023
12 checks passed
@koic koic deleted the add_new_minitest_redundant_message_argument_cop branch November 29, 2023 23:40
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.

2 participants