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

Fix incorrect code length calculations for few more patterns #10543

Merged

Conversation

nobuyo
Copy link
Contributor

@nobuyo nobuyo commented Apr 16, 2022

Follow up #10469 and #10520.

This PR improve code length calculation for few more patterns like follows:

def test
  foo(
    foo,
    foo: :bar,
  )
end

def test
  foo(foo: :bar,
      baz: :quux)
end

Previously, it always subtracted 2 under certain conditions, but now it considers cases where hash begins/ends on the same line as the parentheses or there are other arguments.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@nobuyo nobuyo force-pushed the fix-incorrect-code-length-calculation-2 branch 2 times, most recently from 46653e0 to 355e759 Compare April 16, 2022 08:12
@nobuyo nobuyo force-pushed the fix-incorrect-code-length-calculation-2 branch from 355e759 to 14fa793 Compare April 16, 2022 08:48
@nobuyo nobuyo marked this pull request as ready for review April 18, 2022 12:03
Copy link
Member

@Darhazer Darhazer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test coverage. Thank you 🙇

end

def another_args?(node)
node.send_type? && node.children.count > 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node.send_type? && node.children.count > 3
node.send_type? && node.arguments.count > 1

is easier to understand

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also better use call_type? as it also covers csend (&.) nodes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I've updated another_args? and add a test case.

@nobuyo nobuyo force-pushed the fix-incorrect-code-length-calculation-2 branch from 14fa793 to 476aca5 Compare April 18, 2022 22:49
@bbatsov bbatsov merged commit d321c95 into rubocop:master Apr 20, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 20, 2022

Nicely done! Thanks!

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.

None yet

3 participants