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 a CopCount formatter #439

Merged
merged 1 commit into from
Aug 17, 2013
Merged

Add a CopCount formatter #439

merged 1 commit into from
Aug 17, 2013

Conversation

petehamilton
Copy link
Contributor

Allows you to see a list of cops with offences, ordered by offence count.

e.g.

❯ be rubocop -f p -f copcount app/controllers
Inspecting 98 files
CCCCCCCCCCCCCCCWCCCCC..CCCCCC.CCCCCCCC.CCWWCCCCCC.CCCCW..CCCCCWCCCCCCCCCWCCCC.CWCCCC.CCCCCCCCWCCCC

Offences: ...SNIP...

98 files inspected, 134 offences detected

(87)  Documentation
(12)  DotPosition
(8)   AvoidGlobalVars
(7)   EmptyLines
(6)   AssignmentInCondition
(4)   Blocks
(4)   CommentAnnotation
(3)   BlockAlignment
(1)   IndentationWidth
(1)   AvoidPerlBackrefs
(1)   ColonMethodCall

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 16, 2013

Nice idea, but I have some feedback:

  • The CopCount name is a bit misleading; can't think of a better name right now, though.
  • You should mention the new formatter in the README
  • You should fix the style problems within the code of the new formatter

@yujinakayama @jonas054 @edzhelyov Would you like to add something more?

@petehamilton
Copy link
Contributor Author

  • Agree on the name. I had the same problem, happy to go with whatever you think is best.
  • Will add note to Readme.
  • As for the style issues, that couldn't be more embarrassing 😉 Will fix immediately.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 17, 2013

Looks good. Thanks!

bbatsov added a commit that referenced this pull request Aug 17, 2013
@bbatsov bbatsov merged commit 8899dd3 into rubocop:master Aug 17, 2013
@jonas054
Copy link
Collaborator

Sorry for this late reply, but I still want to comment.

  • This formatter is a great idea.
  • Did you consider (and reject) OffenceCount, @petehamilton ? To me it's the first thing that springs to mind. I mean it is offences, not cops, we're counting. And the letter o is not taken so it would be -f o.
  • There's a bug in the formatter causing far to much space between the count and the cop name. I will add a comment to the code separately.

offence_count = total_offence_count(cop_offences)
cop_offences.each do |cop_name, count|
count_string = "(#{count.to_s})"
output.puts "#{count_string.ljust(offence_count + 4)}#{cop_name}\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

It shouldn't be ljust(offence_count + 4). If you really want to base the justification on the total count, it should be ljust(offence_count.to_s.length + 4) or something to that effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally correct. No idea how this slipped through.

@petehamilton
Copy link
Contributor Author

I really like OffenceCount, in fact, I had the same idea (Offences over Cops) today after rethink off @bbatsov's comments and was in the process of renaming anyway!

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 18, 2013

Well, the new version is still not out, so feel free to rename the formatter and address the rest of @jonas054's comments in a separate PR.

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