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

Enforce assert_operator instead of assert with operator expression #255

Closed
TSMMark opened this issue Aug 28, 2023 · 1 comment · Fixed by #260
Closed

Enforce assert_operator instead of assert with operator expression #255

TSMMark opened this issue Aug 28, 2023 · 1 comment · Fixed by #260
Labels
feature request Request for new functionality

Comments

@TSMMark
Copy link
Contributor

TSMMark commented Aug 28, 2023

Is your feature request related to a problem? Please describe.

When reviewing PRs of teammates using for example assert(a < b)

Describe the solution you'd like

I'd like rubocop to recommend for example assert_operator(a, :<, b)

Additional context

I was surprised I couldn't find this cop, as it seems pretty simple to implement (possibly naively) and it's in the minitest style guide https://github.com/rubocop/minitest-style-guide#assert-operator

Would you accept a PR for a new cop Minitest/AssertOperator ?

Thanks

@andyw8
Copy link
Contributor

andyw8 commented Aug 28, 2023

👍 Sounds like a useful cop to add.

@koic koic added the feature request Request for new functionality label Sep 5, 2023
koic added a commit to koic/rubocop-minitest that referenced this issue Sep 21, 2023
…uteOperator` cops

Fixes rubocop#255.

This PR adds new `Minitest/AssertOperator` and `Minitest/RefuteOperator` cops.

## `Minitest/AssertOperator` cop

This cop enforces the use of `assert_operator(expected, :<, actual)` over `assert(expected < actual)`.

```ruby
# bad
assert(expected < actual)

# good
assert_operator(expected, :<, actual)
```

## `Minitest/RefuteOperator` cop

This cop enforces the use of `refute_operator(expected, :<, actual)` over `refute(expected < actual)`.

```ruby
# bad
refute(expected < actual)

# good
refute_operator(expected, :<, actual)
```
@koic koic closed this as completed in #260 Sep 22, 2023
koic added a commit that referenced this issue Sep 22, 2023
…d_refute_operator_cops

[Fix #255] Add new `Minitest/AssertOperator` and `Minitest/RefuteOperator` cops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants