Sha256: 61d0d3b23b11db4b6028fe488cc7d89de867ecf815b711f0da0e3b64051475cc

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module RuboCop::Git
# ref. https://github.com/thoughtbot/hound/blob/d2f3933/app/models/style_checker.rb
class StyleChecker
  def initialize(modified_files,
                 rubocop_options,
                 config_file,
                 custom_config = nil)
    @modified_files = modified_files
    @rubocop_options = rubocop_options
    @config_file = config_file
    @custom_config = custom_config
  end

  def violations
    file_violations = @modified_files.map do |modified_file|
      FileViolation.new(modified_file.absolute_path, offenses(modified_file))
    end

    file_violations.select do |file_violation|
      file_violation.offenses.any?
    end
  end

  private

  def offenses(modified_file)
    violations = style_guide.violations(modified_file)
    violations_on_changed_lines(modified_file, violations)
  end

  def violations_on_changed_lines(modified_file, violations)
    violations.select do |violation|
      modified_file.relevant_line?(violation.line)
    end
  end

  def style_guide
    @style_guide ||= StyleGuide.new(@rubocop_options,
                                    @config_file,
                                    @custom_config)
  end
end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rubocop-git2-0.1.4 lib/rubocop/git/style_checker.rb
cs-rubocop-git-0.1.4 lib/rubocop/git/style_checker.rb