validate_todos.rb 821 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env ruby
  2. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  3. require 'yaml'
  4. # This script validates Rubocop's todo*.yml files and complains if there
  5. # are any exclude entries that point to nonexisting files.
  6. obsolete_excludes = []
  7. puts 'Checking for obsolete rubocop excludes...'
  8. Dir.glob("#{__dir__}/todo*.yml").each do |f|
  9. YAML.load_file(f).each_value do |section|
  10. next if !section.key? 'Exclude'
  11. section['Exclude'].each do |file|
  12. next if file.include? '*'
  13. obsolete_excludes.push(file) if !File.exist? "#{__dir__}/../#{file}"
  14. end
  15. end
  16. end
  17. if obsolete_excludes.count.positive?
  18. puts 'Obsolete rubocop todo*.yml entries found for these files:'
  19. obsolete_excludes.sort.uniq.each do |file|
  20. puts " - #{file}"
  21. end
  22. exit false
  23. end
  24. puts 'done.'