<commit_before>require 'formula'
require 'keg'
require 'bottles'
require 'cmd/prune'

module Homebrew extend self

  def cleanup
    if ARGV.named.empty?
      cleanup_all
    else
      ARGV.formulae.each { |f| cleanup_formula(f) }
    end
  end

  def cleanup_all
    return unless HOMEBREW_CELLAR.directory?

    HOMEBREW_CELLAR.subdirs.each do |rack|
      begin
        cleanup_formula Formula.factory(rack.basename.to_s)
      rescue FormulaUnavailableError
        # Don't complain about directories from DIY installs
      end
    end

    cleanup_cache

    unless ARGV.dry_run?
      Homebrew.prune
      rm_DS_Store
    end
  end

  def cleanup_formula f
    if f.installed?
      f.rack.subdirs.each do |keg|
        if f.version > Keg.new(keg).version
          if f.can_cleanup?
            if !Keg.new(keg).linked?
              if ARGV.dry_run?
                puts "Would remove: #{keg}"
              else
                puts "Removing: #{keg}..."
                rm_rf keg
              end
            else
              opoo "Skipping (old) #{keg} due to it being linked"
            end
          else
            opoo "Skipping (old) keg-only: #{keg}"
          end
        end
      end
    elsif f.rack.subdirs.length > 1
      # If the cellar only has one version installed, don't complain
      # that we can't tell which one to keep.
      opoo "Skipping #{f.name}: most recent version #{f.version} not installed"
    end
  end<commit_msg>cleanup: use Pathname#rmtree instead of FileUtils<commit_after>require 'formula'
require 'keg'
require 'bottles'
require 'cmd/prune'

module Homebrew extend self

  def cleanup
    if ARGV.named.empty?
      cleanup_all
    else
      ARGV.formulae.each { |f| cleanup_formula(f) }
    end
  end

  def cleanup_all
    return unless HOMEBREW_CELLAR.directory?

    HOMEBREW_CELLAR.subdirs.each do |rack|
      begin
        cleanup_formula Formula.factory(rack.basename.to_s)
      rescue FormulaUnavailableError
        # Don't complain about directories from DIY installs
      end
    end

    cleanup_cache

    unless ARGV.dry_run?
      Homebrew.prune
      rm_DS_Store
    end
  end

  def cleanup_formula f
    if f.installed?
      f.rack.subdirs.each do |keg|
        if f.version > Keg.new(keg).version
          if f.can_cleanup?
            if !Keg.new(keg).linked?
              if ARGV.dry_run?
                puts "Would remove: #{keg}"
              else
                puts "Removing: #{keg}..."
                keg.rmtree
              end
            else
              opoo "Skipping (old) #{keg} due to it being linked"
            end
          else
            opoo "Skipping (old) keg-only: #{keg}"
          end
        end
      end
    elsif f.rack.subdirs.length > 1
      # If the cellar only has one version installed, don't complain
      # that we can't tell which one to keep.
      opoo "Skipping #{f.name}: most recent version #{f.version} not installed"
    end
  end
{'fraction_non_alphanumeric': 0.07769929364278506, 'fraction_numerical': 0.0006727211570803902, 'mean_word_length': 1.816287878787879, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7533741', 'n_tokens_mistral': 988, 'n_tokens_neox': 929, 'n_words': 267}