Sha256: c81bfbd783b317b2d7dab97334946fb23543246218e6cabc3f0f834378657cf3

Contents?: true

Size: 718 Bytes

Versions: 1

Compression:

Stored size: 718 Bytes

Contents

# frozen_string_literal: true

require "parser"
require "rubocop/cop/legacy/corrector"

module Slimembedcop
  # Apply auto-corrections to Template file.
  class TemplateCorrector
    def initialize(path, offenses, source)
      @path = path
      @offenses = offenses
      @source = source
    end

    def run
      ::RuboCop::Cop::Legacy::Corrector.new(source_buffer, corrections).rewrite
    end

    private

    def corrections
      @offenses.select(&:corrector).map do |offense|
        lambda do |corrector|
          corrector.import!(offense.corrector, offset: offense.offset)
        end
      end
    end

    def source_buffer
      ::Parser::Source::Buffer.new(@path, source: @source)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slimembedcop-0.1.0 lib/slimembedcop/template_corrector.rb