Skip to content

Instantly share code, notes, and snippets.

@henrich-m
Last active February 16, 2018 19:09

Revisions

  1. henrich-m revised this gist Feb 16, 2018. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions rubocop_analyzer.rb
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,7 @@
    top_10 = offenses.group_by { |f| f['cop_name'] }
    .map { |key, values| [key, values.count] }
    .sort_by { |_, count| count }
    .reverse
    .first(20)
    .last(30)

    top_10.each do |cop_name, count|
    puts "#{cop_name} - #{count}"
  2. henrich-m revised this gist Feb 16, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rubocop_analyzer.rb
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    .map { |key, values| [key, values.count] }
    .sort_by { |_, count| count }
    .reverse
    .first(10)
    .first(20)

    top_10.each do |cop_name, count|
    puts "#{cop_name} - #{count}"
  3. henrich-m created this gist Feb 16, 2018.
    17 changes: 17 additions & 0 deletions rubocop_analyzer.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    require 'json'

    Kernel.system('rubocop app lib spec -f json -P > rubocop.json')

    data = JSON.parse(File.read('rubocop.json'))

    offenses = data['files'].flat_map { |f| f['offenses'] }

    top_10 = offenses.group_by { |f| f['cop_name'] }
    .map { |key, values| [key, values.count] }
    .sort_by { |_, count| count }
    .reverse
    .first(10)

    top_10.each do |cop_name, count|
    puts "#{cop_name} - #{count}"
    end