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 false positive for Metrics/MethodLength and Metrics/BlockLength #3622

Merged
merged 1 commit into from
Oct 15, 2016

Conversation

meganemura
Copy link
Contributor

@meganemura meganemura commented Oct 14, 2016

Metrics/MethodLength and Metrics/BlockLength cops count lines of code incorrectly.
These cops count not only inside body but also definition/receiver.

Example for Metrics/BlockLength:

# frozen_string_literal: true
[    # This line is treated as beginning of the block in counting logic
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  10,
  11,
  12,
  13,
  14,
  15,
  16,
  17,
  18,
  19,
  20,
  21,
  22,
  23,
  24
].each do |x|  # 25
  puts x       # 26
end

RuboCop says

test.rb:2:1: C: Metrics/BlockLength: Block has too many lines. [26/25]
[ ...
^

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 are passing.
  • The new code doesn't generate RuboCop offenses.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.

@savef
Copy link
Contributor

savef commented Oct 14, 2016

Good find. 👍

@meganemura meganemura force-pushed the fix-length-metrics branch 2 times, most recently from 8a8f147 to 9d3d5f1 Compare October 15, 2016 01:11
@bbatsov bbatsov merged commit 8b05e9d into rubocop:master Oct 15, 2016
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