Sha256: 4f297534e66656e66e26e22a31ce5bbd5253183e3b2bc568e4a240fd01b38276

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'reek'
require 'reek/cli/options'
require 'reek/source/source_locator'

module Danger
  # Lints Ruby files via [Reek](https://rubygems.org/gems/reek).
  # Results are sent as inline comments.
  #
  # @example Running Reek
  #
  #          # Runs Reek on modified and added files in the PR
  #          reek.lint
  #
  # @see  blooper05/danger-reek
  # @tags ruby, reek, lint
  class DangerReek < Plugin
    # Runs Ruby files through Reek.
    # @return [Array<Reek::SmellWarning, nil>]
    def lint
      files_to_lint = fetch_files_to_lint
      code_smells   = run_linter(files_to_lint)
      warn_each_line(code_smells)
    end

    private

    def run_linter(files_to_lint)
      files_to_lint.flat_map do |file|
        examiner = ::Reek::Examiner.new(file)
        examiner.smells
      end
    end

    def fetch_files_to_lint
      files = git.modified_files + git.added_files
      ::Reek::Source::SourceLocator.new(files).sources
    end

    def warn_each_line(code_smells)
      code_smells.each do |smell|
        message = smell.message.capitalize
        source  = smell.source
        smell.lines.each do |line|
          warn(message, file: source, line: line)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-reek-0.1.1 lib/reek/plugin.rb