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 an exception to Metrics/ParameterLists. #4848

Merged
merged 2 commits into from
Nov 25, 2017

Conversation

reitermarkus
Copy link
Contributor

@reitermarkus reitermarkus commented Oct 8, 2017

Add an exception for Metrics/ParameterLists when passing a lambda/proc to set_trace_func.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests(rake spec) are passing.
  • The new code doesn't generate RuboCop offenses that are checked by rake internal_investigation.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

@reitermarkus reitermarkus force-pushed the parameter-list-exception branch 2 times, most recently from 19d59a0 to 1aefee7 Compare October 8, 2017 20:30
add_offense(node) do
self.max = count
end
end

private

def argument_to_set_trace_func?(node)
node.parent && node.parent.parent &&
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@reitermarkus reitermarkus force-pushed the parameter-list-exception branch 3 times, most recently from ca8e561 to d10dcd7 Compare October 8, 2017 23:15
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 9, 2017

It might be better if something like this is configurable. I hate hardcoding exceptions this way.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 9, 2017

I've been thinking about this a moment more and I came up with a couple of related notes:

  • This is a good opportunity to improve the pretty bad documentation of this cop
  • Why is this flagging lambas and procs to begin with? Seems it should flag only instance and class method definitions.

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).

@Drenmi
Copy link
Collaborator

Drenmi commented Oct 9, 2017

It might be better if something like this is configurable. I hate hardcoding exceptions this way.

Makes sense. Perhaps an IgnoreLambda option?

Why is this flagging lambas and procs to begin with? Seems it should flag only instance and class method definitions.

Good point. Could be an oversight, since both def and lambda/proc have a nested args node.

@reitermarkus
Copy link
Contributor Author

reitermarkus commented Oct 9, 2017

Well, at least the name of the cop doesn't suggest that lamba/proc aren't covered by it, since they are still parameter lists. I wouldn't expect them to be excluded.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 9, 2017

Well, at least the name of the cop doesn't suggest that lamba/proc aren't covered by it, since they are still parameter lists. I wouldn't expect them to be excluded.

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.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 9, 2017

Good point. Could be an oversight, since both def and lambda/proc have a nested args node.

That's my assumption as well.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 17, 2017

@reitermarkus Ping :-)

@reitermarkus
Copy link
Contributor Author

I don't know what the plan is here now. Ignoring lambdas altogether?

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 22, 2017

Yeah, I'd just ignore lambdas completely.

@reitermarkus reitermarkus force-pushed the parameter-list-exception branch 4 times, most recently from fbf2398 to 778f000 Compare October 23, 2017 20:36
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 5, 2017

The changes look OK. Just squash, rebase and add a changelog entry.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 15, 2017

@reitermarkus Ping :-)

@reitermarkus reitermarkus force-pushed the parameter-list-exception branch 2 times, most recently from 2ce1927 to 931ae79 Compare November 22, 2017 22:32
@reitermarkus
Copy link
Contributor Author

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][])
Copy link
Collaborator

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.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 24, 2017

@reitermarkus I think you forgot to add yourself to the end of the changelog.

@reitermarkus
Copy link
Contributor Author

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. 😄

@reitermarkus reitermarkus force-pushed the parameter-list-exception branch from 931ae79 to c3f99e7 Compare November 24, 2017 18:19
@bbatsov bbatsov merged commit b8e3d12 into rubocop:master Nov 25, 2017
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 25, 2017

👍

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.

3 participants