-
-
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 an exception to Metrics/ParameterLists
.
#4848
Add an exception to Metrics/ParameterLists
.
#4848
Conversation
19d59a0
to
1aefee7
Compare
add_offense(node) do | ||
self.max = count | ||
end | ||
end | ||
|
||
private | ||
|
||
def argument_to_set_trace_func?(node) | ||
node.parent && node.parent.parent && |
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.
You could probably use a node matcher, like:
def_node_matcher :argument_to_set_trace_func?, <<-PATTERN
^^(send nil :set_trace_function _)
PATTERN
Each ^
ascends one level in the AST.
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.
Thanks, I will try that.
ca8e561
to
d10dcd7
Compare
It might be better if something like this is configurable. I hate hardcoding exceptions this way. |
I've been thinking about this a moment more and I came up with a couple of related notes:
Don't know about the others, but I consider the current behavior a bug (that's why I added the note about documentation - right now it's hard to tell if this was intentional or not). |
Makes sense. Perhaps an
Good point. Could be an oversight, since both |
Well, at least the name of the cop doesn't suggest that |
But I know we created this cop with the intent to avoid people defining methods with many parameters. It was never the intention to check call sites, which is what your patch is addressing. Flagging those seems pretty pointless as often they are part of the API of some other method. |
That's my assumption as well. |
@reitermarkus Ping :-) |
I don't know what the plan is here now. Ignoring lambdas altogether? |
Yeah, I'd just ignore lambdas completely. |
fbf2398
to
778f000
Compare
The changes look OK. Just squash, rebase and add a changelog entry. |
@reitermarkus Ping :-) |
2ce1927
to
931ae79
Compare
Should be ready now. |
CHANGELOG.md
Outdated
@@ -4,6 +4,7 @@ | |||
|
|||
### New features | |||
|
|||
* [#4848](https://github.com/bbatsov/rubocop/pull/4848): Exclude lambdas and procs from `Metrics/ParameterLists`. ([@reitermarkus][]) |
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 should normally go under Changes
.
@reitermarkus I think you forgot to add yourself to the end of the changelog. |
Ah! I couldn't figure out why my link wasn't working. 😄 |
931ae79
to
c3f99e7
Compare
👍 |
Add an exception for
Metrics/ParameterLists
when passing a lambda/proc toset_trace_func
.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).