-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 Style/MinMax
cop
#4711
Add new Style/MinMax
cop
#4711
Conversation
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.
👍
|
||
context 'with an array literal containing calls to `#min` and `#max`' do | ||
it 'registers an offense if the receivers match' do | ||
expect_offense(<<-RUBY.strip_indent) |
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.
I guess you should add one example of return foo.min, foo.max
.
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.
Ah. Yes. Perhaps parallel assignment, too. bar = foo.min, foo.max
I guess the inverse method doesn't exist right? I'm just wondering whether to flag |
Yeah. It doesn't exist. I was actually thinking about this as well. Might add it. I think I'll do |
c411f9c
to
c115b6e
Compare
RUBY | ||
end | ||
|
||
it 'does not register an offense if there are additional receivers' do |
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.
In this test there is only one receiver, foo
. Perhaps reword as “does not register an offense if there are additional elements in the array”?
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.
Good catch!
You should also take a look at those build failures. |
c115b6e
to
4e963c9
Compare
This cop checks for potential uses of `Enumberable#minmax`, e.g.: ``` [foo.min, foo.max] ``` can be changed to: ``` foo.minmax ```
4e963c9
to
f832af5
Compare
@bbatsov: Support for |
👍 |
Just got back from vacation, so I wrote this small cop to get back into flow. It can be extended to also check for potential uses of
Enumerable#minmax_by
, but I don't have the time right now. 🙂This cop checks for potential uses of
Enumberable#minmax
, e.g.:can be changed to:
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).rake spec
) are passing.rake internal_investigation
.and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).