Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 26, 2022 12:16 am GMT

Aggregate offenses count in .rubocop_todo.yml

Are you all fighting RuboCop offenses?

Today I have written a simple Ruby script to aggregate the number of offenses in .rubocop_todo.yml, so let me share it in this article.

# aggregate_rubocop_todo_offenses.rbrequire 'date'# Aggregate up to 365 days in advance.365.times do |i|  # Get the 1st commit hash before `i` days.  # The format `%H` means "commit hash". See `git log --help` for more info.  commit_sha = `git log -1 --format='%H' --before=#{i}.day`.rstrip  # Get the .rubocop_todo.yml content at the commit.  rubocop_todo_content = `git show #{commit_sha}:.rubocop_todo.yml`.rstrip  # Get the total count of offenses in the .rubocop_todo.yml.  # The offenses count is described in the form like `# Offense count: 42` per cop.  offenses_count = rubocop_todo_content.scan(/count: (\d+)/).flatten.map(&:to_i).sum  # Output date and count in TSV format.  puts [    Date.today - i,    offenses_count  ].join("")end

Run the above script and you will see the following output:

$ ruby aggregate_rubocop_todo_offenses.rb2022-07-26      1647612022-07-25      1647632022-07-24      1647642022-07-23      1653032022-07-22      1653032022-07-21      1652962022-07-20      165290...2021-11-27      193170

In such cases, it's convenient to paste the data into Google Spreadsheet to generate a chart.

chart

It's a crazy amount, but slowly decreasing in these days. Good...

In fact, I recently created a GitHub Action workflow that automatically corrects offenses and continuously creates new pull requests, so offenses count is gradually decreasing only by pushing merge button, but I'll get to that in another time.

If you are interested, please add your reactions!


Original Link: https://dev.to/r7kamura/aggregate-offenses-count-in-rubocoptodoyml-4oda

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To