r7kamura
Posted on July 26, 2022
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.rb
require '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("\t")
end
Run the above script and you will see the following output:
$ ruby aggregate_rubocop_todo_offenses.rb
2022-07-26 164761
2022-07-25 164763
2022-07-24 164764
2022-07-23 165303
2022-07-22 165303
2022-07-21 165296
2022-07-20 165290
...
2021-11-27 193170
In such cases, it's convenient to paste the data into Google Spreadsheet to generate a 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! 🦄 ✨
Posted on July 26, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
March 17, 2023