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

A way to sort rubocop output by files with the most violations #2481

Closed
illegalnumbers opened this issue Dec 7, 2015 · 7 comments
Closed

Comments

@illegalnumbers
Copy link

It would be very helpful to be able to have rubocop output just the filenames of particular violators and list out how many violations the file has with them sorted by the file with the most violations in it. That way you can take care of files with the largest number of problems first!

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 19, 2015

We already have https://github.com/bbatsov/rubocop#file-list-formatter and https://github.com/bbatsov/rubocop#offense-count-formatter

Guess you want some mixture of them - filename (total offences in file).

@alexdowad
Copy link
Contributor

The offense count formatter seems to be exactly what @bytenel is asking for. I suggest this can be closed.

@jonas054
Copy link
Collaborator

I think what he wants is something that could be achieved with a ruby one-liner that does some processing of JSON output. I ran the following on the RuboCop project itself:

./bin/rubocop -c config/default.yml --format json | ruby -rjson -e 'JSON.parse(ARGF.read)["files"].map { |h| [h["offenses"].size, h["path"]] }.sort.each { |count, path| printf "%4d %s\n", count, path}'

and got

[...]
   9 lib/rubocop/cop/variable_force.rb
   9 lib/rubocop/formatter/disabled_config_formatter.rb
   9 lib/rubocop/node_pattern.rb
   9 lib/rubocop/options.rb
  11 lib/rubocop/cop/style/extra_spacing.rb
  14 lib/rubocop/cop/style/indentation_width.rb
  16 lib/rubocop/cop/style/conditional_assignment.rb

(worst offenders last).

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 30, 2015

Still, this seems like a potentially useful formatter to me.

@jonas054
Copy link
Collaborator

And shouldn't be too hard to implement. Coming up with a name is the worst part.
[so]rted list of offense count per file?

@alexdowad
Copy link
Contributor

Just pushed a new formatter... still needs changelog and specs.

@jonas054
Copy link
Collaborator

jonas054 commented Jan 1, 2016

still needs changelog and specs

and README.

alexdowad added a commit to alexdowad/rubocop that referenced this issue Jan 1, 2016
As requested by Ben Nelson, this formatter lists all the offensive files in
the inspected project, with the most offensive ones first. Output looks like:

    4  test1.rb
    2  test2.rb
    1  test3.rb
    --
    7  Total
@bbatsov bbatsov closed this as completed in a83d302 Jan 3, 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

No branches or pull requests

4 participants