Sha256: d24f6fca5d56363766b18782ad7a530c691de35b369be3ec6da4084053a44b15

Contents?: true

Size: 1.34 KB

Versions: 157

Compression:

Stored size: 1.34 KB

Contents

require "tempfile"
require "yaml"
require_relative "rubocop"

module Standard
  module Runners
    class Genignore
      def call(config)
        # Place to temporally store the ignored files.
        temp_file = Tempfile.new("excluded.txt")
        begin
          # Run Rubocop to generate the files with errors into the temp file.
          config.rubocop_options[:formatters] = [["json", temp_file.path]]
          config.rubocop_options[:out] = temp_file.path
          exit_code = Runners::Rubocop.new.call(config)

          result = JSON.parse(temp_file.read)
          ignore = result["files"].select { |file|
            file["offenses"].size > 0
          }.map { |file|
            {
              file["path"] => file["offenses"].map { |o| o["cop_name"] }.uniq
            }
          }

          # Read the files with errors from the temp file.
          yaml_format_errors = {"ignore" => ignore}

          # Regenerate the todo file.
          File.open(".standard_todo.yml", "w") do |file|
            file.puts "# Auto generated files with errors to ignore."
            file.puts "# Remove from this list as you refactor files."
            file.write(yaml_format_errors.to_yaml)
          end
          exit_code
        ensure
          # Clean up temp file.
          temp_file.close
          temp_file.unlink
        end
      end
    end
  end
end

Version data entries

157 entries across 157 versions & 5 rubygems

Version Path
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/runners/genignore.rb