-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Change AssertEmptyLiteral
cop to check for assert_equal
#118
Conversation
a78b495
to
b6d465b
Compare
cc @tejasbubane who authored this in #38 |
This change will be complemented by #120 and will be acceptable. |
CHANGELOG.md
Outdated
@@ -2,6 +2,10 @@ | |||
|
|||
## master (unreleased) | |||
|
|||
### Bug fixes | |||
|
|||
* [#118](https://github.com/rubocop-hq/rubocop-minitest/pull/118): Fix `Minitest/AssertEmptyLiteral` by making it check for `assert_equal([], array)` instead of `assert([], array)`. ([@cstyles][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change. Can you mark **(Breaking)**
and squash your commits into one?
* [#118](https://github.com/rubocop-hq/rubocop-minitest/pull/118): Fix `Minitest/AssertEmptyLiteral` by making it check for `assert_equal([], array)` instead of `assert([], array)`. ([@cstyles][]) | |
* [#118](https://github.com/rubocop-hq/rubocop-minitest/pull/118): **(Breaking)** Fix `Minitest/AssertEmptyLiteral` by making it check for `assert_equal([], array)` instead of `assert([], array)`. ([@cstyles][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 70f02e0
While this cop is correct that we should be using `assert_empty(list)` over `assert([], list)`, it's right for the wrong reasons. That example is bad because it's using `assert` and not `assert_equal`. An empty list/hash is truthy so the assertion will always succeed. That is, `assert([], [1, 2, 3])` will succeed even though at a glance it looks like it shouldn't. I believe that what this cop is intending to check for is `assert_equal([], list)` instead so I've updated the references to `assert` to `assert_equal`. Issue rubocop#117 proposes that we try to detect when `assert` is used where the user likely wanted `assert_equal` so while this cop will no longer register a violation for `assert([], list)`, if that proposal is accepted then a future cop *will* register a violation.
b6d465b
to
70f02e0
Compare
Nicely done! |
This PR marks `Minitest/AssertEmptyLiteral` as safe auto-correction. Introduced as unsafe auto-correction in rubocop#85, but now safe auto-correction with changes in rubocop#118.
While this cop is correct that we should be using
assert_empty(list)
over
assert([], list)
, it's right for the wrong reasons. That exampleis bad because it's using
assert
and notassert_equal
. An emptylist/hash is truthy so the assertion will always succeed. That is,
assert([], [1, 2, 3])
will succeed even though at a glance it lookslike it shouldn't. I believe that what this cop is intending to check
for is
assert_equal([], list)
instead so I've updated the referencesto
assert
toassert_equal
.Issue #117 proposes that we try to detect when
assert
is used wherethe user likely wanted
assert_equal
so while this cop will no longerregister a violation for
assert([], list)
, if that proposal isaccepted then a future cop will register a violation.
edit: #120 adds such a cop.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.